. How to do it? Update:

Using <= and> = in XSLT

I would like to use <=and >=the comparison values <xsl:if test="">. How to do it?

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=". &lt; 1">
            <td style="background-color: red;"><xsl:value-of select="." /></td>
        </xsl:when>

        <xsl:when test="1 &lt;= . &lt; 2">
            <td style="background-color: blue;"><xsl:value-of select="." /></td>
        </xsl:when>

        <xsl:when test="2 &lt;= . &lt; 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
+3
source share
2 answers

In addition to @Oded, the correct answer is :

0.1. You should never escape an operator >in XSLT. Just write:>

0.2. You can avoid exiting the operator< .

Instead:

  x &lt; y

You can write:

not(x >= y)

Instead:

1 &lt;= . and . &lt; 2 

You can write:

2 > . and not(1 > .)

0.3. In XPath 1.0, operators <and are >not defined in strings (only for numbers).

Finally , this is actually a XPath 1.0 question.

+2
source

< > &lt; &gt; .

. xsl:if w3schools.


Update:

, , .

:

1 &lt;= . &lt; 2

Try:

1 &lt;= . and . &lt; 2

< > XSLT.

+4

Source: https://habr.com/ru/post/1777633/


All Articles