using variables in test property with matches
Posted: Fri Sep 16, 2016 1:58 am
I would like to define a set of regular expressions as variables at the top of a pattern, then use them in various combinations on multiple rule elements. I want to use them in the test property of assert and report elements. I get different results when I try to use these variables and when I use the literal regular expression. I've tried to look for similar examples without success. Not sure what I have wrong and I would appreciate having my mistake identified. Thanks!
The XML file:
The Schematron file:
The result is that the first assert, using literal regular expressions, passes.
But the second assert, using variable representations of the regular expressions fail.
Below is the output from running the schematron.
I suspect there is a problem with my variable definition.
Thanks again for pointing out my error!
Rich Wood
The XML file:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<assignedSubject>A23-23-1234</assignedSubject>
<assignedSubject>51-00-01</assignedSubject>
<assignedSubject>51-00-02</assignedSubject>
<assignedSubject>51-00-06</assignedSubject>
</Document>
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
<sch:pattern id="regexVariableTest">
<sch:let name="regex01" value="'[A-Z]?\d\d-\d\d-\d{2}'"/>
<sch:let name="regex02" value="'[A-Z]?\d\d-\d\d-\d{4}'"/>
<sch:rule context="//assignedSubject">
<sch:assert test="matches(normalize-space(.),'
^[A-Z]?\d\d-\d\d-\d{2}$ |
^[A-Z]?\d\d-\d\d-\d{4}$
','x')"
role="error">
message:1
</sch:assert>
<sch:assert test="matches(normalize-space(.),'
^$regex01$ |
^$regex02$
','x')"
role="error">
message:2
</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>
But the second assert, using variable representations of the regular expressions fail.
Below is the output from running the schematron.
I suspect there is a problem with my variable definition.
Thanks again for pointing out my error!
Rich Wood
Code: Select all
E[ISO Schematron] message:2
E[ISO Schematron] message:2
E[ISO Schematron] message:2
E[ISO Schematron] message:2