开发者

XSL and European format for currency when supplied number value has comma for decimal

开发者 https://www.devze.com 2023-02-05 18:42 出处:网络
The format-number function does not seem to be able to handle a european number for formatting.Is there something I can do to the \"number\" paramter of that function so that it will work?What do Euro

The format-number function does not seem to be able to handle a european number for formatting. Is there something I can do to the "number" paramter of that function so that it will work? What do European programmers do about this?

For example; This code below works where a decimal-format is created with the decimal and grouping separators are defined AND when the "number" parameter of the format-number is provided with a period "." as the initial decimal delimeter.

    <!-- define num开发者_如何学Gober format to use -->
    <xsl:decimal-format 
         name="european" 
         decimal-separator=',' 
         grouping-separator='.' />  
    <!-- format the number -->
    <xsl:value-of select="format-number(1234.56,
                                        '#.##0,00;(#.##0,00)',
                                        'european')"/>

HOWEVER, if the supplied number parameter is already partially euro formatted, a number like 1234,56...where a comma "," is in the number initially rather than a period ".", then the format-number function will return "NaN".

Does anybody have a way to resolve this? Or do you convert the originally supplied number of 1234,56 to 1234.56 so that it will work?

Does anybody know how to solve this issue?


For any numerical data you should use a number format XSLT/XPath recognizes (i.e. the double format of/for XSLT/XPath 1.0 or one of the formats the schema specification defines with XSLT/XPath 2.0) and only format it for the output representation as required. If you have input data in a different format then indeed you need to convert it with string functions first to a format XSLT/XPath accepts e.g. number(translate('1234,56', ',', '.')) as the easiest approach in XPath 1.0 or using relace in XPath 2.0.


The design intention is that XML should represent values such as dates and numbers in "international standard" format, and the presentation should then be localized depending on the preferences of individual users. So format-number is designed to take an "international format" number as input, and produce a "localized number" as output. If the design of your XML doesn't follow that convention, you'll have to convert it "by hand", for example using translate() in XSLT 1.0 or regular expressions in XSLT 2.0.

0

精彩评论

暂无评论...
验证码 换一张
取 消