Schematron-Basic

Implementation: A mimimal concept demonstration generating simple text
Author: Rick Jelliffe
Current version: 2001-03-13
Previous version: 1999-11-5

Intro: Schematron is a way of using XPath Paths and Expressions to validate that an XML file (file A) obeys certain rules, specified by the user in another XML file (file B).

Examples of user need for this might include:

It does that by using an XML file B, valid to the schema DTD, together with the schematron XSL file, to create an XSLT file (XSL file C).

This is then used with XML file A , to validate your XML file against the rules you have created!

Rules file (XML file B) + schematron-basic.xsl => XSL file C
Your XML file A + XSL file C           => Report file.

The report file finally output informs you of either exceptions (assert elements) or compliances (report elements) that you have specified.

Under Win32, this is achieved in a two stage process: To use rules file v.xml to validate document.xml,

del report.txt
xt v.xml schematron-basic.xsl temp.xsl
xt document.xml temp.xsl report.txt
del temp.xsl
more report.txt

Warning: Look out for errors after the second run of xt,these will need to be traced back to the xml source, e.g., in the test attribute of <assert> or <report> elements.

Downloading

Download The Schematron preprocessor from http://www.ascc.net/xml/schematron/1.5/schematron1-5/schematron-basic.xsl

Requires:

  1. James Clark's XT processor for XSLT, available from http://www.jclark.com/ (or any XSLT processor that conforms to the W3C recommendation.)
  2. Java (required by XT).

Running

The Schematron is a command line utility in the current implementation.

On UNIX, use the following commands (make sure that XT has been installed correctly):

java -Dcom.jclark.xsl.sax.parser=com.jclark.xml.sax.CommentDriver \ 
        com.jclark.xsl.sax.Driver schemafile.xml  schematron.xsl  > tmp.xsl 
java -Dcom.jclark.xsl.sax.parser=com.jclark.xml.sax.CommentDriver \ 
        com.jclark.xsl.sax.Driver datafile.xml  tmp.xsl 
rm tmp.xsl

On Windows, use the following command line (make sure that XT has been installed correctly):

xt schemafile.xml  schematron.xsl  tmp.xsl 
xt datafile.xml  tmp.xsl  output.txt 

Example Schematron Schema

Here are is a demonstration schema.

WAI: Web Accessability Inititative Guidelines

Many of the WAI guidelines can be turned into a schema easily. Here is the schema, and here is an evil test file. And here is the result.

Of course, any HTML in XML file or XHTML file can be used. The test file is certainly not good or even valid HTML (against the HTML DTDs). But you can see that this WAI schema does not require documents that are valid; it only is interested in validating the patterns that WAI is interested in. (Actually, I have just made each section in the WAI guidelines into a pattern: this perhaps is slack, since really a pattern should be a bunch or rules that are somehow interconnecting.)


Copyright (C) Rick Jelliffe, Academia Sinica Computing Centre. Thanks to David Pawson for the introductory material. The Schematron software and this page are available for any public use, under the conditions of the GPL or MPL, but please mention our names in any documentation or About screens for any products that uses it. Comments, fixes and upgrades welcome: email ricko@gate.sinica.edu.tw.