Page 1 of 1

How to use function matches in schematron?

Posted: Wed Jan 04, 2012 4:53 pm
by sabine84
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

Re: How to use function matches in schematron?

Posted: Fri Jan 06, 2012 12:45 pm
by adrian
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.

Code: Select all

<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
Regards,
Adrian

Re: How to use function matches in schematron?

Posted: Tue Feb 08, 2022 11:16 pm
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>

Re: How to use function matches in schematron?

Posted: Fri Feb 11, 2022 10:07 am
by tavy
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:

Code: Select all

<sch:report test="matches(Document_number, '^.{19}EL[V|X]')">Achtung! </sch:report>
Similar for the second example, you should remove the "not()":

Code: Select all

<sch:report test="matches(('1234567'), '^[0-9]{7}$|^[0-9]{9}$')"> Test faild</sch:report>
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