Reserved Word Filter: For the instance document to be
valid it must not contain these words:
Different Type of Checking
Note that the checking needed for the Reserved Word Filter is a fundamentally different
type of checking than we did in the tutorial on co-constraint checking.
There we "compared data values". Here we are "checking existence of."
Here is a Schematron rule which expresses the Reserved Word Filter:
The document must not contain the words SCRIPT or FUNCTION
Read as: Within the context of a <Document> element (the root element),
I assert that the count of the number of nodes containing 'SCRIPT' is zero, and
the count of the number of nodes containing 'FUNCTION' is zero.
The rule on the previous slide is the only rule needed to implement the Reserved Word Filter, so
let's embed it within a pattern element:
<sch:pattern name="Reserved Word Filter">
<sch:p>These reserved words are not allowed anywhere in the
Validate this (valid) XML instance document against the Schematron schema:
valid-document.xml (example02 folder)
Validate this (invalid) XML instance document against the Schematron schema:
invalid-document.xml (example02 folder)
Use both Oxygen XML and Topologi to perform the validation.
Display All Errors?
Did you notice in the last example the validator only displayed one error message.
But there are multiple errors in the document - the SCRIPT in the second <para> element,
the FUNCTION in the third <para> element, the SCRIPT and FUNCTION in the fourth <para> element.
Here's why: there's only one node in the XML instance document which matches the rule -- the <Document> element.
And within the rule is only one assertion. The assertion failed and one error message was displayed.
How do we design the Schematron schema so that an error message is displayed if there is an occurrence of SCRIPT and
an error message is displayed if there is an occurrence of FUNCTION?
Answer: use multiple assertions in the same rule.
The check-reserved-words schema we have examined assumed that all reserved words are in upper-case.
We want the schema to perform case-insensitive validation. That is, it doesn't matter
whether the XML instance document uses, for example, SCRIPT, Script, or script.
Also, currently the schema only displays one error message. We want it to display an error for
each occurrence of (case insensitive) SCRIPT or FUNCTION. To keep things simple,
only check the <Para> elements for the reserved words.
Modify this schema check-reserved-words.sch (lab01 folder)
to validate each Para element for occurrence of (case insensitive) SCRIPT or FUNCTION. (Add a second assertion)