<?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/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="/">

  <!-- Imports stylesheet to convert TEI into HTML. -->
  

  <data>
    <title>
      
        <xsl:value-of select="/tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title[not(@type)]"/>
      
    </title>
    <metadata>
      
    </metadata>
    <css>
      
    </css>
    <js>
      
    </js>
    <content>
      
        <xsl:apply-templates select="/tei:TEI"/>
      
    </content>
  </data>
</xsl:template></xsl:stylesheet>