首页 > Web开发 > 详细

XSL简明教程(6)XSL过滤和查询

时间:2016-02-07 00:24:45      阅读:144      评论:0      收藏:0      [点我收藏+]
原著:Jan Egil Refsnes 翻译:阿捷

六. XSL的过滤和查询


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

<xsl:for-each select="CATALOG/CD[ARTIST=‘Bob Dylan‘]">

参数的逻辑选择有:

= (等于)

=! (不等于)

<& 小于

>& 大于等于


和前面同样的例子(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>


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

XSL简明教程(6)XSL过滤和查询

原文:http://www.jb51.net/article/2350.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!