您可以尝试使用translate
和format-number
当您检索RESP。当你显示数据时。
我在想着sg。像这样:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<document>
<xsl:apply-templates select="document/number[1]">
<xsl:with-param name="val" select="0"/>
</xsl:apply-templates>
</document>
</xsl:template>
<xsl:template match="number">
<xsl:param name="val"/>
<xsl:choose>
<xsl:when test="not(following::number)">
<sum>
<xsl:value-of select="format-number($val + translate(./text(),',',''), '###.##')"/>
</sum>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="following::number">
<xsl:with-param name="val" select="$val + translate(./text(),',','')"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
这对于你的输入生成以下的输出:
<?xml version='1.0' encoding='UTF-8' ?>
<document>
<sum>3185.11</sum>
</document>
@rakaszeru:正确的,但要记住隐式的铸造:这'$ VAL +编号(翻译(./文本() ',',''))'与这个'$ val + translate(。,',','')'相同。 – 2011-04-22 16:00:45
谢谢,我会更新我的答案以提高效率(我只是先检查一下)。 – rekaszeru 2011-04-22 16:02:16