我需要XSLT转换来赚钱。
在输入的XML数据中,价格是数字:
<prices>
<price>1234</price>
<price>1234.5</price>
</prices>在XSLT转换之后,我需要输出XML如下(捷克格式):
<prices>
<price>1 234,-</price>
<price>1 234,50</price>
</prices>可以使用XSLT完成吗?非常感谢。
编辑:,我正在使用XSLT2.0。
发布于 2011-11-23 14:25:10
此转换(在XSLT的两个版本中):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:decimal-format
name="Cz1"
grouping-separator=" "
decimal-separator="_"/>
<xsl:decimal-format
name="Cz2"
grouping-separator=" "
decimal-separator=","/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="price/text()">
<xsl:value-of select="format-number(., '# ##0,00', 'Cz2')"/>
</xsl:template>
<xsl:template match="price/text()[. = floor(.)]" priority="3">
<xsl:value-of select="format-number(., '# ##0', 'Cz1')"/>
<xsl:text>,-</xsl:text>
</xsl:template>
</xsl:stylesheet>在提供的XML文档上应用时
<prices>
<price>1234</price>
<price>1234.5</price>
</prices>生成想要的、正确的结果
<prices>
<price>1 234,-</price>
<price>1 234,50</price>
</prices>发布于 2011-11-21 10:58:53
如果样式表有NumberFormat对象的实例,则可以将数字呈现为特定于地区的money String。您可以使用java.text.NumberFormat.getInstance(Locale locale).getCurrencyInstance()获得一个。然后将其添加到样式表中,然后离开。
发布于 2011-11-21 11:45:03
使用http://www.w3.org/TR/xslt20/#format-number,如
<xsl:decimal-format
name="f1"
grouping-separator=" "
decimal-separator=","/>
<xsl:template match="price">
<xsl:copy>
<xsl:value-of select="format-number(., '# ###0,00', 'f1')"/>
</xsl:copy>
</xsl:template>不过,我不知道怎样才能得到那种",-“。
https://stackoverflow.com/questions/8210617
复制相似问题