xsltlife
xsltlife

Reputation: 163

How to use greater than and lower than in xslt

I want to use this for logic. my logic is If the wind speed is >4 and ≤15, then use the graphic. How can I use xslt for >4 and ≤15.

Tried code:

<xsl:when test="td[7] > 4 -and- td[7] ">

I am using XSLT 2.0

Upvotes: 1

Views: 2432

Answers (1)

freefaller
freefaller

Reputation: 19953

Instead of < and >, use &lt; and &gt;...

<xsl:when test="td[7] &gt; 4 and td[7] &lt;= 15">...</xsl:when>

Notice how I put the = straight after the &lt; to replicate <=


As per the comment by @TimC, the only one you have to escape is the < to &lt;.

The > can be left as is, but my preference is to change both for consistency.


As per the comment by @MichaelKay, XPath 2.0 allow you to use just lt and gt...

<xsl:when test="td[7] gt 4 and td[7] lt= 15">...</xsl:when>

And he also notes that another way of writing the same thing, but still using >...

<xsl:when test="15 >= td[7] and td[7] > 4">...</xsl:when>

Upvotes: 4

Related Questions