ISO Schematron Validators built on the "Skeleton"

Here are some Schematron validators built on the so-called "reference" implementation of ISO Schematron. Note that we are currently rearranging distribution into two distribution, one for XSLT1 and one for XSLT2 engines. The following validators may not be in synch with the most recent version; as they are ported, they will be put in the distributions.

Schematron Validation Report Language (SVRL)

SVRL is a simple report language defined as part of ISO Schematron. It provides a fairly full set of information from validating a document, and can be used as the basis of subsequent transformations.

The implementation of SVRL is now part of the main Schematron distribution. There are two versions, one for the XSLT1 implementation and one for the more sophisticated XSLT2 implementation.

To invoke this in a shell script, use something like the following (this .BAT script uses SAXON XSLT engine: change it to suit your XSLT engine's calling conventions):

REM Compile the schema and run it agains the document to produce the SVRL result
java -jar saxon9he.jar -o standard-compiled.xsl standard.sch  ..\ISO_Schematron\iso_svrl.xsl 
java -jar saxon9he.jar -o test-doc.svrl test-doc.xml standard-compiled.xsl  

You can see this kind of use in the linked process diagram (SVG).

To get the full power of ISO Schematron, there are an additional two pre-processor scripts in the main distribution. If this is too complicated, consider using the Schematron for Ant task.

Schematron Text

Schematron Text is a validator that gives simple text output when errors (failed assertion or successful report) is found. The result is written to output as simple text.

To invoke this in a shell script, use something like the following (this .BAT script uses SAXON XSLT engine: change it to suit your XSLT engine's calling conventions):


REM Compile the schema and run it against the document to produce simple text output
java -jar saxon9he.jar -o schema-compiled.xsl schema.sch   ..\ISO_Schematron\iso_schematron_text.xsl
java -jar saxon9he.jar test-doc.xml    schema-compiled.xsl 

To get the full power of ISO Schematron, there are an additional two pre-processor scripts in the main distribution. If this is too complicated, consider using the Schematron for Ant task.

Schematron Terminator

Schematron Terminitor is a validator that terminates when the first error (failed assertion or successful report) is found. The result is written to output as simple text. This provides faster detection of invalidity. If used with an XSLT engine that sets its exit status code to error when <xsl:message terminate='yes' is used, then Schematron Terminator can be followed in a batch file or shell script by conditional tests. This way, the batch file can perform different actions depending on whether the file is valid or invalid.

To invoke this in a shell script, use something like the following (this .BAT script uses SAXON XSLT engine: change it to suit your XSLT engine's calling conventions):


REM Compile the schema and run it against the document to produce an error code
java -jar saxon9he.jar -o schema-compiled.xsl schema.sch   ..\ISO_Schematron\iso_schematron_terminator.xsl
java -jar saxon9he.jar test-doc.xml    schema-compiled.xsl 

To get the full power of ISO Schematron, there are an additional two pre-processor scripts in the main distribution. If this is too complicated, consider using the Schematron for Ant task.

Testing SVRL with a Schematron Schema

An SVRL document is an XML document like any other, and you can use Schematron to detect the presence or absense of patterns.

For example, we can validate a document using iso_svrl.xsl to produce an SVRL report, then test this report using iso_schematron_terminator.xsl to return an error code if some condition is met.

For example, here is a schema to test an SVRL document:

<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron"  >

  <sch:title>Tester Program for SVRL</sch:title>
  
  <sch:p>This schema tests an SVRL document that has been created by
  validating another document using some Schematron schema using the
  iso_svrl.xsl stylesheet. If there were any failed assertions or
  successful reports, the document succeeds. If you validate this 
  using the iso_schematron_terminator.xsl stylesheet and some XSLT
  engines, then you can use this to generate status messages for
  use in batch files etc. </sch:p>
  
  <sch:ns prefix="svrl" uri="http://purl.oclc.org/dsdl/svrl" />
  
  <sch:pattern  id="P1"> 
     <sch:rule context="svrl:schematron-output">
	<sch:report test="svrl:failed-assert[1] | svrl:successful-report[1]"
		>An error was found</sch:report>
     </sch:rule>
     
  </sch:pattern>
  
</sch:schema>

This schema can be used in a sequence like the following script:

REM Compile the schema and run it agains the document to produce the SVRL result
java -jar saxon9he.jar -o standard-compiled.xsl standard.sch  ..\ISO_Schematron\iso_svrl.xsl 
java -jar saxon9he.jar -o test-doc.svrl test-doc.xml standard-compiled.xsl  

REM Compile the schema and run it against the SVRL to produce an error code
java -jar saxon9he.jar -o svrl_tester-compiled.xsl svrl_tester.sch   ..\ISO_Schematron\iso_schematron_terminator.xsl
java -jar saxon9he.jar test-doc.xml   svrl_tester-compiled.xsl 

Testing Flags

ISO Schematron and SVRL support various features to make this kind of technique powerful. For example, rules, asserts and reports can have a flag attribute. This allows simple boolean conditions to be signalled.

So if we change the original schema to add a flag:

     <sch:rule context="head">
     <sch:assert test="title" flag="warning"i
		>A head should have a title</sch:assert>
     </sch:rule>

The SVRL will now also have the flag:

   <svrl:failed-assert test="title" flag="warning">
      <svrl:text>A head should have a title</svrl:text>
   </svrl:failed-assert>

Now, our testing schema will have tests on the presence of the flag attribute:

     <sch:rule context="svrl:schematron-output">
	<sch:report test="*[@flag='warning']" 
		>A warning was found</sch:report>
     </sch:rule>

As before, if this testing schema is run using Schematron Terminator implementation, your scripts can be smart about processing documents based on conditions. Of course, the flags can be set by the presence of more than just errors: they can be set based on business criteria or the document's state.