I would like to use <= and >= when comparing values in <xsl:if test="">. How to do that?
Update:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1>Average classsize per user and module</h1>
<table border="1">
<tr>
<th>User Email</th>
<th>Module Code</th>
<th>Average Value</th>
</tr>
<xsl:apply-templates select="//classsize" />
</table>
</body>
</html>
</xsl:template>
<xsl:template match="average">
<xsl:choose>
<xsl:when test=". < 1">
<td style="background-color: red;"><xsl:value-of select="." /></td>
</xsl:when>
<xsl:when test="1 <= . < 2">
<td style="background-color: blue;"><xsl:value-of select="." /></td>
</xsl:when>
<xsl:when test="2 <= . < 3">
<td style="background-color: yellow;"><xsl:value-of select="." /></td>
</xsl:when>
<xsl:otherwise>
<td style="background-color: white;"><xsl:value-of select="." /></td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="//classsize">
<tr>
<td><xsl:value-of select="email" /></td>
<td><xsl:value-of select="modulecode" /></td>
<xsl:apply-templates select="average" />
</tr>
</xsl:template>
</xsl:stylesheet>
average < 1 - in red
1 <= average < 2 - in blue
2 <= average < 3 - in yellow
average >= 3 - white
You can escape the < and > to < and >, respectively.
See the example for xsl:if on w3schools.
Update:
After seeing you condition, I am not surprised it doesn't work.
Instead of:
1 <= . < 2
Try:
1 <= . and . < 2
You can't chain the < and > like that in XSLT.
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