<?xml version="1.0" encoding="UTF-8"?>

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


<!-- strip leading and trailing whitespace from all elements ... -->
<xsl:strip-space elements="*"/>

<xsl:param name="expandID">empty</xsl:param>
<xsl:param name="contentID">foo</xsl:param>


<xsl:variable name="elementID" select="$contentID"/>
<xsl:variable name="elementName" select="name(//*[@id = $contentID])"/>
<xsl:variable name="elementType" select="//*[@id = $contentID]/@type"/>

<xsl:output method="html" media-type="text/html"/>

<!-- ******************************************************* -->
<!-- ******************************************************* -->

<!-- root template: controls overall page layout --> 

<xsl:template match="/">
  <tr>
    <td width="25%" valign="top"><!-- cell for TOC -->
      <table border="0" cellspacing="4" cellpadding="0">
        <tr><td><h2>
          <a href="itDecIndex.php">The Decameron</a>
        </h2></td></tr>
        <xsl:apply-templates select="//head" mode="toc"/>
      </table>
    </td>
    <td align="left" valign="top"><!-- cell for main content -->
      <div>
       <xsl:choose>
        <xsl:when test="$elementName = 'div1' and $elementType = 'Day'">
         <xsl:apply-templates select="//*[@id = $contentID]/argument" mode="argument"/>
        </xsl:when>
        <xsl:when test="$elementName = 'div2'">
         <xsl:apply-templates select="//div2[@id = $contentID]" mode="content"/>
        </xsl:when>
        <xsl:when test="$elementName = 'prologue'">
         <xsl:apply-templates select="//prologue"/>
        </xsl:when>
        <xsl:otherwise>
         <xsl:apply-templates select="//epilogue"/>
        </xsl:otherwise>
       </xsl:choose>
      </div>
    </td>
  </tr>
</xsl:template>


<!-- ******************************************************* -->
<!-- ******************************************************* -->


<!-- these two templates control the table of contents -->

<xsl:template match="head" mode="toc">
  <xsl:variable name="parentID" select="parent::*/@id"/>
    <xsl:choose>
      <!-- take unwanted heads out of the picture -->
      <xsl:when test="not(parent::div1) and not(parent::prologue) and not(parent::epilogue)">
      </xsl:when>
      <!-- prologue, epilogue don't need expand values -->
      <xsl:when test="parent::prologue or parent::epilogue">
       <tr height="20">
        <td>
         <p class="toctitle">
          <a class="arrow" href="itDecShowText.php?myID={$parentID}&amp;expand=">
           <xsl:value-of select="."/>
          </a>
         </p>
        </td>
       </tr>
      </xsl:when>
      <xsl:otherwise>
       <xsl:choose>
       <!-- give one head "collapse" param, subheads -->
	<xsl:when test="$expandID = $parentID">
         <tr height="20">
          <td>
           <p class="toctitle">
            <a class="arrow" href="itDecShowText.php?myID={$parentID}&amp;collapse={$parentID}&amp;expand=">
             <xsl:value-of select="."/>
            </a>
           </p>
          </td>
         </tr>
         <xsl:call-template name="subHeads"/>
        </xsl:when>
	<xsl:otherwise>
         <tr height="20">
          <td>
           <p class="toctitle">
            <a class="arrow" href="itDecShowText.php?myID={$parentID}&amp;expand={$parentID}">
             <xsl:value-of select="."/>
            </a>
           </p>
          </td>
         </tr>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
</xsl:template>

<xsl:template name="subHeads">
  <xsl:for-each select="following-sibling::div2">
  <xsl:variable name="parentDivID" select="parent::div1/@id"/>
  <xsl:if test="$expandID = $parentDivID">
    <tr>
      <td height="18" valign="top">
        <p class="thesis">
          &#160;&#160;&#160;&#160;<a class="arrow" href="itDecShowText.php?myID={@id}&amp;expand={$expandID}">
           <xsl:value-of select="child::head"/>
          </a>
        </p>
      </td>
    </tr>
  </xsl:if>
  </xsl:for-each>
</xsl:template>

<!-- ******************************************************* -->
<!-- ******************************************************* -->


<!-- templates for prologue, epilogue -->


<xsl:template match="prologue">
  <xsl:variable name="nextID"><xsl:value-of select="following::div1[@id][position()= 1]/@id"/></xsl:variable>
  <xsl:variable name="nextExpandID" select="$nextID"/>
   <p class="framing">[Voice: author]
   </p>
   <xsl:apply-templates select="preceding-sibling::argument/p" mode="argument"/>
   <xsl:apply-templates mode="content"/>
 <p>
  <a class="singleNav" href="itDecShowText.php?myID={$nextID}&amp;expand={$nextExpandID}">
   <img src="gfx/s_ar_right_navy.gif" alt="next" />
  </a>
 </p>
</xsl:template>

<xsl:template match="epilogue">
   <xsl:apply-templates mode="content"/>
</xsl:template>

<!-- ******************************************************* -->
<!-- ******************************************************* -->


<!-- templates for mode=argument -->


<xsl:template match="argument" mode="argument">
  <xsl:variable name="nextID"><xsl:value-of select="following::div2[@id][position()= 1]/@id"/></xsl:variable>
  <xsl:variable name="nextExpandID"><xsl:value-of select="parent::div1/@id"/></xsl:variable>
 <h2><xsl:value-of select="preceding-sibling::head"/></h2>
 <p class="framing">[Voice: author]
 </p>
  <xsl:apply-templates select="p" mode="argument"/>
 <p>
  <a class="singleNav" href="itDecShowText.php?myID={$nextID}&amp;expand={$nextExpandID}">
   <img src="gfx/s_ar_right_navy.gif" alt="next" />
  </a>
 </p>
</xsl:template>

<xsl:template match="p" mode="argument">
 <p class="framing">
  <xsl:apply-templates mode="content"/>
 </p>
</xsl:template>


<!-- ******************************************************* -->
<!-- ******************************************************* -->


<!-- templates for mode=content -->

<xsl:template match="div2" mode="content">
  <xsl:variable name="nextID"><xsl:value-of select="following-sibling::div2[@id][position()= 1]/@id"/></xsl:variable>
  <xsl:variable name="nextExpandID"><xsl:value-of select="parent::div1/@id"/></xsl:variable>
  <xsl:apply-templates mode="content"/>
 <p>
  <a class="singleNav"
href="itDecShowText.php?myID={$nextID}&amp;expand={$nextExpandID}">
   <img src="gfx/s_ar_right_navy.gif" alt="next" />
  </a>
 </p>
</xsl:template>


<xsl:template match="div3" mode="content">
 <div>
  <xsl:apply-templates mode="content"/>
 </div>
</xsl:template>


<xsl:template match="argument" mode="content">
 <xsl:apply-templates mode="content"/>
</xsl:template>


<xsl:template match="head" mode="content">
 <h2>
  <xsl:apply-templates mode="content"/>
 </h2>
</xsl:template>


<xsl:template match="p" mode="content">
 <xsl:variable name="voice" select="ancestor::*[@who][position()= 1]/@who"/>
  <xsl:choose>
   <xsl:when test="parent::argument">
    <p>
     <span class="framing">[Voice: author]</span><br/>
      <em><xsl:apply-templates mode="content"/></em>
    </p>
   </xsl:when>
   <xsl:otherwise>
    <p>
     <span class="framing">[Voice: <xsl:value-of select="$voice"/>]</span><br/>
      <xsl:apply-templates mode="content"/>
     </p>
   </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<xsl:template match="lg" mode="content">
 <p>
  <xsl:if test="position()= 1">
   <span class="framing">[Voice: <xsl:value-of select="parent::div3/@who"/>]</span><br/>
  </xsl:if>
  <xsl:apply-templates mode="content"/>
 </p>
</xsl:template>


<xsl:template match="l" mode="content">
 <xsl:apply-templates mode="content"/>
 <br/>
</xsl:template>

<xsl:template match="q" mode="content">
 <xsl:text>"</xsl:text><xsl:apply-templates mode="content"/><xsl:text>"</xsl:text>
</xsl:template>

<xsl:template match="title" mode="content">
 <em>
  <xsl:apply-templates mode="content"/>
 </em>
</xsl:template>

<xsl:template match="milestone" mode="content">
 <xsl:variable name="ancestorID" select="ancestor::*[@id][1]/@id"/>
 <xsl:variable name="selfID" select="@id"/>
 <a href="showEngTrans.php?myID={@id}&amp;back={$ancestorID}&amp;expand={$expandID}">[<xsl:value-of select="substring($selfID, 7, 3)"/>]
 </a>
</xsl:template>


<!-- ******************************************************* -->
<!-- ******************************************************* -->



<!-- COMMENTED OUT





 -->

</xsl:stylesheet>

