I’m having trouble getting XSLT to return just the category values from the XML. Why is lastupdate and path being returned? …and how can I stop this? Thanks in advance.
XML Document
<?xml version="1.0"?>
<categories count="3">
<lastupdate>08/12/2010 12:27</lastupdate>
<path>C:\</path>
<category>Music</category>
<category>News</category>
<category>Sport</category>
</categories>
My XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="categories">
<html>
<body>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<xsl:apply-templates/>
</td>
</tr>
</tbody>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="category">
<a>
<xsl:value-of select="." />
</a>
</xsl:template>
</xsl:stylesheet>
Output HTML
<html>
<body>
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>08/12/2010 12:27C:\
<a>Music</a>
<a>News</a>
<a>Sport</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
In your code you are applying template for all
categories‘ child element nodes. See http://www.w3.org/TR/xslt#built-in-ruleThus you need the following code:
To get desired ouput: