Auto-generating Standards from Schematron Schemas

by Rick Jelliffe

Schematron is an ISO standard (ISO/IEC IS 19757-3) schema language for expressing assertions about the presence or absence of patterns in a document, usually using XPath. ISO standards are supposed to contain verifiable statements about some technology. And there is an schema for ISO standards (refer to How to write your own ISO Standard. So why not combine them? Executable specifications may provide the best form of verifiability!

I've made a little stylesheet that converts Schematron schemas into ISO Standard annexes. Each pattern becomes a separate clause, and assertions are treated as constraints and report statements are treated as errors that must be reported. The stylesheet handles abstract rules and abstract patterns (though these are starting to go into XPath territory and so are borderline ugly), and the @see attribute. Phases are treated as conformance profiles. Diagnostics are stripped out, they might perhaps have some use in application standards rather than document standards.

As well as its assertions, Schematron allows quite a bit of rich text and titles. The stylesheet handles bullet and numbered lists, most kinds of inline styling. The output is validated against eh RELAX NG Compact schema from the draft TR that I was using. (I had to clean up numbered lists a little: the drft stylesheet provided its own autonumbering when using <ol>.)

So is this a serious idea? Actually, yes. Schematron was developed with the human aspect of schemas as a very high priority, unlike any other schema language that I am aware of. By design, it is intended to be useful for generating documentation suitable for domain experts rather than XPath developers. (I am working on a commercial product that provides this as part of a collaborative schema development environment; the betas look good.)

So I hope that as more organizations take up Schematron to specify part or all of their standards, they will adopt this kind of approach, so that they end up with standards with no gaps between what is required and what is validatable. Note that you can still make Schematron assertions even when there is no XPath to check it: so Schematron does not back you into the corner that other schema languages do, where you have no high level constructs to document constraints beyond the capability of the validation expression language: refer to Expressing untested and untestable constraints in Schematron.

The stylesheet and an example

Schematron Validation Reporting Language is a small language specified as part of ISO Schematron for representing the output of a validation,. It can then be transformed into lots of other uses.

First: here is the Schematron schema for SVRL, unchanged from the ISO standard except I added three IDs that were missing (the XSLT expects patterns to have IDs): Download file

Next, here is the XSLT script: Download file

Here is the output from the script, using the SC34 schema: Download file

And , here is that output then converted to HTML, using the draft previewing script from ISO. (The SourceForge project has an XSL-FO generator): Download file

As a bonus, here is a blank XSLT template with all the Schematron elements exposed, for anyone who wants to make their own complex pretty-printer/transformer for Schematron schemas:
Download file

The annex generated is, I think, pretty acceptable as a draft standard, especially since the schema was written as a real schema and not as text in a standard per se. Obviously some things can be improved, such as being consistent with 'should' and 'is', but I think this is a viable, useful and efficient approach to improving the quality of standards for XML vocabularies and document types.


Phil Fearon
2007-08-19 00:51:52
Your collaborative schema development environment, will this have improved support for XPath developers than we currently get?

I ask because Schematron schema development tests the XPath skills of developers in different ways to when XPath is used in an XSLT environment. Some well-establised XML tools understandably emphasise dynamic XSLT debugging features and provide more limited capabilities when it comes to working statically with XPath.

I've been developing a non-commercial stand-alone XPath (not specifically Schematron) product to try and fill this gap, though take-up of the Beta product has been disappointing. It would be good to think that more fully developed (and supported) commercial XPath products are on their way.

Useful downloads by the way.

Phil Fearon