This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Working with Scientific Notation
- From: "Michael H. Semcheski" <mhs-list at aylix dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Fri, 04 Oct 2002 14:34:01 -0400
- Subject: Re: [xsl] Working with Scientific Notation
- References: <3D9DBDF3.5090906@aylix.com> <200210041637.RAA31024@penguin.nag.co.uk>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Just to sort of wrap this up, this is the solution I came up (many
thanks to David Carlisle for the real meat of this solution).
The problem was that Excel's ss:Data nodes sometime come in scientific
notation, and sometimes as non-scientific notation numbers.
Here it is, you could easilly call it by doing something like:
<xsl:call-template name="Scientific">
<xsl:with-param name="Num" select="."/>
</xsl:call-template>
It handles the number whether or not the scientific notation is part of
the number.
<xsl:template name="Scientific">
<xsl:param name="Num"/>
<xsl:if test="boolean(number(substring-after($Num,'E')))">
<xsl:call-template name="Scientific_Helper">
<xsl:with-param name="m"
select="substring-before($Num,'E')"/>
<xsl:with-param name="e"
select="substring-after($Num,'E')"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="not(boolean(number(substring-after($Num,'E'))))">
<xsl:value-of select="$Num"/>
</xsl:if>
</xsl:template>
<xsl:template name="Scientific_Helper">
<xsl:param name="m"/>
<xsl:param name="e"/>
<xsl:choose>
<xsl:when test="$e = 0 or not(boolean($e))">
<xsl:value-of select="$m"/>
</xsl:when>
<xsl:when test="$e > 0">
<xsl:call-template name="Scientific_Helper">
<xsl:with-param name="m" select="$m * 10"/>
<xsl:with-param name="e" select="$e - 1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$e < 0">
<xsl:call-template name="Scientific_Helper">
<xsl:with-param name="m" select="$m div 10"/>
<xsl:with-param name="e" select="$e + 1"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list