Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用<;=和>;=在XSLT中_Xslt_Xpath - Fatal编程技术网

使用<;=和>;=在XSLT中

使用<;=和>;=在XSLT中,xslt,xpath,Xslt,Xpath,比较中的值时,我希望使用=。怎么做 更新: <?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 cla

比较
中的值时,我希望使用
=
。怎么做

更新:

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

每个用户和模块的平均类大小
用户电子邮件
模块代码
平均值

平均值<1-红色
1您可以分别将
转义为

请参见上的
xsl:if
示例


更新:

<?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>
看到你的情况后,我并不惊讶它不起作用

而不是:

1 &lt;= . &lt; 2
  x &lt; y
1 &lt;= . and . &lt; 2 
尝试:


您不能像XSLT中那样链接

除了@Oded的正确答案之外

.1在XSLT中永远不需要转义
操作符。只要写:


.2一个人可以避免逃脱
@Moshin-那么你有另一个问题,请发布你的代码。而不是
1=。2
try
1。和。2
。如果您仍然有问题,请发布一个示例XML输入文档。@Oded:+1回答得好。小提示:您可以“链接”比较运算符,但比较的结果是一个布尔值,该值将隐式转换为数字(0或1),用于下一次比较(除非是相等比较)好问题,+1。参见我的答案,了解如何编写比较而不必逃避
+1个好答案的示例。也可以将其写成
y>x
,而不是
xy
not(x >= y)
1 &lt;= . and . &lt; 2 
2 > . and not(1 > .)