diff --git a/.gitignore b/.gitignore index 4018ada..ce9d61a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +*.sw? *~ .#* \#*# diff --git a/bin/stron b/bin/stron index 426fa3d..b6c6224 100755 --- a/bin/stron +++ b/bin/stron @@ -6,22 +6,29 @@ require 'schematron' include LibXML +if __FILE__ == $0 + XML.default_line_numbers = true -puts "Usage: stron [schematron] [instance doc]" if ARGV.size != 2 + begin -# use the line numbers -XML.default_line_numbers = true + # get args + schema_file = ARGV.shift or raise "schematron file required" + instance_file = ARGV.shift or raise "instance doc file required" -# Get sch and xml from command line -schema_doc = XML::Document.file ARGV[0] -instance_doc = XML::Document.file ARGV[1] + # parse the xml + schema_doc = XML::Document.file schema_file + instance_doc = XML::Document.file instance_file + stron = Schematron::Schema.new schema_doc + + # validate + stron.validate(instance_doc).each do |error| + puts '%s "%s" on line %d: %s' % error.values_at(:type, :name, :line, :message) + end + + rescue => e + puts "Usage: stron [schematron] [instance doc]" + puts e.message + exit 1 + end -stron = Schematron::Schema.new schema_doc -stron.validate(instance_doc).each do |error| - puts '%s "%s" on line %d: %s' % [ - error[:type], - error[:name], - error[:line], - error[:message] - ] end diff --git a/iso-schematron-xslt1/iso_abstract_expand.xsl b/iso-schematron-xslt1/iso_abstract_expand.xsl new file mode 100644 index 0000000..057c7c1 --- /dev/null +++ b/iso-schematron-xslt1/iso_abstract_expand.xsl @@ -0,0 +1,296 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Suppressed abstract pattern was here + + + + + + + Start pattern based on abstract + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iso-schematron-xslt1/iso_dsdl_include.xsl b/iso-schematron-xslt1/iso_dsdl_include.xsl new file mode 100644 index 0000000..44e5573 --- /dev/null +++ b/iso-schematron-xslt1/iso_dsdl_include.xsl @@ -0,0 +1,1160 @@ + + + + + + + + + + true + true + true + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in RELAX NG extRef + include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + Schema error: Use include to + include fragments, not a whole + schema + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Schema error: Use include to include + fragments, not a whole schema + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in DTLL include + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in CRDL include + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fatal error: Xinclude href contains fragment + identifier # + + + + + + + Fatal error: Sorry, this software only + supports simple ids in XInclude xpointers + + + + + + + Fatal Error: Impossible URL in XInclude + include + + + + + + + + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file and fallback + file: + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in XLink embedding + link + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iso-schematron-xslt1/iso_schematron_message.xsl b/iso-schematron-xslt1/iso_schematron_message.xsl new file mode 100644 index 0000000..d59b8f3 --- /dev/null +++ b/iso-schematron-xslt1/iso_schematron_message.xsl @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + ( + / + ) + + + \ No newline at end of file diff --git a/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl b/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl new file mode 100644 index 0000000..b2c40d8 --- /dev/null +++ b/iso-schematron-xslt1/iso_schematron_skeleton_for_xslt1.xsl @@ -0,0 +1,1821 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #ALL + + + +false + +true + + + + + true + false + + + + + + + true + false + + + + + + + + + @*| + + * + node() + *|comment()|processing-instruction() + + + + + + + + + + + + +default + +false + + + +1 + + + + + Schema error: Schematron elements in old and new namespaces found + + + + + + + + + + + + + + + + + Schema error: in the queryBinding attribute, use 'xslt' + + + + + 1.0 + + + + + + + + + This XSLT was automatically generated from a Schematron schema. + + + + + 1.0 + + + + + + + + + + Fail: This implementation of ISO Schematron does not work with + schemas using the "" query language. + + + + + Implementers: please note that overriding process-prolog or process-root is + the preferred method for meta-stylesheets to use where possible. + + + + + + + + + + PHASES + + PROLOG + + KEYS + + DEFAULT RULES + + SCHEMA METADATA + + SCHEMATRON PATTERNS + + + + + + + + + + + + + + + + + + + + + + + Phase Error: no phase with name has been defined. + + + + + + + MODE: SCHEMATRON-SELECT-FULL-PATH + This mode can be used to generate an ugly though full XPath for locators + + + + + + + + + + + + + + + + + + + + + + + + + MODE: SCHEMATRON-FULL-PATH + This mode can be used to generate an ugly though full XPath for locators + + + + + + / + + + + + + [] + + + + *[local-name()=' + ' and namespace-uri()=' + + '] + + + [] + + + + + + + + + + / + + @ + + @*[local-name()=' + + ' and namespace-uri()=' + + '] + + + + + + + + + MODE: SCHEMATRON-FULL-PATH-2 + + This mode can be used to generate prefixed XPath for humans + + + + + + / + + + [ + + ] + + + + + /@ + + + + + MODE: GENERATE-ID-FROM-PATH + + + + + + + + + + + + + + + + + + + + + + . + + + + + + + MODE: SCHEMATRON-FULL-PATH-3 + + + This mode can be used to generate prefixed XPath for humans + (Top-level element has index) + + + + + + / + + + [ + + ] + + + + + /@ + + + + + MODE: GENERATE-ID-2 + + + U + + + U + + + + + U. + + n + + + + + U. + + _ + + _ + + + + + Strip characters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no pattern attribute in <active> + + + + Reference Error: the pattern "" has been activated but is not declared + + + + + + + + Markup Error: no test attribute in <assert + + + ASSERT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no test attribute in <report> + + + + REPORT + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no id attribute in <diagnostic> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no rule attribute in <extends> + + + Reference Error: the abstract rule "" has been referenced but is not declared + + + + + + + + + + + + + + Markup Error: no name attribute in <key> + + + Markup Error: no path or use attribute in <key> + + + + + + + + + + + + + + + + Markup Error: no path or use attribute in <key> + + + + + + + + + + + + Schema error: The key element is not in the ISO Schematron namespace. Use the XSLT namespace. + + + + + + + + Schema error: Empty href= attribute for include directive. + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + + Schema error: Use include to include fragments, not a whole schema + + + + + + + + + + Warning: Variables should not be used with the "xpath" query language binding. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no uri attribute in <ns> + + + Markup Error: no prefix attribute in <ns> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + //( + + ( + + ) + | + + ) + [not(self::text())] + + + + + + + + + + + + + Schema implementation error: This schema has abstract patterns, yet they are supposed to be preprocessed out already + + + + + + + + + + PATTERN + + + + + + + + + + + + + + + + + + + + Markup Error: no id attribute in <phase> + + + + + + + + Markup Error: no context attribute in <rule> + + + RULE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no id attribute on abstract <rule> + + + Markup Error: (2) context attribute on abstract <rule> + + + + + + Markup Error: context attribute on abstract <rule> + + + + + + + + + + + + + + + + + + + + + + + + + + + Markup Error: no select attribute in <value-of> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Warning: + + must not contain any child elements + + + + + + + + + + + + + + + + + + + + + + + + + Reference error: A diagnostic "" has been referenced but is not declared + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Using the XSLT namespace with a prefix other than "xsl" in + Schematron rules is not supported + in this processor: + + + + + + + + + + + + + + + + + + + + Error: unrecognized element in ISO Schematron namespace: check spelling + and capitalization + + + + + + + + + + + + + Warning: unrecognized element + + + + + + + + + + + + + + + Warning: unrecognized element + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + title + + + + + + + schema-title + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl b/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl new file mode 100644 index 0000000..dae74ff --- /dev/null +++ b/iso-schematron-xslt1/iso_svrl_for_xslt1.xsl @@ -0,0 +1,588 @@ + + + + + + + + + + + + + + + + +true + + + + + + + + + + + #ALL + + +false +true +true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + xslt1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +   +   +   + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/iso-schematron-xslt1/readme.txt b/iso-schematron-xslt1/readme.txt new file mode 100644 index 0000000..3dedbbf --- /dev/null +++ b/iso-schematron-xslt1/readme.txt @@ -0,0 +1,83 @@ +ISO SCHEMATRON 2010 + +XSLT implementation by Rick Jelliffe with assistance from members of Schematron-love-in maillist. + +2010-01-25 + +Two distributions are available. One is for XSLT1 engines. +The other is for XSLT2 engines, such as SAXON 9. + + +This version of Schematron splits the process into a pipeline of several different XSLT stages. + +1) First, preprocess your Schematron schema with iso_dsdl_include.xsl. +This is a macro processor to assemble the schema from various parts. +If your schema is not in separate parts, you can skip this stage. + +2) Second, preprocess the output from stage 1 with iso_abstract_expand.xsl. +This is a macro processor to convert abstract patterns to real patterns. +If your schema does not use abstract patterns, you can skip this +stage. + +3) Third, compile the Schematron schema into an XSLT script. +This will typically use iso_svrl_for_xslt1.xsl or iso_svrl_for_xslt2.xsl +(which in turn invoke iso_schematron_skeleton_for_xslt1.xsl or iso_schematron_skeleton_for_saxon.xsl) +However, other "meta-styleseets" are also in common use; the principle of operation is the same. +If your schema uses Schematron phases, supply these as command line/invocation parameters +to this process. + +4) Fourth, run the script generated by stage 3 against the document being validated. +If you are using the SVRL script, then the output of validation will be an XML document. +If your schema uses Schematron parameters, supply these as command line/invocation parameters +to this process. + + +The XSLT2 distribution also features several next generation features, +such as validating multiple documents. See the source code for details. + +Schematron assertions can be written in any language, of course; the file +sch-messages-en.xhtml contains the diagnostics messages from the XSLT2 skeleton +in English, and this can be used as template to localize the skeleton's +error messages. Note that typically programming errors in Schematron are XPath +errors, which requires localized messages from the XSLT engine. + +ANT +--- +To give an example of how to process a document, here is a sample ANT task. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iso_impl/iso_abstract_expand.xsl b/iso_impl/iso_abstract_expand.xsl index e7c2b7f..cfc0a13 100644 --- a/iso_impl/iso_abstract_expand.xsl +++ b/iso_impl/iso_abstract_expand.xsl @@ -18,9 +18,9 @@ --> - + - + diff --git a/iso_impl/iso_dsdl_include.xsl b/iso_impl/iso_dsdl_include.xsl index 2bcf626..126857e 100644 --- a/iso_impl/iso_dsdl_include.xsl +++ b/iso_impl/iso_dsdl_include.xsl @@ -21,14 +21,14 @@ * @xml:id * id() for typed schemas (e.g. from DTD) [NOTE: XInclude does not support this] * untyped @id - - The proposed behaviour for the update to ISO Schematron has been implemented. If an - include points to an element with the same name as the parent, then that element's - contents will be included. This supports the merge style of inclusion. - - When an inclusion is made, it is preceded by a PI with target DSDL_INCLUDE_START - and the href and closed by a PI with target DSDL_INCLUDE_START and the href. This is - to allow better location of problems, though only to the file level. + + The proposed behaviour for the update to ISO Schematron has been implemented. If an + include points to an element with the same name as the parent, then that element's + contents will be included. This supports the merge style of inclusion. + + When an inclusion is made, it is preceded by a PI with target DSDL_INCLUDE_START + and the href and closed by a PI with target DSDL_INCLUDE_START and the href. This is + to allow better location of problems, though only to the file level. Limitations: * No rebasing: relative paths will be interpreted based on the initial document's @@ -39,21 +39,21 @@ * XInclude handling of xml:base and xml:lang not implemented --> - - + + - - - - - - - - - - - + + + + + + + + + + + @@ -166,17 +166,17 @@ - - - - - Unable to open referenced included file: - - - - + + + + + Unable to open referenced included file: + + + + - @@ -185,7 +185,7 @@ - + @@ -208,10 +208,10 @@ - - - - + + + + @@ -225,22 +225,22 @@ - + - - - - - - - - - - - - + + + + + + + + + + + + @@ -256,60 +256,60 @@ | //iso:*[@id= $fragment-id ]"/> - - + + - - - - - - - Unable to open referenced included file: - - - - + + + + + + + Unable to open referenced included file: + + + + + $theDocument//iso:*[@id= $fragment-id ]" /> - - - - - - Unable to locate id attribute: - - - - - - - - + + + + + + Unable to locate id attribute: + + + + + + + + Schema error: Use include to include fragments, not a whole schema - - - + + + - - - + + + @@ -325,30 +325,30 @@ - - - - - - - Unable to locate id attribute: - - - - - - + + + + + + + Unable to locate id attribute: + + + + + + Schema error: Use include to include fragments, not a whole schema @@ -357,159 +357,159 @@ + --> - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Error: Impossible URL in Schematron include + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + + + + + + + + + + Unable to open referenced included file: + + + + + + + + + + Unable to locate id attribute: + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - Error: Impossible URL in Schematron include - - - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - - - - - - - Unable to open referenced included file: - - - - - - - - - - Unable to locate id attribute: - - - - - - - - - - - - - - - - - - - - - - + @@ -522,16 +522,16 @@ - - - - - - - - - - + + + + + + + + + + @@ -549,14 +549,14 @@ - - - - Unable to open referenced included file: - - - - + + + + Unable to open referenced included file: + + + + - + @@ -611,11 +611,11 @@ - - - - - + + + + + @@ -630,14 +630,14 @@ - - - - - - - - + + + + + + + + @@ -653,14 +653,14 @@ - - - - Unable to open referenced included file: - - - - + + + + Unable to open referenced included file: + + + + - + @@ -695,9 +695,9 @@ - - - + + + @@ -711,14 +711,14 @@ - - - - - - - - + + + + + + + + @@ -735,14 +735,14 @@ - - - - Unable to open referenced included file: - - - - + + + + Unable to open referenced included file: + + + + - + @@ -778,9 +778,9 @@ - - - + + + @@ -801,15 +801,15 @@ - - - - - - - - - + + + + + + + + + @@ -841,10 +841,10 @@ - @@ -855,10 +855,10 @@ - @@ -896,9 +896,9 @@ - - - + + + @@ -913,14 +913,14 @@ - - - - - - - - + + + + + + + + @@ -936,14 +936,14 @@ - - - - Unable to open referenced included file: - - - - + + + + Unable to open referenced included file: + + + + - + @@ -977,11 +977,11 @@ - - - + + + - + diff --git a/lib/schematron.rb b/lib/schematron.rb index 5a9618f..085f582 100644 --- a/lib/schematron.rb +++ b/lib/schematron.rb @@ -7,12 +7,12 @@ module Schematron include LibXSLT # The location of the ISO schematron implemtation lives - ISO_IMPL_DIR = File.join File.dirname(__FILE__), "..", 'iso_impl' + ISO_IMPL_DIR = File.join File.dirname(__FILE__), "..", 'iso-schematron-xslt1' # The file names of the compilation stages ISO_FILES = [ 'iso_dsdl_include.xsl', 'iso_abstract_expand.xsl', - 'iso_svrl.xsl' ] + 'iso_svrl_for_xslt1.xsl' ] # Namespace prefix declarations for use in XPaths NS_PREFIXES = { @@ -27,7 +27,7 @@ def initialize(doc) xforms = ISO_FILES.map do |file| Dir.chdir(ISO_IMPL_DIR) do - doc = XML::Document.file file + doc = open(file) { |io| XML::Document.string io.read } LibXSLT::XSLT::Stylesheet.new doc end