xsl-list
[Top] [All Lists]

RE: [xsl] format decimal numbers issue

2008-03-22 08:53:53

<xsl:variable name="tput">
      <xsl:call-template name="display-dec-sec">
               <xsl:with-param name="value" select="$count 
div $timeSpan * 1000" />
      </xsl:call-template>
 </xsl:variable>

So you call display-dec-sec supplying a number, and you get back a string
representation such as "5.894 s"

<td>
       <xsl:call-template name="display-dec-sec">
               <xsl:with-param name="value" select="$tput" />
       </xsl:call-template>
</td>

Now you're calling display-dec-sec again, only this time you don't supply a
number, you supply a string like "5.894 s".

<xsl:template name="display-dec-sec">
     <xsl:param name="value" />
             <xsl:value-of 
select="format-number($value,'#,.000 s')" />
     </xsl:template>

[xslt] C:\detail.xsl:153: Fatal Error! Cannot convert string "5.894 s"
to a double

format-number will try to convert the supplied value to a number before
formatting it. But it can't convert "5.894 s" to a number because it is
already formatted.

Note: the " s" in the picture is in fact legal. I'm less sure about the
adjacent "," and ".". It's definitely NOT allowed in XSLT 2.0: "A
sub-picture must not contain a grouping-separator-sign adjacent to a
decimal-separator-sign.". In 1.0, it's defined by reference to the JDK 1.1
specification, and there's no copy of that available online any more.

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--