Reputation: 215
I have this XML:
<table title = "Fuzzy Bunnies">
<tgroup cols = "2">
<tbody>
<colspec colname = "Bunny Name"></colspec>
<colspec colname = "Bunny Traits"></colspec>
<row>
<entry>
Bugs Bunny
</entry>
<entry>
Likes to mess with people. Known for saying "What's up, Doc?"
</entry>
</row>
<row>
<entry>
Easter Bunny
</entry>
<entry>
Brings candy and/or hides eggs on Easter.
</entry>
</row>
<row>
<entry>
Little Bunny Foo Foo
</entry>
<entry>
Used to pick up field mice and bop them on the head. Turned into a goon by the good fairy.
</entry>
</row>
<row>
<entry>
Roger Rabbit
</entry>
<entry>
Toon who was framed.
</entry>
</row>
<row>
<entry>
Peter Rabbit
</entry>
<entry>
Ridiculously cute. Loses his jacket and shoes stealing veggies.
</entry>
</row>
</tbody>
</tgroup>
</table>
and this XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:template match="@*|node()">
<html>
<head>
<style>
body{font-family:Arial;font-size:.95em;}
p{font-family:Arial;font-size:.95em;text-align:left;}
h1{font-size:1.25em;color:Navy;font-weight:bold;}
h2{font-size:1em;}
h3{font-size:.75em;font-weight:bold;}
.caption{font-weight:bold;text-align:center;}
.graphic{text-align:center;}
table{border-collapse:collapse;}
table,th,td{border:1px solid gray;}
th{color:white;background-color:Navy;}
td{font-size:.9em;}
</style>
</head>
<body>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</body>
</html>
</xsl:template>
<xsl:template match = "table">
<table>
<tr>
<th colspan="2">Fuzzy Bunnies</th>
</tr>
<tr>
<th>Bunny Name</th>
<th>Bunny Traits</th>
</tr>
<xsl-apply-templates select = "row"/>
</table>
</xsl:template>
<xsl:template match = "row">
<tr>
<xsl:apply-templates select="entry"/>
</tr>
</xsl:template>
<xsl:template match = "entry">
<td>
<xsl:value-of select ="."/>
</td>
</xsl:template>
</xsl:stylesheet>
I want an HTML table with the headings listed in the template, and each entry in its own cell. When I open the file in Firefox or IE, I get the table header, but no content.
A couple things to note. One, this is a chunk of a larger XML document. The only thing I've cut out of the XSLT is templates for nodes that aren't part of the table. Likewise, for the XML, I've cut it down to just the table. Another is that the XML is formatted based on a standard which I can't change, so any changes need to be to the XSLT.
I have looked at the other table questions and I don't think this is a duplicate.
Upvotes: 0
Views: 932
Reputation: 167571
Well you have very strange patterns and select expression, for instance why do you want to output for all nodes match="@*|node()"
a complete HTML document structure? Usual you want to do that for match="/"
or match="/*"
.
As for the problem, the row
elements are not children of the table
but are nested further down the structure, so doing <xsl-apply-templates select = "row"/>
in the table
template will not process the rows, you need select=".//row"
.
Of course there can be further problems in the part you have "cut out of the XSLT is templates for nodes that aren't part of the table", if there you do not make sure that processing reaches the table
element(s) then the template will never be used.
Upvotes: 1