带逗号的 XSLT 格式编号 [英] XSLT format-number with comma

查看:29
本文介绍了带逗号的 XSLT 格式编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对这个元素和其他元素进行类似的格式化,所以它看起来像这个 2,590:

I'm trying to format this and other elements alike, so it would look like this 2,590:

<Add_Amount>2,59</Add_Amount>

这样做:

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

....

    <xsl:value-of select="translate(format-number(Add_Amount, '#.###,000', 'dkk'), ',', '.')" />

输出结果为 NaN.非常感谢任何帮助.

And the output comes out NaN. Any help is greatly appreciated.

谢谢.

//丹尼尔

推荐答案

使用:

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="/">
   <xsl:value-of select=
   "format-number(translate(., ',','.'), '#.###,000', 'd')"/>
 </xsl:template>
</xsl:stylesheet>

应用于提供的 XML 文档时:

<Add_Amount>2,59</Add_Amount>

产生想要的结果:

2,590

你的代码的问题是 2,59 不是一个有效的数字,必须在将它作为 的第一个参数传递之前转换为这样的数字>format-number().

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆