In my last two articles, I covered the basics of Schematron—enough of it to create a basic schema with assertions, rules and patterns. However, there is more to Schematron than was covered in those articles, and some of Schematron's other features are very useful and worth mentioning. In this article, we'll take a look at more of Schematron's features, delving deeper into the Schematron schema language.
More Schematron Features - More on assertions (Page 2 of 5 )
At the assertion level of Schematron, basic assertion functionality is provided by the assert element. An assertion made using this element can either be met or unmet, and if unmet, then validation fails. That's not all that can be done on the assertion level, though.
Going back to the assert element, a message is given if the assertion test evaluates to false. So, if something is not found, then the message goes out. There is a similar element that works differently, though. The report element also features an assertion test, but, in this case, if the assertion test evaluates to true (in other words, if something is found), then the message is given. The report element, then, can be seen as the opposite of the assert element.
For example, consider an XML document that deals with animals. Inside of the document is a snake element. Other animals may have legs that are represented using a leg element, but snakes, obviously, do not have legs. We can ensure that this is the case using the report element. If a snake element is found to contain a leg element, then a message needs to be displayed:
<report test="leg">The snake has a leg.</report>
The following XML would cause the above report to give its message: