Validating XCRI-CAP using Schematron

Here I hope to give a quick start on how to use Schematron with your XCRI-CAP documents to give useful feedback.

The instructions here were originally tested on OS X but should also work on Windows or your Linux disto of choice providing you have Java. If there are any differences I am not aware of please leave a comment.

Setting up your environment

You will need:

• ISO Schematron
• A Schematron Schema
• An XLST processer
• An XCRI-CAP document for validation.

ISO Schematron
We’ll be using ISO Schematron, which is available for download from the schematron website: The file we want is, I recommend unzipping it to your desktop and renaming it schematron. Place the XCRI-CAP document you wish to validate into this directory.

The schematron schema is transformed into a XLST stylesheet using a XLST processor; in this example I am going to use Saxon-B for Java, which is an open source XSLT processor.

Once downloaded you will need to add saxon.jar to your classpath. On OS X 10.5+ you can place it into your /Library/extensions/Java directory.

Schematron Schema
A Schematron schema is needed validate against your XCRI-CAP XML document. The schema takes the form of xpath expressions; I have written one based on XCRI-CAP 1.1 which you can download here; feel free to use and modify. Once downloaded place into your schematron directory. You will also need this list of postcodes.
Now you should now have a directory named schematron with multiple files; it is important that you have the following five:

• iso_svrl_for_xlst2.xsl
• iso_schematron_skeleton_for_saxon.xsl
• xcri.iso.sch
• postcodes.xml
• your own XCRI-CAP document!

Validating your XCRI-CAP documents

First we need to create an xsl stylesheet which will be used as the validation engine against our XCRI-CAP document.
Open a terminal/prompt navigate to your schematron directory and issue the following command:

java net.sf.saxon.Transform -o xcri.iso.sch.tmp.xsl -s xcri.iso.sch iso_svrl_for_xslt2.xsl

This will use the Saxon processor we installed earlier to compile the schema into an XLST stylesheet (xcri.iso.sch.tmp.xsl) using our schema, Schematron xsl and the Saxon processor. The next step is to use the file we have created against our XCRI-CAP document to create an error report. To do this run the following changing ‘myfile.xml’ to the name of your document:

java net.sf.saxon.Transform -o -s myfile.xml xcri.iso.sch.tmp.xsl

You should now have an error report called The report is in SVRL format which is a simple language defined in ISO schematon. SVRL can be used as the basis for further transformations and to demonstrate this I have written a small xsl which you can use to transform this into an HTML document. If you wish to do so, download to your schematron directory, make any modifications you require and use the following:

java net.sf.saxon.Transform -o errors.html svrl_transformer.xsl

You should now have the HTML document of errors in your schematron directory errors.html

Line Numers
You should now be producing feedback on your XCRI-CAP documents and producing a simple html document of errors. If you are using a version of Saxon that allows access to its extensions then you we can use the saxon:linenumber() extension to report line numbers.

To do so replace these files in your schematron directory with these modified versions:



And run though the validation steps again with the -l flag set. eg:

java net.sf.saxon.Transform -l -o xcri.iso.sch.tmp.xsl -s xcri.iso.sch iso_svrl_for_xslt2.xsl

java net.sf.saxon.Transform -l -o -s myfile.xml xcri.iso.sch.tmp.xsl

java net.sf.saxon.Transform -l -o errors.html svrl_transformer.xsl

Don’t have time to give it a go? You can use the ‘beta’ web based validator that will validate your XCRI-CAP document using the same steps shown in this post. You can find the validator a:

Comments very welcome!

8 Replies to “Validating XCRI-CAP using Schematron”

  1. I’ve given the online version a go, and it seemed to work fine. I do get prompted to login each time I hit the page – although cancelling the login box and carrying on seems to work.

    I don’t know if this is helpful, but I was wondering about the validation of any ‘identifier’ elements. The wiki recommends the use of URLs that resolve to human readable content – is there any scope for checking at least the use of an http URI as an identifier, and giving a warning where this isn’t done? Not sure whether this is (a) a good idea or (b) do-able

  2. I’ve been trying the online validator. Seems to work OK, but I get a popup box telling me ‘authentication is required’ when I access the page – this seems to be untrue – or at least, cancelling the pop up allows you to continue and validate a file.

    A couple of comments:

    1) It would be good to be able to point the validator at a URL rather than upload a file
    2) How does validation work with identifiers? I don’t think (at the moment) the validator checks if the default indentifier is a URI (as specified in the wiki

  3. Hi Dave,

    I got a copy of your iso_svrl_for_xslt2.xsl, which handles the line nubmer. It doesn’t work for me (see a snippet of the report below). As you will see the line number is always set -1. I got saxon B you have suggested in my class path, any idea?

    Line Number: -1.ISSN should have attribute pub-type=”ppub” for print or pub-type=”epub” for electronic publication.

    Line Number: -1.ISSN does not conform to the expected syntax of two groups of four digits separated by a hyphen (-). The final character can be an ‘X’ rather than a number.

  4. Hi Dave

    Sorry it’s me again, I didn’t see that I have to set the flag -l to get line number working. You showed above how to set if you run it in command line, how to set to run in Java application (currently running the sample on eclipse).


  5. Hi

    I haven’t tried it in eclipse so I don’t know, If I get chance I’ll have a look over the next few days. This tutorial is a bit out of date now and I would hear how you get on with it in eclipse.

Leave a Reply

Your email address will not be published. Required fields are marked *