在XSLT 1.0中将String转换为Integer [英] Convert String to Integer in XSLT 1.0
本文介绍了在XSLT 1.0中将String转换为Integer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将xslt中的字符串值转换为整数值。我使用xslt 1.0,所以我不能使用xslt 2.0中支持的那些功能。
请帮助。
I want to convert a string value in xslt to an integer value. I am using xslt 1.0, so i can't use those functions supported in xslt 2.0. Please help.
推荐答案
添加到jelovirt的答案,您可以使用number()将值转换为数字,然后round(),floor()或ceiling()得到一个整数。
Adding to jelovirt's answer, you can use number() to convert the value to a number, then round(), floor(), or ceiling() to get a whole integer.
示例
<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 -->
这篇关于在XSLT 1.0中将String转换为Integer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文