BUG: XSL FormatNumber Function Formats String Data Incorrectly with German Locale (293469)
The information in this article applies to:
- Microsoft XML 2.0
- Microsoft XML 2.5
- Microsoft XML 2.6
- Microsoft XML 3.0
- Microsoft XML 3.0 SP1
This article was previously published under Q293469 SYMPTOMS
When you use the FormatNumber function with the "http://www.w3.org/TR/WD-xsl" namespace, and the computer's regional setting is set to German (Germany), the string data is formatted incorrectly.
For example, when you use the following Extensible Markup Language (XML) data
<amount currency='USD'>2.7</amount>
with the following
<xsl:template match='amount'>
<xsl:eval>formatnumber(this.text, "###,##0.00")</xsl:eval>
</xsl:template>
the output is
27,00
The expected result is 2,70.
CAUSE
The period (.) decimal separator is ignored inside the string data on a computer whose regional setting is set to German (Germany). This causes the data to be formatted incorrectly.
NOTE: If you try to pass in "2,7" on a computer whose regional setting is set to English (United States), the comma (,) decimal separator is ignored.
RESOLUTION
This problem is discussed here for reference purposes only, because the Extensible Stylesheet Language (XSL) FormatNumber function has been superseded by the XSLT format-number function of the new
"http://www.w3.org/1999/XSL/Transform" namespace.
There are two ways to work around this problem:
- Always pass in a numeric value instead of string data to FormatNumber.
- Use the new format-number function with xsl:decimal-format to set the decimal rules, as follows:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html"/> <xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' />
<xsl:template match="/">
<HTML><BODY>
<xsl:apply-templates select='root/amount' />
</BODY></HTML>
</xsl:template>
<xsl:template match='amount'>
<xsl:value-of select="format-number(., '###.###,00', 'european')"/> </xsl:template>
</xsl:stylesheet>
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 10/16/2002 |
---|
Keywords: | kbBug kbDSupport kbMSXMLnosweep KB293469 |
---|
|