XSL vs Regionalisation/Internationalization Number Formats

浪尽此生 提交于 2019-12-02 03:53:02

问题


Is there any regionalisation support built into XSL when it comes to formatting numbers?

At present my underlying XML contains numbers in UK/US format, for example 54321.12345. I can do a select sum on this to give me a total in the same format. I can format the number using format-number(54321.12345, '###,###.#####') to give me 54,321.12345.

However when I want this to run on a different region setting on my machine such as Central European countries which have the comma seperator as "." and the decimal seperator as "," I want to format my numbers in this way to give me 54.321,12345.

Is there a nice way to do this in XSL?

Thanks,

Andez


回答1:


From http://www.w3.org/TR/xslt#format-number

The xsl:decimal-format element declares a decimal-format, which controls the interpretation of a format pattern used by the format-number function.

<!-- Category: top-level-element -->
<xsl:decimal-format
  name = qname 
  decimal-separator = char 
  grouping-separator = char 
  infinity = string 
  minus-sign = char 
  NaN = string 
  percent = char 
  per-mille = char 
  zero-digit = char 
  digit = char 
  pattern-separator = char />



回答2:


I now have the following xsl:

<!-- define number format to use -->
<xsl:decimal-format name="european" decimal-separator=',' grouping-separator='.' />

<!-- format the number -->
<xsl:value-of select="format-number(54321.12345,'###.##0,0000', 'european')"/>


来源:https://stackoverflow.com/questions/4625330/xsl-vs-regionalisation-internationalization-number-formats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!