Subject: [xsl] questions on "number('+5')" From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> Date: Mon, 30 Aug 2010 11:38:02 +0200 |
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> number('5')=</xsl:text> <xsl:value-of select="number('5')"/> <xsl:text> number('-5')=</xsl:text> <xsl:value-of select="number('-5')"/> <xsl:text> number('+5')=</xsl:text> <xsl:value-of select="number('+5')"/> <xsl:text> </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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Why does the addition of , Wolfgang Laun | Thread | Re: [xsl] questions on "number('+5', Hermann Stamm-Wilbra |
RE: [xsl] Xslt protect with passwor, Praveen Chauhan | Date | RE: [xsl] Xslt protect with passwor, jeroen |
Month |