使用<;=和>;=在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=". < 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>
每个用户和模块的平均类大小
用户电子邮件
模块代码
平均值
平均值<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=". < 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>
看到你的情况后,我并不惊讶它不起作用
而不是:
1 <= . < 2
x < y
1 <= . and . < 2
尝试:
您不能像XSLT中那样链接
。除了@Oded的正确答案之外:
.1在XSLT中永远不需要转义
操作符。只要写:
.2一个人可以避免逃脱
@Moshin-那么你有另一个问题,请发布你的代码。而不是1=。2
try1。和。2
。如果您仍然有问题,请发布一个示例XML输入文档。@Oded:+1回答得好。小提示:您可以“链接”比较运算符,但比较的结果是一个布尔值,该值将隐式转换为数字(0或1),用于下一次比较(除非是相等比较)好问题,+1。参见我的答案,了解如何编写比较而不必逃避+1个好答案的示例。也可以将其写成y>x
,而不是xy
。
not(x >= y)
1 <= . and . < 2
2 > . and not(1 > .)