<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
<td><xsl:value-of select="catalog/cd/title" /></td>
<td><xsl:value-of select="catalog/cd/artist" /></td>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
尝试一下 »

下面的实例循环遍历每个 cd 元素,并创建带有每个 cd 元素的 title 和 artist 的值的表格行:

<?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="/">
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
<xsl:for-each select="catalog/cd">
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>

</xsl:stylesheet>
尝试一下 » XSLT 元素参考手册 XSLT 元素参考手册