我想将xslt中的字符串值转换为整数值。我正在使用xslt 1.0,所以我不能使用xslt 2.0中支持的那些功能。
请帮忙。

最佳答案

除了jelovirt的答案之外,您还可以使用number()将值转换为数字,然后使用round(),floor()或ceiling()来获得一个整数。


<xsl:variable name="MyValAsText" select="'5.14'"/>
<xsl:value-of select="number($MyValAsText) * 2"/> <!-- This outputs 10.28 -->
<xsl:value-of select="floor($MyValAsText)"/> <!-- outputs 5 -->
<xsl:value-of select="ceiling($MyValAsText)"/> <!-- outputs 6 -->
<xsl:value-of select="round($MyValAsText)"/> <!-- outputs 5 -->

关于string - 在XSLT 1.0中将字符串转换为整数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1265886/

10-13 06:59