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

Subject: [xsl] questions on "number('+5')"
From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx>
Date: Mon, 30 Aug 2010 11:38:02 +0200

from the XPath 1.0 specification [1] on the value of number() function
applied to a string:
  The number function converts its argument to a number as follows:
    * a string that consists of optional whitespace followed by an
      optional minus sign followed by a Number followed by whitespace
      is converted to the IEEE 754 number that is nearest (according
      to the IEEE 754 round-to-nearest rule) to the mathematical value
      represented by the string; any other string is converted to NaN
  [30]   Number ::= Digits ('.' Digits?)?
                    | '.' Digits
  [31]   Digits ::= [0-9]+

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

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

Two questions:
1) Is it true that XSLT processors returning 5 are non-compliant?
2) Is  the following a good workaround?

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

Here are the stylesheet/XML file used to generate the table:
$ cat number-plus.xml
<?xml-stylesheet href="number-plus.xsl" type="text/xsl"?>
$ cat number-plus.xsl
<xsl:stylesheet version="1.0"
  <xsl:output method="html"/>

  <xsl:template match="/">
    <xsl:value-of select="number('5')"/>
    <xsl:value-of select="number('-5')"/>
    <xsl:value-of select="number('+5')"/>
$ xsltproc number-plus.xsl number-plus.xml

[1] http://www.w3.org/TR/xpath/#function-number

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

Current Thread