<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="*">
<xsl:apply-templates />
</xsl:template>


<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="/">
<html>
<head>
<link rel="stylesheet" type="text/css" href="contents.css"/>
<title><xsl:value-of select="//chapter/@name"/> - <xsl:value-of select="//chapter/title"/></title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>

<xsl:template match="contents">
<col style="width:95%" /><col style="width:5%; text-align:right;"/>
<xsl:apply-templates/>

</xsl:template>

<xsl:template match="intro|conclusion">
<table><tr>
<td><h2><xsl:apply-templates select="title"/></h2></td><td><xsl:value-of select="page"/></td>
</tr></table>
</xsl:template>

<xsl:template match="chapter">
<tr>
<td colspan="2"><h2><xsl:value-of select="@name"/> - <xsl:value-of select="title"/></h2></td>
</tr>
<xsl:apply-templates select="sketch" />
<table class="listing">
<col class="col1"/><col class="col2"/>
<xsl:apply-templates select="item" />
</table>
</xsl:template>

<xsl:template match="chapter/item">
<tr>
<td><xsl:apply-templates select="title"/></td>
<td><xsl:value-of select="page"/></td>
</tr>
</xsl:template>

<xsl:template match="sketch">
<table class="sketch">
<col class="col1"/><col class="col2"/>
<xsl:apply-templates select="item" />
</table>
</xsl:template>

<xsl:template match="sketch//item">
<tr>
<td>
<xsl:if test=".[not(title)]">
(Unique category)
</xsl:if>
<xsl:apply-templates select="title"/>
</td><td>
<xsl:if test=".[not(page)]">
<xsl:value-of select="../page"/>
</xsl:if>

<xsl:apply-templates select="page"/>
</td>
<!-- <xsl:if test="item">-->
<td> 
<table>
<col class="col1"/><col class="col2"/>
<xsl:apply-templates select="item" /></table>
</td>
<!-- </xsl:if> -->
</tr>
</xsl:template>

<xsl:template match="sketch//item/title">
<a><xsl:attribute name="href">#<xsl:value-of select="../page"/></xsl:attribute><xsl:apply-templates /></a><xsl:apply-templates select="../note"/>
</xsl:template>

<xsl:template match="chapter/item/title|intro/title|conclusion/title">
<a><xsl:attribute name="name"><xsl:value-of select="../page"/></xsl:attribute></a>
<xsl:apply-templates />
</xsl:template>

<xsl:template match="note">
<div class="note">Note.
<xsl:apply-templates />
</div>
</xsl:template>

</xsl:stylesheet>