I have the following code block in my xslt;
<xsl:when test="StatusData/Status/Temperature > 27">
<td bgcolor="#ffaaaa">
<xsl:value-of select="StatusData/Status/Temperature" />
</td>
</xsl:when>
But as you might guess when the value is 34,5 instead of 34.5 it is recognised as a string which makes integer comparison not possible. I thought replacing , with . would be solution that needs a char replace. My question is how I can do this or It would be great to know more about string operations in XSLT...
XSLT string length is defined as a string function and takes a single string argument and returns an integer value representing the number of characters in the string. It converts any declared type into a string except that an empty parenthesis cannot be converted. The whitespaces are taken into the count.
To see if two elements are the same, XSLT compares their string values using the equals sign ("=").
string-length() Function — Returns the number of characters in the string passed in as the argument to this function. If no argument is specified, the context node is converted to a string and the length of that string is returned.
There is a translate()
function in XPath:
test="translate(StatusData/Status/Temperature, ",", ".") > 27"
Additionally you should make use of the number function, which converts it's argument to a number (or NaN, if that fails):
test="number(translate(StatusData/Status/Temperature, ",", ".")) > 27.0"
See the documentation for translate()
and the documentation for number()
at w3.org.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With