<?xml version='1.0' encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

<!-- 

	tei2html.xsl - an XSLT file to transform a TEI document into XHTML
	
	Eric Lease Morgan (eric_morgan@infomotions.com)
	2008-05-11 - based on a version for the Ticer School
	
-->

<xsl:output 
 method='xml'
 omit-xml-declaration='no'
 indent='yes'
 doctype-public='-//W3C//DTD XHTML 1.0 Transitional//EN' 
 doctype-system='http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' />
 
<xsl:template match='TEI.2'>
 <html>
 
  <head>

   <!-- title tag -->
   <title> 
	<xsl:for-each select="teiHeader/fileDesc/titleStmt/title">
	 <xsl:if test='./@type = "main"'>
	  <xsl:value-of select='.' />
	 </xsl:if>
	</xsl:for-each>
	<xsl:text> / </xsl:text>
	<xsl:for-each select="teiHeader/fileDesc/titleStmt/author/name">
	 <xsl:if test='./@type = "main"'>
	  <xsl:value-of select='.' />
	 </xsl:if>
	</xsl:for-each>
	<xsl:text> </xsl:text>
	<xsl:value-of select="teiHeader/fileDesc/titleStmt/author/dateRange"/>
   </title> 

   <!-- id -->
   <meta>
	<xsl:attribute name='name'>id</xsl:attribute>
	<xsl:attribute name='content'><xsl:value-of select='normalize-space(teiHeader/fileDesc/publicationStmt/idno)' /></xsl:attribute>
   </meta>

   <!-- author -->
   <meta>
	<xsl:attribute name='name'>creator</xsl:attribute>
	<xsl:for-each select="teiHeader/fileDesc/titleStmt/author/name">
	 <xsl:if test='./@type = "main"'>
	  <xsl:attribute name='content'><xsl:value-of select='.' /></xsl:attribute>
	 </xsl:if>
	</xsl:for-each>
   </meta>
  
   <!-- date -->
   <meta>
	<xsl:attribute name='name'>date</xsl:attribute>
	<xsl:attribute name='content'><xsl:value-of select='normalize-space(teiHeader/profileDesc/creation/date)' /></xsl:attribute>
   </meta>

   <!-- publisher -->
   <meta>
	<xsl:attribute name='name'>publisher</xsl:attribute>
	<xsl:attribute name='content'><xsl:value-of select='normalize-space(teiHeader/fileDesc/publicationStmt/publisher)' /></xsl:attribute>
   </meta>

   <!-- source -->
   <meta>
	<xsl:attribute name='name'>source</xsl:attribute>
	<xsl:attribute name='content'>
	 <xsl:for-each select="/TEI.2/teiHeader/fileDesc/sourceDesc/p"><xsl:value-of select='normalize-space(.)'/> </xsl:for-each>
	</xsl:attribute>
   </meta>

   <!-- notes -->
   <xsl:for-each select="/TEI.2/teiHeader/fileDesc/notesStmt/note">
	<xsl:if test='./@type = "description"'>
	 <meta>
	  <xsl:attribute name='name'>description</xsl:attribute>
	  <xsl:attribute name='content'><xsl:value-of select='.' /></xsl:attribute>
	 </meta>
	</xsl:if>
   </xsl:for-each>     

   <!-- rights -->
   <meta>
	<xsl:attribute name='name'>rights</xsl:attribute>
	<xsl:attribute name='content'><xsl:value-of select='normalize-space(teiHeader/fileDesc/publicationStmt/availability/p)' /></xsl:attribute>
   </meta>
   
   <style type='text/css'>
   
	h1, h2, h3, h4, h5, h6 { font-family : sans-serif };

   </style>
   
  </head>
  
  <body style='margin:5%;'>
   
   <!-- "title" page -->
   <h1 style='text-align:center'><xsl:value-of select='teiHeader/fileDesc/titleStmt/title' /></h1>
   <p style='text-align:center'>
	<xsl:text>Originally written/published in </xsl:text>
	<xsl:value-of select='teiHeader/profileDesc/creation/date' />
	<xsl:text> by </xsl:text>
	<xsl:for-each select="teiHeader/fileDesc/titleStmt/author/name">
	 <xsl:if test='./@type = "main"'>
	  <xsl:value-of select='.' />
	 </xsl:if>
	</xsl:for-each>
	<xsl:text> </xsl:text>
	<xsl:value-of select="teiHeader/fileDesc/titleStmt/author/dateRange"/>
   </p>

   <!-- cool table of contents -->
   <xsl:if test='/TEI.2/text/body/div1'>
	<h2>Table of contents</h2>
	<p>
	<xsl:for-each select="/TEI.2/text/body/div1">
	 <a><xsl:attribute name="href">#<xsl:value-of select='./@n' /></xsl:attribute><xsl:value-of select='./head' /></a><br />
	</xsl:for-each>
	</p>
   </xsl:if>
   
   <!-- do the heavy lifting -->
   <xsl:apply-templates/>
   
   <!-- finish up -->
   <hr />
  
   <h2>Colophon</h2>
   <p>This file was originally marked up using the Text Encoding Initiative XML markup language for use for during an XML workshop (<a><xsl:attribute name='href'>http://infomotions.com/musings/xml-in-libraries/</xsl:attribute>http://infomotions.com/musings/xml-in-libraries/</a>) by <xsl:value-of select='teiHeader/fileDesc/titleStmt/respStmt/name'/> on <xsl:value-of select='teiHeader/fileDesc/publicationStmt/date'/> . This file's unique identifier is <xsl:value-of select='teiHeader/fileDesc/publicationStmt/idno'/>. <xsl:value-of select='teiHeader/fileDesc/sourceDesc/p'/>.</p>
  
  </body>
  
 </html>
 
</xsl:template>

<!-- division #1 (div1) -->
<xsl:template match="div1">
 <h2><a><xsl:attribute name="name"><xsl:value-of select='./@n' /></xsl:attribute><xsl:attribute name="id">n<xsl:value-of select='./@n' /></xsl:attribute><xsl:value-of select='./head' /></a></h2>
 <xsl:apply-templates />
</xsl:template>

<!-- division #2 (div2) -->
<xsl:template match="div2">
 <h3><xsl:value-of select='./@type' /><xsl:text> </xsl:text><xsl:value-of select='./@n' /><xsl:text>. </xsl:text><xsl:value-of select='./head' /></h3>
 <xsl:apply-templates />
</xsl:template>

<!-- division #3 (div3) -->
<xsl:template match="div3">
 <h4><xsl:value-of select='./@type' /><xsl:text> </xsl:text><xsl:value-of select='./@n' /><xsl:text>. </xsl:text><xsl:value-of select='./head' /></h4>
 <xsl:apply-templates />
</xsl:template>

<!-- division #4 (div4) -->
<xsl:template match="div4">
 <h5><xsl:value-of select='./@type' /><xsl:text> </xsl:text><xsl:value-of select='./@n' /><xsl:text>. </xsl:text><xsl:value-of select='./head' /></h5>
 <xsl:apply-templates />
</xsl:template>

<!-- division #5 (div5) -->
<xsl:template match="div5">
 <h6><xsl:value-of select='./@type' /><xsl:text> </xsl:text><xsl:value-of select='./@n' /><xsl:text>. </xsl:text><xsl:value-of select='./head' /></h6>
 <xsl:apply-templates />
</xsl:template>

<!-- paragraph (p) -->
<xsl:template match="p">
 <xsl:choose>
 <xsl:when test='./@rend = "right"'>
  <p style='text-align:right'><xsl:apply-templates /></p>
 </xsl:when>
 <xsl:when test='./@rend = "center"'>
  <p style='text-align:center'><xsl:apply-templates /></p>
 </xsl:when>
 <xsl:when test='./@rend = "pre"'>
  <pre><xsl:apply-templates /></pre>
 </xsl:when>
 <xsl:otherwise>
  <p><xsl:apply-templates /></p>
 </xsl:otherwise>
 </xsl:choose>
</xsl:template>

<!-- quote (quote) -->
<xsl:template match="quote">
 <blockquote><xsl:apply-templates /></blockquote>
</xsl:template>

<!-- line group (lg) -->
<xsl:template match="lg">
 <p><xsl:apply-templates /></p>
</xsl:template>

<!-- line (l) -->
<xsl:template match="l">
 <xsl:apply-templates /><br />
</xsl:template>


<!-- do nothing templates -->

<!-- teiheader (do nothing) -->
<xsl:template match="teiHeader" />

<!-- teiheader (do nothing) -->
<xsl:template match="front" />

<!-- teiheader (do nothing) -->
<xsl:template match="back" />

<!-- head (head) -->
<xsl:template match="head" />

</xsl:stylesheet>
