Skip to content

Testing Schematron with Attributes

Amanda Galtman edited this page May 28, 2024 · 3 revisions

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.

Schematron fails to visit attributes when running XSpec v2.3.2 and earlier

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:

Working around the skeleton Schematron implementation bug

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.

Clone this wiki locally