打印

[XML教程] xsl简明教程(6)xsl过滤和查询[xml]

xsl简明教程(6)xsl过滤和查询[xml]

六. xsl的过滤和查询

如果我们希望只显示满足一定的条件的xml数据应该怎么做呢?还是上面的例子代码,我们只需要在xsl:for-each元素的select属性中加入参数就可以,类似:

<xsl:for-each select="catalog/cd[artist='bob dylan']">

参数的逻辑选择有:

= (等于)

=! (不等于)

&lt& 小于


&gt& 大于等于


和前面同样的例子(cd_catalog_sort.xsl):


<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/tr/wd-xsl">

<xsl:template match="/">

<html>

<body>

<table border="2" bgcolor="yellow">

<tr>

<th>title</th>

<th>artist</th>

</tr>

<xsl:for-each select="catalog/cd[artist='bob dylan']">

<tr>

<td><xsl:value-of select="title"/></td>

<td><xsl:value-of select="artist"/></td>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>


你可以自己测试一下,看到的结果有什么不同。

TOP

这里有最好的教程!

TOP

返回顶部
AYBlue

Processed in 0.059209 second(s), 7 queries.

当前时区 GMT+8, 现在时间是 2008-11-22 16:52 京ICP备06054220号

清除 Cookies - 联系我们 - 163K.com - Archiver - WAP