Schematron assert test cannot use let variable
Posted: Fri Jul 25, 2025 9:08 am
I have a schema (ODD converted to RelaxNG) for validating XML files with mixed content. Several of the Schematron tests seem to be uneconomical, for example this one to control the @who attribute of the change element:
[code]
<attDef ident="who" mode="change" usage="opt">
<constraintSpec ident="check-xmlid_change" scheme="schematron">
<constraint>
<sch:rule context="tei:change/@who">
<sch:let name="noteMakers"
value="//tei:editor/@xml:id | //tei:respStmt/@xml:id"/>
<sch:let name="plusHash"
value="for $maker in $noteMakers return concat('#', $maker)"/>
<sch:assert test=". = //tei:editor/concat('#', @xml:id) or . = //tei:respStmt/concat('#', @xml:id)"
role="error">Permissible values are "<sch:value-of select="$plusHash"/>".
</sch:assert>
</sch:rule>
</constraint>
</constraintSpec>[/code]
The let variable plusHash is only used to list the permissible values of @who in the error message. The assert test makes no use of plusHash but instead in effect repeats the steps that were used to create it. This seems clumsy. Is there a way of using the variable plusHash in the assert test that does not trigger an out-of-scope or other error?
[code]
<attDef ident="who" mode="change" usage="opt">
<constraintSpec ident="check-xmlid_change" scheme="schematron">
<constraint>
<sch:rule context="tei:change/@who">
<sch:let name="noteMakers"
value="//tei:editor/@xml:id | //tei:respStmt/@xml:id"/>
<sch:let name="plusHash"
value="for $maker in $noteMakers return concat('#', $maker)"/>
<sch:assert test=". = //tei:editor/concat('#', @xml:id) or . = //tei:respStmt/concat('#', @xml:id)"
role="error">Permissible values are "<sch:value-of select="$plusHash"/>".
</sch:assert>
</sch:rule>
</constraint>
</constraintSpec>[/code]
The let variable plusHash is only used to list the permissible values of @who in the error message. The assert test makes no use of plusHash but instead in effect repeats the steps that were used to create it. This seems clumsy. Is there a way of using the variable plusHash in the assert test that does not trigger an out-of-scope or other error?