The syntax for an included file is
<iso:include href='filename.sch'/>
This element can appear anywhere within the schema element, replacing patterns, rules etc. The only validity constraint is that the resulting Schematron file must be
valid to the Schematron schema. The include file itself must be valid XML, valid to
the part of the schema that it will instantiate. It must also have a single root,
i.e. such an included file cannot contain two rules (which would equate to two roots!)
Processing an include requires that it is the first step in the chain of steps needed
to process a Schematron file. This is because the included content may itself contain
abstract patterns which require processing. See
Chapter 11, ISO implementation StylesheetsChapter 11, ISO implementation Stylesheets for an example stylesheet.
An example is shown in
Example 8.5, “A simple include example” below, which is a simple example whereby a single rule is in an external file and
included into the main Schematron file.
Example 8.5. A simple include example
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- The main Schematron file -->
<iso:schema xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
xmlns:sch="http://www.ascc.net/xml/schematron"
queryBinding='xslt2'
schemaVersion="ISO19757-3">
<iso:title>Test ISO schematron file. Introduction mode </iso:title>
<!-- Not used in first run -->
<iso:ns prefix="dp" uri="http://www.dpawson.co.uk/ns#" />
<iso:pattern id="doc.checks">
<iso:title>checking an XXX document</iso:title>
<iso:rule context="doc">
<iso:report
test="chapter">Report date.<iso:value-of select="current-dateTime()"/></iso:report>
</iso:rule>
</iso:pattern>
<iso:pattern id="chapter.checks">
<iso:title>Basic Chapter checks</iso:title>
<iso:p>All chapter level checks. </iso:p>
<iso:include href='input.incl'/>
</iso:pattern>
</iso:schema>
<!-- The included file input.incl-->
<?xml version="1.0" encoding="iso-8859-1"?>
<iso:rule context="chapter"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
>
<iso:assert test="title">Chapter should have a title</iso:assert>
<iso:report test="count(para)"><iso:value-of select="count(para)"/> paragraphs</iso:report>
<iso:assert test="count(para) >= 1">A chapter must have one or more paragraphs</iso:assert>
<iso:assert test="*[1][self::title]">Title must be first child of chapter</iso:assert>
<iso:assert test="@id">All chapters must have an ID attribute</iso:assert>
</iso:rule>
The mechanics are simple, it is the classic software engineering include pattern.
The referenced text is inserted into the referring file at the point of inclusion.
The time at which this is done is implementation dependent, though the stylesheet
which implements the abstract patterns provides the ideal time for processing inclusions.
See
Chapter 11, ISO implementation StylesheetsChapter 11, ISO implementation Stylesheets for an example stylesheet which processes inclusions.