5

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...

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Thanx a lot.

it works but with one simple modification:

test="number(translate(StatusData/Status/Temperature, ',', '.')) > 27.0"

by the way it is not about XSLT it is about XPath :) good to learn...

Comments

0

In XSL 2 you can also use the full-fledged replace() which even supports regex patterns.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.