Schematron & XPath 2.0 string/numeric comparisons

Having trouble installing Oxygen? Got a bug to report? Post it all here.
XedMada
Posts: 13
Joined: Mon May 24, 2010 7:20 pm

Schematron & XPath 2.0 string/numeric comparisons

Post by XedMada »

I recently added queryBinding="xslt2" to my Schematron so I could use XPath 2.0. After doing so, it seems all of my assertion tests containing comparisons of > or < are having issues (reporting incorrectly.) It seems inequality tests are not working out.

e.g.
schema:

Code: Select all


<pattern id="limit_order">
<rule context="foo" role="error">
<assert test="not(@l_lim > @h_lim)">
Limits must be in high/low order.</assert>
</rule>
</pattern>
samples:

Code: Select all


<foo l_lim="50" h_lim="255" />
fails

Code: Select all


<foo l_lim="200" h_lim="255" />
passes

Code: Select all


<foo l_lim="050" h_lim="255" />
passes


Specifying the attributes as numbers seems to resolve the issue:

Code: Select all


<pattern id="limit_order">
<rule context="foo" role="error">
<assert test="not(number(@l_lim) > number(@h_lim))">
Limits must be in high/low order.</assert>
</rule>
</pattern>
All previous examples pass.

I understand the notion of string vs. numeric comparison, but I thought this was taken care of for you since it worked before adding xslt2 to the schema. Is this a bug, am I missing something, or must I add number() all over my schema?

cheers,
-X
XedMada
Posts: 13
Joined: Mon May 24, 2010 7:20 pm

Re: Schematron & XPath 2.0 string/numeric comparisons

Post by XedMada »

Sorry, forgot to mention: OSX 10.6.6 & oXygen Editor 12.1 build 2011012011
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Re: Schematron & XPath 2.0 string/numeric comparisons

Post by george »

This is how it works in XPath 2.0.
See http://www.w3.org/TR/xpath20/#id-general-comparisons
The case when XPath 1.0 compatibility mode is false
***
a. If both atomic values are instances of xs:untypedAtomic, then the values are cast to the type xs:string.
***

Best Regards,
George
George Cristian Bina
Post Reply