|
|
Listing A.6 displays the contents of the file bookHTML1.xsl, which demonstrates how to apply an XSL stylesheet to the XML data in book.xml in order to generate an HTML table.
Listing A.6 bookHTML1.xsl
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <html><body> <table border="1"> <tr> <th>Number</th> <th>Length</th> <th>Description</th> </tr> <xsl:apply-templates/> </table> </body></html> </xsl:template> <!-- IMPORTANT: don't include a leading "/" --> <xsl:template match="chapters/chapter"> <xsl:for-each select="."> <tr> <td><xsl:value-of select="./number"/></td> <td><xsl:value-of select="./length"/></td> <td><xsl:value-of select="./desc"/></td> </tr> </xsl:for-each> </xsl:template> <xsl:template match="author|title|desc|appendices"> </xsl:template> </xsl:stylesheet>
|
|