我想将 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/