Subject: Re: [xsl] questions on "number('+5')" From: Hermann Stamm-Wilbrandt <STAMMW@xxxxxxxxxx> Date: Mon, 30 Aug 2010 12:00:46 +0200 |
> 2) Is the following a good workaround? > <xsl:variable name="str" select="'+5'"/> > <xsl:value-of select="number(substring($str,1+starts-with($node,'+')))"/> Sorry, there was a typo in the last line ($node should be $str). And the question should be: Is the following a good workaround for getting 5 as a result on all processors? Probably this is better for being able to deal with white-space: number(substring($str,1+starts-with(normalize-space($str),'+'))) 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: Hermann Stamm-Wilbrandt/Germany/IBM@IBMDE To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Date: 08/30/2010 11:38 AM Subject: [xsl] questions on "number('+5')" 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 -> |
---|---|---|
[xsl] questions on "number('+5')", Hermann Stamm-Wilbra | Thread | Re: [xsl] questions on "number('+5', Michael Kay |
RE: [xsl] Xslt protect with passwor, jeroen | Date | RE: [xsl] Xslt protect with passwor, G. Ken Holman |
Month |