带逗号的XSLT格式编号 [英] XSLT format-number with comma
本文介绍了带逗号的XSLT格式编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< Add_Amount> ; 2,59< / Add_Amount>
这样做:
< xsl:decimal-format name =dkkdecimal-separator =,grouping-separator =。/>
....
< xsl:value-of select =translate(format-number(Add_Amount,'#。###,000','dkk'),',','。')/ >
并输出NaN。
任何帮助,非常感谢。
谢谢。
// Daniel
解决方案
使用:
format-number(translate(。,',','。'),'#。###,000','d')
此次转换:
< xsl :stylesheet version =1.0
xmlns:xsl =http://www.w3.org/1999/XSL/Transform>
< xsl:output method =text/>
< xsl:decimal-format name =d
decimal-separator =,grouping-separator =。/>
< xsl:template match =/>
format-number(translate(。,',','。'),'#。###,000','d') />
< / xsl:template>
< / xsl:stylesheet>
应用于提供的XML文档:
$ b
< Add_Amount> 2,59< / Add_Amount>
产生想要的结果:
2,590
问题你的代码> 2,59
不是一个有效的数字,必须转换成这样的形式,然后把它作为第一个参数 format-number()
。
I'm trying to format this and other elements alike, so it would look like this 2,590:
<Add_Amount>2,59</Add_Amount>
Doing it like this:
<xsl:decimal-format name="dkk" decimal-separator="," grouping-separator="."/>
....
<xsl:value-of select="translate(format-number(Add_Amount, '#.###,000', 'dkk'), ',', '.')" />
And the output comes out NaN. Any help is greatly appreciated.
Thanks.
//Daniel
解决方案
Use:
format-number(translate(., ',','.'), '#.###,000', 'd')
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:decimal-format name="d"
decimal-separator="," grouping-separator="."/>
<xsl:template match="/">
<xsl:value-of select=
"format-number(translate(., ',','.'), '#.###,000', 'd')"/>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
<Add_Amount>2,59</Add_Amount>
produces the wanted result:
2,590
The problem with your code is that 2,59
isn't a valid number and must be converted to such, before passing this as the first argument of format-number()
.
这篇关于带逗号的XSLT格式编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文