xsl-list
[Top] [All Lists]

Re: Working with Scientific Notation

2002-10-04 11:34:01
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 &gt; 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 &lt; 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



<Prev in Thread] Current Thread [Next in Thread>