Subject: Re: [xsl] Floating point numbers in msxml xslt processor From: "Jagdishwar B" <jagdishwar.beemanati@xxxxxxxxx> Date: Wed, 14 Jun 2006 21:04:14 +0200 |
> is it true that msxml processor does not treat the floating point > numbers (with scientific notation) like 1.234e-3 as numeric values.
yes the same is true of all XSLT1 processors. 1.234e-3 is a syntax error in XPath1 (it is floating point syntax in XPath2)
> my client application uses the msxml (Internet explorer 6). > is there any workaround to make it work.
in pure xslt use substring-after to split on the e and then multiply or divide by 10 the specified number of times.
thanks for the inputs. I managed to get it woking.. (although bit lengthy... as i dint find any other option :)- )
theXML: <root> <elemOne>1.234e-3</elemOne> <elemTwo>200</elemTwo> </root>
theXSL: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="root"> <result> <val> <xsl:call-template name="multiplySciNumWithOther"> <xsl:with-param name="paramOneBase" select="substring-before(elemOne,'e')"/> <xsl:with-param name="paramOnePower" select="substring-after(elemOne,'e')"/> <xsl:with-param name="paramTwo" select="elemTwo"/> </xsl:call-template> </val> </result> </xsl:template> <xsl:template name="multiplySciNumWithOther"> <xsl:param name="paramOneBase" select="0"/> <xsl:param name="paramOnePower" select="0"/> <xsl:param name="paramTwo" select="1"/> <xsl:if test="$paramOnePower > 0"> <xsl:call-template name="multiplySciNumWithOther"> <xsl:with-param name="paramOneBase" select="$paramOneBase * 10"/> <xsl:with-param name="paramOnePower" select="$paramOnePower - 1"/> <xsl:with-param name="paramTwo" select="$paramTwo"/> </xsl:call-template> </xsl:if> <xsl:if test="$paramOnePower < 0"> <xsl:call-template name="multiplySciNumWithOther"> <xsl:with-param name="paramOneBase" select="$paramOneBase div 10"/> <xsl:with-param name="paramOnePower" select="$paramOnePower + 1"/> <xsl:with-param name="paramTwo" select="$paramTwo"/> </xsl:call-template> </xsl:if> <xsl:if test="$paramOnePower = 0"> <xsl:value-of select="$paramOneBase * $paramTwo"/> </xsl:if> </xsl:template> </xsl:stylesheet>
transformedXML: <result> <val>0.24680000000000002</val> </result>
David
-- Kind Regards,
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Floating point numbers in, David Carlisle | Thread | RE: [xsl] Floating point numbers in, Michael Kay |
Re: [xsl] $variable//childNode, andrew welch | Date | [xsl] separating token problems, Sara Mitchell |
Month |