xsl-list
[Top] [All Lists]

Re: [xsl] questions on "number('+5')"

2010-08-30 12:43:54

So "number('+5')" should result in NaN.

In XSLT 1.0, yes, it should. In XSLT 2.0 it should result in the integer 5.
Here is the result of "number('+5')" for different XSLT processors:
Chrome      NaN
DataPower   NaN
Firefox     NaN
IE          NaN
Opera       5
Safari      NaN
saxon       5
xalan       5
xsltproc    NaN

Saxon 9.x correctly reports the result 5. Saxon 6.5.5 correctly reports the result NaN.


Two questions:
1) Is it true that XSLT processors returning 5 are non-compliant?
They are non-compliant with XSLT 1.0, yes.

2) Is  the following a good workaround?

<xsl:variable name="str" select="'+5'"/>
<xsl:value-of select="number(substring($str,1+starts-with($node,'+')))"/>

It depends a bit on the syntax you want to accept and the error checking you want to perform. For many purposes, number(translate($str, '+','')) would work adequately.

Michael Kay
Saxonica

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>