xslt 中十进制格式的条件选择
我正在尝试根据 XML 的某些信息修改样式表的十进制格式。更准确的是,我有一个像这样的 XML,
<?xml version="1.0" encoding="ISO-8859-1"?>
<REPORT>
<LANGUAGE>2</LANGUAGE>
<MYVALUE>123456.78</MYVALUE>
</REPORT>
如果语言为 2,我试图将十进制格式定义为欧洲格式,否则为默认格式。所以我创建了以下模板,
<xsl:template match="REPORT">
<xsl:if test="$language=2">
<xsl:decimal-format decimal-separator=',' grouping-separator='.' />
</xsl:if>
<xsl:value-of select ="format-number(MYVALUE,'###.###,00')"/>
</xsl:template>
它以欧洲格式或标准格式显示数字。但我收到以下错误
xsl:decimal-format is not allowed in thisposition in the stylesheet!
如果我尝试将十进制格式放在模板之外,则会收到一条消息,指出 sthylsheet 中的此位置不允许使用 xsl:if。如何更改 XML 中的十进制格式?
谢谢 何塞
I'm trying to modify the decimal-format of a stylesheet based on certain information of an XML. More exaclty, I've a XML like this
<?xml version="1.0" encoding="ISO-8859-1"?>
<REPORT>
<LANGUAGE>2</LANGUAGE>
<MYVALUE>123456.78</MYVALUE>
</REPORT>
I'm trying to define the decimal format as european if the language is 2, and default otherwse. So I've created the following template
<xsl:template match="REPORT">
<xsl:if test="$language=2">
<xsl:decimal-format decimal-separator=',' grouping-separator='.' />
</xsl:if>
<xsl:value-of select ="format-number(MYVALUE,'###.###,00')"/>
</xsl:template>
So it shows the number in european format or in standard format. But I'm getting the following error
xsl:decimal-format is not allowed in this position in the stylesheet!
If I try to put the decimal-format outside the template, then I get the message that the xsl:if is not allowed in this position in the sthylsheet. How can I change the decimal-format based in the XML?
Thanks
Jose
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该元素只能在该元素的正下方定义。定义后,您可以在 fromat-number 函数中使用定义的格式。
The element can only defined directly underneat the element. After definition you then can use the defined formats in the fromat-number function.
decimal-format
必须是顶级元素,但是您可以命名它,然后在条件构造中引用该名称,也许像下面这样的内容适合您。decimal-format
must be a top-level element, however you can name it and then refer to the name in a conditional construct, perhaps something like the following will work for you.