<!-- 
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">

<!-- apparatus processing -->

<!-- apparatus entries in text -->
<xsl:template match="app">
    <xsl:apply-templates/><a href="{concat(concat($appFile,'#'),ancestor::l/@id)}" target="{$rightFrame}"><sup><font size="-1">*</font></sup></a>
</xsl:template>

<xsl:template match="rdg">
	<xsl:if test="contains(@wit,$preferredWitness)">
    	<xsl:apply-templates/>
    </xsl:if>
</xsl:template>

<!-- build apparatus -->
<xsl:template name="appList">
	<center>
		<table width="95%" border="1" cols="1" cellspacing="0">
			<xsl:apply-templates select="//l[descendant::app]" mode="printapp"/>
		</table>
	</center>
</xsl:template>

<xsl:template match="l" mode="printapp">
	<xsl:variable name="targFile">
	    <xsl:call-template name="find-parent"/>
	</xsl:variable>
	<tr>
		<td><a name="{@id}" href="{concat(concat($targFile,'.htm#'),@id)}" target="{$leftFrame}"><xsl:value-of select="substring(@id,2,6)"/></a><br/>
			<ul>
				<xsl:for-each select="descendant::app">
					<li><xsl:apply-templates select="./rdg" mode="printapp"/></li>
				</xsl:for-each>
			</ul>
		</td>
	</tr>
</xsl:template>

<xsl:template match="rdg" mode="printapp">
	<xsl:call-template name="extractWit">
		<xsl:with-param name="lijst" select="@wit"/>
	</xsl:call-template>: 
	<xsl:apply-templates mode="printapp"/>
	<xsl:choose>
		<xsl:when test="following-sibling::rdg">
			<xsl:text>; </xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>.</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<xsl:template name="extractWit">
	<xsl:param name="lijst"/>
	<xsl:variable name="wit" select="substring-before($lijst,' ')"/>
	<xsl:if test="$wit=''">
		<a href="{concat(concat($drukgeschFile,'#'),$lijst)}" target="{$leftFrame}"><xsl:value-of select="$lijst"/></a>
	</xsl:if>
	<xsl:if test="not($wit='')">
		<a href="{concat(concat($drukgeschFile,'#'),$wit)}" target="{$leftFrame}"><xsl:value-of select="$wit"/></a>, 
	</xsl:if>
	<xsl:variable name="lijstrest" select="substring-after($lijst,' ')"/>
	<xsl:if test="string-length($lijstrest)>0">
		<xsl:call-template name="extractWit">
			<xsl:with-param name="lijst" select="$lijstrest"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>

</xsl:stylesheet>
