简体   繁体   English

在XSLT 1.0中将String转换为Integer

[英]Convert String to Integer in XSLT 1.0

I want to convert a string value in xslt to an integer value. 我想将xslt中的字符串值转换为整数值。 I am using xslt 1.0, so i can't use those functions supported in xslt 2.0. 我使用xslt 1.0,所以我不能使用xslt 2.0中支持的那些功能。 Please help. 请帮忙。

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. 添加到jelovirt的答案,您可以使用number()将值转换为数字,然后使用round(),floor()或ceiling()来获取整数。

Example

<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 does not have an integer data type, only double. XSLT 1.0没有整数数据类型,只有double。 You can use number() to convert a string to a number. 您可以使用number()将字符串转换为数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM