xsl-list
[Top] [All Lists]

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

2010-08-30 04:38:17

Hello,

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"?>
<dummy/>
$
$ cat number-plus.xsl
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

  <xsl:output method="html"/>

  <xsl:template match="/">
<html><pre>
    <xsl:text>&#10;number('5')=</xsl:text>
    <xsl:value-of select="number('5')"/>
    <xsl:text>&#10;number('-5')=</xsl:text>
    <xsl:value-of select="number('-5')"/>
    <xsl:text>&#10;number('+5')=</xsl:text>
    <xsl:value-of select="number('+5')"/>
    <xsl:text>&#10;</xsl:text>
</pre></html>
  </xsl:template>
</xsl:stylesheet>
$
$ xsltproc number-plus.xsl number-plus.xml
<html><pre>
number('5')=5
number('-5')=-5
number('+5')=NaN
</pre></html>
$


[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


--~------------------------------------------------------------------
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>