![]()
Xml文件
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
3 <catalog>
4 <cd>
5 <title>Empire Burlesque</title>
6 <artist>Bob Dylan</artist>
7 <country>USA</country>
8 <company>Columbia</company>
9 <price>10.90</price>
10 <year>1985</year>
11 </cd>
12 <cd>
13 <title>agogo</title>
14 <artist>Jeffary</artist>
15 <country>UK</country>
16 <company>yarmv</company>
17 <price>20.90</price>
18 <year>2005</year>
19 </cd>
20 <cd>
21 <title>China People</title>
22 <artist>1942</artist>
23 <country>China</country>
24 <company>beijin</company>
25 <price>18.90</price>
26 <year>2013</year>
27 </cd>
28 <cd>
29 <title>China People2</title>
30 <artist>1943</artist>
31 <country>China</country>
32 <company>beijin</company>
33 <price>28.90</price>
34 <year>2013</year>
35 </cd>
36 </catalog>
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
3 <xsl:template match="/">
4 <html>
5 <body>
6 <h2>My CD Collection</h2>
7 <table border="1">
8 <tr bgcolor="#9acd32">
9 <th align="left">Title</th>
10 <th align="left">Artist</th>
11 <th align="left">Price</th></tr>
12 <xsl:for-each select="catalog/cd">
13 <xsl:sort select="price"/>
14 <xsl:if test="price>15">
15 <tr>
16 <td><xsl:value-of select="title"/></td>
17
18 <xsl:choose>
19 <xsl:when test="price>25">
20 <td bgcolor="#ff00ff"><xsl:value-of select="artist"/></td></xsl:when>
21 <xsl:when test="20>price">
22 <td bgcolor="#cccccc"><xsl:value-of select="artist"/></td> </xsl:when>
23 <xsl:otherwise>
24 <td><xsl:value-of select="artist"/></td> </xsl:otherwise>
25 </xsl:choose>
26 <td>
27
28 <xsl:value-of select="price"/></td></tr>
29 </xsl:if>
30 </xsl:for-each>
31 </table>
32 </body>
33 </html>
34 </xsl:template>
35
36 </xsl:stylesheet>

帮助文档下载