A few days ago Rick Jelliffe mentioned some of the new capabilities that XPath 2.0 adds to Schematron.
The things that he mentioned sounded very exciting to me, so I put together what is for me a typical set of data requirements. I then implemented those data requirement using Schematron+XPath 2.0. Then, for comparison, I attempted to implement the same data requirements using XML Schemas.
It was a very enlightening experience. Schematron+XPath 2.0 was able to implement all of my data requirements (including all grammar constraints). Conversely, XML Schemas was only able to implement the grammar constraints (which are actually of lesser importance to me than my other data requirements).
Of course, this represents only one example; other examples must be explored. Nonetheless, the fact that Schematron+XPath 2.0 could implement all of my (fairly extensive) data requirements is very exciting.
Below is my set of data requirements followed by the Schematron+XPath 2.0 implementation, as well as the XML Schema implementation. Perhaps you have similar data requirements?
Schematron+XPath 2.0 was able to express:
Conversely, XML Schemas was only able to express the grammar constraints (data requirements, #1 and #8). It was unable to express the other data requirements (#2 - #7).
<?xml version="1.0" encoding="UTF-8"?> <Document classification="secret"> <NumParas>4</NumParas> <Para classification="unclassified"> One if by land, two if by sea; </Para> <Para classification="confidential"> And I on the opposite shore will be, Ready to ride and spread the alarm </Para> <Para classification="unclassified"> Ready to ride and spread the alarm Through every Middlesex, village and farm, </Para> <Para classification="secret"> For the country folk to be up and to arm. </Para> <Hash>304</Hash> </Document>
Here's the sample xml instance document.
Here's the Schematron + XPath 2.0 implementation.
xmlns:saxon="http://saxon.sf.net/" saxon:allow-all-built-in-types="yes"These two lines enable you to use, in your Schematron schema, expressions like "castable as xs:nonNegativeInteger". The basic version of XPath 2.0 only allows you to use "castable" with non-derived datatypes such as integer and string. Since nonNegativeInteger derives from integer, it is not allowed in basic XPath 2.0. However, SAXON provides a flag (the above two lines) that you can add to your stylesheet to instruct SAXON "Please permit me to use "castable" with all of the datatypes. Note: you will not need to add these two lines if you are using SAXON-SA (the schema-aware version of SAXON).
Here's the XML Schema implementation.
I would like to gratefully thank the following people for their help with creating my example and with helping me to realize the power of Schematron + XPath 2.0:
Last Updated: October 26, 2007