Schematron's Six Basic Elements

There are only 6 basic elements in ISO Schematron which makes it very easy to learn, especially if you already know XPaths. (There are others, but these mainly just help construct nice user interfaces for validators.) Here is the basic structure

So here is a very small example. It is a mini-schema for Schematron.

<schema xmlns="">
 <title>A Schematron Mini-Schema for Schematron</title>
 <ns prefix="sch" uri="">
   <rule context="sch:schema">
     <assert test="sch:pattern"
     >A schema contains patterns.</assert>
     <assert test="sch:pattern/sch:rule[@context]"
     >A pattern is composed of rules.
     These rules should have context attributes.</assert>
     <assert test="sch:pattern/sch:rule/sch:assert[@test] 
or sch:pattern/sch:rule/sch:report[@test]" >A rule is composed of assert and report statements.
These rules should have a test attribute.
</assert> </rule> </pattern> </schema>

In that mini-schema, the rule element sets the context: the rule applies to any sch:schema element in a document. The rules say that there must be at least one child element sch:pattern, at least one child element sch:pattern with a child sch:rule with a context attribute, and at least one child element sch:pattern with a child sch:rule with a sch:assert or sch:reportwith a test attribute.

This is probably not the most useful schema: it only tells you what is wrong with an empty document rather than checking a full Schematron schema. However, it does show that there are many different kinds of schemas possible: some of them similar to DTDs and some of them very different. Schematron lets you perform many kinds of new validation!

Please note that as of 2004, existing implementations of Schematron use the pre-ISO namespace