Testing Schematron with Attributes - xspec/xspec GitHub Wiki
This page pertains to XSpec v2.3.2 and earlier. When using v3.0.3 and later, you will not see the failures in the example below and do not need a workaround.
Suppose you have this Schematron schema containing <sch:rule context="@media-type">
:
test.sch
<sch:schema queryBinding="xslt2" xmlns:sch="http://purl.oclc.org/dsdl/schematron">
<sch:pattern>
<sch:rule context="@media-type">
<sch:assert test=". = 'text/plain'">A media-type attribute must be an allowed value.</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
And suppose you test it with this XSpec:
test.xspec
<x:description schematron="test.sch" xmlns:x="http://www.jenitennison.com/xslt/xspec">
<x:scenario label="when a media-type attribute is not an allowed value">
<x:context>
<rlink media-type="image/png" />
</x:context>
<x:expect-assert label="that should raise an assertion failure" />
</x:scenario>
</x:description>
The test fails:
C:\test>xspec.bat -s test.xspec
...
when a media-type attribute is not an allowed value
that should raise an assertion failure assert
FAILED
...
passed: 0 / pending: 0 / failed: 1 / total: 1
It fails, because the skeleton Schematron implementation bundled into XSpec fails to visit attributes in this case:
- Attribute optimization bug
- Bug related to attributes
- attribute nodes in context of schematron rule
- When using XSLT 2, Schematron ignores rules that have attributes in their context
To make sch:rule
work with attributes, you have to either rewrite your @context
or fix the skeleton Schematron implementation privately. See a StackOverflow answer. Unfortunately, the development of the skeleton Schematron implementation has been ceased and there is virtually no hope of its official fixes.
Alternatively, use another implementation of Schematron, following instructions in Using SchXslt with XSpec v2.3.2 and earlier.