|
Subject: [xsl] Cannot compare xs:untypedAtomic to xs:double From: "Jorge . chocolate.camera@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 29 Jul 2015 18:54:28 -0000 |
When comparing numeric values of node attributes to a double, I have
to explicitly convert those attribute values too into a double or else
Saxon complains that I cannot compare an untyped value to a double. It
gets kind of tiring having to do so on each comparison when you are
comparing lots of values a lot of times, and it makes the code less
readable.
I have this tree of nodes:
<root width="10">
<item x="1.0" width="3.5"/>
<item x="6.5" width="1.5"/>
<item x="3.5" width="3.0"/>
</root>
and I want to select items not falling cleanly in either the left or
right half of <root> (the 3rd item being so).
So, being <root> the context node, I try to select those items with:
<xsl:variable name="WIDTH" select="@width" as="xs:double"/>
<xsl:sequence select="item[@x lt $WIDTH div 2 and @x + @width gt
$WIDTH div 2]"/>
but Saxon complains:
> Warning: on line 9 of stylesheet.xsl:
> Comparison of xs:untypedAtomic? to xs:double will fail unless the first operand is empty
> Warning: on line 9 of stylesheet.xsl:
> Comparison of xs:untypedAtomic? to xs:double will fail unless the first operand is empty
> Error on line 9 of stylesheet.xsl:
> XPTY0004: Cannot compare xs:untypedAtomic to xs:double
> in built-in template rule
> Transformation failed: Run-time errors were reported
If I instead convert each attribute value into a double before the comparison:
<xsl:sequence select="item[number(@x) lt $WIDTH div 2 and
number(@x) + number(@width) gt $WIDTH div 2]"/>
I get the expected result.
Considering that the input tree actually is generated some steps above
via an identity copy and stored into a variable, is there a way to
create it so that Saxon does know that those attribute values are
doubles, and therefore not needing to be wrapping each attribute
mention with number() every single time I want to compare numbers?
I am using XSLT 2.0, Saxon-HE 9.2.1.2J.
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] Re: XPath 1.0 challenge: sele, Costello, Roger L. c | Thread | Re: [xsl] Cannot compare xs:untyped, Imsieke, Gerrit, le- |
| Re: [xsl] XPath 1.0 challenge: sele, David Carlisle d.p.c | Date | Re: [xsl] Cannot compare xs:untyped, Imsieke, Gerrit, le- |
| Month |