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.
Thanks, "number(translate($str, '+',''))" is better since it lets number()
function deal with whitespace.
Mit besten Gruessen / Best wishes,
Hermann Stamm-Wilbrandt
Developer, XML Compiler, L3
WebSphere DataPower SOA Appliances
----------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Martin Jetter
Geschaeftsfuehrung: Dirk Wittkopp
Sitz der Gesellschaft: Boeblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
From: Michael Kay <mike(_at_)saxonica(_dot_)com>
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Date: 08/30/2010 07:44 PM
Subject: Re: [xsl] questions on "number('+5')"
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>
--~--
--~------------------------------------------------------------------
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>
--~--