<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" exclude-result-prefixes="tei"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0">
   <xsl:output method="html" version="4.01" encoding="utf-8" indent="no"
      doctype-system="http://www.w3.org/TR/html4/strict.dtd"
      doctype-public="-//W3C//DTD HTML 4.01//EN"/>

   <xsl:strip-space elements="tei:app tei:choice"/>

   <xsl:include href="samples-optionlists.xsl"/>

   <xsl:variable name="docType">
      <!-- used to assign javascript for showing XML -->
      <xsl:choose>
         <xsl:when test="//tei:titleStmt[contains(tei:title, 'Witness #')]">discrete</xsl:when>
         <xsl:when
            test="/descendant::tei:div[@type eq 'poem'] or /descendant::tei:lg[@type eq 'poem']"
            >poem</xsl:when>
         <xsl:otherwise>other</xsl:otherwise>
      </xsl:choose>
   </xsl:variable>

   <xsl:variable name="homePage">../GHCWhome.html</xsl:variable>

   <xsl:variable name="contentsPage">../FrontandBackMatter/contents.html</xsl:variable>

   <xsl:variable name="vmLogo">../vm-images/poweredby.gif</xsl:variable>

   <xsl:variable name="cssInclude">../src/samples.css</xsl:variable>

   <xsl:variable name="search-URL">/search.xqy</xsl:variable>

   <!-- The JavaScript include file. Keep in mind that, as of April 1, 2008,
   the current beta version of Firefox 3.0 has instituted strong JavaScript
   security policies that prevent the inclusion of any JS files from outside
   of the current directory when loading a document from the local filesystem
   (i.e., anything on your local computer not beginning with "http://").
   Because of this, if you want to use the VM offline, you will need to
   move the JavaScript includes into the same directory as your TEI documents,
   and modify the filename below (for example, "../src/samples.js" becomes
   "samples.js") -->
   <xsl:variable name="jsInclude">../src/samples.js</xsl:variable>
   <!-- edited by Theodore Koterwas 21/04/2011: set a Fvariable panZoomImage
        and javascript includes for adding pan and zoom functionality via OpenLayers
   -->
   <xsl:variable name="panZoomImage">true</xsl:variable>
   <xsl:variable name="OpenLayersInclude">../src/OpenLayers.js</xsl:variable>
   <xsl:variable name="panZoomImageInclude">../src/panZoomImage.js</xsl:variable>
   <!-- end Theodore Koterwas edit -->

   <xsl:variable name="initialVersions">1</xsl:variable>

   <!-- To change the VM so that the bibliographic information page does not
   appear at the initial load, change "true" to "false" below -->
   <xsl:variable name="displayBibInfo">false</xsl:variable>

   <!-- To change the VM so that line numbers are hidden by default, change
  "true" to "false" below -->
   <xsl:variable name="displayLineNumbers">false</xsl:variable>

   <!-- To change the VM's default method of displaying notes, modify the
   following variable:
      - popup: Popup footnote icons
      - inline: Inline note viewer panel
      - none: hide notes
   -->
   <xsl:variable name="notesFormat">none</xsl:variable>

   <xsl:variable name="fullTitle">
      <xsl:choose>
         <xsl:when test="//tei:titleStmt/tei:title != ''">
            <xsl:value-of select="//tei:titleStmt/tei:title"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>No title specified</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:variable>

   <xsl:variable name="truncatedTitle">
      <xsl:call-template name="truncateText">
         <xsl:with-param name="string" select="$fullTitle"/>
         <xsl:with-param name="length" select="40"/>
      </xsl:call-template>
   </xsl:variable>

   <xsl:variable name="witnesses" select="//tei:witness[@xml:id]"/>

   <xsl:variable name="numWitnesses" select="count($witnesses)"/>

   <xsl:template match="/">
      <html lang="en">
         <xsl:call-template name="htmlHead"/>
         <body onload="init();">
            <xsl:if test="
                  $docType = ('discrete',
                  'poem')">
               <xsl:attribute name="class">
                  <xsl:value-of select="$docType"/>
               </xsl:attribute>
            </xsl:if>
            <xsl:call-template name="mainBanner"/>
            <xsl:call-template name="manuscriptArea"/>
            <xsl:call-template name="imageViewer"/>
            <!-- <p>There are <xsl:value-of select="count($witnesses)" /> witnesses.</p> -->

         </body>
      </html>
   </xsl:template>

   <xsl:template name="htmlHead">
      <head>
         <title>
            <xsl:value-of select="$truncatedTitle"/>
            <xsl:text/>
         </title>
         <link rel="stylesheet" type="text/css">
            <xsl:attribute name="href">
               <xsl:value-of select="$cssInclude"/>
            </xsl:attribute>
         </link>
         <script type="text/javascript">
            <xsl:attribute name="src">
               <xsl:value-of select="$jsInclude"/>
             </xsl:attribute>
         </script>

         <!-- edited by Theodore Koterwas 21/04/2011: test panZoomImage
              and include the appropriate javascript
         -->
         <xsl:if test="$panZoomImage = 'true'">
            <script type="text/javascript">
               <xsl:attribute name="src">
                  <xsl:value-of select="$OpenLayersInclude"/>
               </xsl:attribute>
            </script>
            <script type="text/javascript">
               <xsl:attribute name="src">
                  <xsl:value-of select="$panZoomImageInclude"/>
               </xsl:attribute>
            </script>
         </xsl:if>
         <!-- end Theodore Koterwas edit -->
         <script type="text/javascript">
                function showxml(url) {
                    doc = window.open(url, "XML", "resizable=yes,scrollbars=yes,location=no,width=960,height=800");
                    doc.focus();
                }</script>
         <script type="text/javascript">
                function showxml - raw(url) {
                    doc = window.open(url, "XML", "resizable=yes,scrollbars=yes,location=no,width=960,height=800");
                    doc.focus();
                }</script>
         <script type="text/javascript">
            <xsl:call-template name="jsWitnessArray"/>
         </script>
      </head>
   </xsl:template>

   <xsl:template name="jsWitnessArray"> var witnesses = new Array(); <xsl:for-each
         select="$witnesses">
         <xsl:variable name="witID" select="@xml:id"/> witnesses["<xsl:value-of select="$witID"/>"]
         = "<xsl:for-each select="ancestor::tei:listWit[@xml:id]">
            <xsl:value-of select="@xml:id"/>
            <xsl:text>;</xsl:text>
         </xsl:for-each>
         <xsl:value-of select="$witID"/>"; </xsl:for-each> var maxPanels = <xsl:value-of
         select="$numWitnesses"/>; </xsl:template>

   <xsl:template name="mainBanner">
      <!-- Project title added by R. Whalen, 4/1/2008. 
      <div id="mainBannerTitle">
         The Digital Temple
      </div>

      <div>
         <font color="green">Parallel View of Williams MS. Jones B62 (#w), Bod. MS. Tanner 307 (#b),
            and the 1633 <i>Temple</i> (#p)</font>
      </div>
      Removed by Theodore Koterwas 19/4/2011 - moved to templates and added with call-template -->
      <div id="mainBanner">
         <!--added by Theodore Koterwas 19/4/2011 -->
         <xsl:call-template name="mainHeading"/>
         <!-- end added by Theodore Koterwas 19/4/2011 -->
         <!-- VM4 logo dropped 12/14/2012 -->
         <!--<xsl:call-template name="brandingLogo"/>-->
         <xsl:call-template name="headline"/>
         <xsl:call-template name="mainControls"/>
      </div>
   </xsl:template>

   <xsl:template name="mainHeading">
      <div id="mainHeading">
         <div id="mainHeadingTitle">Complete Works Digital Archive</div>
         <br/>&#8195;&#8195;&#8195; &#8226; <!-- <a>
            <xsl:attribute name="href">
               <xsl:value-of select="$contentsPage"/>
            </xsl:attribute>
            <xsl:text>General Contents</xsl:text>
         </a><br/> &#8195;&#8195;&#8195; &#8226; -->
         <a>
            <xsl:attribute name="href">
               <xsl:value-of select="$homePage"/>
            </xsl:attribute>
            <xsl:text>CWDA Home</xsl:text>
         </a>
      </div>
   </xsl:template>

   <xsl:template name="headline">
      <xsl:variable name="XML-file" select="replace(base-uri(.), '.*/', '')"/>
      <xsl:variable name="showXML-type">
         <xsl:choose>
            <xsl:when test="$docType eq 'poem'">showxml</xsl:when>
            <xsl:otherwise>showxml-raw</xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="showXML" select="$XML-file"/>
      <div id="headline">
         <xsl:value-of select="$truncatedTitle"/>
         <span class="versionCount">
            <xsl:text> has </xsl:text>
            <xsl:value-of select="$numWitnesses - 0"/>
            <xsl:text> versions</xsl:text>
         </span>
         <xsl:text> (</xsl:text>
         <a href="{$showXML}" target="dynamic" style="text-decoration:none">see TEI-XML</a>
         <xsl:text>)</xsl:text>
      </div>
   </xsl:template>

   <xsl:template name="mainControls">
      <!-- HERE DS: Call templates in the optionlist include file -->
      <xsl:variable name="filename"
         select="concat(replace(base-uri(.), '.*/(.*)\.xml', '$1'), '.html')"/>
      <!--<xsl:message>File: <xsl:value-of select="$filename"/></xsl:message>-->
      <div id="contentsTables">
         <p style="font-variant:small-caps; font-weight:bold; font-size:110%;">Table of Contents</p>
         <p>
            <xsl:apply-templates select="$linearForm/*" mode="options">
               <xsl:with-param name="URL" select="$filename" tunnel="yes"/>
            </xsl:apply-templates>
         </p>
         <!--<p>
            <xsl:apply-templates select="$alphaForm/*" mode="options">
               <xsl:with-param name="URL" select="$filename" tunnel="yes"/>
            </xsl:apply-templates>
         </p>
         <p>
            <xsl:apply-templates select="$englishLinearForm/*" mode="options">
               <xsl:with-param name="URL" select="$filename" tunnel="yes"/>
            </xsl:apply-templates>
         </p>
         <p>
            <xsl:apply-templates select="$englishAlphaForm/*" mode="options">
               <xsl:with-param name="URL" select="$filename" tunnel="yes"/>
            </xsl:apply-templates>
         </p>
           <p>
            <xsl:apply-templates select="$firstLineForm/*" mode="options">
               <xsl:with-param name="URL" select="$filename" tunnel="yes"/>
            </xsl:apply-templates>
         </p>-->
      </div>
      <div id="mainControls">
         <input type="button" id="newPanel" value="Add Witness" onclick="openPanel();"
            style="font-family:Times New Roman;"/>
         <!-- <input type="button" id="bibToggle" value="Bibliographic Info" onclick="toggleBiblio();" />
            &#8226; removed by R. Whalen, 4/1/2008. -->
         <!-- <input type="button" id="helpToggle" value="Help Viewer" onclick="toggleHelp();" />
            &#8226; removed by R. Whalen, 4/1/2008. -->
         <label for="toggleLineNumbers"> Verse line numbers:</label>
         <input type="checkbox" id="toggleLineNumbers" onclick="toggleLineNumbers(this.checked);">
            <xsl:if test="$displayLineNumbers != 'false'">
               <xsl:attribute name="checked">checked</xsl:attribute>
            </xsl:if>
         </input>

         <!--  Notes:<select id="notesMenu">
            <xsl:choose>
               <xsl:when test="//tei:body//tei:note[not(@type = 'image')]">
                  <xsl:attribute name="onchange">
                     <xsl:text>notesFormat(this.value);</xsl:text>
                  </xsl:attribute>
                  <option value="popup">
                     <xsl:if test="$notesFormat = 'popup'">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                     </xsl:if>
                     <xsl:text>Popup notes</xsl:text>
                  </option>
                  <option value="inline">
                     <xsl:if test="$notesFormat = 'inline'">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                     </xsl:if>
                     <xsl:text>Inline notes</xsl:text>
                  </option>
                  <option value="none">
                     <xsl:if test="$notesFormat = 'none'">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                     </xsl:if> Hide notes </option>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:attribute name="disabled">
                     <xsl:text>disabled</xsl:text>
                  </xsl:attribute>
                  <option>No notes found</option>
               </xsl:otherwise>
            </xsl:choose>
         </select> -->
         <!-- <xsl:text>&#160;•&#160;</xsl:text>
         <input type="button" id="search" value="Search"
            onclick="window.location.href='{$search-URL}';"/>  -->
      </div>
   </xsl:template>

   <xsl:template name="manuscriptArea">
      <div id="mssArea">
         <xsl:apply-templates select="/tei:TEI/tei:teiHeader/tei:fileDesc"/>
         <xsl:call-template name="manuscriptPanel">
            <xsl:with-param name="increment" select="'1'"/>
         </xsl:call-template>
         <xsl:call-template name="notesPanel"/>
      </div>
   </xsl:template>

   <xsl:template name="manuscriptPanel">
      <xsl:param name="increment"/>
      <div class="panel mssPanel">
         <div class="panelBanner">
            <img class="closePanel" onclick="closePanel(this.parentNode.parentNode);"
               src="../vm-images/closePanel.gif" alt="X"/>
            <xsl:text>Witness </xsl:text>
            <select class="witnessMenu"
               onchange="changeWitness(this.value,this.parentNode.parentNode);">
               <xsl:for-each select="//tei:witness[not(@xml:id = 'hutch')]">
                  <option>
                     <xsl:if test="position() = number($increment)">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                     </xsl:if>
                     <xsl:attribute name="value">
                        <xsl:value-of select="@xml:id"/>
                     </xsl:attribute>
                     <xsl:value-of select="position()"/>
                     <xsl:text>: </xsl:text>
                     <xsl:choose>
                        <xsl:when test="@xml:id = 'edition'">
                           <xsl:value-of select="@xml:id"/>
                           <xsl:text> (copy text: </xsl:text>
                           <xsl:value-of select="@corresp"/>
                           <xsl:text>)</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:text>#</xsl:text>
                           <xsl:value-of select="@xml:id"/>
                        </xsl:otherwise>
                     </xsl:choose>
                  </option>
               </xsl:for-each>
            </select>
         </div>
         <div class="mssContent">
            <xsl:for-each select="$witnesses">
               <xsl:variable name="witID" select="@xml:id"/>
               <xsl:for-each
                  select="//tei:note[@type = 'image']/tei:witDetail[@target = concat('#', $witID)]//tei:graphic[@url]">
                  <xsl:call-template name="imageLink">
                     <xsl:with-param name="imageURL" select="@url"/>
                     <xsl:with-param name="witness"
                        select="translate(ancestor::tei:witDetail/@wit, '#', '')"/>
                  </xsl:call-template>
               </xsl:for-each>
            </xsl:for-each>
            <xsl:apply-templates select="//tei:body"/>
         </div>
      </div>
      <xsl:if test="$increment &lt; $initialVersions">
         <xsl:call-template name="manuscriptPanel">
            <xsl:with-param name="increment" select="number($increment) + 2"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>


   <xsl:template match="/tei:TEI/tei:teiHeader/tei:fileDesc">
      <div class="panel" id="bibPanel">
         <xsl:if test="$displayBibInfo != 'true'">
            <xsl:attribute name="style">
               <xsl:text>display: none;</xsl:text>
            </xsl:attribute>
         </xsl:if>
         <div class="panelBanner">
            <img class="closePanel" onclick="toggleBiblio();" alt="X"
               src="../vm-images/closePanel.gif"/> Bibliographic Information </div>
         <div class="bibContent">
            <h2>
               <xsl:value-of select="$fullTitle"/>
            </h2>
            <xsl:if test="tei:titleStmt/tei:author">
               <h3> by <xsl:value-of select="tei:titleStmt/tei:author"/>
               </h3>
            </xsl:if>
            <!-- Removed by R. Whalen, 10/13/10. <xsl:if test="tei:sourceDesc">
               <h4>Original Source</h4>
               <xsl:apply-templates select="tei:sourceDesc"/>
               </xsl:if> -->
            <h4>Witness List</h4>
            <ul>
               <xsl:for-each select="$witnesses">
                  <li>
                     <strong>
                        <xsl:text>Witness </xsl:text>
                        <xsl:value-of select="@xml:id"/>
                        <xsl:text>:</xsl:text>
                     </strong>
                     <xsl:text> </xsl:text>
                     <xsl:value-of select="."/>
                  </li>
               </xsl:for-each>
            </ul>
            <xsl:if test="tei:notesStmt/tei:note[@anchored = 'true' and not(@type = 'image')]">
               <h4>Notes</h4>
               <xsl:for-each
                  select="tei:notesStmt/tei:note[@anchored = 'true' and not(@type = 'image')]">
                  <div class="note">
                     <xsl:if test="@type">
                        <em class="label">
                           <xsl:value-of select="@type"/>
                           <xsl:text>:</xsl:text>
                        </em>
                        <xsl:text> </xsl:text>
                     </xsl:if>
                     <xsl:apply-templates/>
                     <xsl:if test="position() != last()">
                        <hr/>
                     </xsl:if>
                  </div>
               </xsl:for-each>
            </xsl:if>
            <!--Removed by R. Whalen, 10/13/10.  <h4>Electronic Edition Information:</h4> -->
            <xsl:if test="tei:titleStmt/tei:respStmt">
               <h5>Responsibility Statement:</h5>
               <ul>
                  <xsl:for-each select="tei:titleStmt/tei:respStmt">
                     <li>
                        <xsl:value-of
                           select="concat(translate(substring(tei:resp, 1, 1), 'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), substring(tei:resp, 2, string-length(tei:resp)))"/>
                        <xsl:for-each select="tei:name | tei:persName | tei:orgName | tei:other">
                           <xsl:text> </xsl:text>
                           <xsl:value-of select="."/>
                           <xsl:choose>
                              <xsl:when test="position() = last()"/>
                              <xsl:when test="position() = last() - 1">
                                 <xsl:if test="last() > 2">
                                    <xsl:text>,</xsl:text>
                                 </xsl:if>
                                 <xsl:text> and </xsl:text>
                              </xsl:when>
                              <xsl:otherwise>
                                 <xsl:text>, </xsl:text>
                              </xsl:otherwise>
                           </xsl:choose>
                        </xsl:for-each>
                     </li>
                  </xsl:for-each>
                  <xsl:if test="tei:titleStmt/tei:sponsor">
                     <li>
                        <xsl:text>Sponsored by </xsl:text>
                        <xsl:for-each
                           select="tei:titleStmt/tei:sponsor/tei:orgName | tei:titleStmt/tei:sponsor/tei:persName | tei:titleStmt/tei:sponsor/tei:name | tei:titleStmt/tei:sponsor/tei:other">
                           <xsl:apply-templates select="."/>
                           <xsl:choose>
                              <xsl:when test="position() = last()"/>
                              <xsl:when test="position() = last() - 1">
                                 <xsl:if test="last() > 2">
                                    <xsl:text>,</xsl:text>
                                 </xsl:if>
                                 <xsl:text> and </xsl:text>
                              </xsl:when>
                              <xsl:otherwise>
                                 <xsl:text>, </xsl:text>
                              </xsl:otherwise>
                           </xsl:choose>
                        </xsl:for-each>
                     </li>
                  </xsl:if>
                  <xsl:if test="tei:titleStmt/tei:funder">
                     <li>
                        <xsl:text>Funding provided by </xsl:text>
                        <xsl:for-each
                           select="tei:titleStmt/tei:funder/tei:orgName | tei:titleStmt/tei:funder/tei:persName | tei:titleStmt/tei:funder/tei:name | tei:titleStmt/tei:funder/tei:other">
                           <xsl:apply-templates select="."/>
                           <xsl:choose>
                              <xsl:when test="position() = last()"/>
                              <xsl:when test="position() = last() - 1">
                                 <xsl:if test="last() > 2">
                                    <xsl:text>,</xsl:text>
                                 </xsl:if>
                                 <xsl:text> and </xsl:text>
                              </xsl:when>
                              <xsl:otherwise>
                                 <xsl:text>, </xsl:text>
                              </xsl:otherwise>
                           </xsl:choose>
                        </xsl:for-each>
                     </li>
                  </xsl:if>
               </ul>
            </xsl:if>
            <xsl:apply-templates select="tei:publicationStmt"/>
            <!-- Removed by R. Whalen, 10/13/10. <xsl:if test="tei:encodingDesc/tei:editorialDecl">
               <h4>Encoding Principles</h4>
               <xsl:apply-templates select="tei:encodingDesc/tei:editorialDecl"/>
               </xsl:if>
               <xsl:apply-templates select="/tei:TEI/tei:teiHeader/tei:encodingDesc"/> -->
         </div>
      </div>
   </xsl:template>

   <xsl:template match="tei:publicationStmt">
      <h5>Publication Details:</h5>
      <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="tei:publicationStmt/tei:publisher">
      <p>
         <xsl:text>Published by </xsl:text>
         <xsl:apply-templates/>
         <xsl:text>.</xsl:text>
      </p>
   </xsl:template>

   <xsl:template match="tei:publicationStmt/tei:availability">
      <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="/tei:TEI/tei:teiHeader/tei:encodingDesc">
      <h4>Encoding Principles</h4>
      <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="/tei:TEI/tei:teiHeader/tei:encodingDesc/tei:editorialDecl">
      <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="//tei:encodingDesc/tei:classDecl"/>

   <xsl:template match="//tei:encodingDesc/tei:tagsDecl"/>

   <xsl:template match="//tei:encodingDesc/tei:charDecl"/>

   <xsl:template name="notesPanel">
      <div class="panel" id="notesPanel">
         <xsl:if test="$notesFormat != 'inline'">
            <xsl:attribute name="style">
               <xsl:text>display: none;</xsl:text>
            </xsl:attribute>
         </xsl:if>
         <div class="panelBanner">
            <!-- Textual Notes changed to Notes - R. Whalen 16-03-2010 -->
            <img class="closePanel" onclick="hideNotesPanel();" alt="X"
               src="../vm-images/closePanel.gif"/> Notes </div>
         <xsl:for-each select="//tei:body//tei:note[not(@type = 'image')]">
            <xsl:if test="not(ancestor::tei:note)">
               <div>
                  <xsl:attribute name="class">
                     <xsl:text>noteContent</xsl:text>
                     <xsl:if test="ancestor::*/@wit">
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="translate(ancestor::*/@wit, '#', '')"/>
                     </xsl:if>
                  </xsl:attribute>
                  <!--   <xsl:if test="ancestor::*/@wit">
                     <div class="witnesses">
                        <xsl:value-of select="translate(ancestor::*/@wit,'#','')"/>
                     </div>
                  </xsl:if>-->
                  <xsl:choose>
                     <xsl:when test="ancestor::tei:l">
                        <div class="position">
                           <xsl:attribute name="onclick">
                              <xsl:text>matchLine('line</xsl:text>
                              <xsl:value-of select="generate-id(ancestor::tei:l)"/>
                              <xsl:text>');</xsl:text>
                           </xsl:attribute>
                           <xsl:choose>
                              <xsl:when test="ancestor::tei:l[@n]">
                                 <xsl:text>Line number </xsl:text>
                                 <xsl:value-of select="ancestor::tei:l/@n"/>
                              </xsl:when>
                              <xsl:otherwise>
                                 <xsl:text>Unnumbered line</xsl:text>
                              </xsl:otherwise>
                           </xsl:choose>
                        </div>
                     </xsl:when>
                     <xsl:when test="ancestor::tei:p and ancestor::tei:app">
                        <div class="position">
                           <xsl:attribute name="onclick">
                              <xsl:text>matchApp('app-</xsl:text>
                              <xsl:value-of select="generate-id(ancestor::tei:app)"/>
                              <xsl:text>');</xsl:text>
                           </xsl:attribute>
                        </div>
                     </xsl:when>
                  </xsl:choose>
                  <xsl:apply-templates/>
               </div>
            </xsl:if>
         </xsl:for-each>
         <div id="noNotesFound" class="noteContent"> Sorry, but there are no notes associated with
            any currently displayed witness. </div>
      </div>
   </xsl:template>

   <!-- Add tei:ab. R. Whalen 11-4-2010. -->
   <xsl:template
      match="tei:fw | tei:hi | tei:head | tei:epigraph | tei:div | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 | tei:div8 | tei:lg | tei:l | tei:quote | tei:speaker | tei:title | tei:trailer | tei:seg | tei:pb"
      priority="-1">
      <div>
         <xsl:attribute name="class">
            <xsl:value-of select="name(.)"/>
            <xsl:if test="@n">
               <xsl:text> </xsl:text>
               <xsl:value-of select="name(.)"/>
               <xsl:text>-n</xsl:text>
               <xsl:value-of select="@n"/>
            </xsl:if>
            <xsl:if test="@type">
               <xsl:text> type-</xsl:text>
               <xsl:value-of select="@type"/>
            </xsl:if>
            <xsl:if test="@rend">
               <xsl:text> rend-</xsl:text>
               <xsl:value-of select="@rend"/>
            </xsl:if>
         </xsl:attribute>
         <xsl:apply-templates/>
      </div>
   </xsl:template>

   <xsl:template name="imageLink">
      <xsl:param name="imageURL"/>
      <xsl:param name="witness"/>
      <xsl:param name="folio"/>
      <!-- xsl:choose added by James Cummings 2011-05-03 to enable folio-references instead of image -->
      <xsl:variable name="folioString">
         <xsl:choose>
            <xsl:when test="translate($witness, '#', '') = 'B'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'W'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Cm48'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Fj1'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Bla41'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Bla21'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Bla38'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Bla75'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Fv45'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Cp52'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Cp71'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Op40'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Jp52'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'WL70'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'WLH'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'WL75'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'T'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'P'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'D'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'NAp36'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'NAp04'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'SLD'">p. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Ros'">f. </xsl:when>
            <xsl:when test="translate($witness, '#', '') = 'Fva'">f. </xsl:when>
            <!-- (add more tests here for other non-folio witnesses -->
            <xsl:otherwise>
               <xsl:apply-templates/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:choose>
         <xsl:when test="$imageURL != '' and $folio">
            <a>
               <xsl:attribute name="class">
                  <xsl:text>imageLink </xsl:text>
                  <xsl:if test="$witness != ''">
                     <xsl:text> </xsl:text>
                     <xsl:value-of select="$witness"/>
                  </xsl:if>
               </xsl:attribute>
               <xsl:attribute name="onclick">
                  <xsl:text>return showImgPanel(event, 'imageViewer','</xsl:text>
                  <xsl:value-of select="$imageURL"/>
                  <xsl:text>','</xsl:text>
                  <xsl:value-of select="$witness"/>
                  <!-- edited by Theodore Koterwas 21/04/2011: to pass the folioString, folio, and panZoomImage
                    variables to showImgPanel
               -->
                  <xsl:text>','</xsl:text>
                  <xsl:value-of select="$folioString"/>
                  <xsl:text>','</xsl:text>
                  <xsl:value-of select="$folio"/>
                  <xsl:text>','-250','0',</xsl:text>
                  <xsl:value-of select="$panZoomImage"/>
                  <xsl:text>);</xsl:text>
                  <!-- end Theodore Koterwas edit-->
               </xsl:attribute>
               <xsl:value-of select="concat($folioString, $folio)"/>
            </a>
         </xsl:when>
         <xsl:when test="$imageURL != '' and not($folio)">
            <img src="../vm-images/image.gif">
               <xsl:attribute name="class">
                  <xsl:text>imageLink</xsl:text>
                  <xsl:if test="$witness != ''">
                     <xsl:text> </xsl:text>
                     <xsl:value-of select="$witness"/>
                  </xsl:if>
               </xsl:attribute>
               <xsl:attribute name="onclick">
                  <xsl:text>return showImgPanel(event, 'imageViewer','</xsl:text>
                  <xsl:value-of select="$imageURL"/>
                  <xsl:text>','</xsl:text>
                  <xsl:value-of select="$witness"/>
                  <!-- edited by Theodore Koterwas 21/04/2011: to pass the folioString, folio, and panZoomImage
                    variables to showImgPanel
               -->
                  <xsl:text>','</xsl:text>
                  <xsl:value-of select="$folioString"/>
                  <xsl:text>','</xsl:text>
                  <xsl:value-of select="$folio"/>
                  <xsl:text>','-250','0',</xsl:text>
                  <xsl:value-of select="$panZoomImage"/>
                  <xsl:text>);</xsl:text>
                  <!-- end Theodore Koterwas edit-->
               </xsl:attribute>
            </img>
         </xsl:when>
         <xsl:otherwise/>
      </xsl:choose>
   </xsl:template>



   <xsl:template match="tei:l">
      <!-- Add @rend functionality to tei:l. R. Whalen, 11-5-2010. -->
      <div>
         <xsl:attribute name="class">
            <xsl:value-of select="name(.)"/>
            <xsl:if test="@rend">
               <xsl:text> rend-</xsl:text>
               <xsl:value-of select="@rend"/>
            </xsl:if>
         </xsl:attribute>
         <xsl:variable name="uniqueID" select="generate-id(.)"/>
         <div>
            <xsl:attribute name="class">
               <xsl:text>line</xsl:text>
               <xsl:text> line</xsl:text>
               <xsl:value-of select="$uniqueID"/>
            </xsl:attribute>
            <xsl:attribute name="onclick">
               <xsl:text>matchLine('line</xsl:text>
               <xsl:value-of select="$uniqueID"/>
               <xsl:text>');</xsl:text>
            </xsl:attribute>
            <div>
               <xsl:choose>
                  <xsl:when test="@n">
                     <xsl:attribute name="class">
                        <xsl:text>linenumber</xsl:text>
                     </xsl:attribute>
                     <xsl:if test="$displayLineNumbers = 'false'">
                        <xsl:attribute name="style">
                           <xsl:text>visibility: hidden;</xsl:text>
                        </xsl:attribute>
                     </xsl:if>
                     <xsl:value-of select="@n"/>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:attribute name="class">
                        <xsl:text>emptynumber</xsl:text>
                     </xsl:attribute>
                     <xsl:text>&#160;</xsl:text>
                  </xsl:otherwise>
               </xsl:choose>
            </div>
            <xsl:apply-templates/>
         </div>
      </div>
      <xsl:for-each select=".//*[@facs]">
         <xsl:call-template name="imageLink">
            <xsl:with-param name="imageURL">
               <xsl:choose>
                  <xsl:when test="contains(@facs, '#')">
                     <xsl:variable name="facsID" select="translate(@facs, '#', '')"/>
                     <xsl:if test="//tei:facsimile//tei:graphic[@xml:id = $facsID]/@url">
                        <xsl:value-of select="//tei:facsimile//tei:graphic[@xml:id = $facsID]/@url"
                        />
                     </xsl:if>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:value-of select="@facs"/>
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:with-param>
            <xsl:with-param name="witness">
               <xsl:choose>
                  <xsl:when test="@ed">
                     <xsl:value-of select="translate(@ed, '#', '')"/>
                  </xsl:when>
                  <xsl:when test="ancestor::*/@wit">
                     <xsl:value-of select="translate(ancestor::*/@wit, '#', '')"/>
                  </xsl:when>
               </xsl:choose>
            </xsl:with-param>
         </xsl:call-template>
      </xsl:for-each>
   </xsl:template>

   <xsl:template match="tei:hi">
      <span>
         <xsl:attribute name="class">
            <xsl:text>hi</xsl:text>
            <xsl:if test="@rend">
               <xsl:text> rend-</xsl:text>
               <xsl:value-of select="@rend"/>
            </xsl:if>
         </xsl:attribute>
         <xsl:apply-templates/>
      </span>
      <xsl:if test="parent::tei:seg[@type eq 'verticalRend']">
         <br/>
      </xsl:if>
   </xsl:template>

   <xsl:template match="tei:quote">
      <span>
         <xsl:attribute name="class">
            <xsl:text>quote</xsl:text>
            <xsl:if test="@rend">
               <xsl:text> rend-</xsl:text>
               <xsl:value-of select="@rend"/>
            </xsl:if>
         </xsl:attribute>
         <xsl:apply-templates/>
      </span>
   </xsl:template>

   <!-- Add template for CSS processing (span.g {font-weight:bold; }) to highlight ligatures. R. Whalen, 7-21-2008. (Currently disabled in CSS.) -->
   <xsl:template match="tei:g">
      <span class="g">
         <xsl:apply-templates/>
      </span>
   </xsl:template>

   <xsl:template match="tei:del">
      <del>
         <xsl:if test="@rend">
            <xsl:attribute name="class">
               <xsl:text> rend-</xsl:text>
               <xsl:value-of select="@rend"/>
            </xsl:attribute>
         </xsl:if>
         <xsl:apply-templates/>
      </del>
   </xsl:template>

   <xsl:template match="tei:add">
      <ins>
         <xsl:if test="@rend or @place">
            <xsl:attribute name="class">
               <xsl:if test="@rend">
                  <xsl:text>rend-</xsl:text>
                  <xsl:value-of select="@rend"/>
               </xsl:if>
               <xsl:if test="@rend and @place">
                  <xsl:text> </xsl:text>
               </xsl:if>
               <xsl:if test="@place">
                  <xsl:text>place-</xsl:text>
                  <xsl:value-of select="@place"/>
               </xsl:if>
            </xsl:attribute>
         </xsl:if>
         <xsl:apply-templates/>
      </ins>
   </xsl:template>

   <xsl:template match="tei:unclear">
      <span class="unclear">
         <xsl:apply-templates/>
      </span>
   </xsl:template>

   <xsl:template match="tei:lb">
      <br class="linebreak"/>
   </xsl:template>

   <xsl:template match="tei:fw"/>
   <!--  <xsl:if test="@facs">
         <xsl:text> </xsl:text>
         <xsl:value-of select="translate(@ed,'#','')"/>
      </xsl:if>
      <xsl:apply-templates/>
   </xsl:template>-->

   <xsl:template match="tei:pb">
      <!-- James Cummings addition to suppress first tei:pb with xsl:if statement below 2011-05-05 -->
      <xsl:if test="preceding::tei:pb/@ed = @ed">
         <hr>
            <xsl:attribute name="class">
               <xsl:text>pagebreak</xsl:text>
               <xsl:if test="@ed">
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="translate(@ed, '#', '')"/>
               </xsl:if>
            </xsl:attribute>
         </hr>
      </xsl:if>
      <xsl:if test="not(ancestor::tei:l) and @facs">
         <xsl:call-template name="imageLink">
            <xsl:with-param name="imageURL">
               <xsl:choose>
                  <xsl:when test="contains(@facs, '#')">
                     <xsl:variable name="facsID" select="translate(@facs, '#', '')"/>
                     <xsl:if test="//tei:facsimile//tei:graphic[@xml:id = $facsID]/@url">
                        <xsl:value-of select="//tei:facsimile//tei:graphic[@xml:id = $facsID]/@url"
                        />
                     </xsl:if>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:value-of select="@facs"/>
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:with-param>
            <xsl:with-param name="witness">
               <xsl:choose>
                  <xsl:when test="@ed">
                     <xsl:value-of select="translate(@ed, '#', '')"/>
                  </xsl:when>
                  <xsl:when test="ancestor::*/@wit">
                     <xsl:value-of select="translate(ancestor::*/@wit, '#', '')"/>
                  </xsl:when>
               </xsl:choose>
            </xsl:with-param>
            <xsl:with-param name="folio">
               <xsl:value-of select="substring-after(@facs, @ed)"/>
            </xsl:with-param>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>


   <xsl:template match="tei:p">
      <!-- We cannot use the HTML <p>...</p> element here because of the
      different qualities of a TEI <p> and an HTML <p>. For example,
      TEI allows certain objects to be nested within a paragraph (like
      <table>...</table>) that HTML does not -->
      <xsl:choose>
         <xsl:when test="ancestor::tei:note or ancestor::tei:fileDesc or ancestor::tei:encodingDesc">
            <p>
               <xsl:apply-templates/>
            </p>
         </xsl:when>
         <xsl:otherwise>
            <div class="paragraph">
               <xsl:apply-templates/>
            </div>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="tei:milestone[@unit = 'stanza']">
      <br>
         <xsl:attribute name="class">
            <xsl:text>stanzabreak</xsl:text>
            <xsl:if test="@ed">
               <xsl:text> </xsl:text>
               <xsl:value-of select="translate(@ed, '#', '')"/>
            </xsl:if>
         </xsl:attribute>
      </br>
   </xsl:template>

   <xsl:template match="tei:table">
      <table class="mssTable">
         <xsl:apply-templates/>
      </table>
   </xsl:template>

   <xsl:template match="tei:table/tei:row">
      <tr>
         <xsl:apply-templates/>
      </tr>
   </xsl:template>

   <xsl:template match="tei:table/tei:row/tei:cell">
      <td>
         <xsl:apply-templates/>
      </td>
   </xsl:template>

   <xsl:template match="tei:space[@unit = 'char']">
      <xsl:variable name="quantity">
         <xsl:choose>
            <xsl:when test="@quantity">
               <xsl:value-of select="@quantity"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="1"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:call-template name="whiteSpace">
         <xsl:with-param name="iteration" select="1"/>
         <xsl:with-param name="quantity" select="$quantity"/>
      </xsl:call-template>
   </xsl:template>

   <xsl:template name="whiteSpace">
      <xsl:param name="iteration"/>
      <xsl:param name="quantity"/>
      <xsl:text>&#xa0;</xsl:text>
      <xsl:if test="$iteration &lt; $quantity">
         <xsl:call-template name="whiteSpace">
            <xsl:with-param name="iteration" select="$iteration + 1"/>
            <xsl:with-param name="quantity" select="$quantity"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>

   <xsl:template match="tei:note">
      <span class="noteicon">
         <xsl:if test="$notesFormat != 'popup'">
            <xsl:attribute name="style">
               <xsl:text>display: none;</xsl:text>
            </xsl:attribute>
         </xsl:if>
         <xsl:choose>
            <xsl:when test="@type = 'title'">
               <!--  <xsl:value-of select="translate(@n,'#','')"/>-->
               <xsl:text>Title</xsl:text>
            </xsl:when>
            <xsl:when test="@type = 'MC'">
               <!--  <xsl:value-of select="translate(@n,'#','')"/>-->
               <xsl:text>Criticism</xsl:text>
            </xsl:when>
            <xsl:when test="@type = 'sources'">
               <!--  <xsl:value-of select="translate(@n,'#','')"/>-->
               <xsl:text>Sources</xsl:text>
            </xsl:when>
            <xsl:when test="@type = 'texts'">
               <!--  <xsl:value-of select="translate(@n,'#','')"/>-->
               <xsl:text>Witnesses</xsl:text>
            </xsl:when>
            <!-- <xsl:when test="@type = 'app'">
                 <xsl:value-of select="translate(@n,'#','')"/>
               <xsl:text>T</xsl:text>
            </xsl:when> -->
            <!-- <xsl:when test="@type = 'crit'">
                 <xsl:value-of select="translate(@n,'#','')"/>
               <xsl:text>C</xsl:text>
            </xsl:when> -->
            <xsl:when test="@type = 'app' or 'crit'">
               <xsl:value-of select="translate(@n, '#', '')"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text>note</xsl:text>
            </xsl:otherwise>
         </xsl:choose>
         <div class="note">
            <xsl:apply-templates/>
         </div>
      </span>
   </xsl:template>

   <xsl:template match="tei:note//tei:note">
      <br/>
      <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="tei:figure"/>

   <xsl:template match="tei:app">
      <xsl:variable name="uniqueID" select="generate-id()"/>
      <span>
         <xsl:attribute name="class">
            <xsl:text>apparatus</xsl:text>
            <xsl:if test="count(ancestor::tei:l) = 0">
               <xsl:text> app-</xsl:text>
               <xsl:value-of select="$uniqueID"/>
               <xsl:text> clickable</xsl:text>
            </xsl:if>
            <xsl:if test="@type">
               <xsl:text> type-</xsl:text>
               <xsl:value-of select="@type"/>
            </xsl:if>
         </xsl:attribute>
         <xsl:if test="count(ancestor::tei:l) = 0">
            <xsl:attribute name="onclick">
               <xsl:text>matchApp('app-</xsl:text>
               <xsl:value-of select="$uniqueID"/>
               <xsl:text>');</xsl:text>
            </xsl:attribute>
         </xsl:if>
         <xsl:apply-templates/>
      </span>
   </xsl:template>

   <xsl:template match="tei:rdg">
      <xsl:variable name="attrs"
         select="
            normalize-space(translate(string-join((@wit), ', '), '#', ''))"/>
      <span>
         <xsl:attribute name="class">
            <xsl:text>reading </xsl:text>
            <xsl:text> </xsl:text>
            <xsl:value-of select="$attrs"/>
         </xsl:attribute>
         <xsl:apply-templates/>
      </span>
   </xsl:template>

   <xsl:template match="tei:expan"/>

   <xsl:template match="tei:seg[@type eq 'verticalRend']">
      <span class="verticalRend">
         <xsl:apply-templates/>
      </span>
   </xsl:template>


   <!-- <xsl:template match="tei:choice">
      <xsl:choose>
         <xsl:when test="tei:reg and tei:orig">
            <xsl:call-template name="displayChoice">
               <xsl:with-param name="inline" select="tei:reg"/>
               <xsl:with-param name="hover" select="tei:orig"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:message>ERROR: Unable to process children of choice #<xsl:value-of
                  select="count(preceding::tei:choice) + 1"/> correctly.</xsl:message>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template> -->
   <!-- An <app> with type=readingText (which should always be the child of -->
   <!-- a <rdg>) is handled the same way a <choice> is handled. However, we -->
   <!-- know that the only possible children are <rdg>, one of which will   -->
   <!-- have type=rdg, and 1-3 of which will have type=variant. -->
   <!--  <xsl:template match="tei:app[@type eq 'readingText']">-->
   <!-- <xsl:choose>
         <xsl:when test="tei:rdg[@type eq 'rdg'] and tei:rdg[@type eq 'variant']">
            <xsl:call-template name="displayChoice">
               <xsl:with-param name="inline" select="tei:rdg[@type eq 'rdg']"/>
               <xsl:with-param name="hover" select="tei:rdg[@type eq 'variant']|tei:rdg[@resp]"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:message>ERROR: Unable to process children of 'readingText' app #<xsl:value-of
                  select="count(preceding::tei:rdg[@type eq 'readingText'])+1"/>
               correctly.</xsl:message>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>-->
   <!--  <xsl:template match="tei:rdg[@type = 'variant']"/> -->
   <!-- tei:w functionality added by R. Whalen, 3-10-2009. Suspended 3-24-2009.-->
   <!-- <xsl:template match="tei:w">
            <xsl:choose> 
               <xsl:when test="@spelling">
                  <xsl:call-template name="displayChoice">
                     <xsl:with-param name="inline" select="node()"/>
                     <xsl:with-param name="hover" select="@spelling"/>
                     <xsl:with-param name="label" select="'Normalized form:'"/>
                  </xsl:call-template>
               </xsl:when>
               <xsl:when test="@lemma">
                  <xsl:call-template name="displayChoice">
                     <xsl:with-param name="inline" select="node()"/>
                     <xsl:with-param name="hover" select="@lemma"/>
                     <xsl:with-param name="label" select="'Normalized form:'"/>
                  </xsl:call-template>
               </xsl:when> 
               <xsl:otherwise>
                  <xsl:apply-templates/>
               </xsl:otherwise>
            </xsl:choose> 
         </xsl:template>
   <xsl:template name="displayChoice">
      <xsl:param name="inline"/>
      <xsl:param name="hover"/>
      <span class="choice">
         <xsl:apply-templates select="$inline"/>
         <div class="corr">
            <div class="interior">
               <xsl:choose>
                  <xsl:when test="count($hover) gt 0">
                     <xsl:for-each select="$hover">
                        <xsl:if test="@corresp | @resp">
                           <strong>
                              <xsl:value-of select="@corresp | @resp"/>
                              <xsl:text>: </xsl:text>
                           </strong>
                           <xsl:value-of select="."/>
                           <xsl:if test="position() ne last()">
                              <br/>
                           </xsl:if>
                        </xsl:if>
                     </xsl:for-each>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:apply-templates select="$hover"/>
                  </xsl:otherwise>
               </xsl:choose>
            </div>
         </div>
      </span>
   </xsl:template> -->
   <xsl:template name="imageViewer">
      <div class="viewerRoot" id="panel_imageViewer">
         <div title="Click to drag panel." class="viewerHandle" id="handle_imageViewer">
            <span class="viewerHandleLt" id="title_imageViewer">Image Viewer</span>
            <img class="viewerHandleRt" onclick="return hidePanel('imageViewer');" alt="X"
               src="../vm-images/closePanel.gif"/>
         </div>
         <div class="viewerContent" id="content_imageViewer"/>
      </div>
   </xsl:template>
   <xsl:template name="truncateText">
      <xsl:param name="string"/>
      <xsl:param name="length"/>
      <xsl:choose>
         <xsl:when test="string-length($string) > $length">
            <xsl:value-of select="concat(substring($string, 1, $length), '...')"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="$string"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   <xsl:template match="tei:closer">
      <xsl:apply-templates/>
   </xsl:template>
   <xsl:template match="tei:salute">
      <xsl:apply-templates/>
   </xsl:template>
</xsl:stylesheet>
