Altova Mailing List Archives


Re: XSL format-number error/bug?

From: "Dimitre Novatchev" <dnovatchev@-----.--->
To: NULL
Date: 12/29/2003 12:07:00 PM
"kenny cheng" <anonymous@d...> wrote in message
news:03b601c3cdd8$148b2840$a401280a@p......
> Hi,
>
> I'm testing XSL file. I want to format some numbers if
> they are negative values. But the following code only
> works for literal number. If I apply to a node, the .NET
> XSL will fail. Can anyone give me some hint?
>
> A: working
> <xsl:value-of select="format-number(-
> 12512356.15, '###,##0;(##,##0)')"/>
>
> B: not working
> <xsl:value-of select="format-number(columnA, '###,##0;
> (##,##0)')"/>

I cannot reproduce your problem.

This transformation:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

  <xsl:template match="/">
    <xsl:value-of select=
    "format-number(-12512356.15, '###,##0;(##,##0)')"/>

    <xsl:value-of select=
    "format-number(t/a, '###,##0;(##,##0)')"/>

  </xsl:template>
</xsl:stylesheet>

when applied on this source.xml:

<t>
 <a>-12512356.15</a>
 <a>-12512356.15</a>
</t>

produces this output (without raising any exception):

(1251,2356)(1251,2356)


Most probably in your case:

> B: not working
> <xsl:value-of select="format-number(columnA, '###,##0;
> (##,##0)')"/>

the string value of "columnA" is not a representation of a number.

Check this with a

  '<xsl:value-of select="columnA"/>'

Of course, crashing with an exception in this case is a bug -- other XSLT
processors (e.g. MSXML4 and Saxon) output NaN in this case.


Dimitre Novatchev.
FXSL developer, XML Insider,

http://fxsl.sourceforge.net/ -- the home of FXSL
Resume: http://fxsl.sf.net/DNovatchev/Resume/Res.html


Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.