using variables in test property with matches
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 16
- Joined: Tue Jan 12, 2016 9:41 pm
using variables in test property with matches
Post by Richard_Wood »
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
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: using variables in test property with matches
Hi Rich,
Basically when the XML is validated with the Schematron, Oxygen creates an XSLT stylesheet from the Schematron and applies the XSLT stylesheet over the XML.
If you open the schematron file, and use the "Configure Transformation Scenarios" toolbar button you have a predefined scenario which can be used in order to see how the generated XSLT stylesheet looks like.
Basically when you use this construct in the Schematron:
is generated in the XSLT like this:
Because you are inside a string literal (inside the simple quotes) the "$regex01" is not considered a variable reference, it is considered a plain string.
So in such cases you probably need to use in the Schematron the concat() function, something like:
Regards,
Radu
Basically when the XML is validated with the Schematron, Oxygen creates an XSLT stylesheet from the Schematron and applies the XSLT stylesheet over the XML.
If you open the schematron file, and use the "Configure Transformation Scenarios" toolbar button you have a predefined scenario which can be used in order to see how the generated XSLT stylesheet looks like.
Basically when you use this construct in the Schematron:
Code: Select all
<sch:assert test="matches(normalize-space(.),'^$regex01$ |^$regex02$','x')"
role="error">
message:2
</sch:assert>
Code: Select all
<xsl:when test="matches(normalize-space(.),'^$regex01$ |^$regex02$','x')"/>
So in such cases you probably need to use in the Schematron the concat() function, something like:
Code: Select all
<sch:assert test="matches(normalize-space(.), concat('^', $regex01, '$|^', $regex02, '$'),'x')"
role="error">
message:2
</sch:assert>
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service