How to use function matches in schematron?
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 1
- Joined: Wed Jan 04, 2012 4:13 pm
How to use function matches in schematron?
Hello!
Can anybody help me? I want to use regular expressions in my schematron.
here my xml:
<kbl:KBL_container>
<External_reference>
<Document_type>KAB</Document_type>
<Document_number>TAB_886_016_JK_KPR_ELV_____300611</Document_number>
</External_reference>
</kbl:KBL_container>
here my schematron:
<pattern>
<rule context="//External_reference[Document_type='KAB']">
<assert test="matches(Document_number, '^.{19}EL[V|X]')">
Achtung! </assert>
</rule>
</pattern>
Is there a problem with the function "matches"?
I also for ...886_016... only numbers are allowed.
king regards
Can anybody help me? I want to use regular expressions in my schematron.
here my xml:
<kbl:KBL_container>
<External_reference>
<Document_type>KAB</Document_type>
<Document_number>TAB_886_016_JK_KPR_ELV_____300611</Document_number>
</External_reference>
</kbl:KBL_container>
here my schematron:
<pattern>
<rule context="//External_reference[Document_type='KAB']">
<assert test="matches(Document_number, '^.{19}EL[V|X]')">
Achtung! </assert>
</rule>
</pattern>
Is there a problem with the function "matches"?
I also for ...886_016... only numbers are allowed.
king regards
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: How to use function matches in schematron?
Hello,
The problem is that the function matches is from XSLT/XPath 2.0 which is not enabled by default in Schematron.
If you are using Schematron 1.5(namespace http://www.ascc.net/xml/schematron) you need to activate an option in Oxygen:
Options -> Preferences, XML -> XML Parser, Schematron XPath Version: 2.0
If you are using ISO Schematron(namespace http://purl.oclc.org/dsdl/schematron) you have to add an attribute on the schema root: queryBinding="xslt2"
e.g.
Regards,
Adrian
The problem is that the function matches is from XSLT/XPath 2.0 which is not enabled by default in Schematron.
If you are using Schematron 1.5(namespace http://www.ascc.net/xml/schematron) you need to activate an option in Oxygen:
Options -> Preferences, XML -> XML Parser, Schematron XPath Version: 2.0
If you are using ISO Schematron(namespace http://purl.oclc.org/dsdl/schematron) you have to add an attribute on the schema root: queryBinding="xslt2"
e.g.
Code: Select all
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
-
- Posts: 1
- Joined: Tue Feb 08, 2022 11:07 pm
Re: How to use function matches in schematron?
Post by sundark2308 »
I use ISO schematron and added the attribute queryBinding="xslt2 but my regular expression is not working.
This is the regex I used
<sch:report test="not(matches(('1234567'), '^[0-9]{7}$|^[0-9]{9}$'))"/>
I think the problem is when the schematron compiles the schema and generate the XSL the regex is changed that's what it is not working.
Compiled XSL
<xsl:if test="not(matches(('1234567'), '^[0-9]7$|^[0-9]9$'))">
<svrl:successful-report test="not(matches(('1234567'), '^[0-9]7$|^[0-9]9$'))" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
<xsl:attribute name="location">
<xsl:apply-templates select="." mode="schematron-select-full-path">
</xsl:apply-templates>
This is the regex I used
<sch:report test="not(matches(('1234567'), '^[0-9]{7}$|^[0-9]{9}$'))"/>
I think the problem is when the schematron compiles the schema and generate the XSL the regex is changed that's what it is not working.
Compiled XSL
<xsl:if test="not(matches(('1234567'), '^[0-9]7$|^[0-9]9$'))">
<svrl:successful-report test="not(matches(('1234567'), '^[0-9]7$|^[0-9]9$'))" xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias" xmlns:svrl="http://purl.oclc.org/dsdl/svrl">
<xsl:attribute name="location">
<xsl:apply-templates select="." mode="schematron-select-full-path">
</xsl:apply-templates>
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: How to use function matches in schematron?
Hello,
I tested the examples you provided and I think the problem is the assert/report.
For example, if you want to verify if the "Document_number" respects the pattern "^.{19}EL[V|X]')", you need to use a "report" element in order for the problem to be reported when the pattern is not respected. Soemthing like this:
Similar for the second example, you should remove the "not()":
You can find other examples for the matches() function on the W3C specification page:
https://www.w3.org/TR/2010/REC-xpath-fu ... nc-matches
The compiled XSL file looks fine for me. I converted the Schematron in XSL by running the "ISO Schematron to XSLT (compile)" transformation scenario on the Schematron file. What version of Oxygen do you use?
Best Regards,
Octavian
I tested the examples you provided and I think the problem is the assert/report.
For example, if you want to verify if the "Document_number" respects the pattern "^.{19}EL[V|X]')", you need to use a "report" element in order for the problem to be reported when the pattern is not respected. Soemthing like this:
Code: Select all
<sch:report test="matches(Document_number, '^.{19}EL[V|X]')">Achtung! </sch:report>
Code: Select all
<sch:report test="matches(('1234567'), '^[0-9]{7}$|^[0-9]{9}$')"> Test faild</sch:report>
https://www.w3.org/TR/2010/REC-xpath-fu ... nc-matches
The compiled XSL file looks fine for me. I converted the Schematron in XSL by running the "ISO Schematron to XSLT (compile)" transformation scenario on the Schematron file. What version of Oxygen do you use?
Best Regards,
Octavian
Octavian Nadolu
<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