我的 xslt 中有以下代码块;
<xsl:when test="StatusData/Status/Temperature > 27">
<td bgcolor="#ffaaaa">
<xsl:value-of select="StatusData/Status/Temperature" />
</td>
</xsl:when>
但是您可能会猜到,当值是 34,5 而不是 34.5 时,它被识别为字符串,这使得整数比较变得不可能。我想用 .将是需要 char 替换的解决方案。我的问题是我该怎么做
或者
了解更多有关 XSLT 中的字符串操作的信息会很棒...
最佳答案
有一个translate()
XPath 中的函数:
test="translate(StatusData/Status/Temperature, ",", ".") > 27"
此外,您应该使用 number 函数,它将其参数转换为数字(或 NaN,如果失败):
test="number(translate(StatusData/Status/Temperature, ",", ".")) > 27.0"
见documentation for
translate()
和 documentation for number()
在 w3.org。
关于xslt - 如何在 XSLT 中进行字符串操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/268116/