Project

Profile

Help

Saxon-ee functionality

Added by Rob Brown over 5 years ago

I am evaluating saxon-ee and have a question about its capability. I have made an assumption that may be wrong.

When comparing 2 elements that contain strings e1="2" and e2="11" the expression e1 > e2 will return true.

When comparing 2 variables typed as xs:integer that contain numbers v1="2" and v2="11" the expression v1 > v2 will return false.

When using saxon-ee I assume that if I use a schema to type e1 and e2 as xs:integer the above expression will return false, which matches the output of the typed variables expression.

Is this a correct assumption? My tests are not showing this but it will take some time to create a self-contained sample to upload. If my assumption is wrong, there is no point in doing this work.

If the assumption is correct (I hope so), there must be a bug in my xsl or xsd and I will chase it down.

Will saxon-ee allow me to get the desired results? I want to prevent my users from having to cast elements as numbers all the time before doing comparisons or math.

Thanks very much.


Replies (1)

RE: Saxon-ee functionality - Added by Michael Kay over 5 years ago

Yes, that's the way it's supposed to work.

The main thing is to be sure that the nodes in question are part of a tree that has been validated and type-annotated. In most cases you can achieve this by specifying -val:strict on the command line. But be careful with nodes in temporary trees (i.e. constructed trees in variables) -- they won't be typed unless the instruction that creates the nodes requests validation.

Another useful trick is to specify typed="strict" on xsl:mode. This ensures that if you accidentally apply-templates to an untyped node, you'll get an error. It also allows Saxon to make compile-time assumptions about what type the matched nodes are going to be, which reduces the amount of run-time type checking needed.

    (1-1/1)

    Please register to reply