Format numbers in XML using XSLT

瘦欲@ 提交于 2020-01-05 12:11:36

问题


I have one number in my input xml file like this 0.20 but I want to change to 0,20(comma instead of dot) in my output xml file through xslt. How can I format this number? I don't want to use any templates for it.


回答1:


Use format-number($x, '0.00', 'european')

in conjuction with

<xsl:decimal-format name="european" decimal-separator="," grouping-separator="."/>



回答2:


There are different approaches based on which XSLT version you are using.

Assuming you have the value 0.20 in an element as below

<element>0.20</element>

XSLT 1.0 provides a translate() function which allows replacement of the character from within a string using the following statement.

<xsl:value-of select="translate(element,'.',',')" />

XSLT 2.0 provides a replace() function to do the same. However when using XSLT 2.0, it is better to escape the period/dot since dot signifies value of current node and could lead to incorrect interpretations.

<xsl:value-of select="replace(element,'\.',',')" />



回答3:


Why not you give us the example of input like where is the number and which template you use for this? show the XML and XSLT it will easy to understand your problem:

you can normally use replace () if its coming in a tag like: <tag>0.20</tag>

<xsl:value-of select="replace(tag,'\.',','"/>


来源:https://stackoverflow.com/questions/48576454/format-numbers-in-xml-using-xslt

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