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.
In order for patterns to match properly, and for Schematron to operate, namespaces need to be declared in the schema. This is very simple to do, and is done using the ns element. The ns element must be declared as a child of the schema element. It has two attributes: prefix and uri. These correspond, of course, to the namespace prefix and the namespace URI. In order to declare the namespace used above, the following XML would be used:
<ns prefix="ds" uri="http://developershed.com"/>
Now the schema will work properly with the document:
<assert test="ds:name">An article must have a name.</assert>