1
我遇到了xslt转换问题。
如何转换数字:“2 402.83”为数字。不幸的是,当我使用功能number(string(.))
时,我得到了NaN。我尝试使用替换函数number(replace(string(.), ' ', ''))
,但它不返回任何内容(js中的例外:未捕获的类型错误:无法在“节点”上执行'appendChild':参数1不是类型'节点')。XSLT将字符串数字与空格转换为数字
我的XML:
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd number="1" price="2 402.82"/>
</catalog>
我的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="catalog/cd">
<xsl:for-each select="@price">
<span>
<xsl:value-of select="number(replace(string(.),' ', ''))" />
</span>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>