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

<xsl:output method="html"
            indent="yes"
            encoding="iso-8859-1"
            media-type="text/html"
            doctype-public="-//W3C//DTD HTML 4.0//EN"/>

<!-- ====================================================================== -->
<!-- Included Stylesheets                                                   -->
<!-- ====================================================================== -->

<xsl:include href="parameter.xsl"/>
<xsl:include href="autotoc.xsl"/>
<xsl:include href="structure.xsl"/>
<xsl:include href="component.xsl"/>
<xsl:include href="transcript.xsl"/>

<!-- ====================================================================== -->
<!-- Strip Element Space                                                    -->
<!-- ====================================================================== -->

<xsl:strip-space elements="*"/>

<!-- ====================================================================== -->
<!-- Define Keys                                                            -->
<!-- ====================================================================== -->

<xsl:key name="div-id" match="div" use="@id"/>
<xsl:key name="p-id" match="p" use="@id"/>
<xsl:key name="note-id" match="note" use="@id"/>

<!-- ====================================================================== -->
<!-- Root Template                                                          -->
<!-- ====================================================================== -->

<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="$doc.view='toc'">
      <xsl:call-template name="toc"/>
    </xsl:when>
    <xsl:when test="$doc.view='bbar'">
      <xsl:call-template name="bbar"/>
    </xsl:when>
    <xsl:when test="$doc.view='text'">
      <xsl:choose>
	<xsl:when test="$chunk.id != '0'">
	  <xsl:call-template name="text"/>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:call-template name="default"/>
	</xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:when test="$doc.view='facsimile'">
      <xsl:call-template name="facsimile"/>
    </xsl:when>
    <xsl:when test="$doc.view='revseq'">
      <xsl:call-template name="revseq"/>
    </xsl:when>
    <xsl:when test="$doc.view='revnarr'">
      <xsl:call-template name="revnarr"/>
    </xsl:when>
    <xsl:when test="$doc.view='note'">
      <xsl:call-template name="note"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="frame"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- ====================================================================== -->
<!-- Frame Template                                                         -->
<!-- ====================================================================== -->

<xsl:template name="frame">
<html>
<head>
<title>The Melville Project</title>
</head>
<frameset cols="15%,*">
  <frameset rows="*,20%">
    <frame>
      <xsl:attribute name="name">toc</xsl:attribute>
      <xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=toc&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/>#X</xsl:attribute>
    </frame>
    <frame>
      <xsl:attribute name="name">bbar</xsl:attribute>
      <xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=bbar&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
    </frame>
  </frameset>
  <xsl:choose>
    <xsl:when test="$text.view='reading'">
      <frameset rows="70%,*">
	<frame>
	  <xsl:attribute name="name">text</xsl:attribute>
	  <xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=text&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
	</frame>
	<frameset cols="50%,*">
	  <frame>
	    <xsl:attribute name="name">revseq</xsl:attribute>
	    <xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=revseq&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/>#X</xsl:attribute>
	  </frame>
	  <frame>
	    <xsl:attribute name="name">revnarr</xsl:attribute>
	    <xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=revnarr&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/>#X</xsl:attribute>
	  </frame>
	</frameset>
      </frameset>
    </xsl:when>
    <xsl:when test="$text.view='facsimile'">
      <frameset cols="50%,*">
      <frame>
	<xsl:attribute name="name">facsimile</xsl:attribute>
	<xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=facsimile&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
      </frame>      <frame>
	<xsl:attribute name="name">text</xsl:attribute>
	<xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=text&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
      </frame>
      </frameset>
    </xsl:when>
    <xsl:otherwise>
      <frame>
	<xsl:attribute name="name">text</xsl:attribute>
	<xsl:attribute name="src"><xsl:value-of select="$doc.path"/>&doc.view=text&text.view=<xsl:value-of select="$text.view"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&revnarr.id=<xsl:value-of select="$revnarr.id"/>&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
      </frame>
    </xsl:otherwise>
  </xsl:choose>
</frameset>
<noframes>
  <h1>Sorry, this browser does not support frames.</h1>
</noframes>
</html>
</xsl:template>

<!-- ====================================================================== -->
<!-- TOC Template                                                           -->
<!-- ====================================================================== -->

<xsl:template name="toc">
  <html>
    <head>
      <title>The Melville Project: TOC</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <xsl:if test="$chunk.id = '0'">
	<a name="X"></a>
      </xsl:if>
      <font color="gray">Table of Contents</font>
      <hr/>
      <xsl:call-template name="autotoc"/>
      <hr/>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Button Bar Template                                                    -->
<!-- ====================================================================== -->

<xsl:template name="bbar">
  <html>
    <head>
      <title>The Melville Project: Button Bar</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <div align="center">
	<xsl:choose>
	  <xsl:when test="$text.view='reading'">
	    <a>
	      <xsl:attribute name="href"><xsl:value-of select="$doc.path"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&text.view=transcription&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
	      <xsl:attribute name="target">_top</xsl:attribute>
	      <img>
		<xsl:attribute name="src"><xsl:value-of select="$icon.path"/>trans.gif</xsl:attribute>
		<xsl:attribute name="border">0</xsl:attribute>
	      </img>
	    </a>
	    <img>
	      <xsl:attribute name="src"><xsl:value-of select="$icon.path"/>d_read.gif</xsl:attribute>
	      <xsl:attribute name="border">0</xsl:attribute>
	    </img>
	    <a>
	      <xsl:attribute name="href"><xsl:value-of select="$doc.path"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&text.view=facsimile&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
	      <xsl:attribute name="target">_top</xsl:attribute>
	      <img>
		<xsl:attribute name="src"><xsl:value-of select="$icon.path"/>fac.gif</xsl:attribute>
		<xsl:attribute name="border">0</xsl:attribute>
	      </img>
	    </a>
	  </xsl:when>
	  <xsl:when test="$text.view='transcription'">
	    <img>
	      <xsl:attribute name="src"><xsl:value-of select="$icon.path"/>d_trans.gif</xsl:attribute>
	      <xsl:attribute name="border">0</xsl:attribute>
	    </img>
	    <a>
	      <xsl:attribute name="href"><xsl:value-of select="$doc.path"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&text.view=reading&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
	      <xsl:attribute name="target">_top</xsl:attribute>
	      <img>
		<xsl:attribute name="src"><xsl:value-of select="$icon.path"/>read.gif</xsl:attribute>
		<xsl:attribute name="border">0</xsl:attribute>
	      </img>
	    </a>
	    <a>
	      <xsl:attribute name="href"><xsl:value-of select="$doc.path"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&text.view=facsimile&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
	      <xsl:attribute name="target">_top</xsl:attribute>
	      <img>
		<xsl:attribute name="src"><xsl:value-of select="$icon.path"/>fac.gif</xsl:attribute>
		<xsl:attribute name="border">0</xsl:attribute>
	      </img>
	    </a>
	  </xsl:when>
	  <xsl:otherwise>
	    <a>
	      <xsl:attribute name="href"><xsl:value-of select="$doc.path"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&text.view=transcription&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
	      <xsl:attribute name="target">_top</xsl:attribute>
	      <img>
		<xsl:attribute name="src"><xsl:value-of select="$icon.path"/>trans.gif</xsl:attribute>
		<xsl:attribute name="border">0</xsl:attribute>
	      </img>
	    </a>
	    <a>
	      <xsl:attribute name="href"><xsl:value-of select="$doc.path"/>&chunk.id=<xsl:value-of select="$chunk.id"/>&text.view=reading&toc.depth=<xsl:value-of select="$toc.depth"/>&toc.id=<xsl:value-of select="$toc.id"/></xsl:attribute>
	      <xsl:attribute name="target">_top</xsl:attribute>
	      <img>
		<xsl:attribute name="src"><xsl:value-of select="$icon.path"/>read.gif</xsl:attribute>
		<xsl:attribute name="border">0</xsl:attribute>
	      </img>
	    </a>
	    <img>
	      <xsl:attribute name="src"><xsl:value-of select="$icon.path"/>d_fac.gif</xsl:attribute>
	      <xsl:attribute name="border">0</xsl:attribute>
	    </img>
	  </xsl:otherwise>
	</xsl:choose>
      </div>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Text Template                                                          -->
<!-- ====================================================================== -->

<xsl:template name="text">
  <html>
    <head>
      <title>The Melville Project: Manuscript Text</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <xsl:call-template name="header"/>
      <xsl:apply-templates select="key('div-id', $chunk.id)"/>
      <xsl:call-template name="footer"/>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Facsimile Template                                                     -->
<!-- ====================================================================== -->

<xsl:template name="facsimile">
  <html>
    <head>
      <title>The Melville Project: Facsimile</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <font color="gray">Facsimile: <i><xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='main']"/>: <xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='sub']"/></i></font>
      <hr/>
      <h3><font color="#990000"><xsl:value-of select="key('div-id', $chunk.id)/head"/></font></h3>
      <div align="center">
	<a>
	  <xsl:attribute name="href">
	    <xsl:value-of select="$image.path"/>
	    <xsl:value-of select="key('div-id', $chunk.id)/@id"/>
	    <xsl:text>.jpg</xsl:text>
	  </xsl:attribute>
	  <xsl:attribute name="target">new</xsl:attribute>
	  <img width="400">
	    <xsl:attribute name="src">
	      <xsl:value-of select="$image.path"/><xsl:value-of select="key('div-id', $chunk.id)/@id"/><xsl:text>.jpg</xsl:text>
	    </xsl:attribute>
	  </img>
	</a>
      </div>
      <hr/>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Revision Sequence Template                                             -->
<!-- ====================================================================== -->

<xsl:template name="revseq">
  <html>
    <head>
      <title>The Melville Project: Revision Sequence</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <xsl:choose>
	<xsl:when test="$revnarr.id = '0'">
	  <a name="X"></a>
	  <hr/>
	  <xsl:apply-templates select="key('div-id', 'revseq')"/>
	</xsl:when>
	<xsl:otherwise>
	  <hr/>
	  <xsl:apply-templates select="key('div-id', 'revseq')"/>
	</xsl:otherwise>
      </xsl:choose>
      <hr/>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Revision Narrative Template                                            -->
<!-- ====================================================================== -->

<xsl:template name="revnarr">
  <html>
    <head>
      <title>The Melville Project: Revision Narrrative</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <xsl:choose>
	<xsl:when test="$revnarr.id = '0'">
	  <a name="X"></a>
	  <hr/>
	  <xsl:apply-templates select="key('div-id', 'revnarr')"/>
	</xsl:when>
	<xsl:otherwise>
	  <hr/>
	  <xsl:apply-templates select="key('div-id', 'revnarr')"/>
	</xsl:otherwise>
      </xsl:choose>
      <hr/>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Note Template                                                          -->
<!-- ====================================================================== -->

<xsl:template name="note">
  <html>
    <head>
      <title>The Melville Project: Note</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <xsl:call-template name="header"/>
      <xsl:apply-templates select="key('note-id', $note.id)" mode="note"/>
      <xsl:call-template name="footer"/>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Default Template                                                       -->
<!-- ====================================================================== -->

<xsl:template name="default">
  <html>
    <head>
      <title>The Melville Project: Default</title>
    </head>
    <body bgcolor="#FFFFEC" link="#990000" alink="#990000" vlink="#663300">
      <hr/>
      <xsl:apply-templates select="//front"/>
      <hr/>
    </body>
  </html>
</xsl:template>

<!-- ====================================================================== -->
<!-- Header and Footer Templates                                            -->
<!-- ====================================================================== -->

<xsl:template name="header">
  <xsl:choose>
    <xsl:when test="$text.view='transcription'">
      <font color="gray">Transcription: <i><xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='main']"/> (<xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='sub']"/>)</i></font>
    </xsl:when>
    <xsl:when test="$text.view='facsimile'">
      <font color="gray">Transcription: <i><xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='main']"/> (<xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='sub']"/>)</i></font>
    </xsl:when>
    <xsl:when test="$text.view='reading'">
      <font color="gray">Reading Text: <i><xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='main']"/> (<xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='sub']"/>)</i></font>
    </xsl:when>
    <xsl:otherwise>
      <font color="gray"><i><xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='main']"/> (<xsl:value-of select="//front/titlePage/docTitle/titlePart[@type='sub']"/>)</i></font>
    </xsl:otherwise>
  </xsl:choose>
  <hr/>
</xsl:template>

<xsl:template name="footer">
  <hr/>
</xsl:template>

</xsl:stylesheet>