Table of Contents
Element context(s)
phase
This attribute is optional and restricts evaluation of the patterns the phase contains to the subset of the document its expression matches.
Clause 5.4.13 (
phaseelement)The optional
fromattribute [...] can be used to restrict validation to a subset of a document.
Clause 5.5.7 (
fromattribute)The
fromattribute contains an expression which restricts the evaluation of patterns in a phase to the subset of the document it selects.The expression shall be evaluated in the context of the instance document root. The results become the context against which rule
contextexpressions are evaluated. Variables evaluated in the context of the instance document root are not influenced by the presence offromand so are evaluated and scoped as usual.This behaviour shall not apply to subordinate documents, that is those selected by the
documentsattribute [...].
phase =
element phase {
attribute id { xsd:ID },
attribute from { text }?,
attribute when { pathValue }?,
rich,
(foreign & inclusion* & (p*, let*, active*))
}Example 3. from attribute
Given this instance document:
<foo>
<blort wibble='1'/>
<bar><blort wibble='2'/><blort wibble='3'/></bar>
</foo>and this schema:
<sch:schema schematronEdition='2025' defaultPhase='wibble'> <sch:phase id='wibble' from='/foo/bar'> <sch:active pattern='wibble'/> </sch:phase> <sch:pattern id='wibble'> <sch:rule context='.//blort[@wibble]'> <sch:report test='@wibble'><sch:value-of select='@wibble'/></sch:report> </sch:rule> </sch:pattern> </sch:schema>
only the two instances of wibble (highlighted, at XPath /foo/bar/blort) will be reported, because the from attribute constrains the evaluation context to the XPath given (/foo/bar).
Example 4. from attribute: evaluation returns the empty sequence
Given the same instance document as above and this schema:
<sch:schema schematronEdition='2025' defaultPhase='wibble'> <sch:phase id='wibble' from='/no/such/path'> <sch:active pattern='wibble'/> </sch:phase> <sch:pattern id='wibble'> <sch:rule context='.//blort[@wibble]'> <sch:report test='@wibble'><sch:value-of select='@wibble'/></sch:report> </sch:rule> </sch:pattern> </sch:schema>
nothing is returned because evaluating from (highlighted) returns the empty sequence. The rule will consequently not fire and none of its assertions will be evaluated.
The implication of the phrase "The results become the context against which rule context expressions are evaluated" is that if the results are the empty sequence, there is nothing to validate and so the active patterns belonging to the phase are not evaluated (see Example 4, “from attribute: evaluation returns the empty sequence”).