Click to See Complete Forum and Search --> : XSLT does number() function consider zero as a number?


XSLnewbie
November 24th, 2003, 08:54 PM
When I use the XSLT number() function to check whether a value is a number it correctly identifies text and numbers like 1 through 9 as numbers but it identifies 0 (zero) as Not A Number. This is the case with the Altova (XMLSpy) processor as well as the Microsoft processor. Is this your experience? Can somebody test this with another processor. I thought this was just the way the funtion worked but now I hear that other processors may identify zero as a number, which is the way it should work in my opinion.
Thanks in advance for your help.

khp
November 24th, 2003, 09:48 PM
In Xalan the number function will evaluate the string "0" to the number 0.

According to the xpath 1.0 specification, the number function should work as described by the IEEE 754 standard. I don't happen to have a copy of the IEEE 754 standard specifcation, but I tend to suspect that MS go it wrong again.

XSLnewbie
November 25th, 2003, 12:06 PM
The number function 'confuses' the zero field value with the 1 or 0 result of function test. 1 meaning the field value is a valid number 0 meaning the field value is Not A Number. The number function is correct, the TEST RESULT is wrong.

number(0) doesn't return false. It returns 0. It is the attribute
test="number(0)" that is evaluated as false.

Code it like this below:
<xsl:if test="number(@FieldA) = number(@FieldA)">
...
</xsl:if>

This works because NaN is the only number for which $num = $num is
false

khp
November 25th, 2003, 02:05 PM
I'am sorry, but You are not making much sense to me.

Please post your complete code and your results.