I’m just learning XML and XSL, so please bear with me if this is a stupid question. I can’t seem to find an easy answer to this, so I’m assuming I’m making a simple mistake that folks who write guides wouldn’t think to address.
I have the following XML (just a snippet, here), that I lifted from w3c for learning:
<catalog>My CD Collection
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
</catalog>
And then the following XSL:
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="/">
<h2><xsl:value-of select="catalog" /></h2>
</xsl:for-each>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<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>
For some reason, the XSL is not reading the closing h2 tag and it’s not reading the opening table tag, rendering the entire thing into one huge heading.
Try this. First you were outputing the complete catalog element to the header. Other than this you should probably add this :
On the top of your sheet. The output is what you would expect :