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

六. XSL的过滤和查询

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

 1<xsl:for-each dylan\']\"="" select="\&quot;CATALOG/CD[ARTIST=\'Bob">   
 2  
 3参数的逻辑选择有:   
 4  
 5= (等于)   
 6  
 7=! (不等于)   
 8  
 9&lt;&amp; 小于   
10  
11&gt;&amp; 大于等于 
12
13  
14
15
16和前面同样的例子(cd_catalog_sort.xsl): 
17
18  
19
20
21<?xml version=\'1.0\'?>
22<xsl:stylesheet xmlns:xsl='\"http://www.w3.org/TR/WD-xsl\"'>
23<xsl:template match='\"/\"'>
24<html>
25<body>
26<table bgcolor='\"yellow\"' border='\"2\"'>
27<tr>
28<th>Title</th>
29<th>Artist</th>
30</tr>
31<xsl:for-each dylan\']\"="" select="\&quot;CATALOG/CD[ARTIST=\'Bob">
32<tr>
33<td><xsl:value-of select='\"TITLE\"/'></xsl:value-of></td>
34<td><xsl:value-of select='\"ARTIST\"/'></xsl:value-of></td>
35</tr>
36</xsl:for-each>
37</table>
38</body>
39</html>
40</xsl:template>
41</xsl:stylesheet>
42
43  
44
45
46你可以自己测试一下,看到的结果有什么不同。</xsl:for-each>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus