I am totally new to xml and xsl so I am having some difficulties to make my xml file look the way I wanted it to be. Basically the problem is that the table shows up correctly with all the stuff inside but the contents of the xml are also shown after the table. So i always have a table followed by all the data from xml. And i am testing my xml file on Firefox 16.0.2.
Here is a portion of my xml file.
<root>
<name id = "content_here">
<first> Cathy </first>
<last> Claires </last>
</name>
... more names down here
</root>
and I am trying to display it in a tabular format on Firefox and this is what I did for the xsl file.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="root">
<html>
<body>
<table>
<tr>
<th> id </th>
<th> first name </th>
<th> last name </th>
</tr>
<xsl:for-each select="name">
<tr>
<td> <xsl:value-of select="@id"/> </td>
<td> <xsl:value-of select="first"/> </td>
<td> <xsl:value-of select="last"/> </td>
</tr>
</xsl:for-each>
</table>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Anyone can give me a hint on how to get rid of the extra content after my table? Thank you!
The
xsl:apply-templatesinstruction causes all the node children of your template context (here therootelement) to be slung through the built-in templates. Removing it from your stylesheet should remove the content.Note there’s a better way of doing this though actually using the
xsl:apply-templatesrule.Here
xsl:apply-templatesis used to apply template matching to the children ofrootinside yourtable. When anameelement is matched, atris created. This is generally better practice than usingxsl:for-each.