If you use XML schema languages, you should consider Schematron. This powerful rule-based language lets you make distinctions which other languages find difficult or even impossible to handle. Best of all, you can use it in conjunction with other schema languages. This is the first part of a three-part series.
Using Schematron - Schematron, a rule-based schema language (Page 2 of 4 )
This is where Schematron comes in. Not all schema languages are grammar-based. Schematron is, instead, a rule-based language. In XML Schema, you define precisely the structure of an XML document, explicitly stating what is allowed in the document. By contrast, in Schematron, you define a set of patterns that will be looked for in an XML document, with each pattern containing one or more rules, and each rule containing assertions (we'll discuss exactly what all this means later).
You can use XPath expressions to define what to check for in a given XML document. This allows you to deal with much more than just the structure of an XML document. For example, in the XML document described earlier, we could have set constraints on the relationship between the age and eligible_to_vote elements. We could have said, "If the resident's age is below 18, then the resident should not be able to vote." Or, in the context of the document, "If the text of the age element is less than 18, then the text of the eligible_to_vote element should be 'no'." This is an example of an assertion.
However, there is nothing wrong with using XML Schema or any other grammar-based language, and Schematron does not seek to replace any such languages. In fact, rather than having to choose between Schematron and, for example, XML Schema, it's possible to use Schematron in conjunction with XML Schema. In the XML document we looked at earlier, we could have defined the structure with XML Schema, and we could have defined the relationship between age and eligibility to vote in Schematron. This makes for a very powerful and easy-to-use tool set. Note, however, that just because Schematron is powerful, it isn't difficult to work with. It's actually very simple, with only a few core elements defined.
It's not hard to validate a document against a Schematron schema definition, either. Several implementations exist, but the "skeleton" implementation uses XSLT. So a document can be validated using any XML transformer, such as Saxon. This also allows the output to be given in a variety of formats.