问题
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