ISO Schematron Validators built on the "Skeleton"
Here are some Schematron validators built on the so-called "reference" implementation of ISO Schematron. They are currently at beta status.
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.
- Schematron SVRL is an implementation of SVRL for XSLT. It customizes the iso_schematron_skeleton.xsl implementation of Schematron. This version: 2007-04-03
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 saxon8.jar -o standard-compiled.xsl standard.sch ..\ISO_Schematron\iso_svrl.xsl java -jar saxon8.jar -o test-doc.svrl test-doc.xml standard-compiled.xsl
You can see this kind of use in the linked process diagram (SVG).
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.
- iso_schematron_text.xsl is an implementation of Schematron Text for XSLT courtesy of Ken Holman. It customizes the iso_schematron_skeleton.xsl implementation of Schematron. This version: 2007-02-09
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 saxon8.jar -o schema-compiled.xsl schema.sch ..\ISO_Schematron\iso_schematron_text.xsl java -jar saxon8.jar test-doc.svrl schema-compiled.xsl
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.
- iso_schematron_terminator.xsl is an implementation of Schematron Terminator for XSLT. It customizes the iso_schematron_skeleton.xsl implementation of Schematron. This version: 2007-02-08
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 saxon8.jar -o schema-compiled.xsl schema.sch ..\ISO_Schematron\iso_schematron_terminator.xsl java -jar saxon8.jar test-doc.svrl schema-compiled.xsl
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 saxon8.jar -o standard-compiled.xsl standard.sch ..\ISO_Schematron\iso_svrl.xsl java -jar saxon8.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 saxon8.jar -o svrl_tester-compiled.xsl svrl_tester.sch ..\ISO_Schematron\iso_schematron_terminator.xsl java -jar saxon8.jar test-doc.svrl 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.
