<!DOCTYPE xsl:stylesheet>

<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns="http://www.w3.org/TR/REC-html40">

<xsl:output method="html" indent="yes" encoding="iso-8859-1"/>
<xsl:strip-space elements="*"/>
<xsl:param name='path'>yes</xsl:param>

<xsl:template match='/'>
	<html>
		<xsl:apply-templates/>
	</html>
</xsl:template>

<!-- put title in <title> tag -->
<xsl:template match='teiHeader//titleStmt'>
	<head><title>
		<xsl:for-each select='title'>
			<xsl:apply-templates/>
		</xsl:for-each>
	</title></head>
</xsl:template>

<!-- BEGIN templates -->
<!-- title template -->
<xsl:template name='title'>
	<h2><xsl:value-of select='//titleStmt/title'/></h2>
	<p><xsl:text>Written by </xsl:text><xsl:value-of select='//front/docAuthor'/>
	<xsl:text>, </xsl:text><xsl:value-of select='//front/docDate'/><xsl:text>.</xsl:text>
	<br/><font size="-1"><xsl:value-of select='//publicationStmt'/></font></p>
</xsl:template>

<!-- call templates and stick everything in <body> -->
<xsl:template match='text'>
	<body bgcolor="#FFFFF0">
		<xsl:apply-templates/>
	</body>
</xsl:template>

<!-- put body text in a table, to make it look nice -->
<xsl:template match='body'>
	<center><table width="90%"><tr><td>
		<xsl:call-template name='title'/>
		<xsl:apply-templates/>
	</td></tr></table></center>	
</xsl:template>

<!-- div heads -->
<xsl:template match='div1'>
	<h2><xsl:value-of select='head'/></h2>
	<xsl:apply-templates/>
</xsl:template>

<xsl:template match='div2'>
	<xsl:choose>
		<xsl:when test='(@type="noline")'>
			<h3><xsl:value-of select='head'/></h3>
			<xsl:apply-templates/>
		</xsl:when>
		<xsl:otherwise>
			<h3><xsl:value-of select='head'/></h3>
			<xsl:apply-templates/>
			<hr height="1" width="100" align="left"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- put <p> in <p> -->
<xsl:template match='p'>
	<xsl:choose>
		<xsl:when test='(@rend="indent")'>
			<dl><dd><p><xsl:apply-templates/></p></dd></dl>
		</xsl:when>
		<xsl:otherwise>
			<p><xsl:apply-templates/></p>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- put href tags in -->
<xsl:template match='body//xref'>
	<a href="{unparsed-entity-uri(@doc)}" target="_blank">	
	<!-- <a href="{@url}"> -->	
	<xsl:apply-templates/>
	</a>
</xsl:template>

<!-- internal reference <a href="#foo">-->
<xsl:template match='ref'>
	<xsl:variable name='X'>
		<xsl:value-of select='@target'/>
	</xsl:variable>
	<a href="#{$X}"><xsl:value-of select='.'/></a>
</xsl:template>

<xsl:template match='body//xptr'>
	<a href="{@url}"><xsl:value-of select='@url'/></a>
</xsl:template>

<!-- font changes -->
<xsl:template match='q'>
	<xsl:text>'</xsl:text><xsl:apply-templates/><xsl:text>'</xsl:text>
</xsl:template>
<xsl:template match='emph'>
	<em><xsl:apply-templates/></em>
</xsl:template>
<xsl:template match='hi'>
	<xsl:choose>
		<xsl:when test='(@rend="italics")'>
			<em><xsl:apply-templates/></em>
		</xsl:when>
		<xsl:when test='(@rend="att")'>
			<font color="#000033"><strong><xsl:apply-templates/></strong></font>
		</xsl:when>
		<xsl:otherwise>
			<font color="red"><xsl:apply-templates/></font>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

<!-- <eg> -->
<xsl:template match='eg'>
	<font color="#000033"><pre class="eg"><xsl:apply-templates/></pre></font>
</xsl:template>

<!-- LISTS -->
<xsl:template match='list'>
	<xsl:choose>		
		<xsl:when test='(@type="ordered")'>
			<p><ol>
				<xsl:for-each select='item'>
					<p><li><xsl:apply-templates/></li></p>
				</xsl:for-each>
			</ol></p>
		</xsl:when>	
		<xsl:when test='(@type="bulleted")'>
			<ul>
				<xsl:for-each select='item'>
					<li><xsl:apply-templates/></li>
				</xsl:for-each>
			</ul>
		</xsl:when>
		<xsl:when test='(@type="label")'>
			<ul>
				<xsl:for-each select='item'>
					<li><strong><xsl:value-of select='label'/></strong><xsl:text>: </xsl:text> 
					<xsl:apply-templates/></li><br/>
				</xsl:for-each>
			</ul>
		</xsl:when>
		<xsl:when test='(@type="simple")'>
			<p><dl>
				<xsl:for-each select='item'>
					<dd><xsl:apply-templates/></dd>
				</xsl:for-each>
			</dl></p>
		</xsl:when>
		<!-- not specified -->
		<xsl:otherwise>
			<p><ul>
				<xsl:for-each select='item'>
					<p><li><xsl:apply-templates/></li></p>
				</xsl:for-each>
			</ul></p>
		</xsl:otherwise> 
	</xsl:choose>
</xsl:template>

<!-- tables -->
<xsl:template match='table'>
	<p>
		<table width="90%" cellpadding="5" cellspacing="0" border="1">
			<xsl:apply-templates/>
		</table>
	</p>
</xsl:template>
<xsl:template match='table/row'>
	<tr><xsl:apply-templates/></tr>
</xsl:template>
<xsl:template match='table/row/cell'>
	<td valign="top"><xsl:apply-templates/></td>
</xsl:template>

<!-- gets rid of unwanted stuff -->
<xsl:template match='revisionDesc | notesStmt | profileDesc | sourceDesc | publicationStmt | head | docAuthor | docDate | docTitle | label'>
</xsl:template>

</xsl:stylesheet>
