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
In addidtion to @Oded’s correct answer:
.1. There is never any need to escape the
>operator in XSLT. Just write:>.2. One can avoid escaping the
<operator.Instead of:
you can write:
Instead of:
you can write:
.3. In XPath 1.0 the
<and>operators are not defined on strings (only on numbers).Finally, this is actually an XPath 1.0 question.