RE: [xsl] Float values

Subject: RE: [xsl] Float values
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 26 Jan 2004 11:10:26 -0500
A gloss on this: whether 0.00 and 0 are the same depends on whether they are strings or numbers. Compared as strings they are not the same; compared as numbers they are. In XSLT they could be either.

The OP has xsl:if test="TotalPaid=0". child::TotalPaid here is a node set (the set of all child TotalPaid elements of the current node). So you have to know how to compare a node-set to a number; the XPath 1.0 casting rules are invoked for this:

If one object to be compared is a node-set and the other is a number, then the comparison will be true if and only if there is a node in the node-set such that the result of performing the comparison on the number to be compared and on the result of converting the string-value of that node to a number using the number function is true. [XPath 3.4]

0 is a number; the value 0.00 cast to a number is 0; 0 = 0 is true, so that's what we get.

But if you tested "TotalPaid='0'" that would be a test against a string value; the string "0" is not equal to the string "0.00", so it would test as false.


At 11:59 AM 1/25/2004, Kenny wrote:
It would be true. 0.00 and 0 are the same in XSLT.

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Mark
Sent: Sunday, January 25, 2004 11:29 AM
To: XSL-List
Subject: [xsl] Float values

If a value in an xml file (say TotalPaid) was shown as 0.00

Would the following statement in the xslt stylesheet be correct

xsl:if test="TotalPaid=0" be true or false.


"Thus I make my own use of the telegraph, without consulting
the directors, like the sparrows, which I perceive use it
extensively for a perch." -- Thoreau

XSL-List info and archive:

Current Thread