<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:tei="http://www.tei-c.org/ns/1.0"
                xmlns:xi="http://www.w3.org/2001/XInclude"
                xmlns:kiln="http://www.kcl.ac.uk/artshums/depts/ddh/kiln/ns/1.0"
                exclude-result-prefixes="#all"
                version="2.0">
   <xsl:import href="cocoon://_internal/template/xsl/stylesheets/tei/indices-epidoc.xsl">
      <xsl:stylesheet version="2.0">

  <!-- XSLT to transform an EpiDoc index into HTML. Relies on common
       functionality in indices.xsl. -->

  <xsl:import href="indices.xsl">
            <xsl:stylesheet xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" version="2.0">

  <!-- XSLT to convert index metadata and index Solr results into
       HTML. This is the common functionality for both TEI and EpiDoc
       indices. It should be imported by the specific XSLT for the
       document type (eg, indices-epidoc.xsl). -->

  <xsl:import href="to-html.xsl">
                  <xsl:stylesheet version="2.0">

  <!-- Project-specific XSLT for transforming TEI to
       HTML. Customisations here override those in the core
       to-html.xsl (which should not be changed). -->

  <xsl:import href="../../kiln/stylesheets/tei/to-html.xsl">
                        <xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1" exclude-result-prefixes="#all"
                                        version="2.0">

                           <xsl:import href="../../../stylesheets/defaults.xsl">
                              <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">
  <!--
      Defaults stylesheet. Defines default globals and reads
      parameters from the sitemap.
  -->

  <xsl:param name="language"/>

                                 <!-- Specify a mount path if you are mounting the webapp in a
       subdirectory rather than at the root of the domain. This path
       must either be empty or begin with a "/" and not include a
       trailing slash.

       The value is the URL root for the webapp. -->
  <xsl:variable name="kiln:mount-path" select="''"/>

                                 <!-- $kiln:context-path defines the URL root for the webapp. -->
  <xsl:variable name="kiln:context-path">
                                    <xsl:value-of select="$kiln:mount-path"/>
                                 </xsl:variable>

                                 <!-- Base URL for non-textual content (images, video, etc). If these
       are being served by Cocoon, this should be specified as
       relative to $context-path. Otherwise, a full URL including
       protocol and domain is required.

       This URL must not include a trailing slash. -->
  <xsl:variable name="kiln:content-url" select="''"/>
                                 <xsl:variable name="kiln:content-path">
                                    <xsl:if test="not(starts-with($kiln:content-url, 'http'))">
                                       <xsl:value-of select="$kiln:mount-path"/>
                                    </xsl:if>
                                    <xsl:value-of select="$kiln:content-url"/>
                                 </xsl:variable>

                                 <!-- Base URL for assets (non-content images, CSS, JavaScript,
       etc). If these are being served by Cocoon, this should be
       specified as relative to $context-path. Otherwise, a full URL
       including protocol and domain is required.

       This URL must not include a trailing slash. -->
  <xsl:variable name="kiln:assets-url" select="'/assets'"/>
                                 <xsl:variable name="kiln:assets-path">
                                    <xsl:if test="not(starts-with($kiln:assets-url, 'http'))">
                                       <xsl:value-of select="$kiln:mount-path"/>
                                    </xsl:if>
                                    <xsl:value-of select="$kiln:assets-url"/>
                                 </xsl:variable>

                                 <!-- Base URL for content images. -->
  <xsl:variable name="kiln:images-url" select="concat($kiln:content-path, '/images')"/>
                                 <xsl:variable name="kiln:images-path">
                                    <xsl:if test="not(starts-with($kiln:images-url, 'http'))">
                                       <xsl:value-of select="$kiln:mount-path"/>
                                    </xsl:if>
                                    <xsl:value-of select="$kiln:images-url"/>
                                 </xsl:variable>

                              </xsl:stylesheet>
                           </xsl:import>

                           <!-- Large self-contained aspects of rendering are kept in
       individual files. -->
  <xsl:include href="to-html-amendment.xsl">
                              <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">

  <!-- Transform a TEI document's amendment-related markup into
       HTML. -->

  <!-- Additions, general -->
  <xsl:template match="tei:add">
                                    <xsl:choose>
                                       <xsl:when test="number($amendments)">
                                          <xsl:variable name="hand-title">
                                             <xsl:if test="@hand">
                                                <xsl:text> in the hand of </xsl:text>
                                                <xsl:value-of select="id(substring(@hand, 2))"/>
                                             </xsl:if>
                                          </xsl:variable>
                                          <xsl:choose>
                                             <xsl:when test="@place">
                                                <ins>
                                                   <xsl:attribute name="title">
                                                      <xsl:value-of select="@place"/>
                                                      <xsl:text> addition</xsl:text>
                                                      <xsl:value-of select="$hand-title"/>
                                                   </xsl:attribute>
                                                   <xsl:apply-templates select="@*"/>
                                                   <xsl:call-template name="tei-assign-classes">
                                                      <xsl:with-param name="html-element" select="'add'"/>
                                                      <xsl:with-param name="extra-classes" select="concat('place-', @place)"/>
                                                   </xsl:call-template>
                                                   <xsl:apply-templates select="node()"/>
                                                </ins>
                                             </xsl:when>
                                             <xsl:otherwise>
                                                <ins>
                                                   <xsl:attribute name="title">
                                                      <xsl:text>addition</xsl:text>
                                                      <xsl:value-of select="$hand-title"/>
                                                   </xsl:attribute>
                                                   <xsl:apply-templates select="@*"/>
                                                   <xsl:apply-templates select="tei-assign-classes">
                                                      <xsl:with-param name="html-element" select="'add'"/>
                                                   </xsl:apply-templates>
                                                   <xsl:apply-templates select="node()"/>
                                                </ins>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:apply-templates select="node"/>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:template>

                                 <!-- Additions, supralinear -->
  <xsl:template match="tei:add[@place='supralinear']">
                                    <xsl:choose>
                                       <xsl:when test="number($amendments)">
                                          <ins title="supralinear addition">
                                             <xsl:apply-templates select="@*"/>
                                             <xsl:call-template name="tei-assign-classes">
                                                <xsl:with-param name="html-element" select="'add'"/>
                                             </xsl:call-template>
                                             <sup>
                                                <xsl:apply-templates select="node()"/>
                                             </sup>
                                          </ins>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:apply-templates select="node()"/>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:template>

                                 <!-- Additions, infralinear -->
  <xsl:template match="tei:add[@place='infralinear']">
                                    <ins title="infralinear addition">
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes">
                                          <xsl:with-param name="html-element" select="'add'"/>
                                       </xsl:call-template>
                                       <sub>
                                          <xsl:apply-templates select="node()"/>
                                       </sub>
                                    </ins>
                                 </xsl:template>

                                 <!-- Deletions -->
  <xsl:template match="tei:del[text()|node()]">
                                    <xsl:if test="number($amendments)">
                                       <del title="deletion">
                                          <xsl:apply-templates select="@*"/>
                                          <xsl:call-template name="tei-assign-classes"/>
                                          <xsl:apply-templates/>
                                       </del>
                                    </xsl:if>
                                 </xsl:template>

                                 <xsl:template match="tei:del/@type">
                                    <xsl:attribute name="title">
                                       <xsl:value-of select="@type"/>
                                    </xsl:attribute>
                                 </xsl:template>

                                 <!-- Sic -->
  <xsl:template match="tei:sic">
                                    <xsl:if test="number($corrections)">
                                       <span>
                                          <xsl:apply-templates select="@*"/>
                                          <xsl:call-template name="tei-assign-classes"/>
                                          <xsl:apply-templates select="node()"/>
                                          <xsl:text> </xsl:text>
                                          <span class="tei sic-mark">
                                             <xsl:text>[sic</xsl:text>
                                             <xsl:variable name="corrected-text" select="../tei:corr"/>
                                             <xsl:choose>
                                                <xsl:when test="$corrected-text = ''">
                                                   <xsl:text>: </xsl:text>
                                                   <span class="tei sic-none">
                                                      <xsl:text>delete</xsl:text>
                                                   </span>
                                                </xsl:when>
                                                <xsl:when test="$corrected-text">
                                                   <xsl:text>: </xsl:text>
                                                   <xsl:apply-templates mode="corrections" select="$corrected-text"/>
                                                </xsl:when>
                                                <xsl:otherwise/>
                                             </xsl:choose>
                                             <xsl:text>]</xsl:text>
                                          </span>
                                       </span>
                                    </xsl:if>
                                 </xsl:template>

                                 <!-- Corr -->
  <xsl:template match="tei:corr">
                                    <xsl:if test="not(number($corrections))">
                                       <span>
                                          <xsl:apply-templates select="@*"/>
                                          <xsl:call-template name="tei-assign-classes"/>
                                          <xsl:apply-templates select="node()"/>
                                       </span>
                                    </xsl:if>
                                 </xsl:template>

                                 <!-- Corr, when being processed as the alternative to a displayed
       sic. -->
  <xsl:template match="tei:corr" mode="corrections">
                                    <xsl:apply-templates select="node()"/>
                                 </xsl:template>

                                 <!-- Unclear, general -->
  <xsl:template match="tei:unclear">
                                    <xsl:choose>
                                       <xsl:when test="number($unclear)">
                                          <span>
                                             <xsl:apply-templates select="@*"/>
                                             <xsl:call-template name="tei-assign-classes"/>
                                             <xsl:text>[</xsl:text>
                                             <span class="tei reason" lang="en">
                                                <xsl:text>unclear</xsl:text>
                                                <xsl:if test="@reason">
                                                   <xsl:text> </xsl:text>
                                                   <xsl:value-of select="@reason"/>
                                                </xsl:if>
                                                <xsl:if test="normalize-space(.)">
                                                   <xsl:text>: </xsl:text>
                                                </xsl:if>
                                             </span>
                                             <xsl:apply-templates select="node()"/>
                                             <xsl:text>]</xsl:text>
                                          </span>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:apply-templates select="node()"/>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:template>

                                 <!-- Orig -->
  <xsl:template match="tei:orig">
                                    <xsl:if test="not(number($regularised))">
                                       <span>
        <!-- For now, just use a title attribute, though this assumes
             that the tei:reg does not contain meaningful markup. -->
        <xsl:attribute name="title">
                                             <xsl:apply-templates mode="regularised" select="../tei:reg"/>
                                          </xsl:attribute>
                                          <xsl:apply-templates select="@*"/>
                                          <xsl:call-template name="tei-assign-classes"/>
                                          <xsl:apply-templates select="node()"/>
                                       </span>
                                    </xsl:if>
                                 </xsl:template>

                                 <!-- Reg -->
  <xsl:template match="tei:reg">
                                    <xsl:if test="number($regularised)">
                                       <xsl:apply-templates select="node()"/>
                                    </xsl:if>
                                 </xsl:template>

                                 <!-- Reg, when being processed as the alternative to a displayed
       orig. -->
  <xsl:template match="tei:reg" mode="regularised">
                                    <xsl:apply-templates select="node()"/>
                                 </xsl:template>

                                 <!-- Abbr, general -->
  <xsl:template match="tei:abbr">
                                    <xsl:if test="not(number($regularised))">
                                       <abbr>
                                          <xsl:apply-templates select="@*"/>
                                          <!-- Since HTML uses title for abbreviations, we can either
             just grab a string representation of the tei:expan, or
             hope that it doesn't contain meaningful markup and apply
             templates on it. -->
        <xsl:attribute name="title">
                                             <xsl:value-of select="../tei:expan"/>
                                          </xsl:attribute>
                                          <xsl:call-template name="tei-assign-classes"/>
                                          <xsl:apply-templates select="node()"/>
                                       </abbr>
                                    </xsl:if>
                                 </xsl:template>

                                 <!-- Abbreviations, acronyms -->
  <xsl:template match="tei:abbr[@type='acronym']">
                                    <acronym>
                                       <xsl:apply-templates select="@*"/>
                                       <!-- Since HTML uses title for abbreviations, we can either just
           grab a string representation of the tei:expan, or hope that
           it doesn't contain meaningful markup and apply templates on
           it. -->
      <xsl:attribute name="title">
                                          <xsl:value-of select="../tei:expan"/>
                                       </xsl:attribute>
                                       <xsl:call-template name="tei-assign-classes">
                                          <xsl:with-param name="html-element" select="'abbr'"/>
                                       </xsl:call-template>
                                       <xsl:apply-templates select="node()"/>
                                    </acronym>
                                 </xsl:template>

                                 <!-- Expan -->
  <xsl:template match="tei:expan">
                                    <xsl:if test="number($regularised)">
                                       <xsl:apply-templates select="node()"/>
                                    </xsl:if>
                                 </xsl:template>

                                 <!-- Gaps. -->
  <xsl:template match="tei:gap">
                                    <span lang="en">
                                       <xsl:apply-templates select="@*[not(local-name() = 'desc') and not(local-name() = 'reason')]"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:text>[</xsl:text>
                                       <span class="tei head"
                                             title="Material has been omitted from the transcription at this point.">
                                          <xsl:text>gap — </xsl:text>
                                       </span>
                                       <xsl:apply-templates select="@desc"/>
                                       <xsl:text> </xsl:text>
                                       <xsl:apply-templates select="@reason"/>
                                       <xsl:text>]</xsl:text>
                                    </span>
                                 </xsl:template>

                                 <xsl:template match="tei:gap/@desc">
                                    <span class="tei desc" lang="en">
                                       <xsl:text>omitted: </xsl:text>
                                       <xsl:value-of select="."/>
                                    </span>
                                 </xsl:template>
                                 <xsl:template match="tei:gap/@reason">
                                    <span class="tei reason" lang="en">
                                       <xsl:text>reason: </xsl:text>
                                       <xsl:value-of select="."/>
                                    </span>
                                 </xsl:template>

                              </xsl:stylesheet>
                           </xsl:include>
                           <xsl:include href="to-html-list.xsl">
                              <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">

  <!-- Transform a TEI document's lists into HTML. -->

  <xsl:template match="tei:list">
                                    <xsl:apply-templates select="tei:head"/>
                                    <!-- Determine whether ordered or unordered list -->
    <xsl:variable name="listtype">
                                       <xsl:choose>
                                          <xsl:when test="@type = 'ordered'">
                                             <xsl:value-of select="'ol'"/>
                                          </xsl:when>
                                          <xsl:otherwise>
                                             <xsl:value-of select="'ul'"/>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                    </xsl:variable>
                                    <xsl:element name="{$listtype}">
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes">
                                          <xsl:with-param name="html-element" select="local-name()"/>
                                       </xsl:call-template>
                                       <xsl:apply-templates select="tei:item"/>
                                    </xsl:element>
                                 </xsl:template>

                                 <xsl:template match="tei:list[tei:label]">
                                    <xsl:apply-templates select="tei:head"/>
                                    <table>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates select="tei:item"/>
                                    </table>
                                 </xsl:template>

                                 <xsl:template match="tei:item">
                                    <li>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes">
                                          <xsl:with-param name="html-element" select="local-name()"/>
                                       </xsl:call-template>
                                       <xsl:apply-templates select="node()"/>
                                    </li>
                                 </xsl:template>

                                 <xsl:template match="tei:list[tei:label]/tei:item">
                                    <tr>
                                       <xsl:apply-templates select="preceding-sibling::tei:label[1]"/>
                                       <td>
                                          <xsl:apply-templates select="@*"/>
                                          <xsl:call-template name="tei-assign-classes"/>
                                          <xsl:apply-templates select="node()"/>
                                       </td>
                                    </tr>
                                 </xsl:template>

                                 <xsl:template match="tei:list/tei:label">
                                    <td>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates select="node()"/>
                                    </td>
                                 </xsl:template>

                              </xsl:stylesheet>
                           </xsl:include>
                           <xsl:include href="to-html-note.xsl">
                              <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">

  <!-- Transform a TEI document's notes into HTML. -->

  <!-- Notes, without target -->
  <xsl:template match="tei:note">
                                    <div>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates/>
                                    </div>
                                 </xsl:template>

                                 <xsl:template match="tei:note[not(@n)][not(@target)]">
                                    <xsl:choose>
                                       <xsl:when test="contains(concat(' ', @kiln:class, ' '), ' block ')">
                                          <div>
                                             <xsl:apply-templates select="@*"/>
                                             <xsl:call-template name="tei-assign-classes"/>
                                             <xsl:if test="@resp">
                                                <p class="tei resp">
                                                   <xsl:text>[Note added by </xsl:text>
                                                   <xsl:apply-templates select="id(substring(@resp, 2))"/>
                                                   <xsl:text>:] </xsl:text>
                                                </p>
                                             </xsl:if>
                                             <xsl:apply-templates select="node()"/>
                                          </div>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <span>
                                             <xsl:apply-templates select="@*"/>
                                             <xsl:call-template name="tei-assign-classes"/>
                                             <xsl:if test="@resp">
                                                <span class="tei resp">
                                                   <xsl:text>[Note added by </xsl:text>
                                                   <xsl:apply-templates select="id(substring(@resp, 2))"/>
                                                   <xsl:text>:] </xsl:text>
                                                </span>
                                             </xsl:if>
                                             <xsl:apply-templates select="node()"/>
                                          </span>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:template>

                                 <xsl:template match="tei:note[@n]">
                                    <xsl:variable name="extra-classes">
                                       <xsl:text>footnote</xsl:text>
                                       <xsl:if test="not(following-sibling::tei:*[1][local-name()='note'][@n])">
                                          <xsl:text> last</xsl:text>
                                       </xsl:if>
                                    </xsl:variable>
                                    <div>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes">
                                          <xsl:with-param name="html-element" select="'note'"/>
                                          <xsl:with-param name="extra-classes" select="$extra-classes"/>
                                       </xsl:call-template>
                                       <!-- If the first element in the footnote is not a paragraph,
           then add in a paragraph with the reference back to the
           marker. -->
      <xsl:if test="local-name(child::*[1]) != 'p'">
                                          <p>
                                             <a href="#reference-to-{@xml:id}" title="back">
                                                <sup>
                                                   <xsl:value-of select="@n"/>
                                                </sup>
                                                <xsl:text> </xsl:text>
                                             </a>
                                          </p>
                                       </xsl:if>
                                       <xsl:apply-templates select="node()"/>
                                       <xsl:if test="@resp">
                                          <p class="tei resp">
                                             <xsl:text>[Note added by </xsl:text>
                                             <xsl:apply-templates select="id(substring(@resp, 2))"/>
                                             <xsl:text>]</xsl:text>
                                          </p>
                                       </xsl:if>
                                    </div>
                                 </xsl:template>

                                 <xsl:template match="tei:note[@n]/tei:p[1]">
    <!-- Insert a reference back to the footnote marker if this
         paragraph is the first element in the footnote. -->
    <p>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:if test="not(normalize-space(preceding-sibling::*))">
                                          <a href="#reference-to-{../@xml:id}" title="back">
                                             <sup>
                                                <xsl:value-of select="../@n"/>
                                             </sup>
                                             <xsl:text> </xsl:text>
                                          </a>
                                       </xsl:if>
                                       <xsl:apply-templates select="node()"/>
                                    </p>
                                 </xsl:template>

                                 <!-- Notes, with target -->
  <xsl:template match="tei:note[@target]">
                                    <a>
                                       <xsl:attribute name="href">
                                          <xsl:value-of select="substring(@target, 2)"/>
                                       </xsl:attribute>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates/>
                                    </a>
                                 </xsl:template>

                              </xsl:stylesheet>
                           </xsl:include>
                           <xsl:include href="to-html-rend.xsl">
                              <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">

  <!-- Transform a TEI document's @rend into HTML. -->

  <!-- Generic (CSS-based) -->
  <xsl:template match="tei:hi[@rend]" priority="-1">
                                    <xsl:variable name="class">
                                       <xsl:apply-templates mode="rend-class" select="@rend"/>
                                    </xsl:variable>
                                    <span>
                                       <xsl:attribute name="class">
                                          <xsl:value-of select="normalize-space($class)"/>
                                       </xsl:attribute>
                                       <xsl:apply-templates/>
                                    </span>
                                 </xsl:template>

                                 <!-- Italics -->
  <xsl:template match="tei:hi[@rend='i']">
                                    <i>
                                       <xsl:apply-templates/>
                                    </i>
                                 </xsl:template>

                                 <!-- Bold -->
  <xsl:template match="tei:hi[@rend='b']">
                                    <b>
                                       <xsl:apply-templates/>
                                    </b>
                                 </xsl:template>

                                 <!-- Subscript -->
  <xsl:template match="tei:hi[@rend='sub']">
                                    <sub>
                                       <xsl:apply-templates/>
                                    </sub>
                                 </xsl:template>

                                 <!-- Superscript -->
  <xsl:template match="tei:hi[@rend='sup']">
                                    <sup>
                                       <xsl:apply-templates/>
                                    </sup>
                                 </xsl:template>

                                 <xsl:template match="@rend" mode="rend-class">
                                    <xsl:choose>
                                       <xsl:when test=". = 'i'">
                                          <xsl:text>italic </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'b'">
                                          <xsl:text>bold </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'c'">
                                          <xsl:text>caps </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'u'">
                                          <xsl:text>underline </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'lc'">
                                          <xsl:text>lowercase </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'sc'">
                                          <xsl:text>small-caps </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'lsc'">
                                          <xsl:text>lowercase-small-caps </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'strike'">
                                          <xsl:text>strikethrough </xsl:text>
                                       </xsl:when>
                                       <xsl:when test=". = 'small'">
                                          <xsl:text>smaller </xsl:text>
                                       </xsl:when>
                                       <!-- A colon indicates a CSS rule that belongs in the style
           attribute, so do not handle it here. -->
      <xsl:when test="contains(., ':')"/>
                                       <xsl:otherwise>
                                          <xsl:value-of select="."/>
                                          <xsl:text> </xsl:text>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:template>

                                 <xsl:template match="@rend" mode="rend-style">
                                    <xsl:if test="contains(., ':')">
                                       <xsl:value-of select="."/>
                                       <xsl:text>; </xsl:text>
                                    </xsl:if>
                                 </xsl:template>

                              </xsl:stylesheet>
                           </xsl:include>
                           <xsl:include href="to-html-table.xsl">
                              <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">

  <!-- Transform a TEI document's tables into HTML. -->

  <xsl:template match="tei:cell">
                                    <xsl:variable name="cell-element">
                                       <xsl:choose>
                                          <xsl:when test="@role='label' or parent::tei:row/@role='label'">
                                             <xsl:text>th</xsl:text>
                                          </xsl:when>
                                          <xsl:otherwise>
                                             <xsl:text>td</xsl:text>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                    </xsl:variable>
                                    <xsl:element name="{$cell-element}">
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes">
                                          <xsl:with-param name="html-element" select="'cell'"/>
                                       </xsl:call-template>
                                       <xsl:apply-templates select="node()"/>
                                    </xsl:element>
                                 </xsl:template>

                                 <xsl:template match="tei:row">
                                    <tr>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates select="node()"/>
                                    </tr>
                                 </xsl:template>

                                 <xsl:template match="tei:table">
                                    <table>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates select="node()"/>
                                    </table>
                                 </xsl:template>

                                 <xsl:template match="tei:table/tei:head">
                                    <caption>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates select="node()"/>
                                    </caption>
                                 </xsl:template>

                                 <xsl:template match="tei:cell/@cols">
                                    <xsl:if test=". &gt; 1">
                                       <xsl:attribute name="colspan">
                                          <xsl:value-of select="."/>
                                       </xsl:attribute>
                                    </xsl:if>
                                 </xsl:template>

                                 <xsl:template match="tei:cell/@rows">
                                    <xsl:if test=". &gt; 1">
                                       <xsl:attribute name="rowspan">
                                          <xsl:value-of select="."/>
                                       </xsl:attribute>
                                    </xsl:if>
                                 </xsl:template>

                              </xsl:stylesheet>
                           </xsl:include>
                           <xsl:include href="to-html-teiheader.xsl">
                              <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">

  <!-- Transform a TEI document's teiHeader into HTML. -->

  <xsl:template match="tei:author">
                                    <xsl:if test="not(preceding-sibling::tei:author)">
                                       <p>
                                          <strong>
                                             <xsl:text>Author</xsl:text>
                                             <xsl:if test="following-sibling::tei:author">
                                                <xsl:text>s</xsl:text>
                                             </xsl:if>
                                             <xsl:text>:</xsl:text>
                                          </strong>
                                          <xsl:text> </xsl:text>
                                          <xsl:apply-templates/>
                                          <xsl:for-each select="following-sibling::tei:author">
                                             <xsl:text>; </xsl:text>
                                             <xsl:apply-templates/>
                                          </xsl:for-each>
                                       </p>
                                    </xsl:if>
                                 </xsl:template>

                                 <xsl:template match="tei:bibl">
                                    <xsl:value-of select="."/>
                                 </xsl:template>

                                 <xsl:template match="tei:change">
                                    <li>
                                       <xsl:apply-templates select="@when"/>
                                       <!-- A tei:change may contain so much markup that it is best to
           use the base templates to render it. -->
      <xsl:apply-templates/>
                                       <xsl:apply-templates select="@who"/>
                                    </li>
                                 </xsl:template>

                                 <xsl:template match="tei:publicationStmt/tei:date">
                                    <p>
                                       <strong>Publication date: </strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:value-of select="."/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:encodingDesc">
                                    <section>
                                       <h2 class="title" data-section-title="">
                                          <small>
                                             <a href="#">Encoding description</a>
                                          </small>
                                       </h2>
                                       <div class="content" data-section-content="">
                                          <xsl:apply-templates/>
                                       </div>
                                    </section>
                                 </xsl:template>

                                 <xsl:template match="tei:extent">
                                    <p>
                                       <strong>Extent:</strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:value-of select="normalize-space(.)"/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:fileDesc">
                                    <section>
                                       <h2 class="title" data-section-title="">
                                          <small>
                                             <a href="#">Digital document details</a>
                                          </small>
                                       </h2>
                                       <div class="content" data-section-content="">
                                          <xsl:apply-templates select="tei:*[not(local-name()='sourceDesc')]"/>
                                       </div>
                                    </section>
                                    <xsl:apply-templates select="tei:sourceDesc"/>
                                 </xsl:template>

                                 <xsl:template match="tei:funder">
                                    <p>
                                       <strong>Funder: </strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:apply-templates/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:msDesc">
                                    <xsl:apply-templates select="tei:msIdentifier"/>
                                 </xsl:template>

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

                                 <xsl:template match="tei:publisher">
                                    <p>
                                       <strong>Publisher:</strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:apply-templates/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:pubPlace">
                                    <p>
                                       <strong>Place of publication:</strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:apply-templates/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:respStmt">
                                    <p>
                                       <strong>
                                          <xsl:apply-templates select="tei:resp"/>
                                          <xsl:text>: </xsl:text>
                                       </strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:apply-templates select="tei:*[not(local-name()='resp')]"/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:revisionDesc">
                                    <section>
                                       <h2 class="title" data-section-title="">
                                          <small>
                                             <a href="#">File changelog</a>
                                          </small>
                                       </h2>
                                       <div class="content" data-section-content="">
                                          <ul class="no-bullet">
                                             <xsl:apply-templates/>
                                          </ul>
                                       </div>
                                    </section>
                                 </xsl:template>

                                 <xsl:template match="tei:sourceDesc">
                                    <section>
                                       <h2 class="title" data-section-title="">
                                          <small>
                                             <a href="#">Source document details</a>
                                          </small>
                                       </h2>
                                       <div class="content" data-section-content="">
                                          <xsl:apply-templates/>
                                       </div>
                                    </section>
                                 </xsl:template>

                                 <xsl:template match="tei:teiHeader">
    <!-- Display metadata about this document, drawn from the TEI
         header. -->
    <div class="section-container accordion" data-section="accordion">
                                       <xsl:apply-templates/>
                                       <section>
                                          <h2 class="title" data-section-title="">
                                             <small>
                                                <a href="#">Other Formats</a>
                                             </small>
                                          </h2>
                                          <div class="content" data-section-content="">
                                             <ul class="no-bullet">
                                                <li>
                                                   <a href="{../@xml:id}.xml">
                                                      <abbr title="Text Encoding for Interchange">TEI</abbr>
                                                      <xsl:text> source</xsl:text>
                                                   </a>
                                                </li>
                                             </ul>
                                          </div>
                                       </section>
                                    </div>
                                 </xsl:template>

                                 <xsl:template match="tei:seriesStmt/tei:title">
                                    <p>
                                       <strong>Series title:</strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:apply-templates/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:titleStmt/tei:title">
                                    <p>
                                       <strong>Title:</strong>
                                       <xsl:text> </xsl:text>
                                       <xsl:apply-templates/>
                                    </p>
                                 </xsl:template>

                                 <xsl:template match="tei:change/@when">
                                    <strong>
                                       <xsl:value-of select="."/>
                                       <xsl:text>:</xsl:text>
                                    </strong>
                                    <xsl:text> </xsl:text>
                                 </xsl:template>

                                 <xsl:template match="tei:change/@who">
                                    <xsl:text> [</xsl:text>
                                    <xsl:choose>
                                       <xsl:when test="starts-with(., '#')">
                                          <xsl:variable name="who-id" select="substring(., 2)"/>
                                          <xsl:apply-templates select="ancestor::tei:teiHeader//*[@xml:id=$who-id]"/>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:value-of select="."/>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                    <xsl:text>] </xsl:text>
                                 </xsl:template>

                              </xsl:stylesheet>
                           </xsl:include>

                           <xsl:param name="amendments" select="1"/>
                           <xsl:param name="corrections" select="1"/>
                           <xsl:param name="page-numbers" select="1"/>
                           <xsl:param name="regularised" select="0"/>
                           <xsl:param name="unclear" select="1"/>

                           <!-- Generate divs for TEI sections. -->
  <xsl:template match="tei:group | tei:text | tei:floatingText |                        tei:front | tei:body | tei:back | tei:div">
                              <xsl:call-template name="tei-make-div"/>
                           </xsl:template>

                           <!-- Div heading becomes HTML heading. -->
  <xsl:template match="tei:div/tei:head">
                              <xsl:call-template name="tei-make-hx"/>
                           </xsl:template>

                           <xsl:template match="tei:head">
                              <xsl:call-template name="tei-make-p"/>
                           </xsl:template>

                           <xsl:template match="tei:p | tei:ab">
                              <xsl:choose>
                                 <xsl:when test="contains(concat(' ', @kiln:class, ' '), ' block ')">
                                    <xsl:call-template name="tei-make-div"/>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:call-template name="tei-make-p"/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <xsl:template match="tei:q | tei:quote">
                              <xsl:choose>
                                 <xsl:when test="contains(concat(' ', @kiln:class, ' '), ' block ')">
                                    <blockquote>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates select="node()"/>
                                    </blockquote>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <q>
                                       <xsl:apply-templates select="@*"/>
                                       <xsl:call-template name="tei-assign-classes"/>
                                       <xsl:apply-templates select="node()"/>
                                    </q>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <!-- Letter elements. -->
  <xsl:template match="tei:opener">
                              <xsl:call-template name="tei-make-div"/>
                           </xsl:template>
                           <xsl:template match="tei:closer">
                              <xsl:call-template name="tei-make-div"/>
                           </xsl:template>
                           <xsl:template match="tei:dateline">
                              <xsl:call-template name="tei-make-p"/>
                           </xsl:template>
                           <xsl:template match="tei:salute">
                              <xsl:call-template name="tei-make-p"/>
                           </xsl:template>
                           <xsl:template match="tei:signed">
                              <xsl:call-template name="tei-make-p"/>
                           </xsl:template>

                           <!-- Poetry -->

  <!-- Line groups that contain other line groups -->
  <xsl:template match="tei:lg">
                              <xsl:choose>
                                 <xsl:when test="contains(concat(' ', @kiln:class, ' '), ' block ')">
                                    <xsl:call-template name="tei-make-div"/>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:call-template name="tei-make-p"/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <!-- Line group headings -->
  <xsl:template match="tei:lg/tei:head">
                              <xsl:call-template name="tei-make-span"/>
                              <br/>
                           </xsl:template>

                           <!-- Lines -->
  <xsl:template match="tei:l" name="l">
                              <xsl:call-template name="tei-make-span"/>
                              <xsl:if test="following-sibling::tei:l">
                                 <br/>
                              </xsl:if>
                           </xsl:template>

                           <!-- Index terms -->
  <xsl:template match="tei:index">
                              <span>
                                 <xsl:apply-templates select="@*"/>
                                 <xsl:call-template name="tei-assign-classes">
                                    <xsl:with-param name="html-element" select="'index'"/>
                                    <xsl:with-param name="extra-classes" select="'index-item'"/>
                                 </xsl:call-template>
                                 <xsl:apply-templates select="node()"/>
                              </span>
                           </xsl:template>

                           <xsl:template match="tei:index/tei:term[preceding-sibling::tei:term]">
                              <xsl:text>; </xsl:text>
                              <xsl:apply-templates select="node()"/>
                           </xsl:template>

                           <xsl:template match="tei:emph">
                              <strong>
                                 <xsl:apply-templates/>
                              </strong>
                           </xsl:template>

                           <xsl:template match="tei:foreign">
                              <xsl:call-template name="tei-make-span"/>
                           </xsl:template>

                           <xsl:template match="tei:name[@key]|tei:rs[@key]">
                              <xsl:call-template name="tei-make-span"/>
                           </xsl:template>

                           <!-- References. -->
  <xsl:template match="tei:ref[starts-with(@target, '#')]">
                              <xsl:variable name="target" select="id(substring(@target, 2))"/>
                              <xsl:call-template name="tei-make-ref-link">
                                 <xsl:with-param name="target" select="@target"/>
                              </xsl:call-template>
                           </xsl:template>

                           <xsl:template match="tei:ref">
                              <xsl:choose>
                                 <xsl:when test="contains(concat(' ', @kiln:class, ' '), ' nested-link ')">
                                    <xsl:apply-templates/>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:call-template name="tei-make-ref-link">
                                       <xsl:with-param name="target" select="@target"/>
                                       <xsl:with-param name="n" select="@n"/>
                                    </xsl:call-template>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <xsl:template match="tei:seg">
                              <xsl:call-template name="tei-make-span"/>
                           </xsl:template>

                           <!-- Figures. -->

  <xsl:template match="tei:figure">
                              <xsl:param name="nested-link" select="0"/>
                              <xsl:variable name="container-element">
                                 <xsl:choose>
                                    <xsl:when test="contains(concat(' ', @kiln:class, ' '), ' block ')">
                                       <xsl:text>div</xsl:text>
                                    </xsl:when>
                                    <xsl:otherwise>
                                       <xsl:text>span</xsl:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </xsl:variable>
                              <xsl:element name="{$container-element}">
                                 <xsl:attribute name="id">
                                    <xsl:value-of select="@xml:id"/>
                                 </xsl:attribute>
                                 <xsl:call-template name="tei-assign-classes"/>
                                 <xsl:variable name="root-id"
                                               select="ancestor::tei:TEI/@xml:id | ancestor::tei:teiCorpus/@xml:id"/>
                                 <img src="{$kiln:content-path}/images/{$root-id}/{tei:graphic/@url}">
                                    <xsl:apply-templates mode="tei-alt-text" select="."/>
                                 </img>
                                 <xsl:apply-templates select="*"/>
                              </xsl:element>
                           </xsl:template>

                           <xsl:template match="tei:figure" mode="tei-alt-text">
                              <xsl:attribute name="alt">
                                 <xsl:choose>
                                    <xsl:when test="normalize-space(tei:figDesc)">
                                       <xsl:value-of select="normalize-space(tei:figDesc)"/>
                                    </xsl:when>
                                    <xsl:when test="normalize-space(tei:head)">
                                       <xsl:value-of select="normalize-space(tei:head)"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                       <xsl:text/>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </xsl:attribute>
                           </xsl:template>

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

                           <!-- Glyphs. -->
  <xsl:template match="tei:g">
                              <xsl:variable name="root" select="ancestor::tei:TEI | ancestor::tei:teiCorpus"/>
                              <xsl:variable name="image-id" select="substring(@ref, 2)"/>
                              <xsl:variable name="glyph"
                                            select="ancestor::tei:TEI/tei:teiHeader/tei:encodingDesc/tei:charDecl/tei:glyph[@xml:id=$image-id]"/>
                              <xsl:variable name="url" select="$glyph/tei:graphic/@url"/>
                              <xsl:variable name="title" select="normalize-space($glyph/tei:glyphName)"/>
                              <xsl:variable name="alt" select="normalize-space(.)"/>
                              <xsl:choose>
                                 <xsl:when test="$url">
                                    <xsl:apply-templates select="@*"/>
                                    <span class="tei glyph">
                                       <img alt="{$alt}" src="/etexts/{$root/@xml:id}/{$url}">
                                          <xsl:if test="$title">
                                             <xsl:attribute name="title">
                                                <xsl:value-of select="$title"/>
                                             </xsl:attribute>
                                          </xsl:if>
                                       </img>
                                    </span>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:apply-templates select="node()"/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <!-- Anchors. -->
  <xsl:template match="tei:anchor|tei:milestone[@xml:id]">
                              <a id="{@xml:id}" name="{@xml:id}"/>
                           </xsl:template>

                           <!-- Page breaks. -->
  <xsl:template match="tei:pb">
                              <xsl:choose>
                                 <xsl:when test="number($page-numbers)">
                                    <span class="tei pb" lang="en">
                                       <xsl:apply-templates select="@xml:id"/>
                                       <xsl:variable name="page-label">
                                          <xsl:choose>
                                             <xsl:when test="normalize-space(@n)">
                                                <xsl:text>page </xsl:text>
                                                <xsl:value-of select="normalize-space(@n)"/>
                                             </xsl:when>
                                             <xsl:otherwise>
                                                <xsl:text>page break</xsl:text>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </xsl:variable>
                                       <xsl:choose>
                                          <xsl:when test="not(contains(concat(' ', @kiln:class, ' '), ' nested-link ')) and @xml:id">
                                             <a class="tei pb" href="#{@xml:id}" title="page break">
                                                <xsl:value-of select="$page-label"/>
                                             </a>
                                          </xsl:when>
                                          <xsl:otherwise>
                                             <xsl:value-of select="$page-label"/>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                    </span>
                                 </xsl:when>
                                 <xsl:when test="@xml:id">
                                    <span class="tei pb" id="{@xml:id}"/>
                                 </xsl:when>
                              </xsl:choose>
                           </xsl:template>

                           <!-- Line breaks. -->
  <xsl:template match="tei:lb">
                              <br/>
                           </xsl:template>

                           <xsl:template match="tei:*">
                              <xsl:choose>
                                 <xsl:when test="@rend">
                                    <xsl:call-template name="tei-make-span"/>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:apply-templates/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <xsl:template match="i18n:*|@i18n:*">
                              <xsl:copy>
                                 <xsl:apply-templates select="@*|node()"/>
                              </xsl:copy>
                           </xsl:template>

                           <xsl:template match="@xml:id">
                              <xsl:attribute name="id">
                                 <xsl:value-of select="."/>
                              </xsl:attribute>
                           </xsl:template>

                           <xsl:template match="@xml:lang">
                              <xsl:attribute name="lang">
                                 <xsl:value-of select="."/>
                              </xsl:attribute>
                           </xsl:template>

                           <xsl:template match="@*"/>

                           <!-- Named templates. -->

  <xsl:template name="tei-assign-classes">
                              <xsl:param name="node" select="."/>
                              <xsl:param name="html-element" select="''"/>
                              <xsl:param name="extra-classes" select="''"/>
                              <xsl:variable name="classes">
                                 <xsl:if test="$html-element != local-name($node)">
                                    <xsl:value-of select="local-name($node)"/>
                                    <xsl:text> </xsl:text>
                                 </xsl:if>
                                 <xsl:if test="normalize-space($node/@type)">
                                    <xsl:value-of select="normalize-space($node/@type)"/>
                                    <xsl:text> </xsl:text>
                                 </xsl:if>
                                 <xsl:if test="$node/self::tei:head and $node/parent::tei:figure">
                                    <xsl:text>figurehead </xsl:text>
                                 </xsl:if>
                                 <xsl:if test="$node/self::tei:note[@place]">
                                    <xsl:text>note-float </xsl:text>
                                 </xsl:if>
                                 <xsl:apply-templates mode="rend-class" select="$node/@rend"/>
                                 <xsl:value-of select="$extra-classes"/>
                              </xsl:variable>
                              <xsl:variable name="actual-classes" select="normalize-space($classes)"/>
                              <xsl:if test="$actual-classes">
                                 <xsl:attribute name="class">
                                    <xsl:text>tei </xsl:text>
                                    <xsl:value-of select="$actual-classes"/>
                                 </xsl:attribute>
                              </xsl:if>
                              <xsl:variable name="styles">
                                 <xsl:apply-templates mode="rend-style" select="$node/@rend"/>
                              </xsl:variable>
                              <xsl:variable name="actual-styles" select="normalize-space($styles)"/>
                              <xsl:if test="$actual-styles">
                                 <xsl:attribute name="style">
                                    <xsl:value-of select="$actual-styles"/>
                                 </xsl:attribute>
                              </xsl:if>
                           </xsl:template>

                           <xsl:template name="tei-generate-heading-level">
    <!-- Get the level of the heading, based on how many div ancestors
         the head has. -->
    <xsl:variable name="x">
      <!-- HTML heading elements only go up to 6. Therefore, change
           any deeper level head elements into h6 elements. -->
      <xsl:value-of select="count(ancestor::tei:div)"/>
                              </xsl:variable>
                              <xsl:choose>
                                 <xsl:when test="$x &gt; 5">
                                    <xsl:value-of select="6"/>
                                 </xsl:when>
                                 <xsl:otherwise>
        <!-- Add one to the value because the whole text is not
             enclosed in a div. -->
        <xsl:value-of select="$x+1"/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <xsl:template name="tei-make-div">
                              <div>
                                 <xsl:apply-templates select="@*"/>
                                 <xsl:if test="not(@xml:lang) and ancestor::*[@xml:lang]">
                                    <xsl:attribute name="lang">
                                       <xsl:value-of select="ancestor::*[@xml:lang][1]/@xml:lang"/>
                                    </xsl:attribute>
                                 </xsl:if>
                                 <xsl:call-template name="tei-assign-classes">
                                    <xsl:with-param name="html-element" select="'div'"/>
                                 </xsl:call-template>
                                 <xsl:call-template name="tei-make-run-in-heading"/>
                                 <xsl:apply-templates select="node()"/>
                              </div>
                           </xsl:template>

                           <!-- Convert current element to an HTML h?. -->
  <xsl:template name="tei-make-hx">
                              <xsl:variable name="hx">
                                 <xsl:call-template name="tei-generate-heading-level"/>
                              </xsl:variable>
                              <xsl:element name="h{$hx}">
                                 <xsl:apply-templates select="@*"/>
                                 <xsl:call-template name="tei-assign-classes">
                                    <xsl:with-param name="html-element" select="'head'"/>
                                 </xsl:call-template>
                                 <xsl:apply-templates select="node()"/>
                              </xsl:element>
                           </xsl:template>

                           <xsl:template name="tei-make-p">
                              <p>
                                 <xsl:apply-templates select="@*"/>
                                 <xsl:call-template name="tei-assign-classes">
                                    <xsl:with-param name="html-element" select="'p'"/>
                                 </xsl:call-template>
                                 <xsl:call-template name="tei-make-run-in-heading"/>
                                 <xsl:apply-templates select="node()"/>
                              </p>
                           </xsl:template>

                           <xsl:template name="tei-make-ref-link">
                              <xsl:param name="target"/>
                              <xsl:param name="title" select="''"/>
                              <xsl:param name="n" select="''"/>
                              <xsl:variable name="link">
                                 <a href="{$target}">
                                    <xsl:apply-templates select="@*"/>
                                    <xsl:if test="normalize-space($title)">
                                       <xsl:attribute name="title">
                                          <xsl:value-of select="$title"/>
                                       </xsl:attribute>
                                    </xsl:if>
                                    <xsl:call-template name="tei-assign-classes">
                                       <xsl:with-param name="html-element" select="'ref'"/>
                                    </xsl:call-template>
                                    <xsl:apply-templates select="node()"/>
                                 </a>
                              </xsl:variable>
                              <xsl:choose>
                                 <xsl:when test="parent::tei:cit and not(ancestor::tei:p)">
                                    <p class="tei cite">
                                       <xsl:copy-of select="$link"/>
                                    </p>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:copy-of select="$link"/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:template>

                           <!-- Add a run-in heading if appropriate. -->
  <xsl:template name="tei-make-run-in-heading">
                              <xsl:variable name="run-in-heading"
                                            select="preceding-sibling::*[1]/self::tei:head[contains(@rend, 'run-in')]"/>
                              <xsl:if test="$run-in-heading">
                                 <xsl:variable name="hx">
                                    <xsl:call-template name="tei-generate-heading-level"/>
                                 </xsl:variable>
                                 <span>
                                    <xsl:call-template name="tei-assign-classes">
                                       <xsl:with-param name="node" select="$run-in-heading"/>
                                       <xsl:with-param name="html-element" select="'head'"/>
                                       <xsl:with-param name="extra-classes" select="concat('h', $hx)"/>
                                    </xsl:call-template>
                                    <xsl:apply-templates select="$run-in-heading/node()"/>
                                    <xsl:text> </xsl:text>
                                 </span>
                              </xsl:if>
                           </xsl:template>

                           <xsl:template name="tei-make-span">
                              <span>
                                 <xsl:apply-templates select="@*"/>
                                 <xsl:call-template name="tei-assign-classes"/>
                                 <xsl:apply-templates select="node()"/>
                              </span>
                           </xsl:template>

                        </xsl:stylesheet>
                     </xsl:import>

                  </xsl:stylesheet>
               </xsl:import>

               <xsl:template match="index_metadata" mode="title">
                  <xsl:value-of select="tei:div/tei:head"/>
               </xsl:template>

               <xsl:template match="index_metadata" mode="head">
                  <xsl:apply-templates select="tei:div/tei:head/node()"/>
               </xsl:template>

               <xsl:template match="tei:div[@type='headings']/tei:list/tei:item">
                  <th scope="col">
                     <xsl:apply-templates/>
                  </th>
               </xsl:template>

               <xsl:template match="tei:div[@type='headings']">
                  <thead>
                     <tr>
                        <xsl:apply-templates select="tei:list/tei:item"/>
                     </tr>
                  </thead>
               </xsl:template>

               <xsl:template match="result/doc">
                  <tr>
                     <xsl:apply-templates select="str[@name='index_item_name']"/>
                     <xsl:apply-templates select="arr[@name='index_findspot_upper_level']"/>
                     <xsl:apply-templates select="arr[@name='index_findspot_intermediate_level']"/>
                     <xsl:apply-templates select="arr[@name='index_findspot_lower_level']"/>
                     <xsl:apply-templates select="str[@name='index_abbreviation_expansion']"/>
                     <xsl:apply-templates select="str[@name='index_numeral_value']"/>
                     <xsl:apply-templates select="arr[@name='language_code']"/>
                     <xsl:apply-templates select="str[@name='index_attested_form']"/>
                     <xsl:apply-templates select="arr[@name='index_epithet']"/>
                     <xsl:apply-templates select="str[@name='index_item_type']"/>
                     <xsl:apply-templates select="str[@name='index_item_role']"/>
                     <xsl:apply-templates select="arr[@name='index_external_resource']"/>
                     <xsl:apply-templates select="arr[@name='index_instance_location']"/>
                  </tr>
               </xsl:template>

               <xsl:template match="response/result">
                  <table class="index tablesorter">
                     <xsl:apply-templates select="/aggregation/index_metadata/tei:div/tei:div[@type='headings']"/>
                     <tbody>
                        <xsl:apply-templates select="doc">
                           <xsl:sort select="translate(normalize-unicode(lower-case(.),'NFD'), '̀́̈̃̄̓̔͂ͅ' ,'')"/>
                        </xsl:apply-templates>
                     </tbody>
                  </table>
               </xsl:template>

               <xsl:template match="str[@name='index_abbreviation_expansion']">
                  <td>
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>
  
               <xsl:template match="arr[@name='index_findspot_upper_level']">
                  <td class="larger_cell">
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>
  
               <xsl:template match="arr[@name='index_findspot_intermediate_level']">
                  <td>
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>
  
               <xsl:template match="arr[@name='index_findspot_lower_level']">
                  <td>
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>

               <xsl:template match="str[@name='index_item_name']">
                  <th scope="row">
      <!-- Look up the value in the RDF names, in case it's there. -->
      <xsl:variable name="rdf-name"
                                   select="/aggregation/index_names/rdf:RDF/rdf:Description[@rdf:about=current()][1]/*[@xml:lang=$language][1]"/>
                     <xsl:choose>
                        <xsl:when test="normalize-space($rdf-name)">
                           <xsl:value-of select="$rdf-name"/>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:value-of select="."/>
                        </xsl:otherwise>
                     </xsl:choose>
                  </th>
               </xsl:template>

               <xsl:template match="arr[@name='index_instance_location']">
                  <td>
                     <ul class="index-instances inline-list">
                        <xsl:apply-templates select="str"/>
                     </ul>
                  </td>
               </xsl:template>
  
               <xsl:template match="str[@name='index_item_type']">
                  <td>
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>
  
               <xsl:template match="str[@name='index_item_role']">
                  <td>
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>

               <xsl:template match="str[@name='index_attested_form']">
                  <td>
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>
  
               <xsl:template match="arr[@name='index_epithet']">
                  <td>
                     <xsl:variable name="epithets">
                        <xsl:for-each select="str">
                           <xsl:value-of select="."/>
                           <xsl:if test="position()!=last()">
                              <xsl:text>, </xsl:text>
                           </xsl:if>
                        </xsl:for-each>
                     </xsl:variable>
                     <xsl:value-of select="string-join(distinct-values(tokenize($epithets, ', ')), ', ')"/>
                  </td>
               </xsl:template>
  
               <xsl:template match="arr[@name='index_external_resource']">
                  <td>
                     <xsl:for-each select="str">
                        <xsl:choose>
                           <xsl:when test="contains(., 'http')">
                              <xsl:for-each select="tokenize(., ' ')">
                                 <a target="_blank" href="{.}">
                                    <xsl:value-of select="."/>
                                 </a>
                                 <xsl:text> </xsl:text>
                              </xsl:for-each>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:value-of select="."/>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:for-each>
                  </td>
               </xsl:template>
  
               <xsl:template match="str[@name='index_numeral_value']">
                  <td>
                     <xsl:value-of select="."/>
                  </td>
               </xsl:template>

               <xsl:template match="arr[@name='language_code']">
                  <td>
                     <ul class="inline-list">
                        <xsl:apply-templates select="str"/>
                     </ul>
                  </td>
               </xsl:template>

               <xsl:template match="arr[@name='language_code']/str">
                  <li>
                     <xsl:value-of select="."/>
                  </li>
               </xsl:template>

               <xsl:template match="arr[@name='index_instance_location']/str">
  <!-- This template must be defined in the calling XSLT (eg,
         indices-epidoc.xsl) since the format of the location data is
         not universal. -->
    <xsl:call-template name="render-instance-location"/>
               </xsl:template>

            </xsl:stylesheet>
         </xsl:import>

         <xsl:template name="render-instance-location">
    <!-- This field contains a single string with each location
         component separated by a "#". The components are (as taken
         from stylesheets/solr/epidoc-index-utils.xsl):

           * The content/xml subdirectory containing the indexed
           field, to be used in generating the map:match id used in
           generating the URL of the document containing this
           instance, via kiln:url-for-match. (This is the
           $subdirectory parameter.)

           * The path to the file (minus extension) this instance
           belongs to, relative to the content subdirectory (ie, the
           value in the preceding item), to be passed to the
           kiln:url-for-match call to generate the URL of the document
           containing this instance.

           * The text part numbers in descending hierarchical sequence
           for the instance, separated by ".".

           * The line number of the instance.

           * A Boolean marker (0 or 1) marking if the instance is
           partially or completely resotre (1) or not (0).

    -->
    <xsl:variable name="location_parts" select="tokenize(., '#')"/>
            <xsl:variable name="match_id">
               <xsl:text>local-</xsl:text>
               <xsl:value-of select="$location_parts[1]"/>
               <xsl:text>-display-html</xsl:text>
            </xsl:variable>
            <li>
               <a href="{kiln:url-for-match($match_id, ($language, $location_parts[2]), 0)}">
                  <xsl:if test="$location_parts[5] = '1'">
                     <xsl:text>[</xsl:text>
                  </xsl:if>
                  <span class="index-instance-file">
                     <xsl:value-of select="$location_parts[2]"/>
                  </span>
                  <xsl:if test="$location_parts[3]">
                     <span class="index-instance-text-parts">
                        <xsl:text>.</xsl:text>
                        <xsl:value-of select="$location_parts[3]"/>
                     </span>
                  </xsl:if>
                  <xsl:if test="$location_parts[4]">
                     <xsl:text>.</xsl:text>
                     <span class="index-instance-line">
                        <xsl:value-of select="$location_parts[4]"/>
                     </span>
                  </xsl:if>
                  <!-- for contextual index of words -->
        <xsl:if test="$location_parts[6]">
                     <xsl:text>: </xsl:text>
                     <xsl:value-of select="$location_parts[6]"/>
                  </xsl:if>
                  <xsl:if test="$location_parts[5] = '1'">
                     <xsl:text>]</xsl:text>
                  </xsl:if>
               </a>
            </li>
         </xsl:template>

      </xsl:stylesheet>
   </xsl:import>
   <xsl:import href="cocoon://_internal/template/xsl/stylesheets/text-file-list-to-html.xsl">
      <xsl:stylesheet version="2.0">

         <xsl:template match="response" mode="text-index">
            <table class="tablesorter">
               <thead>
                  <tr>
          <!-- Let us assume that all texts have a filename, ID, and
               title. -->
          <th>Filename</th>
                     <th>ID</th>
                     <th>Title</th>
                     <xsl:if test="result/doc/arr[@name='found_provenance']/str">
                        <th>Findspot</th>
                     </xsl:if>
                     <xsl:if test="result/doc/arr[@name='author']/str">
                        <th>Author</th>
                     </xsl:if>
                     <!--<xsl:if test="result/doc/arr[@name='editor']/str">
            <th>Editor</th>
          </xsl:if>-->
          <xsl:if test="result/doc/str[@name='publication_date']">
                        <th>Publication Date</th>
                     </xsl:if>
                  </tr>
               </thead>
               <tbody>
                  <xsl:apply-templates mode="text-index" select="result"/>
               </tbody>
            </table>
         </xsl:template>

         <xsl:template match="result[not(doc)]" mode="text-index">
            <p>There are no files indexed from
    webapps/ROOT/content/xml/<xsl:value-of select="$document_type"/>!
    Put some there, index them from the admin page, and this page will
    become much more interesting.</p>
         </xsl:template>

         <xsl:template match="result/doc" mode="text-index">
            <tr>
               <xsl:apply-templates mode="text-index" select="str[@name='file_path']"/>
               <xsl:apply-templates mode="text-index" select="str[@name='document_id']"/>
               <xsl:apply-templates mode="text-index" select="arr[@name='document_title']"/>
               <xsl:apply-templates mode="text-index" select="arr[@name='found_provenance']"/>
               <!--<xsl:apply-templates mode="text-index" select="arr[@name='author']" />
      <xsl:apply-templates mode="text-index" select="arr[@name='editor']" />
      <xsl:apply-templates mode="text-index" select="str[@name='publication_date']" />-->
    </tr>
         </xsl:template>

         <xsl:template match="str[@name='file_path']" mode="text-index">
            <xsl:variable name="filename" select="substring-after(., '/')"/>
            <td>
               <a href="{kiln:url-for-match($match_id, ($language, $filename), 0)}">
                  <xsl:value-of select="$filename"/>
               </a>
            </td>
         </xsl:template>

         <xsl:template match="str[@name='document_id']" mode="text-index">
            <td>
               <xsl:number value="number(substring(., 5, 2))" format="1"/>
               <xsl:text>.</xsl:text>
               <xsl:number value="number(substring(., 7, 4))" format="1"/>
            </td>
         </xsl:template>

         <xsl:template match="arr[@name='found_provenance']" mode="text-index">
            <td>
               <xsl:value-of select="string-join(str, '; ')"/>
            </td>
         </xsl:template>
  
         <xsl:template match="arr[@name='document_title']" mode="text-index">
            <td>
               <xsl:value-of select="string-join(str, '; ')"/>
            </td>
         </xsl:template>

         <xsl:template match="arr[@name='author']" mode="text-index">
            <td>
               <xsl:value-of select="string-join(str, '; ')"/>
            </td>
         </xsl:template>

         <xsl:template match="arr[@name='editor']" mode="text-index">
            <td>
               <xsl:value-of select="string-join(str, '; ')"/>
            </td>
         </xsl:template>

         <xsl:template match="str[@name='publication_date']">
            <td>
               <xsl:value-of select="."/>
            </td>
         </xsl:template>

      </xsl:stylesheet>
   </xsl:import>
   <xsl:import href="cocoon://_internal/template/xsl/stylesheets/defaults.xsl">
      <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">
  <!--
      Defaults stylesheet. Defines default globals and reads
      parameters from the sitemap.
  -->

  <xsl:param name="language"/>

         <!-- Specify a mount path if you are mounting the webapp in a
       subdirectory rather than at the root of the domain. This path
       must either be empty or begin with a "/" and not include a
       trailing slash.

       The value is the URL root for the webapp. -->
  <xsl:variable name="kiln:mount-path" select="''"/>

         <!-- $kiln:context-path defines the URL root for the webapp. -->
  <xsl:variable name="kiln:context-path">
            <xsl:value-of select="$kiln:mount-path"/>
         </xsl:variable>

         <!-- Base URL for non-textual content (images, video, etc). If these
       are being served by Cocoon, this should be specified as
       relative to $context-path. Otherwise, a full URL including
       protocol and domain is required.

       This URL must not include a trailing slash. -->
  <xsl:variable name="kiln:content-url" select="''"/>
         <xsl:variable name="kiln:content-path">
            <xsl:if test="not(starts-with($kiln:content-url, 'http'))">
               <xsl:value-of select="$kiln:mount-path"/>
            </xsl:if>
            <xsl:value-of select="$kiln:content-url"/>
         </xsl:variable>

         <!-- Base URL for assets (non-content images, CSS, JavaScript,
       etc). If these are being served by Cocoon, this should be
       specified as relative to $context-path. Otherwise, a full URL
       including protocol and domain is required.

       This URL must not include a trailing slash. -->
  <xsl:variable name="kiln:assets-url" select="'/assets'"/>
         <xsl:variable name="kiln:assets-path">
            <xsl:if test="not(starts-with($kiln:assets-url, 'http'))">
               <xsl:value-of select="$kiln:mount-path"/>
            </xsl:if>
            <xsl:value-of select="$kiln:assets-url"/>
         </xsl:variable>

         <!-- Base URL for content images. -->
  <xsl:variable name="kiln:images-url" select="concat($kiln:content-path, '/images')"/>
         <xsl:variable name="kiln:images-path">
            <xsl:if test="not(starts-with($kiln:images-url, 'http'))">
               <xsl:value-of select="$kiln:mount-path"/>
            </xsl:if>
            <xsl:value-of select="$kiln:images-url"/>
         </xsl:variable>

      </xsl:stylesheet>
   </xsl:import>
   <xsl:import href="cocoon://_internal/template/xsl/stylesheets/menu/menu.xsl">
      <xsl:stylesheet exclude-result-prefixes="#all" version="2.0">

         <xsl:template match="kiln:nav" mode="main-menu">
            <xsl:apply-templates mode="main-menu"/>
         </xsl:template>

         <xsl:template match="ul[@type='menu']" mode="main-menu">
            <xsl:apply-templates mode="main-menu"/>
         </xsl:template>

         <xsl:template match="ul[@type='breadcrumbs']" mode="main-menu"/>

         <xsl:template match="li[ul]" mode="main-menu">
            <xsl:copy>
               <xsl:apply-templates mode="main-menu" select="@*"/>
               <xsl:call-template name="add-class">
                  <xsl:with-param name="class" select="'has-dropdown'"/>
               </xsl:call-template>
               <xsl:apply-templates mode="main-menu"/>
            </xsl:copy>
         </xsl:template>

         <xsl:template match="li/ul" mode="main-menu">
            <xsl:copy>
               <xsl:apply-templates mode="main-menu" select="@*"/>
               <xsl:call-template name="add-class">
                  <xsl:with-param name="class" select="'dropdown'"/>
               </xsl:call-template>
               <xsl:apply-templates mode="main-menu"/>
            </xsl:copy>
         </xsl:template>

         <!-- For the local menu, display only the siblings of the active
       item. -->
  <xsl:template match="kiln:nav" mode="local-menu">
            <xsl:apply-templates mode="local-menu" select="ul[@type='menu']//ul[li/@class='active']/li"/>
         </xsl:template>

         <xsl:template match="li/ul" mode="local-menu"/>

         <xsl:template match="ul/@type" mode="main-menu"/>
         <xsl:template match="@*|node()" mode="main-menu">
            <xsl:copy>
               <xsl:apply-templates mode="main-menu" select="@*|node()"/>
            </xsl:copy>
         </xsl:template>
         <xsl:template match="ul/@type" mode="local-menu"/>
         <xsl:template match="@*|node()" mode="local-menu">
            <xsl:copy>
               <xsl:apply-templates mode="local-menu" select="@*|node()"/>
            </xsl:copy>
         </xsl:template>

         <xsl:template name="add-class">
            <xsl:param name="class"/>
            <xsl:attribute name="class">
               <xsl:if test="@class">
                  <xsl:value-of select="@class"/>
                  <xsl:text> </xsl:text>
               </xsl:if>
               <xsl:value-of select="$class"/>
            </xsl:attribute>
         </xsl:template>

      </xsl:stylesheet>
   </xsl:import>
   <xsl:import href="cocoon://_internal/url/reverse.xsl">
      <xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
                      xmlns:map="http://apache.org/cocoon/sitemap/1.0"
                      exclude-result-prefixes="#all"
                      version="2.0">
         <xsl:function name="kiln:url-for-match" as="xs:string">
            <xsl:param name="match-id" as="xs:string"/>
            <xsl:param name="parameters"/>
            <xsl:param name="cocoon-context"/>
            <xsl:variable name="url">
               <xsl:choose>
                  <xsl:when test="$match-id = 'kiln-introspection-match-url'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>_internal/introspection/url/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-harvest-all-display'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/harvest/all.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-harvest-all'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/harvest/all.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-harvest-display'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/harvest/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-harvest'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/harvest/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-query'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/query/graph/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-generate-authority'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/generate/authority/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-generate-epidoc'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/generate/epidoc/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-generate-index'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/generate/indices/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-generate-tei'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/generate/tei/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-generate-static'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/generate/rdf/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-rdf-query-from-file'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/rdf/construct/graph/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-site-list'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/index/site-list.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-index-all'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/index/all.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-index-indices'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/index/indices/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-index'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/index/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add-all-indices'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/indices/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add-all'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add-tei-eats'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/tei-eats/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add-tei-eats-authority'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/tei-eats-authority/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add-indices'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/indices/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add-index'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/indices/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add-bibliographic-concordance'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/concordance/authority/bibliography.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-add'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/add/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-preprocess-tei-eats'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/preprocess/tei-eats/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-preprocess-eatsml'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/preprocess/eatsml/entities.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-preprocess-eatsml-authority'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/preprocess/eatsml/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/entities.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-solr-preprocess'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/solr/preprocess/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-home-page'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-system-status'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/system-status.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-introspection-index'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/introspection/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-introspection-match'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/introspection/match/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-introspection-template-empty'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/introspection/template/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-introspection-template-xslt'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/introspection/template/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xsl</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-introspection-xslt'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/introspection/xslt/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xsl</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-introspection-match-url'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/introspection/url/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-schematron-validation'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/schematron/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-resource-check'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>admin/resource-check/images/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-image-resource-check'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>admin/resource-check/images/tei/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-image-reference-check'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>admin/resource-check/image-refs/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-admin-image-file-check'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>admin/resource-check/image-files.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-preprocess-tei-no-language'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/tei/preprocess/no-language/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-preprocess-epidoc-no-language'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/epidoc/preprocess/no-language/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-preprocess-tei-language'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/tei/preprocess/language/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-preprocess-epidoc-language'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/epidoc/preprocess/language/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-preprocess-authority-language'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/authority/preprocess/language/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-epidoc-custom-html'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/epidoc/custom/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-search-query'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/search/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-index-extract'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/index/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-typed-metadata'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/metadata/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-metadata'">
                     <xsl:text>cocoon://</xsl:text>
                     <xsl:text>internal/metadata/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-images-gif'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>images/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.gif</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-images-jpeg-thumbnail'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>images/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>-thumb.jpg</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-images-jpeg'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>images/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.jpg</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-images-png'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>images/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.png</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-home-page'">
                     <xsl:text>/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-language-home-page'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-search'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/search/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-tei-index-display'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/texts/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-tei-display-html'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/texts/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-tei-display-xml'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/texts/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-tei-display-pdf'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/texts/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.pdf</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-tei-display-epub'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/texts/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.epub</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-epidoc-index-display'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/inscriptions/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-epidoc-zip'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/inscriptions/zip/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-epidoc-display-html'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/inscriptions/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-epidoc-display-xml'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/inscriptions/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-indices-type-display'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/indices/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-index-display-html'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/indices/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[4-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-concordance-bibliography'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/concordances/bibliography/</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-concordance-bibliography-item'">
                     <xsl:text>/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>/concordance/bibliography/</xsl:text>
                     <xsl:value-of select="$parameters[3-1]"/>
                     <xsl:text>.html</xsl:text>
                  </xsl:when>
                  <xsl:when test="$match-id = 'local-tei-backend-xml'">
                     <xsl:text>/</xsl:text>
                     <xsl:text>text/</xsl:text>
                     <xsl:value-of select="$parameters[2-1]"/>
                     <xsl:text>.xml</xsl:text>
                  </xsl:when>
               </xsl:choose>
            </xsl:variable>
            <xsl:variable name="full-url">
               <xsl:if test="$cocoon-context and not(starts-with($url, 'cocoon://'))">cocoon:/</xsl:if>
               <xsl:value-of select="$url"/>
            </xsl:variable>
            <xsl:value-of select="$full-url"/>
         </xsl:function>
      </xsl:stylesheet>
   </xsl:import>
   <xsl:template match="/">

  

  
    

  
    

  

  
    

  <!-- Imports the default variables. -->
  

  <!-- Imports the menu stylesheet -->
  

  

  
    <html class="no-js">
      
        <head>
            <meta charset="utf-8"/>
            <meta content="width=device-width" name="viewport"/>
            <meta content="IE=edge,chrome=IE8" http-equiv="X-UA-Compatible"/>
            <title>
            
      IAph: 
      <xsl:apply-templates mode="title" select="/aggregation/index_metadata"/>
    
            </title>
          
      
            <link href="{$kiln:assets-path}/foundation/css/normalize.css" rel="stylesheet"
                  type="text/css"/>
            <link href="{$kiln:assets-path}/foundation/css/foundation.min.css" rel="stylesheet"
                  type="text/css"/>
            <link href="{$kiln:assets-path}/styles/base.css" rel="stylesheet" type="text/css"/>
            <link href="{$kiln:assets-path}/styles/site.css" rel="stylesheet" type="text/css"/>
            <link href="{$kiln:assets-path}/images/favicon.png" rel="shortcut icon"
                  type="image/png"/>
            <!-- <link href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" rel="stylesheet" type="text/css" />
            <link href="{$kiln:assets-path}/styles/Control.Geocoder.css" rel="stylesheet" type="text/css" />
            <link href="{$kiln:assets-path}/styles/leaflet.fullscreen.css" rel="stylesheet" type="text/css" />-->
          
      <link href="{$kiln:assets-path}/styles/tablesorter.css" rel="stylesheet"/>
    
          
            <script src="{$kiln:assets-path}/foundation/js/vendor/custom.modernizr.js"> </script>
            <script src="{$kiln:assets-path}/scripts/cookieinfo.min.js" type="text/javascript"
                    id="cookieinfo"/>
            <!-- <script src="{$kiln:assets-path}/foundation/js/vendor/jquery.js"></script>
            <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
            <script src="{$kiln:assets-path}/scripts/leaflet-providers.js"></script> -->
          
          
        </head>
      
      
        <body>
          
            <div id="site-heading">
              <h1 id="site-title">Inscriptions of Aphrodisias 2027</h1>
            </div>
            <nav class="top-bar">
              
                <ul class="title-area">
                  <li class="name">
                    <h1 id="home">
                        <a href="{kiln:url-for-match('local-language-home-page', ($language), 0)}">Home</a>
                     </h1>
                  </li>
                  <li class="toggle-topbar menu-icon">
                    <a href="#">
                        <span>Menu</span>
                     </a>
                  </li>
                </ul>
                <section class="top-bar-section">
                  <ul class="left">
                    <xsl:apply-templates mode="main-menu" select="/aggregation/kiln:nav"/>
                  </ul>
                  <!--<ul class="right">
                    <li class="has-form search">
                      <form action="{kiln:url-for-match('local-search', ($language), 0)}" method="get">
                        <input name="q" placeholder="Search" required="required" type="search" />
                      </form>
                    </li>
                  </ul>-->
                </section>
              
            </nav>
          
          
            <div class="row">
              <div class="large-12 columns">
                  <h1>
                  
      
                     <xsl:apply-templates mode="head" select="/aggregation/index_metadata"/>
    
                  </h1>
              </div>
            </div>
          
          
            <main>
              
               <div class="row">
                  <div class="large-12 columns">
          <!-- Display the index's notes. -->
          <xsl:apply-templates select="/aggregation/index_metadata/tei:div/tei:div[@type='notes']"/>
                     <!-- Display the index. -->
          <xsl:apply-templates select="/aggregation/response/result"/>
                  </div>
               </div>
    
            </main>
          
          
            <footer>
              <p>Powered by <a href="http://kcl-ddh.github.io/kiln/">Kiln</a>/<a href="https://github.com/EpiDoc/EFES">EFES</a>. Theme by <a href="http://foundation.zurb.com/">Foundation</a>.</p>
            </footer>
          
          
      
            <!-- Since we make use of jQuery for other purposes, there
                 is no reason to use Foundation's check whether to use
                 jQuery or Zepto. -->
            <script src="{$kiln:assets-path}/foundation/js/vendor/jquery.js"/>
            <script src="{$kiln:assets-path}/foundation/js/foundation.min.js"/>
            <script>$(document).foundation();</script>
          
            <script src="{$kiln:assets-path}/scripts/jquery.tablesorter.js"/>
            <script>
               <xsl:text>$(document).ready(function() {$(".tablesorter").tablesorter();});</xsl:text>
            </script>
    
        </body>
      
      </html>
  

  

  

  

  


  

  

   </xsl:template>
</xsl:stylesheet>