<!-- 
XSL stylesheet to format TEI XML documents to HTML

Many basic ideas and many details taken from the stylesheets
written by Sebastian Rahtz. I gratefully reproduce his copyright statement:

 Copyright 1999 Sebastian Rahtz/Oxford University  <sebastian.rahtz@oucs.ox.ac.uk>

 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and any associated documentation files (the
 ``Software''), to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject to
 the following conditions:
 
 The above copyright notice and this permission notice shall be included
 in all copies or substantial portions of the Software.
--> 
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:xt="http://www.jclark.com/xt"
  xmlns:saxon="http://icl.com/saxon"
  extension-element-prefixes="saxon xt">

<!-- global table of contents -->
<xsl:template name="globtoc">
	<h3>Vooraf</h3>
	<div class="subtoc">
		<xsl:apply-templates select="//front" mode="toc"/>
	</div>
	<h3>Tekst</h3>
	<div class="subtoc">
		<xsl:apply-templates select="//body" mode="toc"/>
	</div>
	<h3>Achteraf</h3>
	<div class="subtoc">
		<xsl:apply-templates select="//back" mode="toc"/>
	</div>
</xsl:template>

<xsl:template match="front|body|back" mode="toc">
	<xsl:call-template name="globtocinhoud"/>
</xsl:template>

<xsl:template name="globtocinhoud">
	<ul>
		<xsl:for-each select="child::div">
			<li>
				<xsl:variable name="pointer">
					<xsl:apply-templates mode="xrefheader" select="."/>
				</xsl:variable>
				<a class="subtoc" href="{$pointer}" target="{$leftFrame}"><xsl:apply-templates mode="plain" select="head"/></a>
				<xsl:if test="child::div"> 
					<xsl:call-template name="globtocinhoud"/> 
					<xsl:text></xsl:text> 	
				</xsl:if>
			</li>
		</xsl:for-each>
	</ul>
</xsl:template> 

<!-- chapter table of contents -->
<xsl:template name="subtoc">
	<xsl:if test="child::div">
		<p><span class="subtochead"><xsl:value-of select="$subtocWords"/></span></p>
		<div class="subtoc">
			<xsl:call-template name="subtocinhoud"/>
		</div>
	</xsl:if>
</xsl:template> 

<xsl:template name="subtocinhoud">
	<ul>
		<xsl:for-each select="div">
			<xsl:variable name="innerdent">
				<xsl:apply-templates select="." mode="ident"/>
			</xsl:variable>
			<li>
				<a class="subtoc" href="{concat('#',$innerdent)}">
					<xsl:apply-templates mode="plain" select="head"/>
				</a>
				<xsl:if test="child::div">
					<xsl:call-template name="subtocinhoud"/>
					<xsl:text></xsl:text> 	
				</xsl:if>
			</li>
		</xsl:for-each>
	</ul>
</xsl:template> 

</xsl:stylesheet>
