Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 293469 - Last Review: October 16, 2002 - Revision: 1.1
BUG: XSL FormatNumber Function Formats String Data Incorrectly with German Locale
This article was previously published under Q293469
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
The expected result is 2,70.
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.
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="http://support.microsoft.com">
<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>
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Steps to Reproduce Behavior
- Paste the following code in an XML file, and save the file as Text.xml.
<?xml version="1.0" ?>
<?xml-stylesheet type='text/xsl' href='test.xsl' ?>
<root>
<amount currency='USD'>2.7</amount>
</root>
- Paste the following code in an Extensible Stylesheet Language (XSL) file, and save the file as Test.xsl.
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match='/'>
<html><body>
<xsl:apply-templates select='root/amount' />
</body></html>
</xsl:template>
<xsl:template match='amount'>
<xsl:eval>formatnumber(this.text, "###,##0.00")</xsl:eval>
</xsl:template>
</xsl:stylesheet>
- Change your computer locale to German (Germany). To do this, click Start, point to Settings, point to Control Panel, and click Regional Settings. On the General tab, under Your locale (location), select German (Germany).
- In Microsoft Internet Explorer, open Test.xml.
You see the output as 27,00, which is incorrect.
APPLIES TO
- Microsoft XML Parser 2.0
- Microsoft XML Parser 2.5
- Microsoft XML Parser 2.6
- Microsoft XML Parser 3.0
- Microsoft XML Parser 3.0 Service Pack 1
| kbbug kbfix kbmsxmlnosweep KB293469 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate