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.
Assertions can be grouped into rules, and rules can be grouped into patterns. In a similar way, patterns can be grouped into what are called phases. However, phases are different from rules and patterns in that a single pattern can belong to more than one phase. This is because a phase is declared differently from rules and patterns. Instead of containing the patterns themselves, a phase is populated with patterns using the active element, which represents a pattern active within a phase.
Phases allow for different “versions” of a schema. When the document is validated, the user may be able to select which phase to use. When a phase is chosen, then only the active patterns within that phase will be used to validate the document.
Creating a phase is easy. You simply need to use the phase element and set the id attribute in order to give the phase a unique identifier. Below, we create a phase by the name of “phase1”:
<phase id="phase1"> ... </phase>
In order to add a pattern to a phase, the active element is used. The only attribute of the active element is pattern, which is set to the identifier of the pattern you wish to add. Below, we add a pattern named “pattern1” to the phase:
If this phase is used for validation, only pattern1 will be used to validate the document because it is the only active pattern within the phase. All other patterns are inactive.
The names “#ALL” and “#DEFAULT” cannot be used to name a phase. The former is used to indicate that all phases are active. This is the default behavior if no particular phase is specified. The latter is used to indicate that the default phase is active. You can set the default phase of a schema by setting the defaultPhase attribute of the schema element: