<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:h="http://www.w3.org/1999/xhtml">

  <xsl:output
    method="xml"
    doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
    doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
    indent="yes"
    encoding="iso-8859-1"
    />


  <!-- This is a BAD example that will not work
       See stylesheets like:
       xhtml-toc-ns-numbered.xsl
       xhtml-toc-ns.xsl
       xhtml-toc.xsl
       http://tecfa.unige.ch/guides/xml/examples/xsl-toc/
       -->    

  <xsl:template match="/h:html">
  <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title><xsl:value-of select="h:title"/></title>
    </head>
    <body bgcolor="#FFFFFF">
      <xsl:apply-templates select="h:body"/>
    </body>
  </html>
</xsl:template>

<xsl:template match="h:body">
  <strong><a name="toc">Contents</a></strong>
  <xsl:apply-templates select="h:h1|h:h2" mode="toc"/>
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="h:h1" mode="toc">
  <br/>
  <!-- this will take too much time to compute in Firefox, ok with saxon 
  <xsl:number level="any" from="h:body" count="h:h1"/>
  <xsl:text>. </xsl:text> -->
  <a href="#h1_{generate-id(.)}"><xsl:value-of select="."/></a><br/>
</xsl:template>

<xsl:template match="h:h2" mode="toc">
  <span style="font-size:small;">
    <xsl:text> &#160;&#160;§ </xsl:text>
    <!-- this will take to many resources
    <xsl:number level="any" from="h:body" count="h:h1"/>
    <xsl:text>.</xsl:text>
    <xsl:number level="any" from="h:h1" count="h:h2"/>
    <xsl:text> </xsl:text>
    -->
    <a href="#h2_{generate-id(.)}"><xsl:value-of select="."/></a>
  </span>
</xsl:template>

<xsl:template match="h:h1">
  <h1><a name="h1_{generate-id(.)}"><xsl:value-of select="."/></a> (<a href="#toc">&#171;up</a>)</h1>
</xsl:template>

<xsl:template match="h:h2">
  <h2><a name="h2_{generate-id(.)}"><xsl:value-of select="."/></a> (<a href="#toc">&#171;up</a>)</h2>
</xsl:template>


<xsl:template match="*">
     <xsl:copy>
         <xsl:copy-of select="@*"/>
       <xsl:apply-templates/>
     </xsl:copy>
   </xsl:template>

</xsl:stylesheet>

