<?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" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="#all" version="2.0"><xsl:import href="cocoon://_internal/template/xsl/stylesheets/epidoc/start-edition.xsl"><xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1" version="2.0">

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

  <xsl:import href="../../kiln/stylesheets/epidoc/start-edition.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:t="http://www.tei-c.org/ns/1.0" exclude-result-prefixes="t" version="2.0">
   <xsl:output method="xml" encoding="UTF-8"/>

   <xsl:include href="global-varsandparams.xsl"><!-- $Id$ --><xsl:stylesheet version="2.0">

            <!-- Location of file defining the parameters and variables -->
            <xsl:variable name="param-file">
                        <xsl:text>global-parameters.xml</xsl:text>
            </xsl:variable>

            <!-- Location of HGV glossary file relative to the current file -->
            <xsl:param name="hgv-gloss">
                        <xsl:text>../../../xml/idp.data/trunk/HGV_trans_EpiDoc/glossary.xml</xsl:text>
            </xsl:param>

            <!-- Mapping file -->
            <xsl:variable name="mapping-file" select="'../crosswalker/aggregator/mapping/mapping.xml'"/>

            <xsl:param name="topNav" select="document($param-file)//parameter[name = 'topNav']/value[@on = 'yes']"/>
            <xsl:param name="verse-lines" select="document($param-file)//parameter[name = 'verse-lines']/value[@on = 'yes']"/>
            <xsl:param name="leiden-style" select="document($param-file)//parameter[name = 'leiden-style']/value[@on = 'yes']"/>
            <xsl:param name="edn-structure" select="document($param-file)//parameter[name = 'edn-structure']/value[@on = 'yes']"/>
            <xsl:param name="edition-type" select="document($param-file)//parameter[name = 'edition-type']/value[@on = 'yes']"/>
            <xsl:param name="internal-app-style" select="document($param-file)//parameter[name = 'internal-app-style']/value[@on = 'yes']"/>
            <xsl:param name="external-app-style" select="document($param-file)//parameter[name = 'external-app-style']/value[@on = 'yes']"/>
            <xsl:param name="line-inc" select="document($param-file)//parameter[name = 'line-inc']/value"/>
            <xsl:param name="css-loc" select="document($param-file)//parameter[name = 'css-loc']/value"/>
            <xsl:param name="js-dir" select="document($param-file)//parameter[name = 'js-dir']/value"/>
            <xsl:param name="bibliography" select="document($param-file)//parameter[name = 'bibliography']/value[@on = 'yes']"/>
            <xsl:param name="localbibl" select="document($param-file)//parameter[name = 'localbibl']/value"/>
            <xsl:param name="ZoteroUorG" select="document($param-file)//parameter[name = 'ZoteroUorG']/value[@on = 'yes']"/>
            <xsl:param name="ZoteroKey" select="document($param-file)//parameter[name = 'ZoteroKey']/value[@on = 'yes']"/>
            <xsl:param name="ZoteroNS" select="document($param-file)//parameter[name = 'ZoteroNS']/value[@on='yes']"/>
            <xsl:param name="ZoteroStyle" select="document($param-file)//parameter[name = 'ZoteroStyle']/value[@on = 'yes']"/>
    
            <xsl:param name="docroot">../output/data</xsl:param>

            <xsl:variable name="all-grc">
                        <xsl:text>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZἀἁἂἃἄἅἆἇἈἉἊἋἌἍἎἏΑὰάᾀᾁᾂᾃᾄᾅᾆᾇᾈᾉᾊᾋᾌᾍᾎᾏᾲᾳᾴᾶᾷάέΕἐἑἒἓἔἕἘἙἚἛἜἝὲέΗήἠἡἢἣἤἥἦἧἨἩἪἫἬἭἮἯᾐᾑᾒᾓᾔᾕᾖᾗᾘᾙᾚᾛᾜᾝᾞᾟῂῃῄῆῇὴήΙίϊἰἱἲἳἴἵἶἷἸἹἺἻἼἽἾἿὶίῒΐΐῖῗΟόὀὁὂὃὄὅὈὉὊὋὌὍὸό΅ύὐὑὒὓὔὕὖὗὙὛὝὟὺύῢΰΰῦῧϋΩώὠὡὢὣὤὥὦὧὨὩὪὫὬὭὮὯὼώᾠᾡᾢᾣᾤᾥᾦᾧᾨᾩᾪᾫᾬᾭᾮᾯῲῳῴῶῷςῤῥαβγδεζηθικλμνξοπρστυφχψωῬΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ</xsl:text>
                        <!--<xsl:text>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&#x1F00;&#x1F01;&#x1F02;&#x1F03;&#x1F04;&#x1F05;&#x1F06;&#x1F07;&#x1F08;&#x1F09;&#x1F0A;&#x1F0B;&#x1F0C;&#x1F0D;&#x1F0E;&#x1F0F;&#x391;&#x1F70;&#x1F71;&#x1F80;&#x1F81;&#x1F82;&#x1F83;&#x1F84;&#x1F85;&#x1F86;&#x1F87;&#x1F88;&#x1F89;&#x1F8A;&#x1F8B;&#x1F8C;&#x1F8D;&#x1F8E;&#x1F8F;&#x1FB2;&#x1FB3;&#x1FB4;&#x1FB6;&#x1FB7;&#x3AC;&#x3AD;&#x395;&#x1F10;&#x1F11;&#x1F12;&#x1F13;&#x1F14;&#x1F15;&#x1F18;&#x1F19;&#x1F1A;&#x1F1B;&#x1F1C;&#x1F1D;&#x1F72;&#x1F73;&#x397;&#x3AE;&#x1F20;&#x1F21;&#x1F22;&#x1F23;&#x1F24;&#x1F25;&#x1F26;&#x1F27;&#x1F28;&#x1F29;&#x1F2A;&#x1F2B;&#x1F2C;&#x1F2D;&#x1F2E;&#x1F2F;&#x1F90;&#x1F91;&#x1F92;&#x1F93;&#x1F94;&#x1F95;&#x1F96;&#x1F97;&#x1F98;&#x1F99;&#x1F9A;&#x1F9B;&#x1F9C;&#x1F9D;&#x1F9E;&#x1F9F;&#x1FC2;&#x1FC3;&#x1FC4;&#x1FC6;&#x1FC7;&#x1F74;&#x1F75;&#x399;&#x3AF;&#x3CA;&#x1F30;&#x1F31;&#x1F32;&#x1F33;&#x1F34;&#x1F35;&#x1F36;&#x1F37;&#x1F38;&#x1F39;&#x1F3A;&#x1F3B;&#x1F3C;&#x1F3D;&#x1F3E;&#x1F3F;&#x1F76;&#x1F77;&#x1FD2;&#x1FD3;&#x0390;&#x1FD6;&#x1FD7;&#x39F;&#x3CC;&#x1F40;&#x1F41;&#x1F42;&#x1F43;&#x1F44;&#x1F45;&#x1F48;&#x1F49;&#x1F4A;&#x1F4B;&#x1F4C;&#x1F4D;&#x1F78;&#x1F79;&#x385;&#x3CD;&#x1F50;&#x1F51;&#x1F52;&#x1F53;&#x1F54;&#x1F55;&#x1F56;&#x1F57;&#x1F59;&#x1F5B;&#x1F5D;&#x1F5F;&#x1F7A;&#x1F7B;&#x1FE2;&#x1FE3;7#X03B0;&#x1FE6;&#x1FE7;&#x3CB;&#x3A9;&#x3CE;&#x1F60;&#x1F61;&#x1F62;&#x1F63;&#x1F64;&#x1F65;&#x1F66;&#x1F67;&#x1F68;&#x1F69;&#x1F6A;&#x1F6B;&#x1F6C;&#x1F6D;&#x1F6E;&#x1F6F;&#x1F7C;&#x1F7D;&#x1FA0;&#x1FA1;&#x1FA2;&#x1FA3;&#x1FA4;&#x1FA5;&#x1FA6;&#x1FA7;&#x1FA8;&#x1FA9;&#x1FAA;&#x1FAB;&#x1FAC;&#x1FAD;&#x1FAE;&#x1FAF;&#x1FF2;&#x1FF3;&#x1FF4;&#x1FF6;&#x1FF7;&#x3C2;&#x1FE4;&#x1FE5;&#x3B1;&#x3B2;&#x3B3;&#x3B4;&#x3B5;&#x3B6;&#x3B7;&#x3B8;&#x3B9;&#x3BA;&#x3BB;&#x3BC;&#x3BD;&#x3BE;&#x3BF;&#x3C0;&#x3C1;&#x3C3;&#x3C4;&#x3C5;&#x3C6;&#x3C7;&#x3C8;&#x3C9;&#x1FEC;&#x391;&#x392;&#x393;&#x394;&#x395;&#x396;&#x397;&#x398;&#x399;&#x39A;&#x39B;&#x39C;&#x39D;&#x39E;&#x39F;&#x3A0;&#x3A1;&#x3A3;&#x3A4;&#x3A5;&#x3A6;&#x3A7;&#x3A8;&#x3A9;</xsl:text>-->
            </xsl:variable>

            <xsl:variable name="grc-upper-strip">
                        <xsl:text>ABCDEFGHIJKLMNOPQRSTVVWXYZABCDEFGHIJKLMNOPQRSTVVWXYZΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΑΕΕΕΕΕΕΕΕΕΕΕΕΕΕΕΕΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΗΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΙΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟΟΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΥΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΩΣΡΡΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΡΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ</xsl:text>
                        <!--<xsl:text>ABCDEFGHIJKLMNOPQRSTVVWXYZABCDEFGHIJKLMNOPQRSTVVWXYZ&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x391;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x395;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x397;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x399;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x39F;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A5;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A9;&#x3A3;&#x3A1;&#x3A1;&#x391;&#x392;&#x393;&#x394;&#x395;&#x396;&#x397;&#x398;&#x399;&#x39A;&#x39B;&#x39C;&#x39D;&#x39E;&#x39F;&#x3A0;&#x3A1;&#x3A3;&#x3A4;&#x3A5;&#x3A6;&#x3A7;&#x3A8;&#x3A9;&#x3A1;&#x391;&#x392;&#x393;&#x394;&#x395;&#x396;&#x397;&#x398;&#x399;&#x39A;&#x39B;&#x39C;&#x39D;&#x39E;&#x39F;&#x3A0;&#x3A1;&#x3A3;&#x3A4;&#x3A5;&#x3A6;&#x3A7;&#x3A8;&#x3A9;</xsl:text>-->
            </xsl:variable>

            <xsl:variable name="grc-lower-strip">
                        <xsl:text>abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzαααααααααααααααααααααααααααααααααααααααααεεεεεεεεεεεεεεεεηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηηιιιιιιιιιιιιιιιιιιιιιιιιιιοοοοοοοοοοοοοοοουυυυυυυυυυυυυυυυυυυυυυωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωωσρραβγδεζηθικλμνξοπρστυφχψωραβγδεζηθικλμνξοπρστυφχψω</xsl:text>
                        <!--<xsl:text>abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B1;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B5;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B7;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3B9;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3BF;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C5;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C9;&#x3C3;&#x3C1;&#x3C1;&#x3B1;&#x3B2;&#x3B3;&#x3B4;&#x3B5;&#x3B6;&#x3B7;&#x3B8;&#x3B9;&#x3BA;&#x3BB;&#x3BC;&#x3BD;&#x3BE;&#x3BF;&#x3C0;&#x3C1;&#x3C3;&#x3C4;&#x3C5;&#x3C6;&#x3C7;&#x3C8;&#x3C9;&#x3C1;&#x3B1;&#x3B2;&#x3B3;&#x3B4;&#x3B5;&#x3B6;&#x3B7;&#x3B8;&#x3B9;&#x3BA;&#x3BB;&#x3BC;&#x3BD;&#x3BE;&#x3BF;&#x3C0;&#x3C1;&#x3C3;&#x3C4;&#x3C5;&#x3C6;&#x3C7;&#x3C8;&#x3C9;</xsl:text>-->
            </xsl:variable>

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

   <!-- html related stylesheets, these may import tei{element} stylesheets if relevant eg. htm-teigap and teigap -->
   <xsl:include href="htm-teiab.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  
  <xsl:template match="t:ab">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <div class="textpart">
          <span class="ab">
              <xsl:if test="$parm-leiden-style='iospe'">
                <xsl:variable name="div-loc">
                   <xsl:for-each select="ancestor::t:div[@type='textpart']">
                      <xsl:value-of select="@n"/>
                      <xsl:text>-</xsl:text>
                   </xsl:for-each>
                </xsl:variable>
                <xsl:attribute name="id">
                   <xsl:value-of select="concat('div',$div-loc)"/>
                </xsl:attribute>
             </xsl:if>
             <xsl:apply-templates/>
             <!-- if next div or ab begins with lb[break=no], then add hyphen -->
              <xsl:if test="following::t:lb[1][@break='no' or @type='inWord'] and not($parm-edition-type='diplomatic')">
                <xsl:text>-</xsl:text>
             </xsl:if>
             <!-- if final lb in ab is L2R or R2L, then print arrow here -->
             <xsl:if test="not($parm-leiden-style=('ddbdp','sammelbuch'))                  and descendant::t:lb[last()][@rend='left-to-right']">
                <xsl:text>  →</xsl:text>
             </xsl:if>
             <xsl:if test="not($parm-leiden-style=('ddbdp','sammelbuch'))                  and descendant::t:lb[last()][@rend='right-to-left']">
                <xsl:text>  ←</xsl:text>
             </xsl:if>
             <!-- in IOSPE, if followed by lg, include it here (and suppress in htm-teilgandl.xsl) -->
              <xsl:if test="$parm-leiden-style='iospe' and following-sibling::t:*[1][self::t:lg]">
                <xsl:apply-templates select="following-sibling::t:lg/*"/>
              </xsl:if>
          </span>
      </div>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teiaddanddel.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- main templates for subst, add and del found in teiaddanddel.xsl-->
   <xsl:import href="teiaddanddel.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Contains templates for subst, add and del -->
   
   <!-- Imported by htm-teiaddanddel.xsl or called directly from start-txt.xsl -->
   
   <xsl:template match="t:subst">
      <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
      <xsl:param name="parm-internal-app-style" tunnel="yes" required="no"/>
       <xsl:apply-templates/>

      <xsl:if test="$parm-internal-app-style = 'ddbdp'">
         <!-- Found in [htm|txt]-tpl-apparatus -->
         <xsl:call-template name="app-link">
            <xsl:with-param name="location" select="'text'"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>


   <xsl:template match="t:add">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch')">
            <xsl:choose>
               <xsl:when test="parent::t:subst"/>
               <xsl:when test="@place = 'above'">
                  <xsl:text>\</xsl:text>
               </xsl:when>
               <xsl:when test="@place = 'below'">
                  <xsl:text>/</xsl:text>
               </xsl:when>
               <xsl:when test="@place = 'left'">
                  <xsl:text>(added at left: </xsl:text>
               </xsl:when>
               <xsl:when test="@place = 'right'">
                  <xsl:text>(added at right: </xsl:text>
               </xsl:when>
            </xsl:choose>
         </xsl:when>
           <xsl:when test="$parm-leiden-style=('petrae','iospe')">
            <xsl:text>\</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:choose>
               <xsl:when test="parent::t:subst or @place='overstrike'">
                  <xsl:text>«</xsl:text>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:text>`</xsl:text>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates/>
      <xsl:call-template name="cert-low"/>

      <xsl:choose>
          <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch')">
            <xsl:choose>
               <!-- if my parent is subst which in turn is in the appcrit-part of a further app-like element 
                  (i.e. my ancestor is reg, corr, rdg, or del[corrected]), then include value of my sibling del in parens -->
               <xsl:when test="parent::t:subst and ancestor::t:*[local-name()=('reg','corr','rdg')                    or self::t:del[@rend='corrected']]">
                  <!-- If add contains app, *only* render del (because add is rendered before the subst by app templates) -->
                  <xsl:text> (</xsl:text><xsl:choose>
                     <xsl:when test="t:app"><xsl:call-template name="resolvesubst">
                           <!-- From tpl-apparatus.xsl -->
                           <xsl:with-param name="delpath" select="../t:del/node()"/>
                        </xsl:call-template></xsl:when>
                     <xsl:otherwise><xsl:call-template name="resolvesubst">
                           <!-- From tpl-apparatus.xsl -->
                           <xsl:with-param name="delpath" select="../t:del/node()"/>
                           <xsl:with-param name="addpath" select="node()"/>
                        </xsl:call-template></xsl:otherwise></xsl:choose><xsl:text>)</xsl:text>
               </xsl:when>
               <xsl:when test="parent::t:subst"/>
               <xsl:when test="@place = 'above'">
                  <xsl:text>/</xsl:text>
               </xsl:when>
               <xsl:when test="@place = 'below'">
                  <xsl:text>\</xsl:text>
               </xsl:when>
               <xsl:when test="@place = 'left' or @place = 'right'">
                  <xsl:text>)</xsl:text>
               </xsl:when>
            </xsl:choose>
         </xsl:when>
          <xsl:when test="$parm-leiden-style=('petrae','iospe')">
            <xsl:text>/</xsl:text>
         </xsl:when>
         <xsl:when test="parent::t:subst or @place='overstrike'">
            <xsl:text>»</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>´</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>


   <xsl:template match="t:del">
      <xsl:param name="parm-internal-app-style" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:if test="$parm-internal-app-style = 'ddbdp'">
         <xsl:if test="@rend = 'slashes' or @rend = 'cross-strokes'">
            <!-- Found in [htm | txt]-tpl-apparatus -->
            <xsl:call-template name="app-link">
               <xsl:with-param name="location" select="'text'"/>
            </xsl:call-template>
         </xsl:if>
      </xsl:if>

      <xsl:choose>
          <xsl:when test="starts-with($parm-leiden-style, 'edh') or $parm-leiden-style=('petrae','iospe')">
            <xsl:text>[[</xsl:text>
            <xsl:apply-templates/>
            <xsl:text>]]</xsl:text>
         </xsl:when>
          <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and @rend='slashes'">
            <xsl:apply-templates/>
         </xsl:when>
          <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and @rend='cross-strokes'">
            <xsl:apply-templates/>
         </xsl:when>
          <xsl:when test="$parm-leiden-style = 'rib'">
              <xsl:choose>
                  <xsl:when test="@rend='erasure'">
                      <span class="erasure"><xsl:apply-templates/></span>
                  </xsl:when>
                  <xsl:when test="not(@rend)"/>
                  <xsl:otherwise>
                      <xsl:apply-templates/>
                  </xsl:otherwise>
              </xsl:choose>
          </xsl:when>
          <xsl:when test="parent::t:subst"/>
         <xsl:otherwise>
            <xsl:text>⟦</xsl:text>
            <xsl:apply-templates/>
            <xsl:call-template name="cert-low"/>
            <xsl:text>⟧</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

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

   <xsl:template match="t:subst">
      <xsl:apply-imports/>
   </xsl:template>


   <xsl:template match="t:add">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and @place='interlinear'">
            <span style="font-size:smaller;">
               <xsl:apply-imports/>
            </span>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-imports/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>


   <xsl:template match="t:del">
      <xsl:apply-imports/>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teiapp.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains app and its children rdg, ptr, note and lem -->

   <xsl:template match="t:app">
      <xsl:param name="parm-internal-app-style" tunnel="yes" required="no"/>
      <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
      <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="$parm-edn-structure = 'igcyr'">
         <xsl:for-each select=".">
            <p>
               <xsl:value-of select="@loc"/><xsl:text> </xsl:text>
               <xsl:if test="t:lem">
                  <xsl:for-each select="t:lem[@resp]">
                     <xsl:variable name="authors">
                     <xsl:variable name="resp" select="tokenize(./@resp,' ')"/>
                     <xsl:for-each select="$resp">
                           <xsl:variable name="indresp">
                              <xsl:sequence select="substring-after(.,'#')"/>
                           </xsl:variable>
                     <xsl:choose>
                              <xsl:when test="document('Workspace/files/BIBLIOGRAPHY.xml')//t:bibl[@xml:id = $indresp]">
                                 <xsl:for-each select="document('Workspace/files/BIBLIOGRAPHY.xml')//t:bibl[@xml:id = $indresp]">
                                    <xsl:text> </xsl:text>
                                    <xsl:choose><xsl:when test="t:author"><xsl:value-of select="t:author[1]/t:name[@type='surname']"/>
                                       <xsl:if test="t:author[2]">
                                          <xsl:text>-</xsl:text>
                                          <xsl:value-of select="t:author[2]/t:name[@type='surname']"/>
                                       </xsl:if></xsl:when>
                                       <xsl:when test="t:editor">
                                          <xsl:value-of select="t:editor[1]/t:name[@type='surname']"/>
                                          <xsl:if test="t:editor[2]">
                                             <xsl:text>-</xsl:text>
                                             <xsl:value-of select="t:editor[2]/t:name[@type='surname']"/>
                                          </xsl:if>
                                       </xsl:when></xsl:choose>
                                    <xsl:text> </xsl:text>
                                    <xsl:value-of select="t:date"/>
                                 </xsl:for-each>
                              </xsl:when>
                              <xsl:when test="contains($indresp,'SEG')">
                                 <xsl:text> SEG </xsl:text><xsl:value-of select="substring-after($indresp, 'SEG')"/>
                              </xsl:when>
                              <xsl:when test="contains($indresp,'SECir')">
                                 <xsl:text> SECir </xsl:text><xsl:value-of select="substring-after($indresp, 'SECir')"/>
                              </xsl:when>
                              <xsl:when test="contains($indresp,'Sammelbuch')">
                                 <xsl:text> Sammelbuch </xsl:text><xsl:value-of select="$indresp"/>
                              </xsl:when>
                              <xsl:otherwise>
                                 <xsl:text> !</xsl:text><xsl:value-of select="$indresp"/><xsl:text>!</xsl:text>
                              </xsl:otherwise>
                           </xsl:choose>
                           <xsl:if test="not(position()=last())">
                              <xsl:text>, </xsl:text>
                           </xsl:if>
                        </xsl:for-each>
                        </xsl:variable>
                     <xsl:apply-templates><xsl:with-param name="location" tunnel="yes">apparatus</xsl:with-param></xsl:apply-templates>
                     <xsl:text> </xsl:text>
                     <xsl:value-of select="$authors"/>
                     </xsl:for-each>
               </xsl:if>
               <xsl:text> </xsl:text>
               <xsl:for-each select="t:rdg">
                  <xsl:variable name="authors">
                     <xsl:choose><xsl:when test="./@resp">
                        <xsl:variable name="resp" select="tokenize(./@resp,' ')"/>
                        <xsl:for-each select="$resp">
                           <xsl:variable name="indresp">
                              <xsl:sequence select="substring-after(.,'#')"/>
                           </xsl:variable>
                           <xsl:choose>
                              <xsl:when test="document('Workspace/files/BIBLIOGRAPHY.xml')//t:bibl[@xml:id = $indresp]">
                                 <xsl:for-each select="document('Workspace/files/BIBLIOGRAPHY.xml')//t:bibl[@xml:id = $indresp]">
                                    <xsl:text> </xsl:text>
                                    <xsl:choose><xsl:when test="t:author"><xsl:value-of select="t:author[1]/t:name[@type='surname']"/>
                                       <xsl:if test="t:author[2]">
                                          <xsl:text>-</xsl:text>
                                          <xsl:value-of select="t:author[2]/t:name[@type='surname']"/>
                                       </xsl:if></xsl:when>
                                       <xsl:when test="t:editor">
                                          <xsl:value-of select="t:editor[1]/t:name[@type='surname']"/>
                                          <xsl:if test="t:editor[2]">
                                             <xsl:text>-</xsl:text>
                                             <xsl:value-of select="t:editor[2]/t:name[@type='surname']"/>
                                          </xsl:if>
                                       </xsl:when></xsl:choose>
                                    <xsl:text> </xsl:text>
                                    <xsl:value-of select="t:date"/>
                                 </xsl:for-each>
                              </xsl:when>
                              <xsl:when test="contains($indresp,'SEG')">
                                 <xsl:text> SEG </xsl:text><xsl:value-of select="substring-after($indresp, 'SEG')"/>
                              </xsl:when>
                              <xsl:when test="contains($indresp,'SECir')">
                                 <xsl:text> SECir </xsl:text><xsl:value-of select="substring-after($indresp, 'SECir')"/>
                              </xsl:when>
                              <xsl:when test="contains($indresp,'Sammelbuch')">
                                 <xsl:text> Sammelbuch </xsl:text><xsl:value-of select="$indresp"/>
                              </xsl:when>
                              <xsl:otherwise>
                                 <xsl:text> !</xsl:text><xsl:value-of select="$indresp"/><xsl:text>!</xsl:text>
                              </xsl:otherwise>
                           </xsl:choose>
                           <xsl:if test="not(position()=last())">
                              <xsl:text>, </xsl:text>
                           </xsl:if>
                        </xsl:for-each>
                     </xsl:when>
                     <xsl:otherwise>
                        <i18n:text i18n:key="epidoc-xslt-other-reading">
                           <xsl:text>Other reading</xsl:text>
                        </i18n:text>
                        </xsl:otherwise>
                     </xsl:choose>
                     </xsl:variable>
                  <xsl:apply-templates><xsl:with-param name="location" tunnel="yes">apparatus</xsl:with-param></xsl:apply-templates>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="$authors"/>
                  <xsl:if test="./note"><xsl:value-of select="./note"/></xsl:if>
                  <xsl:choose><xsl:when test="not(position() = last())"><xsl:text>; </xsl:text></xsl:when><xsl:otherwise><xsl:text>.</xsl:text></xsl:otherwise></xsl:choose>
               </xsl:for-each>
               <xsl:text> </xsl:text>
               <xsl:for-each select="t:note">
                  <xsl:value-of select="."/>
               </xsl:for-each>
            </p>
            </xsl:for-each>
      </xsl:when>
         <xsl:when test="@resp='previous'">
            <span class="previouslyread">
               <xsl:apply-templates/>
            </span>
         </xsl:when>
         <xsl:when test="@resp='autopsy'"/>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>

      <!-- Found in htm-tpl-apparatus - creates links to footnote in apparatus -->
      <xsl:if test="$parm-internal-app-style = 'ddbdp'">
         <xsl:call-template name="app-link">
            <xsl:with-param name="location" select="'text'"/>
         </xsl:call-template>
      </xsl:if>
  </xsl:template>


  <xsl:template match="t:rdg">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:choose>
          <xsl:when test="$parm-edition-type = 'diplomatic'">
            <xsl:choose>
               <xsl:when test="@resp='previous'"/>
               <xsl:when test="@resp='autopsy'">
                  <xsl:apply-templates/>
               </xsl:when>
               <xsl:when test="not(preceding-sibling::t:lem or preceding-sibling::t:rdg)">
                  <xsl:apply-templates/>
               </xsl:when>
               <xsl:otherwise/>
            </xsl:choose>
         </xsl:when>
         <xsl:when test="@resp='previous'">
            <xsl:apply-templates/>
         </xsl:when>
         <xsl:when test="@resp='autopsy'"/>
         <xsl:when test="parent::t:app"/>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>


  <xsl:template match="t:wit">
      <xsl:choose>
      <!-- Temporary -->
         <xsl:when test="parent::t:app"/>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

   <xsl:template match="t:lem">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:param name="parm-hgv-gloss" tunnel="yes" required="no"/>
      <xsl:choose>
          <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch') and ancestor::t:div[@type='translation']">
            <xsl:variable name="wit-val" select="@resp"/>
            <xsl:variable name="lang" select="ancestor::t:div[@type = 'translation']/@xml:lang"/>
            <span class="term">
              <xsl:apply-templates/>
              <span class="gloss" style="display:none">
              <b><xsl:choose>
                  <xsl:when test="$lang = 'en'">
                    <xsl:if test=".//t:term[@target]">
                      <xsl:text>Glossary/</xsl:text>
                    </xsl:if>
                    <xsl:text>Correction:</xsl:text>
                  </xsl:when>
                  <xsl:when test="$lang = 'de'">
                    <xsl:if test=".//t:term[@target]">
                      <xsl:text>Glossar/</xsl:text>
                    </xsl:if>
                    <xsl:text>Korrektur:</xsl:text>
                  </xsl:when>
                </xsl:choose></b>
                <xsl:for-each select=".//t:term[@target]">
                    <xsl:value-of select="document($parm-hgv-gloss)//t:item[@xml:id = current()/@target]/t:term"/>
                  <xsl:text>. </xsl:text>
                    <xsl:value-of select="document($parm-hgv-gloss)//t:item[@xml:id = current()/@target]/t:gloss[@xml:lang = $lang]"/>
                  <xsl:text>; </xsl:text>
                </xsl:for-each>
                <xsl:value-of select="$wit-val"/>
              </span>
            </span>
         </xsl:when>
          <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch') and ancestor::t:*[local-name()=('reg','corr','rdg')             or self::t:del[@rend='corrected']]">
            <xsl:apply-templates/>
            <xsl:if test="@resp">
               <xsl:choose>
                   <xsl:when test="$parm-leiden-style='ddbdp'"><xsl:text> FNORD-SPLIT </xsl:text></xsl:when>
                  <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
               </xsl:choose>
               <xsl:if test="parent::t:app[@type='BL']">
                  <xsl:text>BL </xsl:text>
               </xsl:if>

               <xsl:value-of select="@resp"/>

               <xsl:if test="parent::t:app[@type='SoSOL']">
                  <xsl:text> (via PE)</xsl:text>
               </xsl:if>
               <xsl:choose>
                   <xsl:when test="$parm-leiden-style='ddbdp'"><xsl:text> FNORD-DELIM </xsl:text></xsl:when>
                  <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
               </xsl:choose>
            </xsl:if>
            <xsl:choose>
               <xsl:when test="parent::t:app[@type='editorial']">
                  <xsl:text> (</xsl:text><xsl:for-each select="following-sibling::t:rdg">
                     <!-- found in tpl-apparatus.xsl -->
                     <xsl:call-template name="app-ed-mult"/>
                  </xsl:for-each><xsl:text>)</xsl:text>
               </xsl:when>
               <xsl:when test="parent::t:app[@type='alternative']">
                  <xsl:text> (or </xsl:text>
                  <xsl:for-each select="following-sibling::t:rdg">
                     <xsl:apply-templates/>
                     <xsl:if test="position()!=last()">
                        <xsl:text> or </xsl:text>
                     </xsl:if>
                  </xsl:for-each>
                  <xsl:text>)</xsl:text>
               </xsl:when>
            </xsl:choose>
         </xsl:when>
         <xsl:when test="parent::t:app[@type='previouslyread']">
            <span class="previouslyread">
               <xsl:apply-templates/>
            </span>
         </xsl:when>
          <xsl:when test="$parm-leiden-style='iospe' and $parm-edition-type='interpretive' and ../t:rdg">
            <xsl:apply-templates/>
            <xsl:for-each select="../t:rdg">
               <xsl:text> resp. </xsl:text>
               <xsl:apply-templates/>
            </xsl:for-each>
         </xsl:when>
         <xsl:when test="$parm-leiden-style='sigidoc' and $parm-edition-type='interpretive' and ../t:rdg"><!-- added by SigiDoc -->
            <xsl:apply-templates/>
            <xsl:for-each select="../t:rdg">
               <i><xsl:text> vel </xsl:text></i>
               <xsl:apply-templates/>
            </xsl:for-each>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teidiv.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

  <xsl:template match="t:div">
    <!-- div[@type = 'edition']" and div[@type='textpart'] can be found in htm-teidivedition.xsl -->
        <div>
          <xsl:if test="parent::t:body and @type">
            <xsl:attribute name="id">
              <xsl:value-of select="@type"/>
            </xsl:attribute>
          </xsl:if>
          <!-- Temporary headings so we know what is where -->
          <xsl:if test="not(t:head)">
            <xsl:choose>
              <xsl:when test="@type='commentary' and @subtype='frontmatter'"><h3>Introduction</h3></xsl:when>
              <xsl:when test="@type='commentary' and @subtype='linebyline'"><h3>Notes</h3></xsl:when>
              <xsl:when test="@type = 'translation'">
                  <h2>
                     <xsl:value-of select="/t:TEI/t:teiHeader/t:profileDesc/t:langUsage/t:language[@ident = current()/@xml:lang]"/>
                     <xsl:text> </xsl:text>
                     <xsl:value-of select="@type"/>
                  </h2>
              </xsl:when>
              <xsl:otherwise>
                  <h2>
                     <xsl:value-of select="@type"/>
                     <xsl:if test="string(@subtype)">
                        <xsl:text>: </xsl:text>
                        <xsl:value-of select="@subtype"/>
                     </xsl:if>
                  </h2>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>

          <!-- Body of the div -->
          <xsl:apply-templates/>

        </div>

  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teidivedition.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

   <!-- Other div matches can be found in htm-teidiv*.xsl -->

   <!-- Text edition div -->
    <xsl:template match="t:div[@type = 'edition']" priority="1">
        <xsl:param name="parm-internal-app-style" tunnel="yes" required="no"/>
        <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
       <div id="edition">
        
<!-- Found in htm-tpl-lang.xsl -->
         <xsl:call-template name="attr-lang"/>
         <xsl:apply-templates/>

         
           <xsl:choose>
               <!-- Apparatus creation: look in tpl-apparatus.xsl for documentation and templates -->
               <xsl:when test="$parm-internal-app-style = 'ddbdp'">
                   <!-- Framework found in htm-tpl-apparatus.xsl -->
                   <xsl:call-template name="tpl-apparatus"/>
               </xsl:when>
               <xsl:when test="$parm-internal-app-style = 'iospe'">
                    <!-- Template found in htm-tpl-apparatus.xsl -->
                    <xsl:call-template name="tpl-iospe-apparatus"/>
               </xsl:when>
               <xsl:when test="$parm-internal-app-style ='fullex'">
                   <!-- Template to be added in htm-tpl-apparatus.xsl -->
                   <xsl:call-template name="tpl-fullex-apparatus"/>
               </xsl:when>
               
<xsl:when test="$parm-internal-app-style ='minex'">
                   <!-- Template to be added in htm-tpl-apparatus.xsl -->
                   <xsl:call-template name="tpl-minex-apparatus"/>
               </xsl:when>


               <!--     the default if nothing is selected is to print no internal apparatus      -->
           </xsl:choose>
      </div>
   </xsl:template>


   <!-- Textpart div -->
    <xsl:template match="t:div[@type='edition']//t:div[@type='textpart']" priority="1">
        <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
        <xsl:param name="parm-internal-app-style" tunnel="yes" required="no"/>
       <xsl:variable name="div-type">
           <xsl:for-each select="ancestor::t:div[@type!='edition']">
               <xsl:value-of select="@type"/>
               <xsl:text>-</xsl:text>
           </xsl:for-each>
       </xsl:variable>
       <xsl:variable name="div-loc">
         <xsl:for-each select="ancestor::t:div[@type='textpart'][@n]">
            <xsl:value-of select="@n"/>
            <xsl:text>-</xsl:text>
         </xsl:for-each>
      </xsl:variable>
      <xsl:if test="@n"><!-- prints div number -->
         <span class="textpartnumber" id="{$div-type}ab{$div-loc}{@n}">
           <!-- add ancestor textparts -->
             <xsl:if test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and @subtype">
              <xsl:value-of select="@subtype"/>
              <xsl:text> </xsl:text>
           </xsl:if>
              <xsl:value-of select="@n"/>
         </span>
          <xsl:if test="child::*[1][self::t:div[@type='textpart'][@n]]"><br/></xsl:if>
      </xsl:if>
      <xsl:apply-templates/>
        <xsl:if test="$parm-internal-app-style = 'iospe' and @n">
           <!-- Template found in htm-tpl-apparatus.xsl -->
           <xsl:call-template name="tpl-iospe-apparatus"/>
       </xsl:if>
   </xsl:template>
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teidivapparatus.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="#all" version="2.0">


  <!-- only triggered if there is a <div type="apparatus"> (i.e. "external appartus") in the XML -->

  <!--<xsl:import href="teidivapparatus.xsl"/>-->

  <!-- Other div matches can be found in htm-teidiv.xsl -->
  <xsl:param name="parm-internal-app-style"/>
  <xsl:param name="parm-external-app-style"/>

  <xsl:variable name="default-language" select="'en'"/>

  <xsl:variable name="local-bibliography">
    <xsl:if test="$parm-external-app-style = 'iospe'">
      <xsl:for-each select="//t:div[@type='bibliography']//(t:bibl | t:biblStruct)">
        <xsl:choose>
          <xsl:when test="t:ptr/@target">
            <!-- I know there is only one, we use for-each only to change context -->
            <xsl:for-each select="t:ptr/@target">
              <xsl:call-template name="source">
                <xsl:with-param name="root" select="ancestor-or-self::t:TEI"/>
                <xsl:with-param name="parm-external-app-style" select="'iospe'" tunnel="yes"/>
              </xsl:call-template>
            </xsl:for-each>
          </xsl:when>
          <xsl:otherwise>
            <t:ref>
              <xsl:apply-templates select="." mode="parse-name-year"/>
            </t:ref>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:if>
  </xsl:variable>

  <xsl:template name="source">
    <xsl:param name="root"/>
    <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>

    <xsl:variable name="source_location">
      <xsl:choose>
        <xsl:when test="$root//t:encodingDesc//t:prefixDef[@ident] and $root//t:encodingDesc//t:prefixDef/@ident = substring-before(., ':')">
          <xsl:value-of select="replace(substring-after(., ':'),             $root//t:encodingDesc//t:prefixDef/@matchPattern,             $root//t:encodingDesc//t:prefixDef/@replacementPattern)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:sequence select="."/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <t:ref>
      <xsl:choose>
        <xsl:when test="$parm-external-app-style = 'iospe'">
          <i18n:text i18n:key="epidoc-xslt-not-collated">
            <xsl:text>not collated</xsl:text>
          </i18n:text>
        </xsl:when>
        <xsl:when test="starts-with($source_location, '#')">
          <xsl:apply-templates select="$root//t:div[@type='bibliography']//(t:bibl | t:biblStruct)[@xml:id=substring-after($source_location, '#')]" mode="parse-name-year"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="document($source_location, $root)" mode="parse-name-year"/>
        </xsl:otherwise>
      </xsl:choose>
    </t:ref>
  </xsl:template>

  <xsl:template name="sources">
    <xsl:param name="root"/>

    <!-- collect all sources -->
    <xsl:variable name="sources">
      <xsl:for-each select="tokenize(@source, ' ')">
        <xsl:call-template name="source">
          <xsl:with-param name="root" select="$root"/>
        </xsl:call-template>
      </xsl:for-each>
    </xsl:variable>

    <!-- preselect sources to be printed -->
    <xsl:variable name="final_printing_sources">
      <xsl:for-each select="$sources/t:ref">
        <xsl:variable name="n_authors_with_same_name_in_local_bib_and_current_sources" select="count($local-bibliography/t:ref[t:name/text() = $sources/t:ref[t:name/text() = current()/t:name/text()]/t:name/text()])"/>
        <xsl:variable name="n_authors_with_same_name_in_current_sources" select="count($sources/t:ref[t:name/text() = current()/t:name/text()])"/>
        <xsl:variable name="first_occurrence_of_this_author_in_sources" select="$sources/t:ref[t:name/text() = current()/t:name/text()][1] = current()"/>
        <xsl:variable name="n_authors_with_same_name_in_local_bib" select="count($local-bibliography/t:ref[t:name/text() = current()/t:name/text()])"/>

        <xsl:if test="not($n_authors_with_same_name_in_local_bib_and_current_sources = $n_authors_with_same_name_in_current_sources)                   or $first_occurrence_of_this_author_in_sources">

          <t:ref>
            <xsl:sequence select="./t:name"/>
            <xsl:if test="$n_authors_with_same_name_in_local_bib != 1                 and not($n_authors_with_same_name_in_local_bib_and_current_sources = $n_authors_with_same_name_in_current_sources)">

              <xsl:sequence select="./t:date"/>
            </xsl:if>
          </t:ref>
        </xsl:if>
      </xsl:for-each>
    </xsl:variable>

    <!-- print references -->
    <xsl:text> </xsl:text>
    <xsl:for-each select="$final_printing_sources/t:ref">
      <xsl:value-of select="t:name"/>

      <xsl:if test="t:date">
        <xsl:text> </xsl:text>
        <xsl:value-of select="t:date"/>
      </xsl:if>
      <xsl:if test="not(position() = last())">
        <xsl:text>, </xsl:text>
      </xsl:if>
    </xsl:for-each>

  </xsl:template>

  <xsl:template match="t:bibl | t:biblStruct" mode="parse-name-year">
    <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
    <t:name>
      <xsl:for-each select=".//t:author[1]">
        <xsl:choose>
          <xsl:when test=".//t:surname">
            <xsl:value-of select=".//t:surname[@xml:lang=$default-language or not(@xml:lang)]"/>
          </xsl:when>
          <xsl:when test=".//t:forename">
            <xsl:value-of select=".//t:forename[@xml:lang=$default-language or not(@xml:lang)]"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="."/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </t:name>
    <t:date>
      <xsl:choose>
        <xsl:when test=".//t:imprint[1]">
          <xsl:value-of select=".//t:imprint[1]//t:date"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select=".//t:date[1]"/>
        </xsl:otherwise>
      </xsl:choose>

    </t:date>
  </xsl:template>

  <xsl:template match="t:div[@type='apparatus']" priority="1">
    <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
    <div id="apparatus">
      <h2>apparatus</h2>
      <p>
        <xsl:apply-templates/>
      </p>
    </div>
  </xsl:template>

  <xsl:template match="t:div[@type='apparatus']//t:app">
    <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
    <span>
      <xsl:attribute name="class">
        <xsl:value-of select="@loc"/>
      </xsl:attribute>
      <xsl:if test="@loc and (not(preceding-sibling::t:app) or @loc != preceding-sibling::t:app[1]/@loc)">
        <xsl:value-of select="translate(@loc, ' ', '.')"/>
        <xsl:text>: </xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
    </span>

    <xsl:choose>
      <xsl:when test="@loc != following-sibling::t:app[1]/@loc">
        <br/>
      </xsl:when>
      <xsl:when test="following-sibling::t:app">
        <xsl:text>; </xsl:text>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="t:div[@type = 'apparatus']//t:rdg">
    <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
    <xsl:apply-templates/>

    <xsl:call-template name="sources">
      <xsl:with-param name="root" select="ancestor-or-self::t:TEI"/>
    </xsl:call-template>

    <xsl:if test="following-sibling::t:rdg and not(following-sibling::*[1][self::t:note])">
      <xsl:text>; </xsl:text>
    </xsl:if>
  </xsl:template>


  <xsl:template match="t:div[@type = 'apparatus']//t:lem">
    <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
    <xsl:apply-templates/>

    <xsl:call-template name="sources">
      <xsl:with-param name="root" select="ancestor-or-self::t:TEI"/>
    </xsl:call-template>

    <xsl:if test="following-sibling::t:* and not(following-sibling::t:*[1][self::t:note]) and not(@source)">
      <xsl:text>: </xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="t:div[@type = 'apparatus']//t:note">
    <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
    <span>
      <xsl:if test="ancestor::t:app">
        <xsl:apply-templates/>
        <xsl:if test="preceding-sibling::t:rdg and following-sibling::t:rdg">
          <xsl:text>; </xsl:text>
        </xsl:if>
      </xsl:if>
    </span>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teifacsimile.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

  <xsl:template match="t:facsimile">
    <!-- Being concerned only with the images, ignore everything else. -->
    <div id="facsimile-images">
      <h2>Facsimile Images</h2>

      <xsl:apply-templates select=".//t:graphic"/>
    </div>
  </xsl:template>

  <!-- Display a local image with thumbnail. -->
  <xsl:template match="t:graphic">
    <xsl:param name="parm-image-loc" select="''" tunnel="yes"/>
    <!-- Create a link to the full image and display a thumbnail
         image.

         The thumbnail image URL is constructed from the original URL
         via prefixing the final "." with "-thumb". This may lead to
         ugly URLs if the original URL does not include an extension
         suffix but does have a "." in it. -->
    <xsl:variable name="url-parts" select="tokenize(@url, '\.')"/>
    <xsl:variable name="count-url-parts" select="count($url-parts)-1"/>
    <a href="{concat($parm-image-loc, @url)}" target="_blank"><!-- @target added by SigiDoc -->
      <img title="{t:desc}">
        <xsl:attribute name="src">
          <xsl:value-of select="$parm-image-loc"/>
          <xsl:value-of select="string-join(subsequence($url-parts, 1, $count-url-parts), '.')"/>
          <xsl:text>-thumb.</xsl:text>
          <xsl:value-of select="subsequence($url-parts, $count-url-parts)[last()]"/>
        </xsl:attribute>
      </img>
    </a>
  </xsl:template>

  <!-- Display an image. -->
  <xsl:template match="t:graphic[contains(@url, '://')]">
    <img src="{@url}" title="{t:desc}"/>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teiforeign.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  
  <xsl:template match="t:foreign">
      <span class="lang">
      <!-- Found in htm-tpl-lang.xsl -->
      <xsl:call-template name="attr-lang"/>
         <xsl:apply-templates/>
      </span>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teifigure.xsl"><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

  <xsl:template match="t:figure">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="@href">
            <a href="{@href}">
               <xsl:apply-templates/>
            </a>
         </xsl:when>
          <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch')">
            <xsl:text>(</xsl:text>
            <xsl:apply-templates/>
            <xsl:text>)</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teig.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  
  <!-- Import templates can be found in teig.xsl -->
  <xsl:import href="teig.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:EDF="http://epidoc.sourceforge.net/ns/functions" exclude-result-prefixes="t EDF" version="2.0">
   <!-- Templates imported by [htm|txt]-teig.xsl -->

   <xsl:function name="EDF:f-wwrap">
      <!-- called by teisupplied.xsl, teig.xsl and teispace.xsl -->
      <xsl:param name="ww-context"/>
      <xsl:choose>
         <xsl:when test="$ww-context/following-sibling::node()[1][(local-name()='lb' and (@break='no' or @type='inWord'))             or normalize-space(.)='' and following-sibling::node()[1][local-name()='lb' and (@break='no' or @type='inWord')]]">
            <xsl:value-of select="true()"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="false()"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:function>

   <xsl:template name="lb-dash">
      <!-- function EDF:f-wwrap declared in htm-teilb.xsl; tests if lb break=no immediately follows g -->
      <xsl:if test="EDF:f-wwrap(.) = true()">
         <xsl:text>- </xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template name="w-space">
      <xsl:if test="ancestor::w">
         <xsl:text> </xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template match="t:g">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="starts-with($parm-leiden-style, 'edh')"/>
         <xsl:when test="starts-with(@ref,'#') and //t:glyph[@xml:id=substring-after(current()/@ref,'#')]">
            <xsl:for-each select="//t:glyph[@xml:id=substring-after(current()/@ref,'#')]">
               <xsl:choose>
                  <xsl:when test="t:charProp[t:localName='glyph-display']">
                     <xsl:value-of select="t:charProp[t:localName='glyph-display']/t:value"/>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:value-of select="t:charProp[t:localName='text-display']/t:value"/>
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:for-each>
         </xsl:when>
         <xsl:when test="contains(@ref,'#')">
            <xsl:value-of select="substring-after(@ref,'#')"/>
         </xsl:when>
         <xsl:when test="@ref">
            <xsl:value-of select="@ref"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="@type"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <!-- London specific template -->
   <xsl:template name="g-london">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:choose>
         <xsl:when test="@type = 'chirho'">
            <xsl:text>⳩</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type = 'taurho'">
            <xsl:text>⳨</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
           <xsl:when test="$parm-edition-type='diplomatic'">
            <xsl:choose>
               <xsl:when test="@type='crux' or @type='cross'">
                  <xsl:text>†</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='crosses'">
                  <xsl:text>††</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='denarius'">
                  <xsl:text>&#55296;&#56726;</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='drachma'">
                  <xsl:text>&#55296;&#56693;</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='sestercius'">
                  <xsl:text>&#55296;&#56728;</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='year'">
                  <xsl:text>L</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='stop'">
                  <xsl:text>•</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:otherwise>
                  <span class="smaller" style="font-style:italic;">
                     <xsl:text> </xsl:text>
                     <xsl:value-of select="@type"/>
                     <xsl:call-template name="g-unclear-symbol"/>
                     <xsl:text> </xsl:text>
                  </span>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <xsl:otherwise>
            <span class="smaller" style="font-style:italic;">
               <xsl:text> </xsl:text>
               <xsl:value-of select="@type"/>
               <xsl:call-template name="g-unclear-string"/>
               <xsl:text> </xsl:text>
            </span>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   
   <!-- IOSPE specific template -->
   <!-- called from htm-teig.xml -->
   <xsl:template name="g-iospe">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:choose>
         <xsl:when test="@type = 'stauros'">
            <xsl:text>+</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type = 'staurogram'">
            <xsl:text>⳨</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type = 'leaf'">
            <xsl:text>❦</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type = 'dipunct'">
            <xsl:text>:</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
           <xsl:when test="$parm-edition-type='diplomatic'">
            <xsl:choose>
               <!--<xsl:when test="@type='denarius'">
                  <xsl:text>&#x10196;</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='sestercius'">
                  <xsl:text>&#x10198;</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>-->
               <xsl:when test="@type='year'">
                  <xsl:text>L</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='stop'">
                  <xsl:text>•</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:otherwise>
                  <span class="smaller" style="font-style:italic;">
                     <xsl:text> </xsl:text>
                     <xsl:value-of select="@type"/>
                     <xsl:call-template name="g-unclear-string"/>
                     <xsl:text> </xsl:text>
                  </span>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <xsl:otherwise>
            <span class="smaller" style="font-style:italic;">
               <xsl:text> </xsl:text>
               <xsl:value-of select="@type"/>
               <xsl:call-template name="g-unclear-string"/>
               <xsl:text> </xsl:text>
            </span>
         </xsl:otherwise>
      </xsl:choose>
      
   </xsl:template>

   <!-- ddb specific template -->
   <xsl:template name="g-ddbdp">
      <xsl:choose>
         <xsl:when test="@type='apostrophe'">
            <xsl:text>’</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='check' or @type='check-mark'">
            <xsl:text>／</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='chirho'">
            <xsl:text>☧</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='dash'">
            <xsl:text>—</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='dipunct'">
            <xsl:text>∶</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='filled-circle'">
            <xsl:text>⦿</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='filler' and @rend='extension'">
            <xsl:text>―</xsl:text>
            <xsl:call-template name="g-unclear-string"/>
         </xsl:when>
         <xsl:when test="@type='latin-interpunct' or @type='middot' or @type='mid-punctus'">
            <xsl:text>·</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='monogram'">
            <span class="italic">
               <xsl:text>monogr.</xsl:text>
               <xsl:call-template name="g-unclear-symbol"/>
            </span>
         </xsl:when>
         <xsl:when test="@type='upper-brace-opening'">
            <xsl:text>⎧</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='center-brace-opening'">
            <xsl:text>⎨</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='lower-brace-opening'">
            <xsl:text>⎩</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='upper-brace-closing'">
            <xsl:text>⎫</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='center-brace-closing'">
            <xsl:text>⎬</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='lower-brace-closing'">
            <xsl:text>⎭</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='parens-upper-opening'">
            <xsl:text>⎛</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='parens-middle-opening'">
            <xsl:text>⎜</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='parens-lower-opening'">
            <xsl:text>⎝</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='parens-upper-closing'">
            <xsl:text>⎞</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='parens-middle-closing'">
            <xsl:text>⎟</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='parens-lower-closing'">
            <xsl:text>⎠</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type = 'rho-cross'">
            <xsl:text>⳨</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='slanting-stroke'">
            <xsl:text>/</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='stauros'">
            <xsl:text>†</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='tachygraphic marks'">
            <span class="italic">
               <xsl:text>tachygr. marks</xsl:text>
               <xsl:call-template name="g-unclear-symbol"/>
            </span>
         </xsl:when>
         <xsl:when test="@type='tripunct'">
            <xsl:text>⋮</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='double-vertical-bar'">
            <xsl:text>‖</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='long-vertical-bar'">
            <xsl:text>|</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='x'">
            <xsl:text>☓</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <xsl:when test="@type='xs'">
            <xsl:text>☓</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
            <xsl:text>☓</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
            <xsl:text>☓</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
            <xsl:text>☓</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
            <xsl:text>☓</xsl:text>
            <xsl:call-template name="g-unclear-symbol"/>
         </xsl:when>
         <!-- Interim error reporting -->
         <xsl:otherwise>
            <text> ((</text>
            <xsl:value-of select="@type"/>
            <xsl:call-template name="g-unclear-string"/>
            <text>)) </text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

    <!-- RIB specific template -->
    <xsl:template name="g-rib">
        <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
        <xsl:choose>
            <xsl:when test="@type = 'chirho'">
                <xsl:text>☧</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='century'">
                <xsl:text>&#55296;&#56731;</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='milliaria'">
                <xsl:text>ↀ</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='leaf'">
                <xsl:text>❦</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='palm'">
                <xsl:text>††</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='star'">
                <xsl:text>*</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='interpunct' and not(node())">
                <xsl:text>·</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='interpunct' and node()">
                <xsl:apply-templates/>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='sestertius' and not(node())">
                <xsl:text>&#55296;&#56728;</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='sestertius' and node()">
                <xsl:apply-templates/>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='denarius'">
                <xsl:text>⸙</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='barless-A'">
                <xsl:text>Λ</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='dot'">
                <xsl:text>.</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='stop'">
                <xsl:text>•</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:when test="@type='crux' or @type='cross'">
                <xsl:text>†</xsl:text>
                <xsl:call-template name="g-unclear-symbol"/>
            </xsl:when>
            <xsl:otherwise>
                <span class="smaller" style="font-style:italic;">
                    <xsl:text> </xsl:text>
                    <xsl:value-of select="@type"/>
                    <xsl:call-template name="g-unclear-string"/>
                    <xsl:text> </xsl:text>
                </span>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
   <xsl:template name="g-unclear-symbol">
      <!-- adds underdot below symbol if parent:unclear -->
      <xsl:if test="parent::t:unclear">
         <xsl:text>̣</xsl:text>
      </xsl:if>
   </xsl:template>
   
   <xsl:template name="g-unclear-string">
      <!-- adds question mark after string if parent:unclear -->
      <xsl:if test="parent::t:unclear">
         <xsl:text>?</xsl:text>
      </xsl:if>
   </xsl:template>

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

  <xsl:template match="t:g">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:call-template name="lb-dash"/>
      <xsl:call-template name="w-space"/>
    
     <xsl:choose>
         <xsl:when test="starts-with($parm-leiden-style, 'edh') or $parm-leiden-style='eagletxt'"/>
         <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
        <!-- Found in teig.xsl -->
        <xsl:call-template name="g-ddbdp"/>
         </xsl:when>
         <xsl:when test="$parm-leiden-style = 'london'">
           <xsl:call-template name="g-london"/>
         </xsl:when>
         <xsl:when test="$parm-leiden-style = 'iospe'">
           <xsl:apply-imports/>
           <!--   removed customization of IOSPE from stylesheets   -->
           <!--<xsl:call-template name="g-iospe"/>-->
        </xsl:when>
         <xsl:when test="$parm-leiden-style = 'rib'">
             <xsl:call-template name="g-rib"/>
         </xsl:when>
         <xsl:when test="$parm-edition-type = 'diplomatic'">
            <xsl:text> </xsl:text>
            <em>
               <span class="smaller">
                  <xsl:apply-imports/>
               </span>
            </em>
            <xsl:text> </xsl:text>
         </xsl:when>
         <xsl:when test="$parm-leiden-style = 'dohnicht'">
           <xsl:text>⊂</xsl:text>
           <xsl:apply-imports/>
           <xsl:text>⊃</xsl:text>
        </xsl:when>
        <xsl:otherwise>
           <xsl:text>((</xsl:text>
           <xsl:apply-imports/>
           <xsl:text>))</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
    
      <xsl:call-template name="w-space"/>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teigap.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Imported templates can be found in teigap.xsl -->
  <xsl:import href="teigap.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:EDF="http://epidoc.sourceforge.net/ns/functions" exclude-result-prefixes="t" version="2.0">
   <!-- Templates imported by [htm|txt]teigap.xsl -->

   <!-- style of the dot defined here -->
   <xsl:function name="EDF:dotchar" as="xs:string">
      <xsl:param name="leidenStyle"/>
      <xsl:param name="gapReason"/>
      <xsl:variable name="dot">
         <xsl:choose>
            <xsl:when test="$leidenStyle = ('ddbdp','sammelbuch')">
               <xsl:text>  ̣</xsl:text>
            </xsl:when>
            <xsl:when test="$leidenStyle = 'panciera' and $gapReason='illegible'">
               <xsl:text>+</xsl:text>
            </xsl:when>
            <xsl:when test="$leidenStyle='london'">
               <xsl:text>·</xsl:text>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text>.</xsl:text>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:sequence select="$dot"/>
   </xsl:function>

   <!-- The highest value of @quantity that will have dots produced -->
   <xsl:function name="EDF:dotmax" as="xs:double">
      <xsl:param name="leidenStyle"/>
      <xsl:variable name="maxnum">
         <xsl:choose>
            <xsl:when test="$leidenStyle = ('ddbdp','sammelbuch')">
               <xsl:number value="8"/>
            </xsl:when>
            <xsl:when test="$leidenStyle = 'sigidoc'"><!-- +++++++++++++++++++++++++++++++++++++++ -->
               <xsl:number value="25"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:number value="3"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:sequence select="$maxnum"/>
   </xsl:function>

   <xsl:template match="t:gap[@reason='omitted']">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="$parm-edition-type = 'diplomatic'"/>
         <xsl:when test="$parm-leiden-style = 'panciera'"><!-- TO BE DONE!!!!!!!!!!!!!!!!!!!!!!!!!! -->
            <xsl:text>〈---〉</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>&lt;</xsl:text>
            <xsl:call-template name="extent-string"/>
            <xsl:text>&gt;</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="t:gap[@reason='ellipsis']">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch')">
            <xsl:if test="string(t:desc) != 'non transcribed'">
               <xsl:value-of select="t:desc"/>
               <xsl:text> </xsl:text>
            </xsl:if>
            <xsl:choose>
               <xsl:when test="@quantity">
                  <xsl:if test="@precision='low'">
                     <xsl:text>ca.</xsl:text>
                  </xsl:if>
                  <xsl:value-of select="@quantity"/>
               </xsl:when>
               <xsl:when test="@atLeast and @atMost">
                  <xsl:value-of select="@atLeast"/>
                  <xsl:text>-</xsl:text>
                  <xsl:value-of select="@atMost"/>
               </xsl:when>
               <xsl:when test="@atLeast ">
                  <xsl:text>≥</xsl:text>
                  <xsl:value-of select="@atLeast"/>
               </xsl:when>
               <xsl:when test="@atMost ">
                  <xsl:text>≤</xsl:text>
                  <xsl:value-of select="@atMost"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:text>?</xsl:text>
               </xsl:otherwise>
            </xsl:choose>
            <xsl:text> </xsl:text>
            <xsl:value-of select="@unit"/>
            <xsl:if test="@quantity &gt; 1 or @extent='unknown' or @atLeast or @atMost">
               <xsl:text>s</xsl:text>
            </xsl:if>
            <xsl:if test="string(t:desc) = 'non transcribed'">
               <xsl:text> untranscribed</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text> ... </xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>


   <xsl:template match="t:gap[@reason='illegible']">
      <!-- certainty -->
      <xsl:if test="child::t:certainty[@match='..']">
         <xsl:text>?</xsl:text>
      </xsl:if>

      <xsl:if test="not(preceding::node()[1][self::text()][normalize-space(.)=''][preceding-sibling::node()[1][self::t:gap[@reason='illegible']]])          and not(preceding::node()[1][self::t:gap[@reason='illegible']])">
         <xsl:call-template name="extent-string"/>
      </xsl:if>
   </xsl:template>


   <xsl:template match="t:gap[@reason='lost']">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-verse-lines" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch') and @unit = 'line' and @extent = 'unknown'"/>
         <xsl:when test="$parm-leiden-style = ('panciera','sigidoc') and @unit = 'line' and @extent = 'unknown'"/><!-- ++++++++++++++++++++++++++++++++++++++++ -->
         <xsl:when test="@unit='line'">
            <xsl:text>[</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <!-- *NB* the lost-opener and lost-closer templates, found in tpl-reasonlost.xsl,
           are no longer used in this version of the stylesheets. They used to serve to limit
           the superfluous square brackets between adjacent gap and supplied elements,
           but this function is now performed by regex in [htm|txt]-tpl-sqbrackets.xsl
           which is called after all other templates are completed.
        -->
            <xsl:text>[</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
      <xsl:if test="$parm-leiden-style='london' and preceding-sibling::node()[1][@part='M' or @part='I'] and not($parm-edition-type='diplomatic')">
         <xsl:text>-</xsl:text>
      </xsl:if>

      <xsl:choose>
         <xsl:when test="$parm-verse-lines='on' and parent::t:seg[@met or @real]">
            <xsl:call-template name="verse-string"/>
         </xsl:when>
         <xsl:otherwise>
            <!-- Don't display again if there is a preceding adjecent gap of the same kind -->
            <xsl:if test="not(preceding::node()[1][self::text()][normalize-space(.)=''][preceding-sibling::node()[1][self::t:gap[@reason='lost']]])                and not(preceding::node()[1][self::t:gap[@reason='lost']])">
               <xsl:call-template name="extent-string"/>
            </xsl:if>
         </xsl:otherwise>
      </xsl:choose>

      <!-- certainty -->
      <xsl:if test="child::t:certainty[@match='..']">
         <xsl:choose>
            <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch')">
               <xsl:text>(?)</xsl:text>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text>?</xsl:text>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:if>

      <xsl:if test="$parm-leiden-style='london' and following-sibling::node()[1][@part='M' or @part='F'] and not($parm-edition-type='diplomatic')">
         <xsl:text>-</xsl:text>
      </xsl:if>

      <xsl:choose>
         <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch') and @unit = 'line' and @extent = 'unknown'"/>
         <xsl:when test="$parm-leiden-style = ('panciera','sigidoc') and @unit = 'line' and @extent = 'unknown'"/>
         <xsl:when test="@unit='line'">
            <xsl:text>]</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <!-- *NB* the lost-opener and lost-closer templates, found in tpl-reasonlost.xsl,
           are no longer used in this version of the stylesheets. They used to serve to limit
           the superfluous square brackets between adjacent gap and supplied elements,
           but this function is now performed by regex in [htm|txt]-tpl-sqbrackets.xsl
           which is called after all other templates are completed.
        -->
            <xsl:text>]</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>


   <xsl:template name="extent-string">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:variable name="cur-dot" select="EDF:dotchar($parm-leiden-style,@reason)"/>
      <xsl:variable name="cur-max" select="EDF:dotmax($parm-leiden-style)"/>
      <!-- Precision of <gap> defined -->
      <xsl:variable name="circa">
         <xsl:choose>
            <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch') and                (@precision='low' or (@unit='character' and number(@quantity) &gt; $cur-max))">
               <xsl:text>ca.</xsl:text>
            </xsl:when>
            <xsl:when test="@precision='low' and not(starts-with($parm-leiden-style, 'edh'))">
               <xsl:text>c. </xsl:text>
            </xsl:when>
         </xsl:choose>
      </xsl:variable>

      <xsl:choose>
         <xsl:when test="@extent='unknown'">
            <xsl:choose>
               <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch')">
                  <xsl:choose>
                     <!-- lines lost -->
                     <xsl:when test="@reason='lost' and @unit='line'">
                        <!--and (not(preceding-sibling::t:lb[2]) or not(following-sibling::*))-->
                        <xsl:text>-- -- -- -- -- -- -- -- -- --</xsl:text>
                     </xsl:when>
                     <!-- illegible vestiges -->
                     <xsl:when test="t:desc = 'vestiges' and @reason = 'illegible'">
                        <xsl:call-template name="tpl-vest">
                           <xsl:with-param name="circa" select="$circa"/>
                        </xsl:call-template>
                     </xsl:when>
                     <!-- other reason illegible and lost/chars caught in the otherwise -->
                     <xsl:otherwise>
                        <xsl:text> -ca.?- </xsl:text>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'london' and not($parm-edition-type='diplomatic')">
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:text> ? </xsl:text>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'london'">
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'edh-itx'">
                  <xsl:text>3</xsl:text>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'edh-names'">
                  <xsl:text>---</xsl:text>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'panciera'">
                  <xsl:choose>
                     <!-- lines lost -->
                     <xsl:when test="@reason='lost' and @unit='line'">
                        <xsl:text>------</xsl:text>
                     </xsl:when>
                     <!--     unknown charcaters lost-->
                     <xsl:when test="@reason='lost' and @unit='character'">
                        <xsl:text>---</xsl:text>
                     </xsl:when>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'sigidoc'"><!-- ++++++++++++++++++++++++++++++++++++++++++++ -->
                  <xsl:choose>
                     <!-- Lost lines: quantity unknown -->
                     <xsl:when test="@reason='lost' and @unit='line'">
                        <xsl:text>[- - -?- - -]</xsl:text>
                     </xsl:when>
                     <!-- Illegible lines: quantity unknown -->
                     <xsl:when test="@reason='illegible' and @unit='line'">
                        <xsl:text>- - -?- - -</xsl:text>
                     </xsl:when>
                     <!-- Lost characters: quantity unknown-->
                     <xsl:when test="@reason='lost' and @unit='character'">
                        <xsl:text>...?...</xsl:text>
                     </xsl:when>
                     <!-- Illegible characters: quantity unknown -->
                     <xsl:when test="@reason='illegible' and @unit='character'">
                        <xsl:text>...?...</xsl:text>
                     </xsl:when>
                  </xsl:choose>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:text>---</xsl:text>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>

         <xsl:when test="@quantity and @unit='character'">
            <xsl:choose>
               <xsl:when test="$parm-edition-type = 'diplomatic'">
                  <xsl:variable name="dots" select="'····························································································································································'"/>
                  <xsl:value-of select="substring($dots, 1, number(@quantity))"/>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'edh-itx'">
                  <xsl:choose>
                     <xsl:when test="number(@quantity) &gt; 2">
                        <xsl:text>3</xsl:text>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:value-of select="@quantity"/>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="number(@quantity) &gt; $cur-max or (number(@quantity) &gt; 0 and @precision='low')"><!-- ++++++++++++++++++++++++++++++++++++++++++++ -->
                  <xsl:choose>
                     <xsl:when test="$parm-leiden-style = 'sigidoc'">
                        <xsl:text>c. </xsl:text>
                        <xsl:value-of select="@quantity"/>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:value-of select="$cur-dot"/>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="$circa"/>
                        <xsl:value-of select="@quantity"/>
                        <xsl:value-of select="$cur-dot"/>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="number(@quantity) &gt; $cur-max or (number(@quantity) &gt; 1 and @precision='low')">
                  <xsl:choose>
                     <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch')">
                        <xsl:choose>
                           <xsl:when test="t:desc = 'vestiges' and @reason = 'illegible'">
                              <xsl:call-template name="tpl-vest">
                                 <xsl:with-param name="circa" select="$circa"/>
                              </xsl:call-template>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:text>- </xsl:text>
                              <xsl:value-of select="$circa"/>
                              <xsl:value-of select="@quantity"/>
                              <xsl:text> -</xsl:text>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:when>
                     <xsl:when test="$parm-leiden-style = 'panciera'">
                        <xsl:text>c. </xsl:text>
                        <xsl:value-of select="@quantity"/>
                     </xsl:when>
                     <xsl:when test="$parm-leiden-style = 'london'">
                        <xsl:value-of select="$cur-dot"/>
                        <xsl:value-of select="$cur-dot"/>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="$circa"/>
                        <xsl:value-of select="@quantity"/>
                        <xsl:value-of select="$cur-dot"/>
                        <xsl:value-of select="$cur-dot"/>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:value-of select="$cur-dot"/>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="$circa"/>
                        <xsl:value-of select="@quantity"/>
                        <xsl:value-of select="$cur-dot"/>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>

               <xsl:when test="$cur-max &gt;= number(@quantity)">
                  <xsl:choose>
                     <xsl:when test="t:desc='vestiges' and @reason='illegible' and ($parm-leiden-style='ddbdp' or $parm-leiden-style='sammelbuch')">
                        <xsl:call-template name="tpl-vest">
                           <xsl:with-param name="circa" select="$circa"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:call-template name="dot-out">
                           <xsl:with-param name="cur-num" select="number(@quantity)"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>

               <xsl:otherwise>
                  <xsl:choose>
                     <xsl:when test="t:desc='vestiges' and @reason='illegible' and ($parm-leiden-style='ddbdp' or $parm-leiden-style='sammelbuch')">
                        <xsl:call-template name="tpl-vest">
                           <xsl:with-param name="circa" select="$circa"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:text> - - - </xsl:text>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>

         <xsl:when test="@atLeast and @atMost and not($parm-leiden-style=('edh-names','edh-itx'))">
            <!-- reason illegible and lost caught in the otherwise -->
            <xsl:choose>
               <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch')">
                  <xsl:choose>
                     <xsl:when test="t:desc='vestiges' and @reason='illegible'">
                        <xsl:call-template name="tpl-vest">
                           <xsl:with-param name="circa" select="$circa"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@unit='character'">
                        <xsl:text> -</xsl:text>
                        <xsl:value-of select="@atLeast"/>
                        <xsl:text>-</xsl:text>
                        <xsl:value-of select="@atMost"/>
                        <xsl:text>- </xsl:text>
                     </xsl:when>
                     <xsl:when test="@unit='line'">
                        <xsl:if test="@reason='illegible'">
                           <xsl:text>Traces </xsl:text>
                        </xsl:if>
                        <xsl:value-of select="@atLeast"/>
                        <xsl:text>-</xsl:text>
                        <xsl:value-of select="@atMost"/>
                        <xsl:text> lines</xsl:text>
                        <xsl:if test="@reason='lost'">
                           <xsl:text> missing</xsl:text>
                        </xsl:if>
                     </xsl:when>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = ('panciera','eagletxt') and not($parm-leiden-style = 'sigidoc')"><!-- +++++++++++++++++++++++++++++ -->
                  <xsl:choose>
                     <xsl:when test="parent::t:name[@type='praenomen']">
                        <xsl:text>-</xsl:text>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:text>c. </xsl:text>
                        <xsl:value-of select="@atLeast"/>
                        <xsl:text> - </xsl:text>
                        <xsl:value-of select="@atMost"/>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = ('panciera','eagletxt') and not($parm-leiden-style = 'sigidoc')"><!-- ++++++++++++++++++++++++++++++++++ -->
                  <xsl:text>c. </xsl:text>
                  <xsl:value-of select="@atLeast"/>
                  <xsl:text> - </xsl:text>
                  <xsl:value-of select="@atMost"/>
               </xsl:when>
               <!-- Lost/illegible characters/lines: approximate extent --><!-- ++++++++++++++++++++++++++++++++++++++++ -->
               <xsl:when test="$parm-leiden-style = 'sigidoc'">
                  <xsl:choose>
                     <xsl:when test="@unit='character'">
                        <xsl:text>c. </xsl:text>
                        <xsl:value-of select="@atLeast"/>
                        <xsl:text> - </xsl:text>
                        <xsl:value-of select="@atMost"/>
                     </xsl:when>
                     <xsl:when test="@unit='line'">
                        <xsl:text>- - -c. </xsl:text>
                        <xsl:value-of select="@atLeast"/>
                        <xsl:text> - </xsl:text>
                        <xsl:value-of select="@atMost"/>
                        <xsl:text>- - -</xsl:text>
                     </xsl:when>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'london'">
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="$circa"/>
                  <xsl:value-of select="@atLeast"/>
                  <xsl:text>-</xsl:text>
                  <xsl:value-of select="@atMost"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="$circa"/>
                  <xsl:value-of select="@atLeast"/>
                  <xsl:text>-</xsl:text>
                  <xsl:value-of select="@atMost"/>
                  <xsl:value-of select="$cur-dot"/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>

         <xsl:when test="@quantity and @unit='line'">
            <xsl:choose>
               <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch')">
                  <xsl:choose>
                     <xsl:when test="desc = 'vestiges' and @reason = 'illegible'">
                        <xsl:call-template name="tpl-vest">
                           <xsl:with-param name="circa" select="$circa"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:choose>
                           <!--<xsl:when test="@extent='unknown' and @reason='lost'">
                              <xsl:text>Text breaks</xsl:text>
                           </xsl:when>-->
                           <!--<xsl:when test="@extent='unknown' and @reason='illegible'">
                              <xsl:text>Traces</xsl:text>
                           </xsl:when>-->
                           <xsl:when test="@reason='lost'">
                              <xsl:value-of select="$circa"/>
                              <xsl:value-of select="@quantity"/>
                              <xsl:text> line</xsl:text>
                              <xsl:if test="number(@quantity) &gt; 1">
                                 <xsl:text>s</xsl:text>
                              </xsl:if>
                              <xsl:text> missing</xsl:text>
                           </xsl:when>
                           <xsl:when test="@reason='illegible'">
                              <xsl:text>Traces </xsl:text>
                              <xsl:value-of select="$circa"/>
                              <xsl:value-of select="@quantity"/>
                              <xsl:text> line</xsl:text>
                              <xsl:if test="number(@quantity) &gt; 1">
                                 <xsl:text>s</xsl:text>
                              </xsl:if>
                           </xsl:when>
                        </xsl:choose>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'london'">
                  <xsl:text>---</xsl:text>
               </xsl:when>
               <xsl:when test="$parm-leiden-style =('panciera','eagletxt') and not(following-sibling::t:lb) and not($parm-leiden-style = 'sigidoc')"><!-- +++++++++++++++++++++++++++++ -->
                  <xsl:text>------</xsl:text>
               </xsl:when>
               <!-- Lost/Illegible lines: approximate quantity --><!-- ++++++++++++++++++++++++++++++++++++++++++++++++ -->
               <xsl:when test="$parm-leiden-style = 'sigidoc' and @precision='low'">
                  <xsl:choose>
                     <xsl:when test="@reason='lost'">
                        <xsl:text>- - -c. </xsl:text>
                        <xsl:value-of select="@quantity"/>
                        <xsl:text>- - -</xsl:text>
                     </xsl:when>
                     <xsl:when test="@reason='illegible'">
                        <xsl:text>- - - c. </xsl:text>
                        <xsl:value-of select="@quantity"/>
                        <xsl:text>- - -</xsl:text>
                     </xsl:when>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'edh-itx'">
                  <xsl:choose>
                     <xsl:when test="not(following-sibling::t:lb)">
                        <xsl:text>&amp;</xsl:text>
                     </xsl:when>
                     <xsl:when test="count(preceding-sibling::t:lb) = 1">
                        <xsl:text>$</xsl:text>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:text>6</xsl:text>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:text> - - - - - - - - - - </xsl:text>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>

         <xsl:when test="@quantity and @unit='cm'">
            <xsl:choose>
               <xsl:when test="desc = 'vestiges' and $parm-leiden-style = ('ddbdp','sammelbuch') and @reason = 'illegible'">
                  <xsl:call-template name="tpl-vest">
                     <xsl:with-param name="circa" select="$circa"/>
                  </xsl:call-template>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:apply-templates/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="$circa"/>
                  <xsl:value-of select="@quantity"/>
                  <xsl:text> cm </xsl:text>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>

         <xsl:otherwise>
            <xsl:choose>
               <xsl:when test="desc = 'vestiges' and $parm-leiden-style = ('ddbdp','sammelbuch') and @reason = 'illegible'">
                  <xsl:call-template name="tpl-vest">
                     <xsl:with-param name="circa" select="$circa"/>
                  </xsl:call-template>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'edh-itx'">
                  <xsl:text>6</xsl:text>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:text> ? </xsl:text>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:value-of select="$cur-dot"/>
                  <xsl:apply-templates/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <!-- Template for lost verse, metre known -->
   <xsl:template name="verse-string">
      <xsl:choose>
         <xsl:when test="parent::t:seg[contains(@real,'+') or contains(@real,'-')]">
            <xsl:call-template name="scansion">
               <xsl:with-param name="met-string" select="translate(parent::t:seg/@real, '+-','ˉ˘')"/>
               <xsl:with-param name="string-len" select="string-length(parent::t:seg/@real)"/>
               <xsl:with-param name="string-pos" select="string-length(parent::t:seg/@real) - 1"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="parent::t:seg[contains(@met,'+') or contains(@met,'-')]">
            <xsl:call-template name="scansion">
               <xsl:with-param name="met-string" select="translate(parent::t:seg/@met, '+-','ˉ˘')"/>
               <xsl:with-param name="string-len" select="string-length(parent::t:seg/@met)"/>
               <xsl:with-param name="string-pos" select="string-length(parent::t:seg/@met) - 1"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:call-template name="extent-string"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <!-- print macron and breve with intervening hard-spaces -->
   <xsl:template name="scansion">
      <xsl:param name="met-string"/>
      <xsl:param name="string-len"/>
      <xsl:param name="string-pos"/>
      <xsl:if test="$string-pos &gt; -1">
         <xsl:text> </xsl:text>
         <xsl:value-of select="substring($met-string, number($string-len - $string-pos), 1)"/>
         <xsl:text> </xsl:text>
         <xsl:call-template name="scansion">
            <xsl:with-param name="met-string" select="$met-string"/>
            <xsl:with-param name="string-len" select="$string-len"/>
            <xsl:with-param name="string-pos" select="$string-pos - 1"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>


   <!-- Template for vestiges -->
   <xsl:template name="tpl-vest">
      <xsl:param name="circa"/>
      <xsl:text>Traces</xsl:text>
      <xsl:choose>
         <xsl:when test="@extent = 'unknown'">
            <xsl:if test="@unit='line'">
               <xsl:text> ?  lines</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text> </xsl:text>
            <xsl:value-of select="$circa"/>
            <xsl:text> </xsl:text>
            <xsl:choose>
               <xsl:when test="string(@atLeast) and string(@atMost)">
                  <xsl:value-of select="@atLeast"/>
                  <xsl:text>-</xsl:text>
                  <xsl:value-of select="@atMost"/>
               </xsl:when>
               <xsl:when test="string(@quantity)">
                  <xsl:value-of select="@quantity"/>
               </xsl:when>
            </xsl:choose>
            <xsl:choose>
               <xsl:when test="@unit = 'line'">
                  <xsl:text> line</xsl:text>
                  <xsl:if test="number(@quantity) &gt; 1 or number(@atMost) &gt; 1">
                     <xsl:text>s</xsl:text>
                  </xsl:if>
               </xsl:when>
               <xsl:when test="@unit = 'character'">
                  <xsl:text> character</xsl:text>
                  <xsl:if test="number(@quantity) &gt; 1 or number(@atMost) &gt; 1">
                     <xsl:text>s</xsl:text>
                  </xsl:if>
               </xsl:when>
               <xsl:when test="@unit = 'cm'">
                  <xsl:text> cm</xsl:text>
               </xsl:when>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>


   <!-- Production of dots -->
   <xsl:template name="dot-out">
      <xsl:param name="cur-num"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:variable name="cur-dot" select="EDF:dotchar($parm-leiden-style,@reason)"/>

      <xsl:if test="$cur-num &gt; 0">
         <xsl:value-of select="$cur-dot"/>

         <xsl:call-template name="dot-out">
            <xsl:with-param name="cur-num" select="$cur-num - 1"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>
</xsl:stylesheet></xsl:import>
  
  <xsl:template match="t:gap[@reason = 'lost']">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:if test="@extent='unknown' and @reason='lost' and @unit='line' and ($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')           and not(preceding-sibling::t:*[1][local-name() = 'lb'])">
         <!--     adds a newline character before gap-extent-line in DDbDP unless <lb/> present    -->
         <br/>
      </xsl:if>
      <span lang="en" class="gap"><xsl:apply-imports/></span>
  </xsl:template>
  
  <xsl:template match="t:gap">
    <span lang="en" class="gap"><xsl:apply-imports/></span>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teihead.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  
  
  <xsl:template match="t:div/t:head">
      <h3>
         <xsl:apply-templates/>
      </h3>
  </xsl:template>
   
   <xsl:template match="t:body/t:head">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-leiden-style='ddbdp'">
            <xsl:element name="p">
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <xsl:otherwise>
            <h2>
               <xsl:apply-templates/>
            </h2>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teihi.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- hi imports in teihi.xsl, html span created here -->
   <xsl:import href="teihi.xsl"><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- html hi part of transformation in htm-teihi.xsl -->

    <xsl:template match="t:hi">
        <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
        <xsl:param name="parm-internal-app-style" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="@rend='ligature'">
               <xsl:choose>
                   <xsl:when test="$parm-leiden-style = ('rib','sigidoc')"><!-- modified by SigiDoc -->
                       <xsl:choose>
                           <xsl:when test="string-length(normalize-space(.))=2">
                               <xsl:value-of select="substring(.,1,1)"/>
                               <xsl:text>͡</xsl:text>
                               <xsl:value-of select="substring(.,2,1)"/>
                           </xsl:when>
                           <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
                       </xsl:choose>
                   </xsl:when>
                   <xsl:otherwise>
                       <xsl:if test="$parm-leiden-style='seg'">
                           <xsl:if test="string-length(normalize-space(.))=2">
                               <xsl:text>͜</xsl:text>
                           </xsl:if>
                       </xsl:if>
                       <xsl:apply-templates/>
                   </xsl:otherwise>
               </xsl:choose>
         </xsl:when>
         <xsl:when test="@rend = 'diaeresis' or @rend = 'grave' or @rend = 'acute' or @rend = 'asper' or @rend = 'lenis' or @rend = 'circumflex'">
             <xsl:apply-templates/>
             <xsl:choose>
                 <!-- if context is inside the app-part of an app-like element, print diacritic in parens here -->
                 <xsl:when test="$parm-internal-app-style = 'ddbdp' and                      ancestor::t:*[local-name()=('reg','corr','rdg')                       or self::t:del[@rend='corrected']]">
                     <!--ancestor::t:*[local-name()=('orig','reg','sic','corr','lem','rdg')
                         or self::t:del[@rend='corrected']
                         or self::t:add[@place='inline']][1][local-name()=('reg','corr','del','rdg')]">-->
                     <xsl:text>(</xsl:text>
                     <!-- found in tpl-apparatus.xsl -->
                     <xsl:call-template name="hirend">
                         <xsl:with-param name="hicontext" select="'no'"/>
                     </xsl:call-template>
                     <xsl:text>)</xsl:text>
                 </xsl:when>
                 <xsl:when test="$parm-internal-app-style = 'ddbdp'">
                     <!-- found in [htm|txt]-tpl-apparatus.xsl -->
                     <xsl:call-template name="app-link">
                         <xsl:with-param name="location" select="'text'"/>
                     </xsl:call-template>
                 </xsl:when>
             </xsl:choose>
         </xsl:when>
           <xsl:otherwise>
               <xsl:apply-templates/>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>

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

   <xsl:template match="t:hi">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
         <!-- No html code needed for these -->
         <xsl:when test="@rend = 'diaeresis' or @rend = 'grave' or @rend = 'acute' or @rend = 'asper' or @rend = 'lenis' or @rend = 'circumflex'">
            <xsl:apply-imports/>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='apex'                                                       -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='apex' and ancestor-or-self::t:*[@xml:lang][1][@xml:lang = 'la']             and not(child::t:unclear)">
            <xsl:element name="span">
               <xsl:attribute name="class">apex</xsl:attribute>
               <xsl:attribute name="title">apex over: <xsl:value-of select="."/>
               </xsl:attribute>
               <xsl:value-of select="translate(., 'aeiou', 'áéíóú')"/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='caps'                                                       -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='caps'">
             <xsl:element name="span">
                 <xsl:attribute name="class">caps</xsl:attribute>
                 <xsl:apply-templates/>
             </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='intraline'                                                  -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='intraline'">
            <xsl:element name="span">
               <xsl:attribute name="class">intraline</xsl:attribute>
               <xsl:attribute name="title">line through</xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='italic'                                                     -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='italic'">
            <xsl:element name="span">
               <xsl:attribute name="class">italic</xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='ligature'                                                   -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='ligature'">
            <xsl:element name="span">
               <xsl:choose>
                  <xsl:when test="$parm-leiden-style=('petrae','iospe')">
                     <xsl:attribute name="class">petraeligature</xsl:attribute>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:attribute name="class">ligature</xsl:attribute>
                  </xsl:otherwise>
               </xsl:choose>
               <xsl:attribute name="title">Ligature: these characters are joined</xsl:attribute>
               <xsl:apply-imports/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='normal'                                                     -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='normal'">
            <xsl:element name="span">
               <xsl:attribute name="class">normal</xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='plain'                                                      -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='plain'">
             <xsl:element name="span">
                 <xsl:attribute name="class">plain</xsl:attribute>
                 <xsl:apply-templates/>
             </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='reversed'                                                   -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='reversed'">
            <xsl:element name="span">
               <xsl:attribute name="class">reversed</xsl:attribute>
               <xsl:attribute name="title">reversed: <xsl:value-of select="."/>
               </xsl:attribute> ((<xsl:apply-templates/>)) </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='small'                                                      -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='small'">
            <xsl:element name="span">
               <xsl:attribute name="class">small</xsl:attribute>
               <xsl:attribute name="title">small character: <xsl:value-of select="."/>
               </xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='strong'                                                     -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='strong'">
            <xsl:element name="strong">
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='subscript'                                                  -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='subscript'">
            <xsl:choose>
               <xsl:when test="$parm-leiden-style = 'iospe'">
                  <xsl:apply-templates/>
               </xsl:when>
                <xsl:when test="$parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch' or $parm-leiden-style = 'sigidoc'"><!-- modified by SigiDoc -->
                  <span style="vertical-align:sub;">
                     <xsl:apply-imports/>
                  </span>
               </xsl:when>
               <xsl:otherwise>
                  <!-- To be decided -->
                  <xsl:apply-templates/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='superscript'                                                -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='superscript'">
            <xsl:choose>
               <xsl:when test="$parm-leiden-style = 'iospe'">
                  <xsl:apply-templates/>
               </xsl:when>
                <xsl:when test="$parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch'">
                  <span style="vertical-align:super;">
                     <xsl:apply-imports/>
                  </span>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:element name="sup">
                     <xsl:apply-templates/>
                  </xsl:element>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='supraline'                                                  -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- I wonder if this should be "overline" to match css practice? TE -->
         <xsl:when test="@rend='supraline'">
            <xsl:element name="span">
               <xsl:attribute name="class">supraline</xsl:attribute>
               <xsl:attribute name="title">line above</xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='tall'                                                       -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='tall'">
            <xsl:element name="span">
               <xsl:attribute name="class">tall</xsl:attribute>
               <xsl:attribute name="title">tall character: <xsl:value-of select="."/>
               </xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- @rend='underline'                                                  -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:when test="@rend='underline'">
            <xsl:element name="span">
               <xsl:attribute name="class">underline</xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:when>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- UNTRAPPED REND VALUE                                               -->
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <xsl:otherwise>
            <xsl:element name="span">
               <xsl:attribute name="class">error</xsl:attribute>
               <xsl:attribute name="title">
                  <xsl:text>hi tag with rend=</xsl:text>
                  <xsl:value-of select="@rend"/>
                  <xsl:text> is not supported!</xsl:text>
               </xsl:attribute>
               <xsl:apply-templates/>
            </xsl:element>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teilb.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:EDF="http://epidoc.sourceforge.net/ns/functions" exclude-result-prefixes="#all" version="2.0">
   <!-- Actual display and increment calculation found in teilb.xsl -->
   <xsl:import href="teilb.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Imported by [htm|txt]-teilb.xsl -->
  
  <xsl:template match="t:lb">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:param name="parm-line-inc" tunnel="yes" required="no"/>
      <xsl:param name="parm-verse-lines" tunnel="yes" required="no"/>
      <xsl:if test="ancestor::t:l">
         <xsl:choose>
            <xsl:when test="@break='no' or @type='inWord'">
               <xsl:text>|</xsl:text>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text> | </xsl:text>
            </xsl:otherwise>
         </xsl:choose>
         <xsl:choose>
        <!-- If verse-line is needed in ddbdp and @n is not a number eg 2a -->
             <xsl:when test="$parm-verse-lines = 'on' and not(number(@n)) and ($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
               <xsl:call-template name="lb-content"/>
            </xsl:when>
            <xsl:when test="number(@n) and @n mod number($parm-line-inc) = 0 and not(@n = 0) and not(starts-with($parm-leiden-style, 'edh'))">
               <xsl:call-template name="lb-content"/>
            </xsl:when>
         </xsl:choose>
      </xsl:if>
      <xsl:if test="$parm-leiden-style=('ddbdp','sammelbuch') and @rend">
        <xsl:text> (</xsl:text>
        <xsl:value-of select="@rend"/>
        <xsl:text>) </xsl:text>
     </xsl:if>
  </xsl:template>
  

  <xsl:template name="lb-content">
      <xsl:choose>
         <xsl:when test="@break='no' or @type='inWord'">
            <xsl:text>(</xsl:text>
            <xsl:value-of select="@n"/>
            <xsl:text>)</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>(</xsl:text>
            <xsl:value-of select="@n"/>
            <xsl:text>) </xsl:text>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

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

   <xsl:template match="t:lb">
       <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:param name="parm-line-inc" tunnel="yes" required="no"/>
       <xsl:param name="parm-verse-lines" tunnel="yes" required="no"/>
       <xsl:param name="location"/>
      
      <xsl:choose>
          <xsl:when test="ancestor::t:lg and $parm-verse-lines = 'on'">
            <xsl:apply-imports/>
            <!-- use the particular templates in teilb.xsl -->
         </xsl:when>

         <xsl:otherwise>
            <xsl:variable name="div-loc">
               <xsl:for-each select="ancestor::t:div[@type= 'textpart']">
                  <xsl:value-of select="@n"/>
                  <xsl:text>-</xsl:text>
               </xsl:for-each>
            </xsl:variable>
            <xsl:variable name="line">
               <xsl:if test="@n">
                  <xsl:value-of select="@n"/>
               </xsl:if>
            </xsl:variable>

            <!-- print hyphen if break=no  -->
            <xsl:if test="(@break='no' or @type='inWord')">
               <xsl:choose>
                  <!--    *unless* edh web  -->
                  <xsl:when test="$parm-leiden-style='eagletxt'"/>
                  <!--    *unless* diplomatic edition  -->
                   <xsl:when test="$parm-edition-type='diplomatic'"/>
                  <!--    *or unless* the lb is first in its ancestor div  -->
                  <xsl:when test="generate-id(self::t:lb) = generate-id(ancestor::t:div[1]/t:*[child::t:lb][1]/t:lb[1])"/>
                   <xsl:when test="$parm-leiden-style = 'ddbdp' and ((not(ancestor::*[name() = 'TEI'])) or $location='apparatus')"/>                                      
                  <!--   *or unless* the second part of an app in ddbdp  -->
                   <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and                            (ancestor::t:corr or ancestor::t:reg or ancestor::t:rdg or ancestor::t:del[parent::t:subst])"/>
                  <!--  *unless* previous line ends with space / g / supplied[reason=lost]  -->
                  <!-- in which case the hyphen will be inserted before the space/g r final ']' of supplied
                     (tested by EDF:f-wwrap in teig.xsl, which is called by teisupplied.xsl, teig.xsl and teispace.xsl) -->
                  <xsl:when test="preceding-sibling::node()[1][local-name() = 'space' or                         local-name() = 'g' or (local-name()='supplied' and @reason='lost') or                         (normalize-space(.)=''                                   and preceding-sibling::node()[1][local-name() = 'space' or                                  local-name() = 'g' or (local-name()='supplied' and @reason='lost')])]"/>              
                  <!-- *or unless* this break is accompanied by a paragraphos mark -->
                  <!-- in which case the hypen will be inserted before the paragraphos by code in htm-teimilestone.xsl -->
                  <xsl:when test="preceding-sibling::node()[not(self::text() and normalize-space(self::text())='')][1]/self::t:milestone[@rend='paragraphos']"/>
                  <xsl:otherwise>
                      <xsl:text>-</xsl:text>
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:if>

            <xsl:choose>
               <xsl:when test="$parm-leiden-style=('edh-itx','edh-names')">
                  <xsl:variable name="cur_anc" select="generate-id(ancestor::node()[local-name()='lg' or local-name()='ab'])"/>
                  <xsl:if test="preceding::t:lb[1][generate-id(ancestor::node()[local-name()='lg' or local-name()='ab'])=$cur_anc]">
                     <xsl:choose>
                        <xsl:when test="$parm-leiden-style='edh-names'                            and not(@break='no' or ancestor::t:w | ancestor::t:name | ancestor::t:placeName | ancestor::t:geogName)">
                           <xsl:text> </xsl:text>
                        </xsl:when>
                        <xsl:when test="$parm-leiden-style=('edh-names')"/>
                        <xsl:when test="@break='no' or ancestor::t:w | ancestor::t:name | ancestor::t:placeName | ancestor::t:geogName">
                           <xsl:text>/</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:text> / </xsl:text>
                        </xsl:otherwise>
                     </xsl:choose>
                  </xsl:if>
               </xsl:when>
               
               <xsl:when test="$parm-leiden-style='eagletxt'">
                  <xsl:variable name="cur_anc" select="generate-id(ancestor::node()[local-name()='lg' or local-name()='ab'])"/>
                  <xsl:if test="preceding::t:lb[1][generate-id(ancestor::node()[local-name()='lg' or local-name()='ab'])=$cur_anc]">
                        
               <xsl:choose>
<xsl:when test="not(@break='no' or ancestor::t:w | ancestor::t:name | ancestor::t:placeName | ancestor::t:geogName)">
                  <xsl:text> / </xsl:text>
               </xsl:when>
               <xsl:when test="@break='no' or ancestor::t:w | ancestor::t:name | ancestor::t:placeName | ancestor::t:geogName">
                  <xsl:text>/</xsl:text>
               </xsl:when>
              </xsl:choose>
                  </xsl:if>
               </xsl:when>

               <xsl:otherwise>
                  <xsl:text>&#13;</xsl:text>
               </xsl:otherwise>
            </xsl:choose>

            
            
            <!-- print arrows right of line if R2L or explicitly L2R -->
            <!-- arrows after final line handled in htm-teiab.xsl -->
            <xsl:if test="not($parm-leiden-style=('ddbdp','sammelbuch'))                 and not(position() = 1)                and preceding::t:lb[1][@rend='left-to-right']">
               <xsl:text>  →</xsl:text>
            </xsl:if>
            <xsl:if test="not($parm-leiden-style=('ddbdp','sammelbuch'))                 and not(position() = 1)                and preceding::t:lb[1][@rend='right-to-left']">
               <xsl:text>  ←</xsl:text>
            </xsl:if>
            
            <xsl:choose>
               <!-- replaced test using generate-id() with 'is' -->
               <xsl:when test="self::t:lb is ancestor::t:div[1]/t:*[child::t:lb][1]/t:lb[1]">
                  <a id="a{$div-loc}l{$line}">
                     <xsl:comment>0</xsl:comment>
                  </a>
                  <!-- for the first lb in a div, create an empty anchor instead of a line-break -->
               </xsl:when>
               <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')                    and (ancestor::t:sic                          or ancestor::t:reg                         or ancestor::t:rdg or ancestor::t:del[ancestor::t:choice])                         or ancestor::t:del[@rend='corrected'][parent::t:subst]">
                  <xsl:choose>
                     <xsl:when test="@break='no' or @type='inWord'">
                        <xsl:text>|</xsl:text>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:text> | </xsl:text>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <xsl:when test="$parm-leiden-style = 'ddbdp' and ((not(ancestor::*[name() = 'TEI']))  or $location='apparatus')">
                  <xsl:choose>
                     <xsl:when test="@break='no' or @type='inWord'">
                        <xsl:text>|</xsl:text>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:text> | </xsl:text>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>              
               <xsl:otherwise>
                  <br id="a{$div-loc}l{$line}"/>
               </xsl:otherwise>
            </xsl:choose>
            <xsl:choose>
               <xsl:when test="$location = 'apparatus'"/>
               <xsl:when test="not(number(@n)) and ($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
                  <!--         non-numerical line-nos always printed in DDbDP         -->
                  <xsl:call-template name="margin-num"/>
               </xsl:when>
               <xsl:when test="number(@n) and @n mod number($parm-line-inc) = 0 and not(@n = 0) and                    not(following::t:*[1][local-name() = 'gap' or local-name()='space'][@unit = 'line'] and                    ($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch'))">
                  <!-- prints line-nos divisible by stated increment, unless zero
                     and unless it is a gap line or vacat in DDbDP -->
                  <xsl:call-template name="margin-num"/>
               </xsl:when>
                <xsl:when test="$parm-leiden-style = 'ddbdp' and preceding-sibling::t:*[1][local-name()='gap'][@unit = 'line']">
                  <!-- always print line-no after gap line in ddbdp -->
                  <xsl:call-template name="margin-num"/>
               </xsl:when>
                <xsl:when test="$parm-leiden-style = 'ddbdp' and following::t:lb[1][ancestor::t:reg[following-sibling::t:orig[not(descendant::t:lb)]]]">
                  <!-- always print line-no when broken orig in line, in ddbdp -->
                  <xsl:call-template name="margin-num"/>
               </xsl:when>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="margin-num">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
         <!-- don't print marginal line number inside tags that are relegated to the apparatus (ddbdp) -->
          <xsl:when test="$parm-leiden-style = 'eagletxt'"/>
<xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')              and (ancestor::t:sic             or ancestor::t:reg             or ancestor::t:rdg or ancestor::t:del[ancestor::t:choice])             or ancestor::t:del[@rend='corrected'][parent::t:subst]"/>
         <xsl:otherwise>
            <span>
                  <xsl:choose>
                      <xsl:when test="$parm-leiden-style = 'ddbdp' and following::t:lb[1][ancestor::t:reg[following-sibling::t:orig[not(descendant::t:lb)]]]">
                        <xsl:attribute name="class">
                           <xsl:text>linenumberbroken</xsl:text>
                        </xsl:attribute>
                        <xsl:attribute name="title">
                           <xsl:text>line-break missing in orig</xsl:text>
                        </xsl:attribute>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:attribute name="class">
                           <xsl:text>linenumber</xsl:text>
                         </xsl:attribute>
                     </xsl:otherwise>
                  </xsl:choose>
               <xsl:value-of select="@n"/>
            </span>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teilgandl.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <xsl:include href="teilgandl.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Called by [htm|txt]-teilgandl.xsl -->

  <xsl:template name="line-context">
      <xsl:param name="parm-line-inc" tunnel="yes" required="no"/>
      <xsl:if test="@met='pentameter'">
         <xsl:text>   </xsl:text>
      </xsl:if>
      <xsl:if test="local-name(preceding-sibling::t:*[1])='lb'">
         <xsl:variable name="pre-lb">
            <xsl:value-of select="preceding-sibling::t:lb[1]/@n"/>
         </xsl:variable>
         <xsl:if test="number($pre-lb) and $pre-lb mod number($parm-line-inc) = 0 and not($pre-lb = 0)">
            <xsl:choose>
               <xsl:when test="@break='no' or @type='inWord'">
                  <xsl:text>(</xsl:text>
                  <xsl:value-of select="$pre-lb"/>
                  <xsl:text>)</xsl:text>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:text>(</xsl:text>
                  <xsl:value-of select="$pre-lb"/>
                  <xsl:text>) </xsl:text>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:if>
      </xsl:if>
      <xsl:apply-templates/>
      <xsl:if test="local-name(following-sibling::t:*[1])='lb'">
         <xsl:text> |</xsl:text>
      </xsl:if>
  </xsl:template>
</xsl:stylesheet></xsl:include>

  <xsl:template match="t:lg">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
        <!-- in IOSPE, if preceded by ab, will be called inside that div (in htm-teiab.xsl) -->
          <xsl:when test="$parm-leiden-style='iospe' and preceding-sibling::t:*[1][local-name()='ab']"/>
        <xsl:otherwise>
        <div class="textpart">
         <!-- Found in htm-tpl-lang.xsl -->
         <xsl:call-template name="attr-lang"/>
            <xsl:apply-templates/>
         </div>
        </xsl:otherwise>
     </xsl:choose>
  </xsl:template>


  <xsl:template match="t:l">
      <xsl:param name="parm-line-inc" tunnel="yes" required="no"/>
      <xsl:param name="parm-verse-lines" tunnel="yes" required="no"/>
      <xsl:choose>
          <xsl:when test="$parm-verse-lines = 'on'">   
            <xsl:variable name="div-loc">
               <xsl:for-each select="ancestor::t:div[@type='textpart']">
                  <xsl:value-of select="@n"/>
                  <xsl:text>-</xsl:text>
               </xsl:for-each>
            </xsl:variable>
            <br id="a{$div-loc}l{@n}"/>
              <xsl:if test="number(@n) and @n mod number($parm-line-inc) = 0 and not(@n = 0)">
               <span class="linenumber">
                  <xsl:value-of select="@n"/>
               </span>
            </xsl:if>
            <!-- found in teilgandl.xsl -->
        <xsl:call-template name="line-context"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teilistanditem.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

  <xsl:template match="t:list">
      <xsl:choose>
         <xsl:when test="@type = 'ordered'">
            <ol>
               <xsl:apply-templates/>
            </ol>
         </xsl:when>
         <xsl:otherwise>
            <ul>
               <xsl:apply-templates/>
            </ul>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>


  <xsl:template match="t:item">
      <li>
         <xsl:apply-templates/>
      </li>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teilistbiblandbibl.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  
  <xsl:template match="t:listBibl">
      <ul>
         <xsl:apply-templates/>
      </ul>
  </xsl:template>


  <xsl:template match="t:listBibl//t:bibl">
      <li>
         <xsl:apply-templates/>
      </li>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teimilestone.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- More specific templates in teimilestone.xsl -->

   <xsl:template match="t:milestone">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>      
       <xsl:choose>
         <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and ancestor::t:div[@type = 'translation']">
            <xsl:if test="@rend = 'break'">
               <br/>
            </xsl:if>
            <sup>
               <strong>
                  <xsl:value-of select="@n"/>
               </strong>
            </sup>
            <xsl:text> </xsl:text>
         </xsl:when>
           <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
            <xsl:choose>
               <xsl:when test="@rend = 'wavy-line'">
                  <xsl:if test="not(parent::t:supplied)">
                     <br/>
                  </xsl:if>
                  <xsl:text>~~~~~~~~</xsl:text>
               </xsl:when>
               <xsl:when test="@rend = 'paragraphos'">
                  <xsl:if test="following-sibling::node()[not(self::text() and normalize-space(self::text())='')][1]/self::t:lb[@break='no']">-</xsl:if>
                  <xsl:if test="not(parent::t:supplied)">
                     <br/>
                  </xsl:if>
                  <xsl:text>——</xsl:text>
               </xsl:when>
               <xsl:when test="@rend = 'horizontal-rule'">
                  <xsl:if test="not(parent::t:supplied)">
                     <br/>
                  </xsl:if>
                  <xsl:text>————————</xsl:text>
               </xsl:when>
            </xsl:choose>
         </xsl:when>
         <xsl:otherwise>
            <br/>
            <xsl:value-of select="@rend"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   
   <!-- commented out by SigiDoc -->
   <!--<xsl:template match="t:cb">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:if test="$parm-leiden-style='iospe'">
         <xsl:element name="span">
            <xsl:attribute name="class" select="'textpartnumber'"/>
            <xsl:attribute name="style" select="'left: -4em;'"/>
            <xsl:text>Col. </xsl:text>
            <xsl:value-of select="@n"/>
            <xsl:element name="br"/>
         </xsl:element>
      </xsl:if>
   </xsl:template>-->
   
   <!-- added by SigiDoc -->
   <xsl:template match="t:cb">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:if test="$parm-leiden-style='sigidoc'">
         <xsl:choose>
            <xsl:when test="@n='a'">
               <xsl:element name="span">
                  <xsl:attribute name="style" select="'vertical-align: super; position: relative; font-family: calibri; font-size: 80%'"/>
                  <xsl:text>a</xsl:text>
               </xsl:element>
            </xsl:when>
            <xsl:when test="@n='b'">
               <xsl:element name="span">
                  <xsl:text> – </xsl:text>
               </xsl:element>
               <xsl:element name="span">
                  <xsl:attribute name="style" select="'vertical-align: super; position: relative; font-family: calibri; font-size: 80%'"/>
                  <xsl:text>b  </xsl:text>
               </xsl:element>
            </xsl:when>
            <xsl:when test="@n='c'">
               <xsl:element name="span">
                  <xsl:text> – </xsl:text>
               </xsl:element>
               <xsl:element name="span">
                  <xsl:attribute name="style" select="'vertical-align: super; position: relative; font-family: calibri; font-size: 80%'"/>
                  <xsl:text>c  </xsl:text>
               </xsl:element>
            </xsl:when>
            <xsl:when test="@n='d'">
               <xsl:element name="span">
                  <xsl:text> – </xsl:text>
               </xsl:element>
               <xsl:element name="span">
                  <xsl:attribute name="style" select="'vertical-align: super; position: relative; font-family: calibri; font-size: 80%'"/>
                  <xsl:text>d  </xsl:text>
               </xsl:element>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:if>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teibibl.xsl"><xsl:stylesheet xmlns:f="http://example.com/ns/functions" xmlns:html="http://www.w3.org/1999/html" exclude-result-prefixes="t f" version="2.0">
	<!--

Pietro notes on 14/8/2015 work on this template, from mail to Gabriel.

- I have converted the TEI bibliography of IRT and IGCyr to ZoteroRDF 
(https://github.com/EAGLE-BPN/BiblioTEI2ZoteroRDF) in this passage I have tried to 
distinguish books, bookparts, articles and conference proceedings.

- I have uploaded these to the zotero eagle open group bibliography 
(https://www.zotero.org/groups/eagleepigraphicbibliography)

- I have created a parametrized template in my local epidoc xslts which looks at the json 
and TEI output of the Zotero api basing the call on the content of ptr/@target in each 
bibl. It needs both because the key to build the link is in the json but the TEI xml is 
much more accessible for the other data. I tried also to grab the html div exposed in the 
json, which would have been the easiest thing to do, but I can only get it escaped and 
thus is not usable.
** If set on 'zotero' it prints surname, name, title and year with a link to the zotero 
item in the eagle group bibliography. It assumes bibl only contains ptr and citedRange.
** If set on 'localTEI' it looks at a local bibliography (no zotero) and compares the 
@target to the xml:id to take the results and print something (in the sample a lot, but 
I'd expect more commonly Author-Year references(.
** I have also created sample values for irt and igcyr which are modification of the 
zotero option but deal with some of the project specific ways of encoding the 
bibliography. All examples only cater for book and article.



-->

	<!--
		
		Pietro Notes on 10.10.2016
		
		this should be modified based on parameters to
		
		* decide wheather to use zotero or a local version of the bibliography in TEI
	
		* assuming that the user has entered a unique tag name as value of ptr/@target, decide group or user in zotero to look up based on parameter value entered at transformation time
	
		* output style based on Zotero Style Repository stored in a parameter value entered at transformation time
		
		
	
	-->

	<xsl:template match="t:bibl" priority="1">
		<xsl:param name="parm-bib" tunnel="yes" required="no"/>
		<xsl:param name="parm-bibloc" tunnel="yes" required="no"/>
		<xsl:param name="parm-zoteroUorG" tunnel="yes" required="no"/>
		<xsl:param name="parm-zoteroKey" tunnel="yes" required="no"/>
		<xsl:param name="parm-zoteroNS" tunnel="yes" required="no"/>
		<xsl:param name="parm-zoteroStyle" tunnel="yes" required="no"/>


		<xsl:choose>
			<!-- default general zotero behaviour prints 
				author surname and name, title in italics, date and links to the zotero item page on the zotero bibliography. 
				assumes the inscription source has no free text in bibl, 
				!!!!!!!only a <ptr target='key'/> and a <citedRange>pp. 45-65</citedRange>!!!!!!!
			it also assumes that the content of ptr/@target is a unique tag used in the zotero bibliography as the ids assigned by Zotero are not
			reliable enough for this purpose according to Zotero forums.
			
			if there is no ptr/@target, this will try anyway and take a lot of time.
			-->

			<xsl:when test="$parm-bib = 'none'">
				<xsl:apply-templates/>
			</xsl:when>

			<xsl:when test="$parm-bib = 'zotero'">
				<xsl:choose>
					<!--					check if there is a ptr at all
					
					WARNING. if the pointer is not there, the transformation will simply stop and return a premature end of file message e.g. it cannot find what it is looking for via the zotero api
					-->
					<xsl:when test=".[t:ptr]">

						<!--						check if a namespace is provided for tags/xml:ids and use it as part of the tag for zotero-->
						<xsl:variable name="biblentry" select="         if ($parm-zoteroNS)         then          concat($parm-zoteroNS, substring-after(./t:ptr/@target, '#'))         else          substring-after(./t:ptr/@target, '#')"/>

						<xsl:variable name="zoteroapitei">

							<xsl:value-of select="concat('https://api.zotero.org/',$parm-zoteroUorG,'/',$parm-zoteroKey,'/items?tag=', $biblentry, '&amp;format=tei')"/>
							<!-- to go to the json with the escaped html included  use &amp;format=json&amp;include=bib,data and the code below: the result is anyway escaped... -->

						</xsl:variable>

						<xsl:variable name="zoteroapijson">
							<xsl:value-of select="concat('https://api.zotero.org/',$parm-zoteroUorG,'/',$parm-zoteroKey,'/items?tag=', $biblentry, '&amp;format=json&amp;style=',$parm-zoteroStyle,'&amp;include=citation')"/>
						</xsl:variable>
						<xsl:variable name="unparsedtext" select="unparsed-text($zoteroapijson)"/>
						<xsl:variable name="zoteroitemKEY">

							<xsl:analyze-string select="$unparsedtext" regex="(\[\s+\{{\s+&quot;key&quot;:\s&quot;)(.+)&quot;">
								<xsl:matching-substring>
									<xsl:value-of select="regex-group(2)"/>
								</xsl:matching-substring>
							</xsl:analyze-string>

						</xsl:variable>

						<xsl:choose>
							<!--this will print a citation according to the selected style with a link around it pointing to the resource DOI, url or zotero item view-->
							<xsl:when test="not(ancestor::t:div[@type = 'bibliography'])">
								<xsl:variable name="pointerurl">
									<xsl:choose>
										<xsl:when test="document($zoteroapitei)//t:idno[@type = 'DOI']">
											<xsl:value-of select="document($zoteroapitei)//t:idno[@type = 'DOI']"/>
										</xsl:when>
										<xsl:when test="document($zoteroapitei)//t:idno[@type = 'url']">
											<xsl:value-of select="document($zoteroapitei)//t:idno[@type = 'url']"/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:value-of select="document($zoteroapitei)//t:biblStruct/@corresp"/>
										</xsl:otherwise>
									</xsl:choose>

								</xsl:variable>

								<a href="{$pointerurl}">

									<xsl:variable name="citation">

										<xsl:analyze-string select="$unparsedtext" regex="(\s+&quot;citation&quot;:\s&quot;&lt;span&gt;)(.+)(&lt;/span&gt;&quot;)">
											<xsl:matching-substring>
												<xsl:value-of select="regex-group(2)"/>
											</xsl:matching-substring>
										</xsl:analyze-string>
									</xsl:variable>
									<xsl:value-of select="$citation"/>
									<xsl:if test="t:citedRange">
										<xsl:text>, </xsl:text>
										<xsl:value-of select="t:citedRange"/>
									</xsl:if>
								</a>
							</xsl:when>
							<!--	if it is in the bibliography print styled reference-->
							<xsl:otherwise>
								<!--	print out using Zotoro parameter format with value bib and the selected style-->
								<xsl:copy-of select="document(concat('https://api.zotero.org/',$parm-zoteroUorG,'/',$parm-zoteroKey,'/items?tag=', $biblentry, '&amp;format=bib&amp;style=',$parm-zoteroStyle))/div"/>

							</xsl:otherwise>
						</xsl:choose>

					</xsl:when>

					<!-- if there is no ptr, print simply what is inside bibl and a warning message-->
					<xsl:otherwise>
						<xsl:value-of select="."/>
						<xsl:message>There is no ptr with a @target in the bibl element <xsl:copy-of select="."/>. A target equal to a tag in your zotero bibliography is
							necessary.</xsl:message>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:value-of select="t:citedRange"/>
			</xsl:when>


			<!--uses the local TEI bibliography at the path specified in parameter parm-bibloc -->
			<xsl:when test="$parm-bib = 'localTEI'">

				<xsl:variable name="biblentry" select="./t:ptr/@target"/>
				<xsl:variable name="biblentryID" select="substring-after(./t:ptr/@target, '#')"/>
				<!--					parameter localbibl should contain the path to the bibliography relative to this xslt -->
				<xsl:variable name="textref" select="document(string($parm-bibloc))//t:bibl[@xml:id = $biblentryID]"/>
				<xsl:for-each select="$biblentry">
					<xsl:choose>
						<!--this will print a citation according to the selected style with a link around it pointing to the resource DOI, url or zotero item view-->
						<xsl:when test="not(ancestor::t:div[@type = 'bibliography'])">

							<!-- basic	render for citations-->
							<xsl:choose>
								<xsl:when test="$textref/@xml:id = $biblentryID">
									<xsl:choose>
										<xsl:when test="$textref//t:author">
											<xsl:value-of select="$textref//t:author[1]"/>
											<xsl:if test="$textref//t:author[2]">
												<xsl:text>-</xsl:text>
												<xsl:value-of select="$textref//t:author[2]"/>
											</xsl:if>
											<xsl:text>, </xsl:text>
										</xsl:when>
										<xsl:when test="$textref//t:editor">
											<xsl:value-of select="$textref//t:editor[1]"/>
											<xsl:if test="$textref//t:editor[2]">
												<xsl:text>-</xsl:text>
												<xsl:value-of select="$textref//t:editor[2]"/>
											</xsl:if>
										</xsl:when>
									</xsl:choose>
									<xsl:text> (</xsl:text>
									<xsl:value-of select="$textref//t:date"/>
									<xsl:text>), </xsl:text>
									<xsl:value-of select="$textref//t:biblScope"/>

								</xsl:when>
								<xsl:otherwise>
									<!--if this appears the id do not really correspond to each other, 
									ther might be a typo or a missing entry in the bibliography-->
									<xsl:message>
										<xsl:text> there is no entry in your bibliography file at </xsl:text>
										<xsl:value-of select="$parm-bibloc"/>
										<xsl:text> with the @xml:id</xsl:text>
										<xsl:value-of select="$biblentry"/>
										<xsl:text>!</xsl:text>
									</xsl:message>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:otherwise>

							<!--						rudimental render for each entry in bibliography-->
							<xsl:choose>
								<xsl:when test="$textref/@xml:id = $biblentryID">
									<xsl:value-of select="$textref"/>
									<!--assumes a sligthly "formatted" bibliography...-->

								</xsl:when>
								<xsl:otherwise>
									<!--if this appears the id do not really correspond to each other, 
									ther might be a typo or a missing entry in the bibliography-->
									<xsl:message>
										<xsl:text> there is no entry in your bibliography file at </xsl:text>
										<xsl:value-of select="$parm-bibloc"/>
										<xsl:text> for the entry </xsl:text>
										<xsl:value-of select="$biblentry"/>
										<xsl:text>!</xsl:text>
									</xsl:message>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>

				</xsl:for-each>

			</xsl:when>
			<xsl:otherwise>
				<!-- This applyes other templates and does not call the zotero api -->
				<xsl:apply-templates/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>


</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teinote.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Template in teinote.xsl -->
  <xsl:import href="teinote.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Imported from [htm|txt]-teinote.xsl -->

  <xsl:template match="t:note">
      <xsl:text>(</xsl:text>
      <xsl:apply-templates/>
      <xsl:text>)</xsl:text>
  </xsl:template>


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

   <xsl:template match="t:note">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
     <xsl:choose>
        <xsl:when test="$parm-leiden-style='iospe' and (ancestor::t:p or ancestor::t:l or ancestor::t:ab)">
           <xsl:apply-imports/>
        </xsl:when>
        <xsl:when test="ancestor::t:p or ancestor::t:l or ancestor::t:ab">
           <i><xsl:apply-imports/></i>
        </xsl:when>
         <xsl:otherwise>
            <p class="note">
               <xsl:apply-imports/>
            </p>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teinum.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Template in teinum.xsl -->
   <xsl:import href="teinum.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">  
  <!-- latinnum span added in htm-teinum.xsl -->
  
   <xsl:template match="t:num">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="not(child::t:* or child::text())"/>
         <xsl:when test="$parm-leiden-style = ('ddbdp','sammelbuch')">
            <xsl:apply-templates/>
            <xsl:if test="@rend='tick'">
               <xsl:text>´</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:when test="$parm-edition-type='interpretive' and ancestor::t:*[@xml:lang][1][@xml:lang = 'grc']             and ((number(@value) and not(contains(@value,'/')))             or (number(@atLeast) and not(contains(@atLeast,'/')))             or (number(@atMost) and not(contains(@atMost,'/'))))">
            <xsl:if test="@value &gt;= 1000 or @atLeast &gt;= 1000 or @atMost &gt;= 1000">
               <xsl:text>͵</xsl:text>
            </xsl:if>
            <xsl:apply-templates/>
            <xsl:if test="@value mod 1000 != 0                or @atLeast mod 1000 != 0                or @atMost mod 1000 != 0">
               <xsl:text>´</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>
  
  
</xsl:stylesheet></xsl:import>

   <xsl:template match="t:num">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
         <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch')              and string(.)">
            <span>
               <xsl:attribute name="title">
                  <xsl:choose>
                     <xsl:when test="contains(@value,'/') or @type='fraction'">
                        <i18n:text i18n:key="epidoc-xslt-fraction">
                           <xsl:text>fraction</xsl:text>
                        </i18n:text>
                     </xsl:when>
                     <xsl:otherwise>
                        <i18n:text i18n:key="epidoc-xslt-number">
                           <xsl:text>number</xsl:text>
                        </i18n:text>
                     </xsl:otherwise>
                  </xsl:choose>
                  <xsl:choose>
                     <xsl:when test="string(@value)">
                        <xsl:text>: </xsl:text>
                        <xsl:value-of select="@value"/>
                     </xsl:when>
                     <xsl:when test="string(@atLeast) or string(@atMost)">
                        <xsl:text>: </xsl:text>
                        <xsl:if test="string(@atLeast)">
                           <xsl:value-of select="@atLeast"/>
                        </xsl:if>
                        <xsl:text>-</xsl:text>
                        <xsl:if test="string(@atMost)">
                           <xsl:value-of select="@atMost"/>
                        </xsl:if>
                     </xsl:when>
                  </xsl:choose>
                  <xsl:if test="child::t:certainty[@match='../@value']">
                     <xsl:text>(?)</xsl:text>
                  </xsl:if>
               </xsl:attribute>
               <xsl:apply-imports/>
            </span>
         </xsl:when>
         <xsl:when test="$parm-leiden-style = 'panciera' and             ancestor::t:*[@xml:lang][1][@xml:lang = 'la']">
            <span class="latinnum">
               <xsl:apply-imports/>
            </span>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-imports/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teip.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

  <xsl:template match="t:p">
      <p>
         <xsl:apply-templates/>
      </p>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teiseg.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- General template in teiseg.xsl -->
  <xsl:import href="teiseg.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- seg[@type='autopsy'] span added in htm-teiseg.xsl -->
  
  <xsl:template match="t:seg | t:w">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:if test="$parm-leiden-style='london' and (@part='M' or @part='F')          and not(preceding-sibling::node()[1][self::t:gap])          and not($parm-edition-type='diplomatic')">
         <xsl:text>-</xsl:text>
      </xsl:if>
    
      <xsl:apply-templates/>
    
      <!-- Found in tpl-certlow.xsl -->
    <xsl:call-template name="cert-low"/>
    
      <xsl:if test="$parm-leiden-style='london' and (@part='I' or @part='M')          and not(following-sibling::node()[1][self::t:gap])          and not(descendant::ex[last()])          and not($parm-edition-type='diplomatic')">
         <xsl:text>-</xsl:text>
      </xsl:if>
  </xsl:template>
  
 

</xsl:stylesheet></xsl:import>
  
  <xsl:template match="t:seg">
      <xsl:choose>
         <xsl:when test="@type='observed' and @subtype='autopsy'">
            <span class="autopsy">
               <xsl:apply-imports/>
            </span>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-imports/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teispace.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

   <xsl:template name="space-content">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:param name="vacat"/>
      <xsl:param name="extent"/>

      <xsl:choose>
          <xsl:when test="$parm-leiden-style = 'london'">
            <i>
               <!-- Found in teispace.xsl -->
               <xsl:call-template name="space-content-1">
                  <xsl:with-param name="vacat" select="$vacat"/>
               </xsl:call-template>
            </i>
         </xsl:when>
          <xsl:when test="$parm-leiden-style = 'panciera'">
            <!-- Found in teispace.xsl -->
            <xsl:call-template name="space-content-2">
               <xsl:with-param name="vacat" select="$vacat"/>
               <xsl:with-param name="extent" select="$extent"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <!-- Found in teispace.xsl -->
            <xsl:call-template name="space-content-2">
               <xsl:with-param name="vacat" select="$vacat"/>
               <xsl:with-param name="extent" select="$extent"/>
            </xsl:call-template>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="dip-space">
      <em>
         <span class="smaller">
            <xsl:call-template name="space-content-1">
               <xsl:with-param name="vacat" select="'vacat '"/>
            </xsl:call-template>
         </span>
      </em>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teisupplied.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Called from teisupplied.xsl -->

    <xsl:template name="supplied-parallel">
        <span class="underline">
            <xsl:apply-templates/>
        </span>
    </xsl:template>
    
    <xsl:template name="supplied-previouseditor">
        <span class="underline">
            <xsl:apply-templates/>
        </span>
    </xsl:template>
    
    <xsl:template name="supplied-similar"><!-- added by SigiDoc -->
        <span class="underline">
            <xsl:apply-templates/>
        </span>
    </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teiterm.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  
  <xsl:template match="t:term">
      <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
      <xsl:param name="parm-hgv-gloss" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
      <!-- Adds caption for hgv translations -->
          <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and ancestor::t:div[@type = 'translation'] and @target">
            <xsl:variable name="lang" select="ancestor::t:div[@type = 'translation']/@xml:lang"/>
            <xsl:variable name="term" select="@target"/>
        
            <xsl:choose>
               <xsl:when test="ancestor::t:lem">
                  <xsl:apply-templates/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:choose>
                      <xsl:when test="document($parm-hgv-gloss)//t:item[@xml:id = $term]/t:gloss[@xml:lang = $lang]/text()"><span class="term">
                    <xsl:apply-templates/>
                          <span class="gloss" style="display:none"><xsl:value-of select="document($parm-hgv-gloss)//t:item[@xml:id = $term]/t:gloss[@xml:lang = $lang]"/></span>                 
                    </span></xsl:when>
                    <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
                  </xsl:choose>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
      
          <xsl:when test="$parm-edn-structure = 'rib'">
              <xsl:choose>
                  <xsl:when test="@xml:lang='grc'"><span class="greek"><xsl:apply-templates/></span></xsl:when>
                  <xsl:when test="@rend='diplo'"><span class="sc"><xsl:apply-templates/></span></xsl:when>
                  <xsl:when test="@xml:lang"><span class="em"><xsl:apply-templates/></span></xsl:when>
                  <xsl:otherwise><xsl:apply-templates/></xsl:otherwise>
              </xsl:choose>
          </xsl:when>

          <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
    
  </xsl:template>
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-teiref.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <xsl:include href="teiref.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Called from [htm|txt]-teiref.xsl -->

   <xsl:template name="reprint-text">
      <xsl:param name="direction"/>

      <xsl:text>[</xsl:text>
      <xsl:text>Reprinted </xsl:text>
      <xsl:value-of select="$direction"/>
      <xsl:text>: </xsl:text>
      <xsl:call-template name="divide-links">
         <xsl:with-param name="val" select="@n"/>
      </xsl:call-template>
      <xsl:text>] </xsl:text>
      <xsl:apply-templates/>
   </xsl:template>



   <!-- Templates used for reprint in ddbdp -->
   <xsl:template name="divide-links">
      <xsl:param name="val"/>
      <xsl:variable name="cur-string">
         <xsl:choose>
            <xsl:when test="contains($val, '|')">
               <xsl:value-of select="substring-before(normalize-space($val), '|')"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$val"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="pass-string" select="substring-after(normalize-space($val), '|')"/>

      <xsl:call-template name="build-path">
         <xsl:with-param name="val" select="$cur-string"/>
         <xsl:with-param name="fol-val">
            <xsl:if test="string($pass-string)">
               <xsl:text>yes</xsl:text>
            </xsl:if>
         </xsl:with-param>
      </xsl:call-template>

      <xsl:if test="string($pass-string)">
         <xsl:call-template name="divide-links">
            <xsl:with-param name="val" select="$pass-string"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>

   <xsl:template name="build-path">
      <xsl:param name="val"/>
      <xsl:param name="fol-val"/>

      <xsl:variable name="cur-file-vol-doc" select="substring-after(normalize-space(/t:TEI/@n), ';')"/>
      <xsl:variable name="cur-file-vol" select="substring-before($cur-file-vol-doc, ';')"/>

      <xsl:variable name="val-col" select="substring-before($val, ';')"/>
      <xsl:variable name="val-vol-doc" select="substring-after($val, ';')"/>
      <xsl:variable name="val-vol" select="substring-before($val-vol-doc, ';')"/>
      <xsl:variable name="val-doc">
         <xsl:value-of select="$val-col"/>
         <xsl:text>.</xsl:text>
         <xsl:if test="string(normalize-space($val-vol))">
            <xsl:value-of select="$val-vol"/>
            <xsl:text>.</xsl:text>
         </xsl:if>
         <xsl:value-of select="substring-after($val-vol-doc, ';')"/>
      </xsl:variable>

      <xsl:variable name="href-link" select="concat('/ddbdp/',$val)"/>

      <!-- Found in [htm|txt]-teiref.xsl -->
      <xsl:call-template name="link-text">
         <xsl:with-param name="href-link" select="$href-link"/>
         <xsl:with-param name="val-doc" select="$val-doc"/>
      </xsl:call-template>

      <xsl:if test="$fol-val = 'yes'">
         <xsl:text> | </xsl:text>
      </xsl:if>
   </xsl:template>
</xsl:stylesheet></xsl:include>
  
  <xsl:template match="t:ref">
      <xsl:choose>
         <xsl:when test="@type = 'reprint-from'">
            <br/>
            <!-- Found in teiref.xsl -->
        <xsl:call-template name="reprint-text">
               <xsl:with-param name="direction" select="'from'"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="@type = 'reprint-in'">
            <br/>
            <!-- Found in teiref.xsl -->
        <xsl:call-template name="reprint-text">
               <xsl:with-param name="direction" select="'in'"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="@type = 'Perseus'">
            <xsl:variable name="col" select="substring-before(@href, ';')"/>
            <xsl:variable name="vol" select="substring-before(substring-after(@href,';'),';')"/>
            <xsl:variable name="no" select="substring-after(substring-after(@href,';'),';')"/>
            <a href="http://www.perseus.tufts.edu/cgi-bin/ptext?doc=Perseus:text:1999.05.{$col}:volume={$vol}:document={$no}">
               <xsl:apply-templates/>
            </a>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>
  

  <xsl:template name="link-text">
      <xsl:param name="href-link"/>
      <xsl:param name="val-doc"/>
    
      <a href="{$href-link}">
         <xsl:value-of select="$val-doc"/>
      </a>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>

   <!-- tei stylesheets that are also used by start-txt -->
   <xsl:include href="teiabbrandexpan.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Contains templates for expan and abbr -->

   <xsl:template match="t:expan">
      <xsl:apply-templates/>
      <!-- Found in tpl-certlow.xsl -->
      <xsl:call-template name="cert-low"/>
   </xsl:template>

   <xsl:template match="t:abbr">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:apply-templates/>
       <xsl:if test="not(ancestor::t:expan) and not($parm-edition-type='diplomatic')">
         <xsl:text>(</xsl:text><xsl:choose>
             <xsl:when test="$parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch'">
               <xsl:text>  </xsl:text>
            </xsl:when>
             <xsl:when test="$parm-leiden-style = 'rib'">
               <xsl:text> . . . </xsl:text>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text>- - -</xsl:text>
            </xsl:otherwise>
         </xsl:choose><xsl:text>)</xsl:text>
           <xsl:if test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
            <!-- Found in tpl-certlow.xsl -->
            <xsl:call-template name="cert-low"/>
         </xsl:if>
      </xsl:if>
   </xsl:template>

   <xsl:template match="t:ex">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-edition-type = 'diplomatic'"/>
           <xsl:when test="$parm-leiden-style = 'edh-names' and parent::t:w"/>
           <xsl:when test="$parm-leiden-style = 'edh-names'">
            <xsl:text>.</xsl:text>
         </xsl:when>
         <xsl:otherwise>
             <!--<xsl:if test="not(($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and ancestor::t:corr[parent::t:choice])">-->
               
<!--            </xsl:if>-->
            <!-- at one point we wanted to suppress abbreviations inside corrected text; we no longer agree with this,
               but are leaving the code here in case it turns out to have been a good idea after all -->
            <xsl:text>(</xsl:text><xsl:apply-templates/>
            <!-- Found in tpl-certlow.xsl -->
            <xsl:call-template name="cert-low"/>
            <xsl:if test="$parm-leiden-style='london' and ancestor::node()[@part='M' or @part='I']                and position()=last()">
               <xsl:text>-</xsl:text>
            </xsl:if><xsl:text>)</xsl:text>
             <!--            <xsl:if test="not(($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and ancestor::t:corr[parent::t:choice])">-->
               
<!--            </xsl:if>-->
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="t:am">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:choose>
          <xsl:when test="$parm-edition-type = 'interpretive'"/>
          <xsl:when test="$parm-edition-type = 'diplomatic'">
            <xsl:apply-templates/>
         </xsl:when>
      </xsl:choose>

   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teicertainty.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

   <xsl:template match="t:certainty">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch','iospe')">
            <xsl:if test="@match='..'">
               <xsl:text>(?)</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:when test="@match='..'">
            <xsl:text>?</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:message>no template in teicertainty.xsl for your use of certainty. Doc: <xsl:value-of select="tokenize(base-uri(),'/')[last()]"/></xsl:message>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teichoice.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

   <xsl:template match="t:choice">
       <xsl:param name="parm-apparatus-style" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="child::t:sic and child::t:corr and $parm-leiden-style=('edh-names','edh-itx')">
            <xsl:text>&lt;</xsl:text>
            <xsl:apply-templates select="t:corr"/>
            <xsl:text>=</xsl:text>
             <xsl:value-of select="translate(t:sic, $all-grc, $grc-upper-strip)"/>
            <xsl:text>&gt;</xsl:text>
         </xsl:when>
          <xsl:when test="child::t:unclear[2] and not(child::t:reg or child::t:sic or child::t:corr or child::t:orig)">
             <xsl:apply-templates select="child::t:unclear[1]"/>
          </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>

      <!-- Found in [htm|txt]-tpl-apparatus -->
      <xsl:if test="$parm-apparatus-style = 'ddbdp' and ((child::t:sic and child::t:corr) or (child::t:orig and child::t:reg))">
         <xsl:call-template name="app-link">
            <xsl:with-param name="location" select="'text'"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teihandshift.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

  <xsl:template match="t:handShift">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
          <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
            <xsl:text>(hand </xsl:text>
            <xsl:value-of select="substring-after(@new, 'm')"/>
            <xsl:if test="@cert='low'">
               <xsl:text>?</xsl:text>
            </xsl:if>
            <xsl:text>) </xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teiheader.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

   <xsl:template match="t:teiHeader"/>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teimilestone.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- General template in [htm|txt]teimilestone.xsl -->

  <xsl:template match="t:milestone[@unit='block']">
     <!-- adds pipe for block, flanked by spaces if not within word -->
      <xsl:if test="not(ancestor::w)">
         <xsl:text> </xsl:text>
      </xsl:if>
      <xsl:text>|</xsl:text>
      <xsl:if test="not(ancestor::w)">
         <xsl:text> </xsl:text>
      </xsl:if>
  </xsl:template>

  <xsl:template match="t:milestone[@rend = 'box']">
     <xsl:param name="parm-internal-app-style" tunnel="yes" required="no"/>
     <xsl:if test="$parm-internal-app-style = 'ddbdp'">
      <!-- Adds links/indication to apparatus - found in [htm|txt]-tpl-apparatus -->
      <xsl:call-template name="app-link">
            <xsl:with-param name="location" select="'text'"/>
         </xsl:call-template>
      </xsl:if>
  </xsl:template>
</xsl:stylesheet></xsl:include>
   <xsl:include href="teiorig.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">  
  
  <xsl:template match="t:orig[not(parent::t:choice)]//text()" priority="1">
      <xsl:value-of select="upper-case(translate(normalize-unicode(translate(.,'ϲ','Ϲ'),'NFD'),'̀́̈̓̔͂ͅ',''))"/>
      <!--<xsl:value-of select="translate(., $all-grc, $grc-upper-strip)"/>-->
  </xsl:template>
  
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="teiorigandreg.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Contains templates for choice/orig and choice/reg and surplus -->

   <xsl:template match="t:choice/t:orig">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-edn-structure = ('rib','sigidoc')"><!-- modified by SigiDoc -->
               <!-- Ignore -->
           </xsl:when>
           <xsl:otherwise>
               <xsl:apply-templates/>
               <xsl:if test="$parm-leiden-style = 'ddbdp'">
                   <!-- found in tpl-certlow.xsl -->
                   <xsl:call-template name="cert-low"/>
                   <!-- if context is inside the app-part of an app-like element, print reg as well -->
                   <xsl:if test="ancestor::t:*[local-name()=('reg','corr','rdg')                         or self::t:del[@rend='corrected']]">
                       <!--<xsl:if test="ancestor::t:*[local-name()=('orig','reg','sic','corr','lem','rdg') 
               or self::t:del[@rend='corrected'] 
               or self::t:add[@place='inline']][1][local-name()=('reg','corr','del','rdg')]">-->
                       <xsl:text> (</xsl:text><xsl:for-each select="../t:reg">
                           <xsl:sort select="position()" order="descending"/>
                           <xsl:call-template name="multreg"/>
                       </xsl:for-each><xsl:text>)</xsl:text>
                   </xsl:if>
               </xsl:if>
               <xsl:if test="$parm-leiden-style='iospe' and ../t:reg and $parm-edition-type='interpretive'">
                   <!-- in iospe style, reg is printed in parenthesis -->
                   <xsl:text> (pro </xsl:text>
                   <xsl:apply-templates select="../t:reg/node()"/>
                   <xsl:text>)</xsl:text>
               </xsl:if>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>

    <xsl:template match="t:choice/t:reg"><!-- added by SigiDoc -->
        <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
        <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
        <xsl:choose>
            <xsl:when test="$parm-leiden-style='sigidoc' and ../t:reg and $parm-edition-type='interpretive'">
                <xsl:text>⸢</xsl:text>
                <xsl:apply-templates select="../t:reg/node()"/>
                <xsl:text>⸣</xsl:text>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    
      <!-- reg is currently not displayed in text in any Leiden-style
          except "iospe" (see under orig, above) 
      and "sigidoc"
      -->
   
</xsl:stylesheet></xsl:include>
   <xsl:include href="teiq.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
    
    <xsl:template match="t:q">
        <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
        <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
        <xsl:choose>
            <xsl:when test="($parm-edn-structure = 'rib')">
                <xsl:text>‘</xsl:text><xsl:apply-templates/><xsl:text>’</xsl:text>
            </xsl:when>
            <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
                <xsl:text>'</xsl:text>
                <xsl:apply-templates/>
                <xsl:text>'</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
</xsl:stylesheet></xsl:include>
   <xsl:include href="teisicandcorr.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Contains templates for choice/sic and choice/corr -->

   <xsl:template match="t:choice/t:sic">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-edition-type='diplomatic' or $parm-leiden-style=('ddbdp','sammelbuch')">
            <xsl:apply-templates/>
            <!-- if context is inside the app-part of an app-like element... -->
            <xsl:if test="ancestor::t:*[local-name()=('reg','corr','rdg')                 or self::t:del[@rend='corrected']]">
               <xsl:text> (i.e. </xsl:text>
               <xsl:apply-templates select="../t:corr/node()"/>
               <xsl:text>)</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise/>
      </xsl:choose>
   </xsl:template>

   <xsl:template match="t:choice/t:corr">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-edition-type='diplomatic' or $parm-leiden-style=('ddbdp','sammelbuch')"/>
         <xsl:otherwise>
            <xsl:choose>
                <xsl:when test="$parm-leiden-style = ('seg','iospe')">
                  <xsl:text>&lt;</xsl:text>
                  <xsl:apply-templates/>
                  <!-- cert-low template found in tpl-certlow.xsl -->
                  <xsl:call-template name="cert-low"/>
                  <xsl:text>&gt;</xsl:text>
               </xsl:when>
                <xsl:when test="starts-with($parm-leiden-style, 'edh')">
                  <xsl:apply-templates/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:text>⸢</xsl:text>
                  <xsl:apply-templates/>
                  <!-- cert-low template found in tpl-certlow.xsl -->
                  <xsl:call-template name="cert-low"/>
                  <xsl:text>⸣</xsl:text>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teispace.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:EDF="http://epidoc.sourceforge.net/ns/functions" exclude-result-prefixes="t EDF" version="2.0">
   <!-- Found in [htm|txt]-teispace.xsl -->

   <xsl:template match="t:space">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <!-- function EDF:f-wwrap declared in htm-teilb.xsl; tests if lb break=no immediately follows space -->
      <xsl:if test="EDF:f-wwrap(.) = true()">
         <xsl:text>- </xsl:text>
      </xsl:if>
      <xsl:choose>
          <xsl:when test="$parm-edition-type = 'diplomatic'">
            <xsl:choose>
               <xsl:when test="@unit='line'">
                  <xsl:text>     </xsl:text>
                  <xsl:call-template name="dip-space"/>
               </xsl:when>
               <xsl:when test="@unit='character' or not(@unit)">
                  <xsl:variable name="sp-ext">
                     <xsl:choose>
                        <xsl:when test="@quantity">
                           <xsl:number value="@quantity"/>
                        </xsl:when>
                        <xsl:when test="number(@extent)">
                           <xsl:number value="@extent"/>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:number value="3"/>
                        </xsl:otherwise>
                     </xsl:choose>
                  </xsl:variable>
                  <xsl:for-each select="1 to $sp-ext">
                     <xsl:text>  </xsl:text>
                  </xsl:for-each>
               </xsl:when>
               <xsl:otherwise/>
            </xsl:choose>
         </xsl:when>

         <xsl:otherwise>
            <xsl:choose>
                <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
                  <xsl:text> vac. </xsl:text>
                  <xsl:choose>
                     <xsl:when test="@quantity">
                        <xsl:if test="@precision='low'">
                           <xsl:text>ca. </xsl:text>
                        </xsl:if>
                        <xsl:value-of select="@quantity"/>
                     </xsl:when>
                     <xsl:when test="@atLeast and @atMost">
                        <xsl:value-of select="@atLeast"/>
                        <xsl:text>-</xsl:text>
                        <xsl:value-of select="@atMost"/>
                     </xsl:when>
                     <xsl:when test="@atLeast ">
                        <xsl:text>≥</xsl:text>
                        <xsl:value-of select="@atLeast"/>
                     </xsl:when>
                     <xsl:when test="@atMost ">
                        <xsl:text>≤</xsl:text>
                        <xsl:value-of select="@atMost"/>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:text>?</xsl:text>
                     </xsl:otherwise>
                  </xsl:choose>
                  <xsl:if test="@unit='line'">
                        <xsl:text> line</xsl:text>
                        <xsl:if test="@quantity &gt; 1 or @extent='unknown' or @atLeast or @atMost">
                           <xsl:text>s</xsl:text>
                        </xsl:if>
                     </xsl:if>
                  
                  <xsl:if test="child::t:certainty[@match='..']">
                     <xsl:text>(?)</xsl:text>
                  </xsl:if>
               </xsl:when>
               
                <xsl:when test="$parm-leiden-style='london'">
                  <xsl:choose>
                     <xsl:when test="@extent = 'unknown'">
                        <!-- Found in [htm|txt]-teispace.xsl -->
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vac '"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@quantity = string(1) and @unit='character'">
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' v '"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@quantity = string(2) and @unit='character'">
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vv '"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="contains('345', @quantity) and @unit='character'">
                        <!-- Found in [htm|txt]-teispace.xsl -->
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vac '"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@quantity &gt;= 6 and @unit='character'">
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vacat '"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@unit='line'">
                        <xsl:text>     </xsl:text>
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vacat '"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vac '"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>

                <xsl:when test="$parm-leiden-style='iospe'">
                  <xsl:variable name="vacat" select="' vac. '"/>
                  <xsl:choose>
                     <xsl:when test="@quantity and @unit='character'">
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="$vacat"/>
                           <xsl:with-param name="extent" select="concat(@quantity,' litt. ')"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@unit='character'">
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="$vacat"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="$vacat"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>

                <xsl:when test="$parm-leiden-style='panciera'">
                  <xsl:variable name="precision">
                     <xsl:if test="@precision = 'low'">?</xsl:if>
                  </xsl:variable>

                  <xsl:choose>
                     <xsl:when test="@extent = 'unknown'">
                        <!-- Found in [htm|txt]-teispace.xsl -->
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vac. '"/>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@quantity and @unit='character'">
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat"><xsl:text> vac. </xsl:text></xsl:with-param>
                           <xsl:with-param name="extent">
                              <xsl:value-of select="@quantity"/>
                              <xsl:value-of select="$precision"/>
                           </xsl:with-param>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@quantity and @unit='line'">
                        <xsl:call-template name="space-content">
                        <!-- Found in [htm|txt]-teispace.xsl -->
                           <xsl:with-param name="vacat"><xsl:text> vac. </xsl:text></xsl:with-param>
                           <xsl:with-param name="extent">
                              <xsl:value-of select="@quantity"/>
                              <xsl:text> line</xsl:text>
                              <xsl:if test="@quantity &gt; 1">
                                 <xsl:text>s</xsl:text>
                              </xsl:if>
                              <xsl:value-of select="$precision"/>
                           </xsl:with-param>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:when test="@quantity and @unit != 'line' and @unit != 'character'">
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat"><xsl:text> vac. </xsl:text></xsl:with-param>
                           <xsl:with-param name="extent">
                              <xsl:value-of select="@quantity"/>
                              <xsl:text> </xsl:text>
                              <xsl:value-of select="@unit"/>
                              <xsl:value-of select="$precision"/>
                           </xsl:with-param>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:call-template name="space-content">
                           <xsl:with-param name="vacat" select="' vac. '"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>

               <xsl:otherwise>
                  <xsl:call-template name="space-content">
                     <xsl:with-param name="vacat" select="' vac. '"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <!-- Called from [htm|txt]-teispace.xsl -->
   <xsl:template name="space-content-1">
      <xsl:param name="vacat"/>
      <xsl:if test="child::t:certainty[starts-with(@match,'..')]">
         <xsl:text>(?)</xsl:text>
      </xsl:if>
      <xsl:value-of select="$vacat"/>
   </xsl:template>


   <!-- Called from [htm|txt]-teispace.xsl -->
   <xsl:template name="space-content-2">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:param name="vacat"/>
      <xsl:param name="extent"/>
       <xsl:if test="$parm-leiden-style='panciera'"><xsl:text>(</xsl:text></xsl:if>
      <xsl:value-of select="$vacat"/>
      <xsl:if test="child::t:certainty[starts-with(@match,'..')]">
         <xsl:text>(?)</xsl:text>
      </xsl:if>
      <xsl:if test="string-length($extent) &gt; 0">
         <xsl:text> </xsl:text>
         <xsl:value-of select="$extent"/>
      </xsl:if>
       <xsl:if test="$parm-leiden-style='panciera'"><xsl:text>)</xsl:text></xsl:if>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teisupplied.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:EDF="http://epidoc.sourceforge.net/ns/functions" exclude-result-prefixes="t EDF" version="2.0">

  <xsl:template match="t:supplied[@reason='lost']">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:param name="location"/>
      <xsl:if test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch') and child::t:*[1][local-name() = 'milestone'][@rend = 'paragraphos']">
         <br/>
      </xsl:if>
      <xsl:choose>
         <xsl:when test="@evidence">
            <xsl:if test="$parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch'">
               <xsl:text>[</xsl:text>
            </xsl:if>
            <xsl:choose>
               <xsl:when test="@evidence = 'parallel'">
                  <!-- Found in [htm|txt]-teisupplied.xsl -->
                  <xsl:call-template name="supplied-parallel"/>
               </xsl:when>
               <xsl:when test="@evidence = 'previouseditor'">
                  <!-- Found in [htm|txt]-teisupplied.xsl -->
                  <xsl:call-template name="supplied-previouseditor"/>
               </xsl:when>
               <xsl:when test="@evidence = 'similar'"><!-- added by SigiDoc -->
                  <!-- Found in [htm|txt]-teisupplied.xsl -->
                  <xsl:call-template name="supplied-similar"/>
               </xsl:when>
            </xsl:choose>
            <xsl:if test="$parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch'">
               <xsl:text>]</xsl:text>
            </xsl:if>
         </xsl:when>
         
         <xsl:otherwise>
        <!--
           *NB* the lost-opener and lost-closer templates, found in tpl-reasonlost.xsl,
           are no longer used in the EpiDoc Example Stylesheets since November 2011.
           They used to serve to limit the superfluous square brackets between adjacent gap
           and supplied elements, but this function is now performed by regex in
           [htm|txt]-tpl-sqbrackets.xsl which is called after all other templates are completed.
        -->
            <xsl:text>[</xsl:text>
            <xsl:choose>
                <xsl:when test="$parm-edition-type = 'diplomatic'">
                  <xsl:variable name="orig-supplied-content">
                     <xsl:value-of select="descendant::text()[not(ancestor::t:reg or ancestor::t:ex                          or ancestor::t:corr or ancestor::t:rdg)]"/>
                  </xsl:variable>
                  <xsl:variable name="sup-context-length">
                     <!-- take all text content that is not restored or expanded -->
                     <xsl:value-of select="translate(normalize-space($orig-supplied-content),' ','')"/>
                     <!-- also add characters for vacats -->
                     <xsl:for-each select="descendant::t:space">
                        <xsl:choose>
                           <xsl:when test="@quantity">
                              <xsl:for-each select="1 to @quantity">
                                 <xsl:text>.</xsl:text>
                              </xsl:for-each>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:text>...</xsl:text>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:for-each>
                     <!-- also add characters for symbols and abbreviations -->
                     <xsl:for-each select="t:g|t:expan[not(child::abbr)]">
                        <xsl:text>.</xsl:text>
                     </xsl:for-each>
                   </xsl:variable>
                  <!-- Found in teigap.xsl -->
                  <xsl:call-template name="dot-out">
                     <xsl:with-param name="cur-num" select="string-length($sup-context-length)"/>
                  </xsl:call-template>
                  <!--<xsl:call-template name="dot-out">
                     <xsl:with-param name="cur-num" select="$space-ex"/>
                  </xsl:call-template>-->
               </xsl:when>
               <xsl:otherwise>
                  <xsl:apply-templates/>
               </xsl:otherwise>
            </xsl:choose>
            <!-- Found in tpl-cert-low.xsl -->
            <xsl:call-template name="cert-low"/>
            <!-- function EDF:f-wwrap declared in htm-teilb.xsl; tests if lb break=no immediately follows supplied -->
            <xsl:if test="EDF:f-wwrap(.) = true()">
               <!-- unless this is in the app part of a choice/subst/app in ddbdp
                      or an EDH leiden style, which doesn't use hyphens-->
                <xsl:if test="(not($parm-leiden-style='ddbdp' and (ancestor::t:*[local-name()=('reg','corr','rdg')                     or self::t:del[parent::t:subst]]))) and (not($location = 'apparatus'))                    and not(starts-with($parm-leiden-style, 'edh') or $parm-leiden-style='eagletxt')">
                  <xsl:text>-</xsl:text>
               </xsl:if>
            </xsl:if>
            <!--
               *NB* the lost-opener and lost-closer templates, found in tpl-reasonlost.xsl,
               are no longer used in the EpiDoc Example Stylesheets since November 2011.
               They used to serve to limit the superfluous square brackets between adjacent gap
               and supplied elements, but this function is now performed by regex in
               [htm|txt]-tpl-sqbrackets.xsl which is called after all other templates are completed.
           -->
            <xsl:text>]</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>
  

  <xsl:template match="t:supplied[@reason='omitted']">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:choose>
          <xsl:when test="$parm-edition-type='diplomatic'"/>
         <xsl:when test="@evidence = 'parallel'">
        <!-- Found in [htm|txt]-teisupplied.xsl -->
        <xsl:call-template name="supplied-parallel"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>&lt;</xsl:text>
            <xsl:apply-templates/>
            <!-- Found in tpl-cert-low.xsl -->
        <xsl:call-template name="cert-low"/>
            <xsl:text>&gt;</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>
  

  <xsl:template match="t:supplied[@reason='subaudible']">
     <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
     <xsl:choose>
        <xsl:when test="starts-with($parm-leiden-style, 'edh') or $parm-leiden-style='eagletxt'"/>
        <xsl:otherwise>   
           <xsl:text>(scil. </xsl:text>
           <xsl:apply-templates/>
           <xsl:call-template name="cert-low"/>
           <xsl:text>)</xsl:text>
        </xsl:otherwise> </xsl:choose>
  </xsl:template>
  

  <xsl:template match="t:supplied[@reason='explanation']">
      <xsl:text>(i.e. </xsl:text>
      <xsl:apply-templates/>
      <xsl:call-template name="cert-low"/>
      <xsl:text>)</xsl:text>
  </xsl:template>


<xsl:template match="t:supplied[@reason='undefined' and @evidence]">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="@evidence = 'parallel'">
            <!-- Found in [htm|txt]-teisupplied.xsl -->
            <xsl:call-template name="supplied-parallel"/>
         </xsl:when>
         <xsl:when test="@evidence = 'previouseditor'">
            <!-- Found in [htm|txt]-teisupplied.xsl -->
            <xsl:call-template name="supplied-previouseditor"/>
         </xsl:when>
         <xsl:when test="@evidence = 'similar'"><!-- added by SigiDoc -->
            <!-- Found in [htm|txt]-teisupplied.xsl -->
            <xsl:call-template name="supplied-similar"/>
         </xsl:when>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teisurplus.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains template for surplus -->
   
    <xsl:template match="t:surplus">
        <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
        <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
        <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:choose>
           <xsl:when test="$parm-edition-type = 'diplomatic'">
               <xsl:apply-templates/>
           </xsl:when>
           <xsl:when test="$parm-leiden-style = 'rib'">
               <xsl:text>&lt; </xsl:text><xsl:apply-templates/><xsl:text> &gt;</xsl:text>
           </xsl:when>
           <xsl:otherwise>
               <xsl:text>{</xsl:text>
               <xsl:apply-templates/>
               <!-- cert-low template found in tpl-certlow.xsl -->
               <xsl:call-template name="cert-low"/>
               <xsl:text>}</xsl:text>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="teiunclear.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

   <xsl:template match="t:unclear">
       <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <xsl:param name="text-content">
         <xsl:choose>
            <xsl:when test="ancestor::t:orig[not(ancestor::t:choice)]">
               <xsl:value-of select="upper-case(translate(normalize-unicode(translate(.,'ϲ','Ϲ'),'NFD'),                   '̀́̈̓̔͂ͅ',''))"/>
            </xsl:when>
            <xsl:when test="ancestor::t:hi[@rend='apex']">
               <xsl:value-of select="translate(., 'aeiou', 'áéíóú')"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="."/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:param>

      <xsl:choose>
          <xsl:when test="$parm-leiden-style=('edh-names','edh-itx')">
            <xsl:apply-templates/>
         </xsl:when>
          <xsl:when test="$parm-edition-type = 'diplomatic'">
            <!-- Calculates the number of middots to output -->
            <xsl:variable name="un-len-all">
               <!-- collects all children text together -->
               <xsl:variable name="un-len-text">
                  <xsl:for-each select="text()">
                     <xsl:value-of select="."/>
                  </xsl:for-each>
               </xsl:variable>
               <!-- Outputs one character per child <g> -->
               <xsl:variable name="un-len-g">
                  <xsl:for-each select="t:g">
                     <xsl:text>a</xsl:text>
                  </xsl:for-each>
               </xsl:variable>
               <xsl:value-of select="string-length($un-len-text) + string-length($un-len-g)"/>
            </xsl:variable>
            
            <xsl:for-each select="1 to $un-len-all">
               <xsl:choose>
                   <xsl:when test="$parm-leiden-style='london'">
                     <xsl:text>·</xsl:text>
                  </xsl:when>
                   <xsl:when test="$parm-leiden-style=('ddbdp','sammelbuch')">
                     <xsl:text>  ̣</xsl:text>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:text>.</xsl:text>
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:for-each>

            <!--<xsl:call-template name="middot">
               <xsl:with-param name="unc-len" select="$un-len-all"/>
            </xsl:call-template>-->
         </xsl:when>
         <xsl:otherwise>
            <xsl:choose>
               <xsl:when test="t:g">
                  <xsl:apply-templates/>
                  <!-- templates (including tests for parent::unclear) are in teig.xsl -->
               </xsl:when>
               <xsl:otherwise>
                  <xsl:variable name="text" select="normalize-space(normalize-unicode($text-content))"/>
                  <xsl:for-each select="1 to string-length()">
                     <xsl:value-of select="concat(substring($text,.,1),'̣')"/>
                  </xsl:for-each>
                  <!--<xsl:call-template name="subpunct">
                     <xsl:with-param name="unc-len" select="string-length($text-content)"/>
                     <xsl:with-param name="abs-len" select="string-length($text-content)+1"/>
                     <xsl:with-param name="text-content" select="$text-content"/>
                  </xsl:call-template>-->
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>


   <!--<xsl:template name="middot">
      <xsl:param name="unc-len"/>
      <xsl:if test="not($unc-len = 0)">
         <xsl:text>·</xsl:text>
         <xsl:call-template name="middot">
            <xsl:with-param name="unc-len" select="$unc-len - 1"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>-->

   <!--<xsl:template name="subpunct">
      <xsl:param name="abs-len"/>
      <xsl:param name="unc-len"/>
      <xsl:param name="text-content"/>
      <xsl:if test="$unc-len!=0">
         <xsl:value-of select="substring($text-content, number($abs-len - $unc-len),1)"/>
         <xsl:text>&#x0323;</xsl:text>
         <xsl:call-template name="subpunct">
            <xsl:with-param name="unc-len" select="$unc-len - 1"/>
            <xsl:with-param name="abs-len" select="string-length($text-content)+1"/>
            <xsl:with-param name="text-content" select="$text-content"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>-->

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

   <!-- html related stylesheets for named templates -->
   <xsl:include href="htm-tpl-cssandscripts.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Called from start-edition.xsl -->

   <xsl:template name="css-script">
      <xsl:param name="parm-css-loc" tunnel="yes" required="no"/>
       
      <link rel="stylesheet" type="text/css" media="screen, projection">
         <xsl:attribute name="href">
            <xsl:value-of select="$parm-css-loc"/>
         </xsl:attribute>
      </link>
   </xsl:template>
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-tpl-apparatus.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Apparatus creation: look in tpl-apparatus.xsl for documentation -->
  <xsl:include href="tpl-apparatus.xsl"><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

   <!-- Generates the DDBDP-style apparatus from the edition -->
   <!-- 
    Adding to Apparatus:
    1. Add to apparatus: [htm | txt]-tpl-apparatus.xsl add case to the ifs and for-each (3 places) 
       - NOTE the app-link 'if' is checking for nested cases, therefore looking for ancestors.
    2. Indicator in text: [htm | txt]-element.xsl to add call-template to [htm | txt]-tpl-apparatus.xsl for links and/or stars.
    3. Add to ddbdp-app template below using local-name() to define context
  -->


   <!-- Defines the output of individual elements in apparatus -->
   <xsl:template name="ddbdp-app">
      <xsl:param name="apptype"/>
      <xsl:variable name="childtype">
         <xsl:choose>
            <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:choice[child::t:orig and child::t:reg]">
               <xsl:text>origreg</xsl:text>
            </xsl:when>
            <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:choice[child::t:sic and child::t:corr]">
               <xsl:text>siccorr</xsl:text>
            </xsl:when>
            <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:subst">
               <xsl:text>subst</xsl:text>
            </xsl:when>
            <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:app[@type='alternative']">
               <xsl:text>appalt</xsl:text>
            </xsl:when>
            <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:app[@type='editorial'][starts-with(@resp,'BL ')]">
               <xsl:text>appbl</xsl:text>
            </xsl:when>
            <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:app[@type='editorial'][starts-with(@resp,'PN ')]">
               <xsl:text>apppn</xsl:text>
            </xsl:when>
            <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:app[@type='editorial']">
               <xsl:text>apped</xsl:text>
            </xsl:when>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="div-loc">
         <xsl:for-each select="ancestor::t:div[@type='textpart'][@n]">
            <xsl:value-of select="@n"/>
            <xsl:text>.</xsl:text>
         </xsl:for-each>
      </xsl:variable>
      <xsl:choose>
         <xsl:when test="not(ancestor::t:choice or ancestor::t:subst or ancestor::t:app or             ancestor::t:hi[@rend=('diaeresis','grave','acute','asper','lenis','circumflex')])">
            <!-- either <br/> in htm-tpl-apparatus or \r\n in txt-tpl-apparatus -->
            <xsl:call-template name="lbrk-app"/>
            <!-- in htm-tpl-apparatus.xsl or txt-tpl-apparatus.xsl -->
            <xsl:call-template name="app-link">
               <xsl:with-param name="location" select="'apparatus'"/>
            </xsl:call-template>
            <xsl:value-of select="$div-loc"/>
            <xsl:value-of select="preceding::t:*[local-name() = 'lb'][1]/@n"/>
            <xsl:if test="descendant::t:lb">
               <xsl:variable name="cnum">
                  <xsl:value-of select="preceding::t:*[local-name() = 'lb'][1]/@n"/>
               </xsl:variable>
               <xsl:if test="descendant::t:lb[position() = last()]/@n != $cnum">
                  <xsl:text>-</xsl:text>
                  <xsl:value-of select="descendant::t:lb[position() = last()]/@n"/>
               </xsl:if>
            </xsl:if>
            <xsl:text>. </xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text> : </xsl:text>
         </xsl:otherwise>
      </xsl:choose>
      <span>
         <xsl:choose>
            <xsl:when test="local-name()=('choice','subst','app')">
               <!-- if there are more app elements inside the text part of the element, deal with them here -->
               <xsl:variable name="part1">
                  <xsl:if test="child::t:*[local-name()=('orig','sic','add','lem')]/t:*[local-name()=('choice','subst','app')]">
                     <!-- <xsl:call-template name="txPtchild"> -->
                     <xsl:call-template name="appcontent">
                        <!-- template txPtchild below -->
                        <xsl:with-param name="apptype" select="$apptype"/>
                        <xsl:with-param name="childtype" select="$childtype"/>
                     </xsl:call-template>
                  </xsl:if>
               </xsl:variable>
               <xsl:variable name="part2">
                  <xsl:if test="child::t:*[local-name()=('orig','sic','add','lem')]/t:*[local-name()=('choice','subst','app')]">
                     <xsl:call-template name="nonTxPtchild">
                        <!-- template nonTxPtchild below -->
                        <xsl:with-param name="apptype" select="$apptype"/>
                        <xsl:with-param name="childtype" select="$childtype"/>
                     </xsl:call-template>
                  </xsl:if>
               </xsl:variable>
               <!-- generate the main content of the app here -->
               <xsl:variable name="part3">
                  <xsl:call-template name="appcontent">
                     <xsl:with-param name="apptype" select="$apptype"/>
                  </xsl:call-template>
               </xsl:variable>
               <xsl:variable name="part4">
                  <xsl:call-template name="nonTxPtchild">
                     <xsl:with-param name="apptype" select="$apptype"/>
                  </xsl:call-template>
               </xsl:variable>
               <xsl:variable name="titleagg">
                  
                  <xsl:choose>                       
                     <xsl:when test="$apptype=('appbl','apppn','apped')">
                        
                           <xsl:choose>   
                              <xsl:when test="($childtype = '' and normalize-space($part4) = '') or ($childtype != '' and normalize-space($part2) = '')"><xsl:call-template name="fnord-seperator">
                                    <xsl:with-param name="part"><xsl:value-of select="$part3"/></xsl:with-param>
                                    <xsl:with-param name="pos">first</xsl:with-param>
                                 </xsl:call-template></xsl:when>
                              <xsl:when test="contains($part3, ' : ') and lem/@resp"><xsl:value-of select="substring-before($part3, ' :')"/></xsl:when>
                              <xsl:otherwise>Current edition</xsl:otherwise>
                           </xsl:choose>
                           
                          <!-- <xsl:if test="starts-with(normalize-space($part3), 'cf.')"> which</xsl:if> --> 
                        
                        <xsl:choose>
                           <xsl:when test="$childtype='subst'"> reports </xsl:when>
                           <xsl:otherwise> gives </xsl:otherwise>
                        </xsl:choose> 
                        
                        
                        <xsl:choose>
                           <xsl:when test="$childtype = 'subst'"><xsl:value-of select="normalize-space($part1)"/>, then changed to <xsl:value-of select="normalize-space($part2)"/></xsl:when>
                           <xsl:when test="$childtype != ''"><xsl:value-of select="normalize-space($part2)"/><xsl:text>, </xsl:text><xsl:value-of select="normalize-space($part1)"/></xsl:when>
                           <xsl:otherwise><xsl:value-of select="normalize-space($part4)"/></xsl:otherwise>
                        </xsl:choose><xsl:call-template name="fnord-seperator">
                           <xsl:with-param name="part"><xsl:value-of select="$part3"/></xsl:with-param>
                           <xsl:with-param name="pos">second</xsl:with-param>
                        </xsl:call-template> 
                        
                        
                     </xsl:when>
                     <xsl:when test="$apptype = 'subst'">
                        
                        
                        <xsl:choose>
                           <xsl:when test="count(tokenize($part3, 'corr. ex')) &gt; 2">
                              
                              <xsl:variable name="bracketed" select="normalize-space(substring-before(substring-after($part3, '('), ')'))"/>
                              
                              Scribe wrote <xsl:value-of select="substring-after($bracketed, 'corr. ex ')"/> <xsl:value-of select="normalize-space(replace(substring-before($part3, '('), 'corr. ex', ', then changed to'))"/>
                           
                           </xsl:when>
                           <xsl:otherwise><xsl:value-of select="normalize-space($part3)"/></xsl:otherwise>
                        </xsl:choose>                                               
                        <xsl:choose>
                           <xsl:when test="$childtype != ''"><xsl:value-of select="normalize-space($part2)"/><xsl:if test="(not(ends-with(normalize-space($part2), ',')))">,</xsl:if><xsl:text> </xsl:text><xsl:value-of select="normalize-space($part1)"/></xsl:when>
                           <xsl:otherwise><xsl:if test="(not(ends-with(normalize-space($part3), ',')))">,</xsl:if> then changed to <xsl:value-of select="normalize-space($part4)"/></xsl:otherwise>
                        </xsl:choose>
                        
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:choose>
                           <xsl:when test="contains($part3, 'FNORD-SPLIT') and contains($part1, 'FNORD-SPLIT') and $childtype != ''">
                              <xsl:call-template name="childpart">
                                 <xsl:with-param name="childtype"><xsl:value-of select="$childtype"/></xsl:with-param>
                                 <xsl:with-param name="apptype"><xsl:value-of select="$apptype"/></xsl:with-param>
                                 <xsl:with-param name="part1"><xsl:value-of select="$part1"/></xsl:with-param>
                                 <xsl:with-param name="part2"><xsl:value-of select="$part2"/></xsl:with-param>
                              </xsl:call-template><xsl:call-template name="fnord-seperator">
                                 <xsl:with-param name="part"><xsl:value-of select="$part3"/></xsl:with-param>
                                 <xsl:with-param name="pos">second</xsl:with-param>
                              </xsl:call-template> 
                           
                           </xsl:when>
                           <xsl:when test="contains($part3, 'FNORD-SPLIT')"> 
                              <xsl:choose>
                                 <xsl:when test="$childtype != ''"><xsl:value-of select="normalize-space($part2)"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space($part1)"/><xsl:if test="not(ends-with(normalize-space($part1), ',')) and not($apptype = 'appalt' and $childtype = '')">,</xsl:if></xsl:when>
                                 <xsl:otherwise><xsl:if test="$apptype = 'appalt' and $childtype = ''">Scribe wrote</xsl:if> <xsl:value-of select="normalize-space($part4)"/><xsl:if test="not(ends-with(normalize-space($part4), ',')) and not($apptype = 'appalt' and $childtype = '')">,</xsl:if></xsl:otherwise>
                              </xsl:choose><xsl:text> </xsl:text>
                              
                              
                              <xsl:variable name="pt3">
                                 <xsl:call-template name="fnord-seperator">
                                    <xsl:with-param name="part"><xsl:value-of select="$part3"/></xsl:with-param>
                                    <xsl:with-param name="pos">first</xsl:with-param>
                                 </xsl:call-template>
                              </xsl:variable>
                              
                              <xsl:choose>
                                 <xsl:when test="$apptype = 'appalt'">
                                    <xsl:choose>
                                       <xsl:when test="contains($part3, 'l.')"><xsl:text>, </xsl:text><xsl:value-of select="normalize-space(substring-after(substring-before($part3, ')(*)'), ' ('))"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(substring-before($part3, ' ('))"/></xsl:when>
                                       <xsl:otherwise><xsl:value-of select="normalize-space($part3)"/></xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:when>
                                 <xsl:otherwise><xsl:if test="$apptype='origreg'">for which </xsl:if><xsl:value-of select="$pt3"/></xsl:otherwise>
                              </xsl:choose>
                              
                              
                           </xsl:when>
                           <xsl:when test="contains($part1, 'FNORD-SPLIT')"> 
                              <xsl:call-template name="childpart">
                                 <xsl:with-param name="childtype"><xsl:value-of select="$childtype"/></xsl:with-param>
                                 <xsl:with-param name="apptype"><xsl:value-of select="$apptype"/></xsl:with-param>
                                 <xsl:with-param name="part1"><xsl:value-of select="$part1"/></xsl:with-param>
                                 <xsl:with-param name="part2"><xsl:value-of select="$part2"/></xsl:with-param>
                              </xsl:call-template>
                                                     
                              <xsl:choose>
                                 <xsl:when test="contains($part3, 'l.') and $apptype = 'appalt'"><xsl:text>, </xsl:text><xsl:value-of select="normalize-space(substring-after(substring-before($part3, ')(*)'), ' ('))"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(substring-before($part3, ' ('))"/></xsl:when>
                                 <xsl:otherwise><xsl:value-of select="normalize-space($part3)"/></xsl:otherwise>
                              </xsl:choose>
                              
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:if test="($apptype = ('appalt') and $childtype = '') or $childtype = ('appalt')">Scribe wrote </xsl:if>
                              <xsl:choose>
                                 <xsl:when test="$childtype='subst'"><xsl:value-of select="normalize-space($part1)"/>, then changed to <xsl:value-of select="normalize-space($part2)"/><xsl:if test="(not(ends-with(normalize-space($part2), ',')))">,</xsl:if></xsl:when>
                                 <xsl:when test="$childtype != ''"><xsl:value-of select="normalize-space($part2)"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space($part1)"/><xsl:if test="(not(ends-with(normalize-space($part1), ',')) and $apptype != 'appalt')">,</xsl:if></xsl:when>
                                 <xsl:otherwise><xsl:value-of select="normalize-space($part4)"/><xsl:if test="(not(ends-with(normalize-space($part4), ',')) and $apptype != 'appalt')">,</xsl:if></xsl:otherwise>
                              </xsl:choose><xsl:text> </xsl:text>
                              
                              <xsl:choose>
                                 <xsl:when test="contains($part3, 'l.') and ($apptype = 'appalt' and $childtype != '')"><xsl:text>, </xsl:text><xsl:value-of select="normalize-space(substring-before($part3, ' ('))"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(substring-after(substring-before($part3, ')(*)'), ' ('))"/></xsl:when>
                                 <xsl:otherwise><xsl:value-of select="normalize-space($part3)"/></xsl:otherwise>
                              </xsl:choose>
                           
                           </xsl:otherwise>
                        </xsl:choose>                      
                     </xsl:otherwise>
                  </xsl:choose>
                <!--  </xsl:if>  -->
               </xsl:variable>
               <xsl:variable name="title">
                  <xsl:call-template name="title-convert">
                     <xsl:with-param name="apptype" select="$apptype"/>
                     <xsl:with-param name="childtype" select="$childtype"/>
                     <xsl:with-param name="obf" select="normalize-space($titleagg)"/>
                  </xsl:call-template>
               </xsl:variable>
              <xsl:attribute name="title"><xsl:apply-templates select="$title" mode="sqbrackets"/></xsl:attribute>
               <!-- <xsl:if test="$apptype = ('appbl')"> and $childtype != ''">  'siccorr', 'subst', 'origreg', 'appalt' and $childtype='subst'"> -->
               <xsl:value-of select="normalize-space(replace(replace($part1, 'FNORD(\S)*', ''), '\(\*\)', ''))"/>               
               <xsl:if test="normalize-space($part1) != '' and (not(ends-with(normalize-space($part1), ','))) and (not(ends-with(normalize-space($part1), '.')))">,</xsl:if> <!--  --><xsl:text> </xsl:text><xsl:value-of select="normalize-space(replace(replace($part3, 'FNORD(\S)*', ''), '\(\*\)', ''))"/>
               <!-- if there are more app elements inside the app part of the element,
      these are handled in the individual templates for the elements in question -->
                <!--[[<xsl:value-of select="$title"/>]]  <xsl:value-of select="$titleagg" />  </xsl:if>-->
            </xsl:when>
            <!-- hi -->
            <xsl:when test="local-name() = 'hi'">
               <xsl:call-template name="hirend"/>
            </xsl:when>

            <!-- del -->
            <xsl:when test="local-name() = 'del'">
               <xsl:choose>
                  <xsl:when test="@rend = 'slashes'">
                     <xsl:text>Text canceled with slashes</xsl:text>
                  </xsl:when>
                  <xsl:when test="@rend = 'cross-strokes'">
                     <xsl:text>Text canceled with cross-strokes</xsl:text>
                  </xsl:when>
               </xsl:choose>
            </xsl:when>

            <xsl:when test="local-name() = 'milestone'">
               <xsl:if test="@rend = 'box'">
                  <xsl:text>Text in box.</xsl:text>
               </xsl:if>
            </xsl:when>
         </xsl:choose>
      </span>
   </xsl:template>

   <xsl:template name="nonTxPtchild">
      <!-- prints the other bit of apparatus content for apps nested in the part of an app not normally printed in edition -->
      <xsl:param name="apptype"/>
      <xsl:param name="childtype"/>
  
      <xsl:choose>
         <!-- *APPED* -->
         <xsl:when test="$apptype=('appbl','apppn','apped')">
             <xsl:apply-templates select="child::t:*[local-name()=('orig','sic','add','lem')]">
                <xsl:with-param name="location" select="'apparatus'"/>
             </xsl:apply-templates> 
         </xsl:when>         
         <!-- *ORIG*  (repeatable) -->
         <xsl:when test="$childtype='origreg' or ($apptype='origreg' and $childtype='')">
            <xsl:text>for which read </xsl:text>
            <xsl:if test="$childtype != ''">
               <xsl:for-each select="child::t:*[local-name()=('orig','sic','add','lem')]/t:choice/t:orig"> 
                  <xsl:sort select="position()" order="descending"/>
                  <!-- <xsl:value-of select="."/> -->
                  <xsl:apply-templates>
                     <xsl:with-param name="location" select="'apparatus'"/>
                  </xsl:apply-templates>
               </xsl:for-each>
            </xsl:if>
            <xsl:if test="$childtype = ''">
              <xsl:for-each select="t:orig"> 
                  <xsl:sort select="position()" order="descending"/>
                  <!-- <xsl:value-of select="."/> -->
                  <xsl:apply-templates>
                     <xsl:with-param name="location" select="'apparatus'"/>
                  </xsl:apply-templates>
              </xsl:for-each>
            </xsl:if>
         </xsl:when>
         <!-- *SIC* -->
         <xsl:when test="$childtype=('siccorr') or $apptype=('siccorr')">
            <xsl:text>((for which read)) </xsl:text>
            <xsl:choose>
               <xsl:when test="child::t:*[local-name()=('orig','sic','add','lem')]/t:choice/t:sic/node()">
                  <xsl:apply-templates select="child::t:*[local-name()=('orig','sic','add','lem')]/t:choice/t:sic/node()">
                     <xsl:with-param name="location" select="'apparatus'"/>
                  </xsl:apply-templates>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:apply-templates select="child::t:*[local-name()=('orig','sic','add','lem')]">
                     <xsl:with-param name="location" select="'apparatus'"/>
                  </xsl:apply-templates>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <!-- *SUBST* -->
         <xsl:when test="$childtype=('subst') or $apptype=('subst')">
            <xsl:apply-templates select="child::t:*[local-name()=('orig','sic','add','lem')]">
               <xsl:with-param name="location" select="'apparatus'"/>
            </xsl:apply-templates>
         </xsl:when>
         <!-- *APPALT* -->
         <xsl:when test="$childtype=('appalt') or $apptype=('appalt')">
            <xsl:apply-templates select="child::t:*[local-name()=('orig','sic','add','lem')]">
               <xsl:with-param name="location" select="'apparatus'"/>
            </xsl:apply-templates>
         </xsl:when>
         <!-- *APPED* -->
         <xsl:when test="$childtype=('appbl','apppn','apped')">
            <xsl:apply-templates select="child::t:*[local-name()=('orig','sic','add','lem')]">
               <xsl:with-param name="location" select="'apparatus'"/>
            </xsl:apply-templates>
         </xsl:when>    
      </xsl:choose>
       <xsl:text> </xsl:text> 
   </xsl:template>

   <xsl:template name="resolvesubst">
      <!-- Deals with old/new encoding of subst -->
      <!-- Used by: txPtchild, appcontent, teiaddanddel.xsl#t:add -->
      <xsl:param name="addpath" select="''"/>
      <xsl:param name="delpath"/><xsl:choose>
         <!-- Old encoding: (still supported) -->
         <xsl:when test="(             not(preceding-sibling::node())             or matches(preceding-sibling::node()[1][self::text()], '[\s\n\r\t]')             or preceding-sibling::node()[1][self::t:lb]             )                and             (             not(following-sibling::node())             or matches(following-sibling::node()[1][self::text()], '[\s\n\r\t]')             )             and(child::t:*[local-name()=('orig','sic','add','lem')])             "><xsl:text>corr. ex </xsl:text>
            <xsl:apply-templates select="$delpath"/>
         </xsl:when>    
         <!-- New encoding (introduced in Nov/Dec 2011) -->
         <!-- get full word -->
         <xsl:otherwise>
            <xsl:variable name="fullword">
               <xsl:call-template name="recurse_back">
                  <xsl:with-param name="step" select="preceding-sibling::node()[1]"/>
               </xsl:call-template>
               <xsl:apply-templates select="t:add/node()"/>
               <xsl:call-template name="recurse_forward">
                  <xsl:with-param name="step" select="following-sibling::node()[1]"/>
               </xsl:call-template>
            </xsl:variable>
            <xsl:value-of select="$fullword"/>
           <!-- <xsl:text> </xsl:text> -->
            <!-- Check that $addpath has been passed (might be excluded, see template matching t:add in teiaddanddel.xsl-->
            <xsl:choose>
               <xsl:when test="$addpath=''"/>
               <xsl:otherwise><xsl:call-template name="trans-string">
                     <xsl:with-param name="trans-text">
                        <xsl:apply-templates select="$addpath"/>
                     </xsl:with-param>
                  </xsl:call-template><xsl:text> </xsl:text>
               </xsl:otherwise>
            </xsl:choose><xsl:text>corr. ex </xsl:text>
            <xsl:call-template name="trans-string">
               <xsl:with-param name="trans-text">
                  <xsl:apply-templates select="$delpath"/>
               </xsl:with-param>
            </xsl:call-template>
         </xsl:otherwise>
      </xsl:choose></xsl:template>

   <xsl:template name="appcontent">
      <!-- prints the content of apparatus; called by ddb-apparatus or by individual elements if nested -->
      <xsl:param name="apptype"/>
      <xsl:param name="childtype"/>


      <xsl:variable name="path">
         <xsl:choose>
            <xsl:when test="$childtype='origreg' or $childtype=('siccorr')">
               <xsl:copy-of select="child::t:*[local-name()=('orig','sic','add','lem')]/t:choice/child::*"/>
            </xsl:when>
            <xsl:when test="$childtype='subst'">
               <xsl:copy-of select="child::t:*[local-name()=('orig','sic','add','lem')]/t:subst/child::*"/>
            </xsl:when>
            <xsl:when test="$childtype='appalt'">
               <xsl:copy-of select="child::t:*[local-name()=('orig','sic','add','lem')]/t:app[@type='alternative']/child::*"/>
            </xsl:when>
            <xsl:when test="$childtype=('appbl','apppn','apped')">
               <xsl:copy-of select="child::t:*[local-name()=('orig','sic','add','lem')]/t:app[@type='editorial']/child::*"/>
            </xsl:when>
            <!-- <xsl:when test="$apptype=('siccorr')"><xsl:value-of select="t:corr/node()"/></xsl:when> -->
            <xsl:otherwise>
               <xsl:copy-of select="node()"/>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>

      <!--*!'<xsl:value-of select="$path"/>'  -  Childtype: '<xsl:value-of select="$childtype"/>' - Apptype: '<xsl:value-of select="$apptype"/>' 
         <xsl:for-each select="$path/*">
         <xsl:value-of select="name()" />:  
         <xsl:for-each select="child::*">
            '<xsl:value-of select="name()" /> - <xsl:value-of select="." />'
            
         </xsl:for-each>       
      </xsl:for-each>-->
  <!--    !*
      
      **<xsl:value-of select="$apptype"/> - <xsl:value-of select="$childtype"/>**-->
      
      <xsl:variable name="parent-lang">
      <xsl:if test="(child::t:*[local-name()=('orig','sic','add','lem')]/t:choice/child::t:reg[@xml:lang] and $childtype = 'origreg') or (child::t:reg[@xml:lang] and $apptype = 'origreg')">
         <xsl:if test="$childtype = 'origreg'">
            <xsl:value-of select="child::t:*[local-name()=('orig','sic','add','lem')]/t:choice/child::t:reg/ancestor::t:*[@xml:lang][1]/@xml:lang"/>           
         </xsl:if>
         <xsl:if test="$apptype = 'origreg'">
            <xsl:value-of select="child::t:reg/ancestor::t:*[@xml:lang][1]/@xml:lang"/>           
         </xsl:if>        
      </xsl:if>
      </xsl:variable>
            
      <xsl:choose>
         <xsl:when test="$childtype != '' and $apptype != $childtype">
            <xsl:call-template name="appchoice">
               <xsl:with-param name="apptype"><xsl:value-of select="$childtype"/></xsl:with-param>
               <xsl:with-param name="path"><xsl:copy-of select="$path"/></xsl:with-param>
               <xsl:with-param name="parent-lang"><xsl:value-of select="$parent-lang"/></xsl:with-param>
            </xsl:call-template><xsl:text> </xsl:text>            
         </xsl:when>
         <xsl:otherwise>
            <xsl:call-template name="appchoice">
               <xsl:with-param name="apptype"><xsl:value-of select="$apptype"/></xsl:with-param>
               <xsl:with-param name="child"><xsl:if test="$childtype != ''">true</xsl:if></xsl:with-param>
               <xsl:with-param name="path"><xsl:copy-of select="$path"/></xsl:with-param>
               <xsl:with-param name="parent-lang"><xsl:value-of select="$parent-lang"/></xsl:with-param>
            </xsl:call-template>            
         </xsl:otherwise>
      </xsl:choose>   
      
      <!-- 
      <xsl:if test="$childtype != '' and $apptype != $childtype">
         {*{<xsl:call-template name="appchoice">
            <xsl:with-param name="apptype"><xsl:value-of select="$childtype"/></xsl:with-param>
            <xsl:with-param name="path"><xsl:copy-of select="$path"/></xsl:with-param>
         </xsl:call-template><xsl:text>, </xsl:text>}}               
      </xsl:if>
      
      {'{<xsl:call-template name="appchoice">
         <xsl:with-param name="apptype"><xsl:value-of select="$apptype"/></xsl:with-param>
         <xsl:with-param name="child"><xsl:if test="$childtype != ''">true</xsl:if></xsl:with-param>
         <xsl:with-param name="path"><xsl:copy-of select="$path"/></xsl:with-param>
      </xsl:call-template>}}
      
      -->
      
<!--     
 -->
      
     <!-- <xsl:choose> -->
         <!-- *REG*  (repeatable) -->
        <!-- <xsl:when test="($apptype='origreg' and $childtype='') or $childtype='origreg'"> -->
            <!--**REG - <xsl:value-of select="$path/t:reg"/>** -->
          <!--   <xsl:for-each select="$path/t:reg">
               <xsl:sort select="position()" order="descending"/>
               <xsl:call-template name="multreg"/>
            </xsl:for-each>
            <xsl:if test="$childtype != ''">
               <xsl:text>, </xsl:text>
            </xsl:if>
         </xsl:when> -->
         <!-- *CORR* -->
     <!--    <xsl:when test="$apptype=('siccorr')"> -->
            <!-- **CORR - <xsl:value-of select="$path/t:corr/node()"/>** -->
      <!--      <xsl:text>l. </xsl:text>
            <xsl:apply-templates select="$path/t:corr/node()"/>
            <xsl:text> (corr)</xsl:text>
         </xsl:when> -->
         <!-- *SUBST* -->
     <!--    <xsl:when test="($apptype='subst' and $childtype='') or $childtype='subst'"> -->
            <!-- **SUBST - <xsl:value-of select="$path/t:del/node()"/>/<xsl:value-of select="$path/t:add/node()"/>** -->
     <!--       <xsl:call-template name="resolvesubst">
               <xsl:with-param name="delpath" select="$path/t:del/node()"/>
               <xsl:with-param name="addpath" select="$path/t:add/node()"/>
            </xsl:call-template>
         </xsl:when> -->
         <!-- *ALT* (repeatable) -->
   <!--      <xsl:when test="$apptype='appalt'"> -->
            <!-- **ALT - <xsl:value-of select="$path/t:rdg"/>** -->
   <!--         <xsl:for-each select="$path/t:rdg">
               <xsl:if test="position()!=1">
                  <xsl:text>,</xsl:text>
               </xsl:if>
               <xsl:text> or </xsl:text>
               <xsl:if test="not(.//text())">
                  <xsl:text>not </xsl:text>
                  <xsl:apply-templates select="preceding-sibling::t:lem"/>
               </xsl:if>
               <xsl:apply-templates/>
            </xsl:for-each>
         </xsl:when> -->
         <!-- *ED* (repeatable) -->
   <!--      <xsl:when test="$apptype=('appbl','apppn','apped')">
            <xsl:if test="starts-with(t:lem/@resp,'BL ')">
               <xsl:if test="starts-with(substring-after(t:lem/@resp,'BL '),'cf.')">
                  <xsl:text> cf.</xsl:text>
               </xsl:if>
               <xsl:text> BL </xsl:text>
            </xsl:if>
            <xsl:choose>
               <xsl:when test="starts-with(substring-after(t:lem/@resp,'BL '),'cf.')">
                  <xsl:value-of select="substring-after(t:lem/@resp,'cf.')"/>
                  <xsl:text> : </xsl:text>
               </xsl:when>
               <xsl:when test="starts-with(t:lem/@resp,'BL ')">
                  <xsl:value-of select="substring-after(t:lem/@resp,'BL ')"/>
                  <xsl:text> : </xsl:text>
               </xsl:when>
               <xsl:when test="starts-with(t:lem/@resp,'PN ')">
                  <xsl:value-of select="substring-after(t:lem/@resp,'PN ')"/>
                  <xsl:text> (via PN) : </xsl:text>
               </xsl:when>
               <xsl:when test="t:lem/@resp">
                  <xsl:value-of select="t:lem/@resp"/>
                  <xsl:text> : </xsl:text>
               </xsl:when>
               <xsl:otherwise/>
            </xsl:choose>
            <xsl:for-each select="t:rdg"> -->
               <!-- found below -->
     <!--          <xsl:call-template name="app-ed-mult-with-param">
                  <xsl:with-param name="check">fnord</xsl:with-param>
               </xsl:call-template>
            </xsl:for-each>
         </xsl:when>
      </xsl:choose> -->
   </xsl:template>
   
   <xsl:template name="appchoice">
      <xsl:param name="apptype"/>
      <xsl:param name="child"/>
      <xsl:param name="path"/>
      <xsl:param name="parent-lang"/>
      
      <!-- **<xsl:value-of select="$apptype"/> - <xsl:value-of select="$child"/>** -->           
      
     <!-- {{ (<xsl:value-of select="$path/*" />) 
            <xsl:for-each select="$path/*">
               <xsl:value-of select="name()" />:  
               {<xsl:for-each select="child::*">
                  '<xsl:value-of select="name()" /> - <xsl:value-of select="." />'
                  
               </xsl:for-each>}       
            </xsl:for-each>}}-->
      <xsl:choose>
         <!-- *REG*  (repeatable) -->
         <xsl:when test="$apptype='origreg'">
            <!-- **REG - <xsl:value-of select="$path/t:reg"/>** -->
            <xsl:for-each select="$path/t:reg">
               <xsl:sort select="position()" order="descending"/>
               <!-- <xsl:value-of select="."/> -->
               <xsl:call-template name="multreg">
                  <xsl:with-param name="parent-lang"><xsl:value-of select="$parent-lang"/></xsl:with-param>
               </xsl:call-template>
            </xsl:for-each>
            <xsl:if test="$child != ''">
               <xsl:text>, </xsl:text>
            </xsl:if>
         </xsl:when>
         <!-- *CORR* -->
         <xsl:when test="$apptype=('siccorr')">
            <!-- **CORR - <xsl:value-of select="$path/t:corr/node()"/>** -->
            <xsl:text>l. </xsl:text>
            <xsl:apply-templates select="$path/t:corr/node()"/>
            <xsl:text> (corr)</xsl:text>
         </xsl:when>
         <!-- *SUBST* -->
         <xsl:when test="$apptype='subst'">
            <!--**SUBST - <xsl:value-of select="$path/t:del/node()"/>/<xsl:value-of select="$path/t:add/node()"/>** -->       
            <xsl:call-template name="resolvesubst">
               <xsl:with-param name="delpath" select="$path/t:del/node()"/>
               <xsl:with-param name="addpath" select="$path/t:add/node()"/>
            </xsl:call-template>
         </xsl:when>
         <!-- *ALT* (repeatable) -->
         <xsl:when test="$apptype='appalt'">
            <!-- **ALT - <xsl:value-of select="$path/t:rdg"/>** -->
            <xsl:for-each select="$path/t:rdg">
               <xsl:if test="position()!=1">
                  <xsl:text>,</xsl:text>
               </xsl:if>
               <xsl:text> or </xsl:text>
               <xsl:if test="(not(.//text())) and (not(.//t:gap))">
                  <xsl:text>not </xsl:text>
                  <xsl:apply-templates select="preceding-sibling::t:lem"/>
               </xsl:if>
               <xsl:apply-templates/>
            </xsl:for-each>
         </xsl:when>
         <!-- *ED* (repeatable) -->
         <xsl:when test="$apptype=('appbl','apppn','apped')">
            <xsl:if test="starts-with($path/t:lem/@resp,'BL ')">
               <xsl:if test="starts-with(substring-after($path/t:lem/@resp,'BL '),'cf.')">
                  <xsl:text> cf.</xsl:text>
               </xsl:if>
               <xsl:text> BL </xsl:text>
            </xsl:if>
            <xsl:choose>
               <xsl:when test="starts-with(substring-after($path/t:lem/@resp,'BL '),'cf.')">
                  <xsl:value-of select="substring-after($path/t:lem/@resp,'cf.')"/>
                  <xsl:text> : </xsl:text>
               </xsl:when>
               <xsl:when test="starts-with($path/t:lem/@resp,'BL ')">
                  <xsl:value-of select="substring-after($path/t:lem/@resp,'BL ')"/>
                  <xsl:text> : </xsl:text>
               </xsl:when>
               <xsl:when test="starts-with($path/t:lem/@resp,'PN ')">
                  <xsl:value-of select="substring-after($path/t:lem/@resp,'PN ')"/>
                  <xsl:text> (via PN) : </xsl:text>
               </xsl:when>
               <xsl:when test="$path/t:lem/@resp">
                  <xsl:value-of select="$path/t:lem/@resp"/>
                  <xsl:text> : </xsl:text>
               </xsl:when>
               <xsl:otherwise/>
            </xsl:choose>
            <xsl:for-each select="$path/t:rdg">
               <!-- found below -->
               <xsl:call-template name="app-ed-mult-with-param">
                  <xsl:with-param name="check">fnord</xsl:with-param>
               </xsl:call-template>
            </xsl:for-each>
         </xsl:when>
      </xsl:choose>      
   </xsl:template>   
   
   <!-- The recurse_* templates handle isolating the piece of text that will be printed in the apparatus,
        by finding the word breaks before and after it.-->
   <xsl:template name="recurse_back">
      <!-- Recurse through preceding sibling nodes until a space or carriage return is found -->
      <!-- Used by hirend, appcontent -->
      <!-- When used by hirend ($origin='hi'), will strip diacritics -->
      <xsl:param name="step"/>
      <xsl:param name="buildup"/>

      <xsl:variable name="origin" select="name()"/>
      <xsl:variable name="origin_id" select="generate-id()"/>

      <xsl:choose>
         <xsl:when test="$step[self::t:lb[not(@break='no')]]">
            <xsl:copy-of select="$buildup"/>
         </xsl:when>
         <xsl:when test="$step[self::text()]">
            <xsl:choose>
               <xsl:when test="matches($step, '[\s\n\r\t]')">
                 <xsl:choose>
                   <xsl:when test="string-length($buildup) = 0">
                     <xsl:choose>
                       <xsl:when test="$origin='hi'">
                         <xsl:call-template name="trans-string">
                           <xsl:with-param name="trans-text">
                             <xsl:call-template name="string-after-space">
                               <xsl:with-param name="test-string" select="$step"/>
                             </xsl:call-template>
                           </xsl:with-param>
                         </xsl:call-template>
                       </xsl:when>
                       <xsl:otherwise>
                         <xsl:call-template name="string-after-space">
                           <xsl:with-param name="test-string" select="$step"/>
                         </xsl:call-template>
                       </xsl:otherwise>
                     </xsl:choose>
                   </xsl:when>
                   <xsl:otherwise><xsl:copy-of select="$buildup"/></xsl:otherwise>
                 </xsl:choose>
               </xsl:when>
               <!-- if the text node is a first child and a space hasn't been located yet... -->
               <xsl:when test="not($step/preceding-sibling::node()[1])">
                  <xsl:variable name="temp-buildup">
                     <xsl:choose>
                        <xsl:when test="$origin='hi'">
                           <xsl:call-template name="trans-string">
                              <xsl:with-param name="trans-text">
                                 <xsl:call-template name="string-after-space">
                                    <xsl:with-param name="test-string" select="$step"/>
                                 </xsl:call-template>
                              </xsl:with-param>
                           </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:call-template name="string-after-space">
                              <xsl:with-param name="test-string" select="$step"/>
                           </xsl:call-template>
                        </xsl:otherwise>
                     </xsl:choose>
                     <xsl:copy-of select="$buildup"/>
                  </xsl:variable>

                  <xsl:for-each select="$step/ancestor::*[preceding-sibling::node()][1]">
                     <xsl:call-template name="recurse_back">
                        <xsl:with-param name="step" select="preceding-sibling::node()[1]"/>
                        <xsl:with-param name="buildup" select="$temp-buildup"/>
                     </xsl:call-template>
                  </xsl:for-each>

               </xsl:when>
               <xsl:otherwise>
                  <xsl:variable name="temp-buildup">
                     <xsl:choose>
                        <xsl:when test="$origin='hi'">
                           <xsl:call-template name="trans-string">
                              <xsl:with-param name="trans-text">
                                 <xsl:call-template name="string-after-space">
                                    <xsl:with-param name="test-string" select="$step"/>
                                 </xsl:call-template>
                              </xsl:with-param>
                           </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:call-template name="string-after-space">
                              <xsl:with-param name="test-string" select="$step"/>
                           </xsl:call-template>
                        </xsl:otherwise>
                     </xsl:choose>
                     <xsl:copy-of select="$buildup"/>
                  </xsl:variable>
                  <xsl:call-template name="recurse_back">
                     <xsl:with-param name="step" select="$step/preceding-sibling::node()[1]"/>
                     <xsl:with-param name="buildup" select="$temp-buildup"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <!-- if the element is nested and a space hasn't been located yet... -->
         <xsl:when test="not($step/preceding-sibling::node()[1])">
            <xsl:for-each select="$step/ancestor::*[preceding-sibling::node()][1]">
               <xsl:call-template name="recurse_back">
                  <xsl:with-param name="step" select="preceding-sibling::node()[1]"/>
                  <xsl:with-param name="buildup" select="$buildup"/>
               </xsl:call-template>
            </xsl:for-each>
         </xsl:when>
         <xsl:when test="$step/preceding-sibling::node()[1][self::t:lb][not(@break='no')]"/>
         <xsl:otherwise>
            <xsl:choose>
               <xsl:when test="$step[self::t:hi]">
                  <xsl:call-template name="recurse_back">
                     <xsl:with-param name="step" select="$step/preceding-sibling::node()[1]"/>
                  </xsl:call-template>
                  <xsl:for-each select="$step">
                     <xsl:call-template name="hirend_print"/>
                  </xsl:for-each>
                  <xsl:copy-of select="$buildup"/>
               </xsl:when>
               <xsl:when test="$step[self::t:subst]">
                  <xsl:call-template name="recurse_back">
                     <xsl:with-param name="step" select="$step/preceding-sibling::node()[1]"/>
                  </xsl:call-template>
                  <xsl:call-template name="trans-string">
                     <xsl:with-param name="trans-text">
                        <xsl:apply-templates select="$step//t:add/node()"/>
                     </xsl:with-param>
                  </xsl:call-template>
                  <xsl:copy-of select="$buildup"/>
               </xsl:when>
               <xsl:when test="($step[self::text] or $step[self::*]) and matches($step, '[\s\n\r\t]')">
                  <xsl:variable name="builddown">
                     <xsl:call-template name="recurse_down_back">
                        <xsl:with-param name="step" select="$step"/>
                        <xsl:with-param name="buildup" select="$buildup"/>
                        <xsl:with-param name="origin" select="$origin"/>
                     </xsl:call-template>
                  </xsl:variable>
                 <xsl:apply-templates select="$builddown/node()"/>
                  <xsl:copy-of select="$buildup"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:variable name="temp-buildup">
                     <xsl:choose>
                        <xsl:when test="$step/t:hi[generate-id()=$origin_id]"/>
                        <xsl:when test="$step/t:hi">
                           <xsl:for-each select="$step/t:hi">
                              <xsl:call-template name="hirend_print"/>
                           </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:apply-templates select="$step"/>
                        </xsl:otherwise>
                     </xsl:choose>
                     <xsl:copy-of select="$buildup"/>
                  </xsl:variable>
                  <xsl:call-template name="recurse_back">
                     <xsl:with-param name="step" select="$step/preceding-sibling::node()[1]"/>
                     <xsl:with-param name="buildup" select="$temp-buildup"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>

   </xsl:template>

   <xsl:template name="recurse_down_back">
      <!-- Recurse through child nodes until a space or carriage return is found. Re-create elements when necessary -->
      <!-- Used by recurse_back -->
      <!-- Handles buildup for right-to-left space/return search -->
      <xsl:param name="step"/>
      <xsl:param name="buildup"/>
      <xsl:param name="origin"/>

      <xsl:choose>
         <xsl:when test="$step[self::text()]">
            <xsl:choose>
               <xsl:when test="$origin='hi'">
                  <xsl:call-template name="trans-string">
                     <xsl:with-param name="trans-text">
                        <xsl:call-template name="string-after-space">
                           <xsl:with-param name="test-string" select="$step"/>
                        </xsl:call-template>
                     </xsl:with-param>
                  </xsl:call-template>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:call-template name="string-after-space">
                     <xsl:with-param name="test-string" select="$step"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
            <xsl:copy-of select="buildup"/>
         </xsl:when>
         <xsl:when test="$step[self::t:hi]">
            <xsl:for-each select="$step">
               <xsl:call-template name="hirend_print"/>
            </xsl:for-each>
            <xsl:copy-of select="$buildup"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:element xmlns="http://www.tei-c.org/ns/1.0" name="{$step/name()}">
               <xsl:sequence select="$step/@*"/>
               <xsl:choose>
                  <xsl:when test="$step/text() and not($step/*)">
                     <xsl:choose>
                        <xsl:when test="$origin='hi'">
                           <xsl:call-template name="trans-string">
                              <xsl:with-param name="trans-text">
                                 <xsl:call-template name="string-after-space">
                                    <xsl:with-param name="test-string" select="$step/text()"/>
                                 </xsl:call-template>
                              </xsl:with-param>
                           </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:call-template name="string-after-space">
                              <xsl:with-param name="test-string" select="$step/text()"/>
                           </xsl:call-template>
                        </xsl:otherwise>
                     </xsl:choose>
                     <xsl:copy-of select="buildup"/>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:for-each select="$step/node()">
                        <xsl:variable name="curstep-id" select="generate-id($step)"/>
                        <xsl:choose>
                           <xsl:when test="matches(., '[\s\n\r\t]')"/>
                           <xsl:when test="following::text()[generate-id(ancestor::node()[1])=$curstep-id and matches(., '[\s\n\r\t]')]">
                              <xsl:call-template name="recurse_down_back">
                                 <xsl:with-param name="step" select="following-sibling::node()[1]"/>
                                 <xsl:with-param name="buildup" select="buildup"/>
                                 <xsl:with-param name="origin" select="$origin"/>
                              </xsl:call-template>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:call-template name="recurse_down_back">
                                 <xsl:with-param name="step" select="."/>
                                 <xsl:with-param name="buildup" select="buildup"/>
                                 <xsl:with-param name="origin" select="$origin"/>
                              </xsl:call-template>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:for-each>
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:element>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="recurse_forward">
      <!-- Recurse through following sibling nodes until a space or carriage return is found -->
      <!-- Used by hirend, appcontent -->
      <xsl:param name="step"/>

      <xsl:variable name="origin" select="name()"/>
      <xsl:variable name="origin_id" select="generate-id()"/>

      <xsl:choose>
         <xsl:when test="$step[self::t:lb[not(@break='no')]]"/>
         <xsl:when test="$step[self::text()]">
            <xsl:choose>
               <xsl:when test="matches($step, '[\s\n\r\t]')">
                  <xsl:choose>
                     <xsl:when test="$origin='hi'">
                        <xsl:call-template name="trans-string">
                           <xsl:with-param name="trans-text">
                              <xsl:call-template name="string-before-space">
                                 <xsl:with-param name="test-string" select="$step"/>
                              </xsl:call-template>
                           </xsl:with-param>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:call-template name="string-before-space">
                           <xsl:with-param name="test-string" select="$step"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:when>
               <!-- if the text node is a first child and a space hasn't been located yet... -->
               <xsl:when test="not($step/preceding-sibling::node()[1])">
                  <xsl:choose>
                     <xsl:when test="$origin='hi'">
                        <xsl:call-template name="trans-string">
                           <xsl:with-param name="trans-text">
                              <xsl:call-template name="string-before-space">
                                 <xsl:with-param name="test-string" select="$step"/>
                              </xsl:call-template>
                           </xsl:with-param>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:call-template name="string-before-space">
                           <xsl:with-param name="test-string" select="$step"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
                  <xsl:for-each select="$step/ancestor::*[following-sibling::node()][1]">
                     <xsl:call-template name="recurse_forward">
                        <xsl:with-param name="step" select="following-sibling::node()[1]"/>
                     </xsl:call-template>
                  </xsl:for-each>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:choose>
                     <xsl:when test="$origin='hi'">
                        <xsl:call-template name="trans-string">
                           <xsl:with-param name="trans-text">
                              <xsl:call-template name="string-before-space">
                                 <xsl:with-param name="test-string" select="$step"/>
                              </xsl:call-template>
                           </xsl:with-param>
                        </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:call-template name="string-before-space">
                           <xsl:with-param name="test-string" select="$step"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
                  <xsl:call-template name="recurse_forward">
                     <xsl:with-param name="step" select="$step/following-sibling::node()[1]"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <!-- If there's no following step, and we're directly inside orig|reg|sic|corr|abbr|expan 
              then we should assume we're at word-end and stop-->
         <xsl:when test="not($step/following-sibling::node()[1])">
            <xsl:if test="not($step/local-name() = ('orig','reg','sic','corr','abbr','expan'))">
               <xsl:choose>
                  <xsl:when test="$step/t:hi[generate-id()=$origin_id]"/>
                  <xsl:when test="$step/t:hi">
                     <xsl:for-each select="$step/t:hi">
                        <xsl:call-template name="hirend_print"/>
                     </xsl:for-each>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:apply-templates select="$step"/>
                  </xsl:otherwise>
               </xsl:choose>
               <xsl:for-each select="$step/ancestor::*[following-sibling::node()][1]">
                  <xsl:call-template name="recurse_forward">
                     <xsl:with-param name="step" select="following-sibling::node()[1]"/>
                  </xsl:call-template>
               </xsl:for-each>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise>
            <xsl:choose>
               <xsl:when test="$step[self::t:hi]">
                  <xsl:for-each select="$step">
                     <xsl:call-template name="hirend_print"/>
                  </xsl:for-each>
                  <xsl:call-template name="recurse_forward">
                     <xsl:with-param name="step" select="$step/following-sibling::node()[1]"/>
                  </xsl:call-template>
               </xsl:when>
               <xsl:when test="$step[self::t:subst]">
                  <xsl:call-template name="trans-string">
                     <xsl:with-param name="trans-text">
                        <xsl:apply-templates select="$step//t:add/node()"/>
                     </xsl:with-param>
                  </xsl:call-template>
                  <xsl:call-template name="recurse_forward">
                     <xsl:with-param name="step" select="$step/following-sibling::node()[1]"/>
                  </xsl:call-template>
               </xsl:when>
               <xsl:when test="($step[self::text] or $step[self::*]) and matches($step, '[\s\n\r\t]')">
                  <xsl:variable name="builddown">
                     <xsl:call-template name="recurse_down">
                        <xsl:with-param name="step" select="$step"/>
                        <xsl:with-param name="origin" select="$origin"/>
                     </xsl:call-template>
                  </xsl:variable>
                  <xsl:variable name="resolve">
                     <xsl:apply-templates select="$builddown/node()"/>
                  </xsl:variable>
                  <xsl:value-of select="$resolve"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:choose>
                     <xsl:when test="$step/t:hi[generate-id()=$origin_id]"/>
                     <xsl:when test="$step/t:hi">
                        <xsl:for-each select="$step/t:hi">
                           <xsl:call-template name="hirend_print"/>
                        </xsl:for-each>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:apply-templates select="$step"/>
                     </xsl:otherwise>
                  </xsl:choose>
                  <xsl:call-template name="recurse_forward">
                     <xsl:with-param name="step" select="$step/following-sibling::node()[1]"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:otherwise>
      </xsl:choose>

   </xsl:template>

   <xsl:template name="recurse_down">
      <!-- Recurse through child nodes until a space or carriage return is found. Re-create elements when necessary -->
      <!-- Used by recurse_forward -->
      <xsl:param name="step"/>
      <xsl:param name="origin"/>

      <xsl:choose>
         <xsl:when test="$step[self::text()]">
            <xsl:call-template name="trans-string">
               <xsl:with-param name="trans-text">
                  <xsl:call-template name="string-before-space">
                     <xsl:with-param name="test-string" select="$step"/>
                  </xsl:call-template>
               </xsl:with-param>
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="$step[self::t:hi]">
            <xsl:for-each select="$step">
               <xsl:call-template name="hirend_print"/>
            </xsl:for-each>
         </xsl:when>
         <xsl:otherwise>
            <xsl:element xmlns="http://www.tei-c.org/ns/1.0" name="{$step/name()}">
               <xsl:sequence select="$step/@*"/>
               <xsl:choose>
                 <xsl:when test="local-name($step/node()[1]) = '' and matches($step/node()[1], '[\s\t\r\n]')">
                   <xsl:choose>
                     <xsl:when test="$origin='hi'">
                       <xsl:call-template name="trans-string">
                         <xsl:with-param name="trans-text">
                           <xsl:call-template name="string-before-space">
                             <xsl:with-param name="test-string" select="$step/node()[1]"/>
                           </xsl:call-template>
                         </xsl:with-param>
                       </xsl:call-template>
                     </xsl:when>
                     <xsl:otherwise>
                       <xsl:call-template name="string-before-space">
                         <xsl:with-param name="test-string" select="$step/node()[1]"/>
                       </xsl:call-template>
                     </xsl:otherwise>
                   </xsl:choose>
                 </xsl:when>
                  <xsl:when test="$step/text() and not($step/*)">
                     <xsl:choose>
                        <xsl:when test="$origin='hi'">
                           <xsl:call-template name="trans-string">
                              <xsl:with-param name="trans-text">
                                 <xsl:call-template name="string-before-space">
                                    <xsl:with-param name="test-string" select="$step/text()"/>
                                 </xsl:call-template>
                              </xsl:with-param>
                           </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                           <xsl:call-template name="string-before-space">
                              <xsl:with-param name="test-string" select="$step/text()"/>
                           </xsl:call-template>
                        </xsl:otherwise>
                     </xsl:choose>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:for-each select="$step/node()">
                        <xsl:call-template name="recurse_down">
                           <xsl:with-param name="step" select="."/>
                           <xsl:with-param name="origin" select="$origin"/>
                        </xsl:call-template>
                     </xsl:for-each>
                  </xsl:otherwise>
               </xsl:choose>
            </xsl:element>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="hirend">
      <!-- prints the value of diacritical <hi> values, either in text (with full word context, called from teihi.xsl) or in app (highlighted character only) -->
      <xsl:param name="hicontext" select="'yes'"/>
      <xsl:if test="$hicontext != 'no'">

         <xsl:variable name="text-before">
            <xsl:choose>
               <xsl:when test="not(preceding-sibling::node()[1])">
                  <xsl:call-template name="recurse_back">
                     <xsl:with-param name="step" select="parent::*"/>
                  </xsl:call-template>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:call-template name="recurse_back">
                     <xsl:with-param name="step" select="preceding-sibling::node()[1]"/>
                  </xsl:call-template>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:variable>

         <!-- This removes unnecessary line breaks that could've come through -->
         <xsl:value-of select="normalize-space($text-before)"/>

      </xsl:if>

      <xsl:call-template name="hirend_print"/>

      <xsl:if test="$hicontext != 'no'">

         <xsl:choose>
            <xsl:when test="not(following-sibling::node()[1])">
               <xsl:call-template name="recurse_forward">
                  <xsl:with-param name="step" select="parent::*"/>
               </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
               <xsl:call-template name="recurse_forward">
                  <xsl:with-param name="step" select="following-sibling::node()[1]"/>
               </xsl:call-template>
            </xsl:otherwise>
         </xsl:choose>

         <!-- found below: inserts "papyrus" or "ostrakon" depending on filename -->
         <xsl:call-template name="support"/>
      </xsl:if>

   </xsl:template>

   <xsl:template name="hirend_print">
      <!-- Determines the value of diacritical <hi> values -->
      <!-- Used by hirend -->
      <xsl:choose>
         <xsl:when test="@rend = 'diaeresis'">
            <xsl:call-template name="trans-string"/>
            <xsl:if test="t:gap">
               <xsl:if test="t:gap[@reason='lost']">
                  <xsl:text>[</xsl:text>
               </xsl:if>
               <xsl:text>  ̣</xsl:text>
            </xsl:if>
            <xsl:text>̈</xsl:text>
            <xsl:if test="t:gap[@reason='lost']">
               <xsl:text>]</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:when test="@rend = 'grave'">
            <xsl:call-template name="trans-string"/>
            <xsl:if test="t:gap">
               <xsl:if test="t:gap[@reason='lost']">
                  <xsl:text>[</xsl:text>
               </xsl:if>
               <xsl:text>  ̣</xsl:text>
            </xsl:if>
            <xsl:text>̀</xsl:text>
            <xsl:if test="t:gap[@reason='lost']">
               <xsl:text>]</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:when test="@rend = 'acute'">
            <xsl:call-template name="trans-string"/>
            <xsl:if test="t:gap">
               <xsl:if test="t:gap[@reason='lost']">
                  <xsl:text>[</xsl:text>
               </xsl:if>
               <xsl:text>  ̣</xsl:text>
            </xsl:if>
            <xsl:text>́</xsl:text>
            <xsl:if test="t:gap[@reason='lost']">
               <xsl:text>]</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:when test="@rend = 'asper'">
            <xsl:call-template name="trans-string"/>
            <xsl:if test="t:gap">
               <xsl:if test="t:gap[@reason='lost']">
                  <xsl:text>[</xsl:text>
               </xsl:if>
               <xsl:text>  ̣</xsl:text>
            </xsl:if>
            <xsl:text>̔</xsl:text>
            <xsl:if test="t:gap[@reason='lost']">
               <xsl:text>]</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:when test="@rend = 'lenis'">
            <xsl:call-template name="trans-string"/>
            <xsl:if test="t:gap">
               <xsl:if test="t:gap[@reason='lost']">
                  <xsl:text>[</xsl:text>
               </xsl:if>
               <xsl:text>  ̣</xsl:text>
            </xsl:if>
            <xsl:text>̓</xsl:text>
            <xsl:if test="t:gap[@reason='lost']">
               <xsl:text>]</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:when test="@rend = 'circumflex'">
            <xsl:call-template name="trans-string"/>
            <xsl:if test="t:gap">
               <xsl:if test="t:gap[@reason='lost']">
                  <xsl:text>[</xsl:text>
               </xsl:if>
               <xsl:text>  ̣</xsl:text>
            </xsl:if>
            <xsl:text>͂</xsl:text>
            <xsl:if test="t:gap[@reason='lost']">
               <xsl:text>]</xsl:text>
            </xsl:if>
         </xsl:when>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="multreg">
      <xsl:param name="parent-lang"/>
      <!-- prints multiple regs in a single choice in sequence -->
      <xsl:choose>
         <xsl:when test="position()!=1">
            <xsl:text>i.e. </xsl:text>
         </xsl:when>
         <xsl:when test="@xml:lang != ancestor::t:*[@xml:lang][1]/@xml:lang or ($parent-lang != '' and @xml:lang != $parent-lang)">
            <xsl:text>i.e. </xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>l. </xsl:text>
         </xsl:otherwise>
      </xsl:choose>
      <xsl:if test="@xml:lang != ancestor::t:*[@xml:lang][1]/@xml:lang or ($parent-lang != '' and @xml:lang != $parent-lang)">
         <xsl:call-template name="reglang">
            <xsl:with-param name="lang" select="@xml:lang"/>
         </xsl:call-template>
      </xsl:if>
      <xsl:apply-templates/>
      <xsl:if test="position()!=last()">
         <xsl:text>, </xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template name="reglang">
      <!-- test to insert language for multi-lang regs -->
      <xsl:param name="lang"/>
      <xsl:choose>
         <xsl:when test="$lang='grc'">
            <xsl:text> Greek </xsl:text>
         </xsl:when>
         <xsl:when test="$lang='la'">
            <xsl:text> Latin </xsl:text>
         </xsl:when>
         <xsl:when test="$lang='cop'">
            <xsl:text> Coptic </xsl:text>
         </xsl:when>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="app-ed-mult">
      <xsl:call-template name="app-ed-mult-with-param">
         <xsl:with-param name="check"/>
      </xsl:call-template>
   </xsl:template>

   <xsl:template name="app-ed-mult-with-param">
      <xsl:param name="check"/>
      <xsl:if test="$check='fnord'">FNORD-SPLIT </xsl:if>
      <xsl:apply-templates>
         <xsl:with-param name="check">fnord</xsl:with-param>
      </xsl:apply-templates>
      <xsl:if test="$check='fnord'"> FNORD-SPLIT </xsl:if>
      <xsl:if test="starts-with(@resp,'BL ')">
         <xsl:if test="starts-with(substring-after(@resp,'BL '),'cf.')">
            <xsl:text> cf.</xsl:text>
         </xsl:if>
         <xsl:text> BL</xsl:text>
      </xsl:if>
      <xsl:text> </xsl:text>
      <xsl:choose>
         <xsl:when test="starts-with(substring-after(@resp,'BL '),'cf.')">
            <xsl:value-of select="substring-after(@resp,'cf.')"/>
         </xsl:when>
         <xsl:when test="starts-with(@resp,'BL ')">
            <xsl:value-of select="substring-after(@resp,'BL ')"/>
         </xsl:when>
         <xsl:when test="starts-with(@resp,'PN ')">
            <xsl:value-of select="substring-after(@resp,'PN ')"/>
            <xsl:text> (via PN)</xsl:text>
         </xsl:when>
         <xsl:when test="string(@resp)">
            <xsl:value-of select="@resp"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text> prev. ed.</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
      <xsl:if test="position()!=last()">
         <xsl:text> : </xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template name="string-after-space">
      <!-- finds all text content before hi up to the preceding space -->
      <xsl:param name="test-string"/>
      <xsl:choose>
         <xsl:when test="matches($test-string, '[\s\n\t\r]')">
            <xsl:call-template name="string-after-space">
               <xsl:with-param name="test-string" select="tokenize($test-string, '[\s\n\t\r]')[last()]"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="$test-string"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="string-before-space">
      <!-- finds all text content after hi up to the next space -->
      <xsl:param name="test-string"/>
      <xsl:choose>
         <xsl:when test="matches($test-string, '[\s\n\t\r]')">
            <xsl:call-template name="string-before-space">
               <xsl:with-param name="test-string" select="tokenize($test-string, '[\s\n\t\r]')[1]"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="$test-string"/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="trans-string">
      <!-- transforms context of <hi> into lowercase unaccented for rendering in app -->
      <xsl:param name="trans-text" select="."/>
      <xsl:value-of select="translate($trans-text, $all-grc, $grc-lower-strip)"/>
   </xsl:template>

   <xsl:template name="childCertainty">
      <!-- called in various places; adds (?) if certainty element applied -->
      <xsl:if test="child::t:certainty[@match='..']">
         <xsl:text>(?)</xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template name="support">
      <!-- called by template "hirend" above; decides whether text support is "ostrakon" or other (prob. = "papyrus") -->
      <xsl:choose>
         <xsl:when test="starts-with(ancestor::t:TEI//t:idno[@type='filename'],'o.')">
            <xsl:text> ostrakon</xsl:text>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text> papyrus</xsl:text>
         </xsl:otherwise>
      </xsl:choose>

   </xsl:template>

   <xsl:template name="title-convert">
      <xsl:param name="obf"/>
      <xsl:param name="apptype"/>
      <xsl:param name="childtype"/>
      <xsl:variable name="scribeswitch">
         <xsl:choose>
            <xsl:when test="$apptype = 'subst' and $childtype != ''"><xsl:value-of select="replace($obf, 'for which read', ', then changed to')"/></xsl:when>
            <xsl:when test="$childtype != ''"><xsl:value-of select="replace($obf, 'for which read', 'Scribe wrote')"/></xsl:when>
            <xsl:when test="$apptype = 'origreg' and contains($obf, 'for which read') and not(contains($obf, ', for which read'))">
               <xsl:value-of select="replace($obf, 'for which read', 'Scribe wrote')"/></xsl:when>
            <xsl:when test="$apptype = 'siccorr'"><xsl:value-of select="replace($obf, '\(\(for which read\)\)', 'Scribe wrote')"/>
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="$obf"/></xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="no-l">
         <xsl:choose>
            <xsl:when test="$apptype = 'siccorr'"><xsl:value-of select="substring-before(replace($scribeswitch, 'l\. ', 'for which correct to '), '(corr)')"/></xsl:when>
            <xsl:when test="$apptype = ('origreg', 'subst', 'appalt', 'apped')"><xsl:value-of select="replace($scribeswitch, 'l\. ', 'for which read ')"/></xsl:when>
            <xsl:when test="contains($scribeswitch, 'prev. ed.')"><xsl:value-of select="replace($scribeswitch, 'l\. ', 'for which read ')"/></xsl:when>
            <xsl:when test="$apptype = 'appbl'"><xsl:value-of select="replace($scribeswitch, 'l\. ', 'normalises to ')"/></xsl:when>
            <xsl:otherwise><xsl:value-of select="replace($scribeswitch, 'l\. ', 'Scribe wrote ')"/></xsl:otherwise>
         </xsl:choose>
      </xsl:variable>
      <xsl:variable name="corrEx">
         <xsl:choose>
            <xsl:when test="$apptype = ('apped', 'apppn', 'appbl')"><xsl:value-of select="replace($no-l, 'corr. ex', 'scribe wrote')"/></xsl:when>
            <!-- <xsl:when test="contains($no-l, '( corr. ex')">Scribe wrote <xsl:value-of select="substring-before(substring-after($no-l, '( corr. ex'), ')')" /><xsl:value-of select="replace(substring-before($no-l, '( corr. ex'), 'corr. ex', ', then changed to ')" /></xsl:when> -->
            <xsl:otherwise><xsl:value-of select="replace($no-l, 'corr. ex', 'Scribe wrote')"/></xsl:otherwise>
         </xsl:choose>        
      </xsl:variable>
      <xsl:variable name="prevEd">
         <xsl:value-of select="replace($corrEx, 'prev. ed.', 'previous edition')"/>
      </xsl:variable>
      <xsl:variable name="cf">
         <xsl:value-of select="replace($prevEd, 'cf.', '')"/>
      </xsl:variable>    
     <!-- <xsl:variable name="linebreaks">
         <xsl:value-of select="replace($cf, '-', '|')"/>
      </xsl:variable> -->
      <xsl:value-of select="normalize-space(replace($cf, '\(\*\)', ''))"/>
      <!-- <xsl:value-of select="$obf" /> --> <!--(<xsl:value-of select="$apptype"/> - <xsl:value-of select="$childtype"/>)  -->
   </xsl:template>
   
   <xsl:template name="fnord-seperator">
      <xsl:param name="part"/>
      <xsl:param name="pos"/><xsl:choose>
               <xsl:when test="contains($part, 'FNORD-SPLIT') and contains($part, ' :') and contains($part, ' FNORD-DELIM') and starts-with($part, 'l. ')">
                  <xsl:for-each select="tokenize(substring-after($part, 'l. '), ' : ')">
                     <xsl:for-each select="tokenize(., ' FNORD-DELIM ')"><xsl:call-template name="fnord-spliter">
                           <xsl:with-param name="line">    
                              <xsl:choose>
                                 <xsl:when test="starts-with(normalize-space(.), 'FNORD-SPLIT')"><xsl:value-of select="substring-after(. , 'FNORD-SPLIT')"/></xsl:when>
                                 <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
                              </xsl:choose>
                           </xsl:with-param>
                           <xsl:with-param name="delim"><xsl:if test="$pos='second' or position() != 1">;</xsl:if></xsl:with-param>                       
                     </xsl:call-template></xsl:for-each>
                  </xsl:for-each>
               </xsl:when>               
               <xsl:when test="contains($part, 'FNORD-SPLIT') and contains($part, ' :') and starts-with($part, 'l. ')">
                  <xsl:for-each select="tokenize(substring-after($part, 'l. '), ' : ')"><xsl:call-template name="fnord-spliter">
                        <xsl:with-param name="line">    
                           <xsl:choose>
                              <xsl:when test="starts-with(normalize-space(.), 'FNORD-SPLIT')"><xsl:value-of select="substring-after(. , 'FNORD-SPLIT')"/></xsl:when>
                              <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
                           </xsl:choose>
                        </xsl:with-param>
                        <xsl:with-param name="delim"><xsl:if test="$pos='second' or position() != 1">;</xsl:if></xsl:with-param>   
                        <xsl:with-param name="tail">true</xsl:with-param></xsl:call-template>
                  </xsl:for-each>                  
               </xsl:when>
               <xsl:when test="contains($part, 'FNORD-SPLIT') and contains($part, ' :') and contains($part, ' FNORD-DELIM')">
                  <xsl:for-each select="tokenize($part, ' : ')"><xsl:for-each select="tokenize(., ' FNORD-DELIM ')"><xsl:call-template name="fnord-spliter">
                        <xsl:with-param name="line">    
                           <xsl:choose>
                              <xsl:when test="starts-with(normalize-space(.), 'FNORD-SPLIT')"><xsl:value-of select="substring-after(. , 'FNORD-SPLIT')"/></xsl:when>
                              <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
                           </xsl:choose>
                        </xsl:with-param>
                        <xsl:with-param name="delim"><xsl:if test="$pos='second' or position() != 1">;</xsl:if></xsl:with-param>                       
                     </xsl:call-template></xsl:for-each></xsl:for-each>
               </xsl:when>
               <xsl:when test="contains($part, 'FNORD-SPLIT') and contains($part, ' :')"><xsl:for-each select="tokenize($part, ' : ')"><xsl:call-template name="fnord-spliter">
                        <xsl:with-param name="line">    
                           <xsl:choose>
                              <xsl:when test="starts-with(normalize-space(.), 'FNORD-SPLIT')"><xsl:value-of select="substring-after(. , 'FNORD-SPLIT')"/></xsl:when>
                              <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
                           </xsl:choose>
                        </xsl:with-param>
                        <xsl:with-param name="delim"><xsl:if test="$pos='second' or position() != 1">;</xsl:if></xsl:with-param>                       
                     </xsl:call-template></xsl:for-each>
               </xsl:when>
               <xsl:when test="contains($part, 'FNORD-SPLIT') and contains($part, ' FNORD-DELIM') and starts-with($part, 'l. ')">
                  <xsl:for-each select="tokenize(substring-after($part, 'l. '), ' FNORD-DELIM ')"><xsl:call-template name="fnord-spliter">
                        <xsl:with-param name="line">    
                           <xsl:choose>
                              <xsl:when test="starts-with(normalize-space(.), 'FNORD-SPLIT')"><xsl:value-of select="substring-after(. , 'FNORD-SPLIT')"/></xsl:when>                             
                              <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
                           </xsl:choose>
                        </xsl:with-param>
                        <xsl:with-param name="delim"><xsl:if test="$pos='second' or position() != 1">;</xsl:if></xsl:with-param>   
                        <xsl:with-param name="tail">true</xsl:with-param>
                     </xsl:call-template></xsl:for-each>                  
               </xsl:when>
               <xsl:when test="contains($part, 'FNORD-SPLIT') and contains($part, ' FNORD-DELIM')">
                  <xsl:for-each select="tokenize($part, ' FNORD-DELIM ')"><xsl:call-template name="fnord-spliter">
                        <xsl:with-param name="line">    
                           <xsl:choose>
                              <xsl:when test="starts-with(normalize-space(.), 'FNORD-SPLIT')"><xsl:value-of select="substring-after(. , 'FNORD-SPLIT')"/></xsl:when>
                              <xsl:otherwise><xsl:value-of select="."/></xsl:otherwise>
                           </xsl:choose>
                        </xsl:with-param>
                        <xsl:with-param name="delim"><xsl:if test="$pos='second' or position() != 1">;</xsl:if></xsl:with-param>                       
                     </xsl:call-template></xsl:for-each>
               </xsl:when>
               <xsl:when test="contains($part, 'FNORD-SPLIT')"><xsl:call-template name="fnord-spliter">
                     <xsl:with-param name="line">
                        <xsl:choose>
                           <xsl:when test="starts-with(normalize-space($part), 'FNORD-SPLIT')"><xsl:value-of select="substring-after($part , 'FNORD-SPLIT')"/></xsl:when>
                           <xsl:otherwise>
                              <xsl:value-of select="$part"/></xsl:otherwise>
                        </xsl:choose>
                     </xsl:with-param>
                     <xsl:with-param name="delim"><xsl:if test="$pos='second'">;</xsl:if></xsl:with-param>   
                  </xsl:call-template></xsl:when>
               <xsl:when test="second">previous edition gave <xsl:value-of select="substring-after($part, ' :')"/></xsl:when>
            </xsl:choose></xsl:template>
      
   <xsl:template name="fnord-spliter">
      <xsl:param name="line"/>
      <xsl:param name="delim"/>
      <xsl:param name="tail"/><xsl:choose>
         <xsl:when test="$tail and not(contains($line, 'FNORD-SPLIT'))"><xsl:value-of select="$delim"/> <xsl:choose>
               <xsl:when test="contains($line,'prev. ed.') and not(starts-with(normalize-space($line), 'prev. ed.'))">
                  previous edition gave <xsl:value-of select="normalize-space(substring-before($line, 'prev. ed.'))"/><xsl:value-of select="normalize-space(substring-after($line, 'prev. ed.'))"/></xsl:when>
               <xsl:otherwise><xsl:value-of select="normalize-space($line)"/></xsl:otherwise>
            </xsl:choose></xsl:when>
         <xsl:otherwise><xsl:if test="contains($line, 'FNORD-SPLIT')">
               <xsl:value-of select="$delim"/><xsl:text> </xsl:text><xsl:choose>
                  <xsl:when test="contains(normalize-space($line), '(corr')">
                     <xsl:value-of select="normalize-space(substring-after($line, 'FNORD-SPLIT'))"/> reports scribe wrote  
                     <xsl:value-of select="normalize-space(substring-before(substring-after(substring-before(normalize-space($line), 'FNORD-SPLIT'), '(corr. ex'), ')'))"/>, then changed to 
                     <xsl:value-of select="normalize-space(substring-before(substring-before(normalize-space($line), 'FNORD-SPLIT'), '(corr. ex'))"/>
                  </xsl:when>
                  <xsl:otherwise><xsl:value-of select="normalize-space(substring-after($line, 'FNORD-SPLIT'))"/> gave <xsl:value-of select="normalize-space(substring-before($line, 'FNORD-SPLIT'))"/></xsl:otherwise></xsl:choose></xsl:if></xsl:otherwise>
      </xsl:choose></xsl:template> 
   
   <xsl:template name="childpart">
      <xsl:param name="part2"/>
      <xsl:param name="part1"/>
      <xsl:param name="childtype"/>
      <xsl:param name="apptype"/>

      <xsl:choose><xsl:when test="normalize-space($part2) = ''"><xsl:call-template name="fnord-seperator">
               <xsl:with-param name="part"><xsl:value-of select="$part1"/></xsl:with-param>
               <xsl:with-param name="pos">first</xsl:with-param>
            </xsl:call-template></xsl:when>
         <xsl:when test="contains($part1, ' : ')"><xsl:value-of select="substring-before($part1, ' :')"/></xsl:when>
         <xsl:otherwise>Current edition</xsl:otherwise>
      </xsl:choose>
      
      <xsl:if test="normalize-space($part2) != ''"> 
         <xsl:if test="starts-with(normalize-space($part1), 'cf.')"> which</xsl:if>  gives <xsl:value-of select="normalize-space($part2)"/><xsl:text> </xsl:text>
      </xsl:if>  
      
      <xsl:variable name="pt1"><xsl:call-template name="fnord-seperator">
            <xsl:with-param name="part"><xsl:value-of select="$part1"/></xsl:with-param>
            <xsl:with-param name="pos">second</xsl:with-param>
         </xsl:call-template>  
      </xsl:variable>
      
      <xsl:choose>
         <xsl:when test="not($apptype = ('apped', 'appbl', 'apppn', 'appalt')) and $childtype = ('apped', 'appbl', 'apppn') and starts-with(normalize-space($pt1), ';')"><xsl:value-of select="normalize-space(substring-after($pt1, ';'))"/></xsl:when>
         <xsl:otherwise><xsl:value-of select="$pt1"/></xsl:otherwise>
      </xsl:choose>    
   </xsl:template>
   

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

  <!-- DDBDP Apparatus framework -->
  <xsl:template name="tpl-apparatus">
    <!-- An apparatus is only created if one of the following is true -->
    <xsl:if test=".//t:choice | .//t:subst | .//t:app |        .//t:hi[@rend = 'diaeresis' or @rend = 'grave' or @rend = 'acute' or @rend = 'asper' or @rend = 'lenis' or @rend = 'circumflex'] |        .//t:del[@rend='slashes' or @rend='cross-strokes'] | .//t:milestone[@rend = 'box']">

      <h2>Apparatus</h2>
      <div id="apparatus">
        <!-- An entry is created for-each of the following instances
                  * choice, subst or app not nested in another;
                  * hi not nested in the app part of an app;
                  * del or milestone.
        -->
        <xsl:for-each select="(.//t:choice | .//t:subst | .//t:app)[not(ancestor::t:*[local-name()=('choice','subst','app')])] |                .//t:hi[@rend=('diaeresis','grave','acute','asper','lenis','circumflex')][not(ancestor::t:*[local-name()=('orig','reg','sic','corr','lem','rdg')                 or self::t:del[@rend='corrected']                 or self::t:add[@place='inline']][1][local-name()=('reg','corr','rdg')                 or self::t:del[@rend='corrected']])] |            .//t:del[@rend='slashes' or @rend='cross-strokes'] | .//t:milestone[@rend = 'box']">

          <!-- Found in tpl-apparatus.xsl -->
          <xsl:call-template name="ddbdp-app">
            <xsl:with-param name="apptype">
              <xsl:choose>
                <xsl:when test="self::t:choice[child::t:orig and child::t:reg]">
                  <xsl:text>origreg</xsl:text>
                </xsl:when>
                <xsl:when test="self::t:choice[child::t:sic and child::t:corr]">
                  <xsl:text>siccorr</xsl:text>
                </xsl:when>
                <xsl:when test="self::t:subst">
                  <xsl:text>subst</xsl:text>
                </xsl:when>
                <xsl:when test="self::t:app[@type='alternative']">
                  <xsl:text>appalt</xsl:text>
                </xsl:when>
                <xsl:when test="self::t:app[@type='editorial'][starts-with(t:lem/@resp,'BL ')]">
                  <xsl:text>appbl</xsl:text>
                </xsl:when>
                <xsl:when test="self::t:app[@type='editorial'][starts-with(t:lem/@resp,'PN ')]">
                  <xsl:text>apppn</xsl:text>
                </xsl:when>
                <xsl:when test="self::t:app[@type='editorial']">
                  <xsl:text>apped</xsl:text>
                </xsl:when>
              </xsl:choose>
            </xsl:with-param>
          </xsl:call-template>
        </xsl:for-each>
      </div>
    </xsl:if>
  </xsl:template>

  <!-- called from tpl-apparatus.xsl -->
  <xsl:template name="lbrk-app">
    <br/>
  </xsl:template>

  <!-- Used in htm-{element} and above to add linking to and from apparatus -->
  <xsl:template name="app-link">
    <!-- location defines the direction of linking -->
    <xsl:param name="location"/>
    <!-- Does not produce links for translations -->
    <xsl:if test="not(ancestor::t:div[@type = 'translation'])">
      <!-- Only produces a link if it is not nested in an element that would be in apparatus -->
      <xsl:if test="not((local-name() = 'choice' or local-name() = 'subst' or local-name() = 'app')          and (ancestor::t:choice or ancestor::t:subst or ancestor::t:app))">
        <xsl:variable name="app-num">
          <xsl:value-of select="name()"/>
          <xsl:number level="any" format="01"/>
        </xsl:variable>
        <xsl:call-template name="generate-app-link">
          <xsl:with-param name="location" select="$location"/>
          <xsl:with-param name="app-num" select="$app-num"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:if>
  </xsl:template>

  <!-- Called by app-link to generate the actual HTML, so other projects can override this template for their own style -->
  <xsl:template name="generate-app-link">
    <xsl:param name="location"/>
    <xsl:param name="app-num"/>
    <xsl:choose>
      <xsl:when test="$location = 'text'">
        <a>
          <xsl:attribute name="href">
            <xsl:text>#to-app-</xsl:text>
            <xsl:value-of select="$app-num"/>
          </xsl:attribute>
          <xsl:attribute name="id">
            <xsl:text>from-app-</xsl:text>
            <xsl:value-of select="$app-num"/>
          </xsl:attribute>
          <xsl:text>(*)</xsl:text>
        </a>
      </xsl:when>
      <xsl:when test="$location = 'apparatus'">
        <a>
          <xsl:attribute name="id">
            <xsl:text>to-app-</xsl:text>
            <xsl:value-of select="$app-num"/>
          </xsl:attribute>
          <xsl:attribute name="href">
            <xsl:text>#from-app-</xsl:text>
            <xsl:value-of select="$app-num"/>
          </xsl:attribute>
          <xsl:text>^</xsl:text>
        </a>
        <xsl:text> </xsl:text>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

  <!-- IOSPE "mini apparatus" framework  -->

  <!-- called from htm-teidivedition.xsl -->
  <xsl:template name="tpl-iospe-apparatus">
    <xsl:if test="not(descendant::t:div[@type='textpart'][@n]) and       (.//t:choice[child::t:corr] or .//t:supplied[@reason='omitted'] or .//t:subst or .//t:hi[@rend=('subscript','superscript')])">
      <xsl:variable name="listapp">
        <!-- generate a list of app entries, with line numbers for each (and render them later) -->
        <xsl:for-each select=".//(t:choice[child::t:corr]|t:supplied[@reason='omitted']|t:subst|t:hi[@rend=('subscript','superscript')])[not(ancestor::t:rdg)]">
          <xsl:element name="app">
            <!-- pseudo-id to avoid duplication of content words in miniapp -->
            <xsl:attribute name="psid" select="generate-id((ancestor::t:w|ancestor::t:name|ancestor::t:placeName|ancestor::t:num)[1])"/>
            <!-- number to group together miniapps from a single line -->
            <xsl:attribute name="n">
              <xsl:value-of select="preceding::t:lb[1]/@n"/>
              <!-- NOTE: need to handle line ranges -->
            </xsl:attribute>
            <xsl:choose>
              <xsl:when test="self::t:choice">
                <xsl:text>orig. </xsl:text>
                <xsl:call-template name="iospe-appcontext">
                  <!-- template below: strips diacritics, omits reg/corr/add/ex, and uppercases -->
                  <xsl:with-param name="context" select="(ancestor::t:w|ancestor::t:name|ancestor::t:placeName|ancestor::t:num)[1]"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="self::t:supplied">
                <xsl:text>orig. </xsl:text>
                <xsl:call-template name="iospe-appcontext">
                  <!-- template below: strips diacritics, omits reg/corr/add/ex, and uppercases -->
                  <xsl:with-param name="context" select="(ancestor::t:w|ancestor::t:name|ancestor::t:placeName|ancestor::t:num)[1]/text()"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="self::t:subst and child::t:add and child::t:del">
                <xsl:text>corr. ex </xsl:text>
                <xsl:call-template name="iospe-appcontext">
                  <!-- template below: strips diacritics, omits reg/corr/add/ex, and uppercases -->
                  <xsl:with-param name="context" select="(ancestor::t:w|ancestor::t:name|ancestor::t:placeName|ancestor::t:num)[1]"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="self::t:hi[@rend=('subscript','superscript')]">
                <xsl:apply-templates/>
                <xsl:choose>
                  <xsl:when test="@rend='subscript'">
                    <xsl:text> i.l.</xsl:text>
                  </xsl:when>
                  <xsl:when test="@rend='superscript'">
                    <xsl:text> s.l.</xsl:text>
                  </xsl:when>
                </xsl:choose>
              </xsl:when>
            </xsl:choose>
          </xsl:element>
        </xsl:for-each>
      </xsl:variable>
      <p class="miniapp">
        <xsl:if test="ancestor-or-self::t:div[@type='textpart'][@n]">
          <xsl:attribute name="id">
            <xsl:text>miniapp</xsl:text>
            <xsl:for-each select="ancestor-or-self::t:div[@type='textpart'][@n]">
              <xsl:value-of select="@n"/>
              <xsl:text>-</xsl:text>
            </xsl:for-each>
          </xsl:attribute>
        </xsl:if>
        <xsl:for-each select="$listapp/app">
          <xsl:if test="not(preceding-sibling::app[@psid=current()/@psid])">
            <xsl:if test="not(preceding-sibling::app[@n=current()/@n])">
              <xsl:value-of select="@n"/>
              <xsl:text>: </xsl:text>
            </xsl:if>
            <xsl:value-of select="."/>
            <xsl:if test="not(position()=last()) and not(following-sibling::app[@psid=current()/@psid])">
              <xsl:text>; </xsl:text>
            </xsl:if>
          </xsl:if>
        </xsl:for-each>
      </p>
    </xsl:if>
  </xsl:template>

  <xsl:template name="iospe-appcontext">
    <xsl:param name="context"/>
      <xsl:apply-templates mode="iospe-context" select="$context"/>
  </xsl:template>
  
  <xsl:template mode="iospe-context" match="t:reg|t:corr|t:add|t:ex|t:rdg"/>
  
  <xsl:template mode="iospe-context" match="text()">
    <xsl:value-of select="upper-case(translate(normalize-unicode(.,'NFD'),'́̓̔͂',''))"/>
  </xsl:template>
  
  <xsl:template mode="iospe-context" match="t:gap|t:supplied[@reason='lost']">
    <xsl:choose>
      <xsl:when test="@quantity ">
      <xsl:for-each select="1 to @quantity"><xsl:text>.</xsl:text></xsl:for-each>
    </xsl:when>
      <xsl:when test="@atMost">
        <xsl:for-each select="1 to @quantity"><xsl:text>.</xsl:text></xsl:for-each>
      </xsl:when>
      <xsl:when test="not(string(normalize-space(self::node())) = '')">
        <xsl:for-each select="1 to string-length(self::node())"><xsl:text>.</xsl:text></xsl:for-each>
      </xsl:when>
      <xsl:otherwise><xsl:text>...</xsl:text></xsl:otherwise>
    </xsl:choose>
  </xsl:template>


  <!-- called from htm-teidivedition.xsl -->

<!--this is the intended default which will deal with the widest range of simple apparatus note marked up inside the text
-->
  <xsl:template name="tpl-fullex-apparatus">

<xsl:variable name="listapp"><!-- generate a list of app entries, with line numbers for each (and render them later) -->

  <xsl:for-each select=".//t:corr[not(ancestor::t:choice)]">
    <xsl:element name="app">
      <xsl:attribute name="n">
        <xsl:value-of select="preceding::t:lb[1]/@n"/>
        <!-- NOTE: need to handle line ranges -->
      </xsl:attribute>
      <xsl:call-template name="intappcorr"/>
    </xsl:element>
  </xsl:for-each>

        <xsl:for-each select=".//t:choice[child::t:reg and not(ancestor::t:rdg)]">
          <xsl:element name="app">
            <xsl:attribute name="n">
              <xsl:value-of select="preceding::t:lb[1]/@n"/>
              <!-- NOTE: need to handle line ranges -->
            </xsl:attribute>
<xsl:call-template name="intappchoice"/>
          </xsl:element>
        </xsl:for-each>
       
  <xsl:for-each select=".//t:choice[child::t:corr and not(ancestor::t:rdg)]">
    <xsl:element name="app">
      <xsl:attribute name="n">
        <xsl:value-of select="preceding::t:lb[1]/@n"/>
        <!-- NOTE: need to handle line ranges -->
      </xsl:attribute>
      <xsl:call-template name="intappsiccorr"/>
    </xsl:element>
  </xsl:for-each>

  <xsl:for-each select=".//t:choice[child::t:unclear and not(ancestor::t:rdg)]">
    <xsl:element name="app">
      <xsl:attribute name="n">
        <xsl:value-of select="preceding::t:lb[1]/@n"/>
        <!-- NOTE: need to handle line ranges -->
      </xsl:attribute>
      <xsl:call-template name="intappunclear"/>
    </xsl:element>
  </xsl:for-each>

          <xsl:for-each select=".//t:subst[not(ancestor::t:rdg)]">
            <xsl:element name="app">
              <xsl:attribute name="n">
                <xsl:value-of select="preceding::t:lb[1]/@n"/>
                <!-- NOTE: need to handle line ranges -->
              </xsl:attribute>
              <xsl:call-template name="intappsubst"/>
            </xsl:element>
          </xsl:for-each>

  <xsl:for-each select=".//t:add[@place='overstrike' and not(ancestor::t:rdg or ancestor::t:subst)]">
    <xsl:element name="app">
      <xsl:attribute name="n">
        <xsl:value-of select="preceding::t:lb[1]/@n"/>
        <!-- NOTE: need to handle line ranges -->
      </xsl:attribute>
      <xsl:call-template name="intappoverstrike"/>
    </xsl:element>
  </xsl:for-each>

  <xsl:for-each select=".//t:add[@place=('above','below') and not(ancestor::t:rdg or ancestor::t:subst)]">
    <xsl:element name="app">
      <xsl:attribute name="n">
        <xsl:value-of select="preceding::t:lb[1]/@n"/>
        <!-- NOTE: need to handle line ranges -->
      </xsl:attribute>
      <xsl:call-template name="intappaddabovebelow"/>
    </xsl:element>
  </xsl:for-each>

            <xsl:for-each select=".//t:hi[@rend=('subscript','superscript') and not(ancestor::t:rdg)]">
              <xsl:element name="app">
                <xsl:attribute name="n">
                  <xsl:value-of select="preceding::t:lb[1]/@n"/>
                  <!-- NOTE: need to handle line ranges -->
                </xsl:attribute>
                <xsl:call-template name="intapphi"/>
              </xsl:element>
            </xsl:for-each>

  <xsl:for-each select=".//t:app[@type='editorial']">
    <xsl:element name="app">
      <xsl:attribute name="n">
        <xsl:value-of select="preceding::t:lb[1]/@n"/>
        <!-- NOTE: need to handle line ranges -->
      </xsl:attribute>
      <xsl:call-template name="intappedit"/>
    </xsl:element>
  </xsl:for-each>

  <xsl:for-each select=".//t:app[@type='alternative']">
    <xsl:element name="app">
      <xsl:attribute name="n">
        <xsl:value-of select="preceding::t:lb[1]/@n"/>
        <!-- NOTE: need to handle line ranges -->
      </xsl:attribute>
      <xsl:call-template name="intappapp"/>
    </xsl:element>
  </xsl:for-each>

       </xsl:variable>

<!--generate the actual apparatus printing the separators between each info and the reference to line number-->
      <p class="miniapp">
        <xsl:if test="ancestor-or-self::t:div[@type='textpart'][@n]">
          <xsl:attribute name="id">
            <xsl:text>miniapp</xsl:text>
            <xsl:for-each select="ancestor-or-self::t:div[@type='textpart'][@n]">
              <xsl:value-of select="@n"/>
              <xsl:text>-</xsl:text>
            </xsl:for-each>
          </xsl:attribute>
        </xsl:if>
        <xsl:for-each select="$listapp/app">
<xsl:sort select="@n" data-type="number"/>
          <xsl:if test="not(preceding-sibling::app[@n=current()/@n])">
            <xsl:text>l.</xsl:text>
<xsl:value-of select="@n"/>
            <xsl:text> </xsl:text>
          </xsl:if>
          <xsl:value-of select="."/>
          <xsl:if test="not(position()=last())">
            <xsl:text> | </xsl:text>
          </xsl:if>
        </xsl:for-each>
      </p>
  </xsl:template>
  

<!--this only renders choice and app-->
  <xsl:template name="tpl-minex-apparatus">
    
    <xsl:variable name="listapp"><!-- generate a list of app entries, with line numbers for each (and render them later) -->
      
      <xsl:for-each select=".//t:choice[child::t:reg and not(ancestor::t:rdg)]">
        <xsl:element name="app">
          <xsl:attribute name="n">
            <xsl:value-of select="preceding::t:lb[1]/@n"/>
            <!-- NOTE: need to handle line ranges -->
          </xsl:attribute>
          <xsl:call-template name="intappchoice"/>
        </xsl:element>
      </xsl:for-each>
      
      <xsl:for-each select=".//t:choice[child::t:corr and not(ancestor::t:rdg)]">
        <xsl:element name="app">
          <xsl:attribute name="n">
            <xsl:value-of select="preceding::t:lb[1]/@n"/>
            <!-- NOTE: need to handle line ranges -->
          </xsl:attribute>
          <xsl:call-template name="intappsiccorr"/>
        </xsl:element>
      </xsl:for-each>
      
      <xsl:for-each select=".//t:app[@type='editorial']">
        <xsl:element name="app">
          <xsl:attribute name="n">
            <xsl:value-of select="preceding::t:lb[1]/@n"/>
            <!-- NOTE: need to handle line ranges -->
          </xsl:attribute>
          <xsl:call-template name="intappedit"/>
        </xsl:element>
      </xsl:for-each>
      
      <xsl:for-each select=".//t:app[@type='alternative']">
        <xsl:element name="app">
          <xsl:attribute name="n">
            <xsl:value-of select="preceding::t:lb[1]/@n"/>
            <!-- NOTE: need to handle line ranges -->
          </xsl:attribute>
          <xsl:call-template name="intappapp"/>
        </xsl:element>
      </xsl:for-each>
      
    </xsl:variable>
    
    <!--generate the actual apparatus printing the separators between each info and the reference to line number-->
    <p class="miniapp">
      <xsl:if test="ancestor-or-self::t:div[@type='textpart'][@n]">
        <xsl:attribute name="id">
          <xsl:text>miniapp</xsl:text>
          <xsl:for-each select="ancestor-or-self::t:div[@type='textpart'][@n]">
            <xsl:value-of select="@n"/>
            <xsl:text>-</xsl:text>
          </xsl:for-each>
        </xsl:attribute>
      </xsl:if>
      <xsl:for-each select="$listapp/app">
        <xsl:sort select="@n" data-type="number"/>
        <xsl:if test="not(preceding-sibling::app[@n=current()/@n])">
          <xsl:text>l.</xsl:text>
          <xsl:value-of select="@n"/>
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="."/>
        <xsl:if test="not(position()=last())">
          <xsl:text> | </xsl:text>
        </xsl:if>
      </xsl:for-each>
    </p>
  </xsl:template>

<!--templates for each internal apparatus feature -->

<xsl:template name="intappapp">
<xsl:apply-templates select="t:rdg"/>
</xsl:template>

  <xsl:template name="intappedit">
    <xsl:if test="t:lem/@source"><xsl:value-of select="t:lem/@source"/><xsl:text>; </xsl:text></xsl:if>
      <xsl:apply-templates select="t:rdg"/>
      <xsl:if test="t:rdg/@source"><xsl:text> </xsl:text><xsl:value-of select="t:rdg/@source"/><xsl:text>; </xsl:text></xsl:if>
  </xsl:template>
  
<!--Correction Without Specification-->

  <xsl:template name="intappcorr">
    
        <xsl:value-of select="."/><xsl:text> corr.</xsl:text>
       
  </xsl:template>

  <!--   Erroneous Substitution

choice with sic and corr

-->
  <xsl:template name="intappsiccorr">
    
        <xsl:text>sic, orig. </xsl:text>
        <xsl:value-of select="t:sic"/>
  </xsl:template>

  <!-- Regularization

choice with reg and orig -->
  <xsl:template name="intappchoice">
    <xsl:if test="self::t:choice">
    <xsl:text>reg., orig. </xsl:text>
    <xsl:call-template name="iospe-appcontext">
      <!-- template below: strips diacritics, omits reg/corr/add/ex, and uppercases -->
      <xsl:with-param name="context" select="(ancestor::t:w|ancestor::t:name|ancestor::t:placeName|ancestor::t:num)[1]"/>
    </xsl:call-template>
  </xsl:if>
  <xsl:value-of select="t:orig"/>
</xsl:template>
  

  <!-- Ambiguous Characters With Alternatives Offered 
choice and multiple unclear (but this currently is not 
handled in the default to render in the text only one unclear or preferred letter)

-->
  <xsl:template name="intappunclear">
   
<xsl:if test="self::t:choice">
      </xsl:if>
    <xsl:for-each select="t:unclear">
      <xsl:if test="not(position()=1)">
        <xsl:text> aut </xsl:text></xsl:if>
<xsl:value-of select="."/></xsl:for-each>
  </xsl:template>


  <!-- Ancient Corrections (Where Both Old And New Text Can Be Read)
subst with del and add 

in the text the text  after correction is printed, in apparatus instead the text originally written
-->
  <xsl:template name="intappsubst">
     
  <xsl:if test="self::t:subst and child::t:add and child::t:del">
    <xsl:text>del </xsl:text>
    <xsl:call-template name="iospe-appcontext">
      <!-- template below: strips diacritics, omits reg/corr/add/ex, and uppercases -->
      <xsl:with-param name="context" select="(ancestor::t:w|ancestor::t:name|ancestor::t:placeName|ancestor::t:num)[1]"/>
    </xsl:call-template>
  </xsl:if>
  <xsl:value-of select="t:del"/>

  </xsl:template>
  


  <!-- Ancient Corrections (Old Text Lost) -->
  <xsl:template name="intappoverstrike">
         <xsl:value-of select="."/><xsl:text> del</xsl:text>
  </xsl:template>


  <!-- Text Addition By Ancient Hand 

<add place="above">αβ</add>
-->

  <xsl:template name="intappaddabovebelow">
    <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
   
        <xsl:value-of select="."/><xsl:text> add </xsl:text><xsl:value-of select="@place"/>
  </xsl:template>


  <!--Raised/Lowered Characters -->
  <xsl:template name="intapphi">
    <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
 
  <xsl:value-of select="@rend"/>
  </xsl:template>


</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-tpl-lang.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains all language related named templates -->  
  
  <xsl:template name="attr-lang">
      <xsl:if test="ancestor-or-self::t:*[@xml:lang]">
         <xsl:attribute name="lang">
            <xsl:value-of select="ancestor-or-self::t:*[@xml:lang][1]/@xml:lang"/>
         </xsl:attribute>
      </xsl:if>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-tpl-metadata.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Called from start-edition.xsl -->

  <xsl:template name="metadata">
      <p>
         <strong>Publikation: </strong>
         <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'principalEdition']             /t:listBibl/t:bibl[@type = 'publication' and @subtype = 'principal']/t:title[@type = 'abbreviated']"/>
         <xsl:text> </xsl:text>
         <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'principalEdition']             /t:listBibl/t:bibl[@type = 'publication' and @subtype = 'principal']/t:biblScope[@type='volume']"/>
         <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'principalEdition']             /t:listBibl/t:bibl[@type = 'publication' and @subtype = 'principal']/t:biblScope[@type='fascicle']"/>
         <xsl:text> </xsl:text>
         <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'principalEdition']             /t:listBibl/t:bibl[@type = 'publication' and @subtype = 'principal']/t:biblScope[@type='numbers']"/>
      </p>
      <xsl:if test="//t:div[@type = 'bibliography' and @subtype = 'otherPublications']">
         <p>
            <strong>Andere Publikationen: </strong>
            <xsl:for-each select="//t:div[@type = 'bibliography' and @subtype = 'otherPublications']//t:bibl">
               <xsl:value-of select="."/>
               <xsl:if test="following-sibling::t:bibl">
                  <xsl:text>; </xsl:text>
               </xsl:if>
            </xsl:for-each>
         </p>
      </xsl:if>
      <p>
         <strong>Datierung: </strong>
         <xsl:value-of select="//t:div[@type = 'commentary' and @subtype = 'textDate']             /t:p/t:date[@type = 'textDate']"/>
      </p>
      <p>
         <strong>Ort: </strong>
         <xsl:value-of select="//t:div[@type = 'history' and @subtype = 'locations']/t:p"/>
      </p>
      <p>
         <strong>Originaltitel: </strong>
         <xsl:value-of select="//t:teiHeader/t:fileDesc/t:titleStmt/t:title"/>
      </p>
      <p>
         <strong>Material: </strong>
         <xsl:value-of select="//t:div[@type = 'description']//t:rs[@type = 'material']"/>
      </p>
      <p>
         <strong>Abbildung: </strong>
         <xsl:choose>
            <xsl:when test="//t:div[@type='bibliography' and @subtype='illustrations']//t:bibl[@type = 'illustration']">
               <xsl:for-each select="//t:div[@type='bibliography' and @subtype='illustrations']//t:bibl[@type = 'illustration']">
                  <xsl:if test="preceding-sibling::t:bibl[@type = 'illustration']">
                     <xsl:text>, </xsl:text>
                  </xsl:if>
                  <xsl:value-of select="."/>
               </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text>keiner</xsl:text>
            </xsl:otherwise>
         </xsl:choose>
         <xsl:if test="string(//t:div[@type='figure']//t:figure/@href)">
            <xsl:for-each select="//t:div[@type='figure']//t:figure[string(@href)]">
               <br/>
               <a href="{@href}">
                  <xsl:value-of select="t:figDesc"/>
               </a>
            </xsl:for-each>
         </xsl:if>
      </p>
      <xsl:if test="//t:div[@type = 'bibliography' and @subtype = 'corrections']">
         <p>
            <strong>
               <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'corrections']/t:head"/>
               <xsl:text>: </xsl:text>
            </strong>
            <xsl:for-each select="//t:div[@type = 'bibliography' and @subtype = 'corrections']//t:bibl">
               <xsl:if test="preceding-sibling::t:bibl">
                  <xsl:text>, </xsl:text>
               </xsl:if>
               <xsl:value-of select="."/>
            </xsl:for-each>
         </p>
      </xsl:if>
      <p>
         <strong>Text der DDBDP: </strong>
         <xsl:variable name="db-link">
            <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'principalEdition']                /t:listBibl/t:bibl[@type = 'DDbDP']/t:series"/>
            <xsl:text>:volume=</xsl:text>
            <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'principalEdition']                /t:listBibl/t:bibl[@type = 'DDbDP']/t:biblScope[@type = 'volume']"/>
            <xsl:text>:document=</xsl:text>
            <xsl:value-of select="//t:div[@type = 'bibliography' and @subtype = 'principalEdition']                /t:listBibl/t:bibl[@type = 'DDbDP']/t:biblScope[@type = 'numbers']"/>
         </xsl:variable>
         <a>
            <xsl:attribute name="href">
               <xsl:text>http://www.perseus.tufts.edu/cgi-bin/ptext?doc=Perseus:text:1999.05.</xsl:text>
               <xsl:value-of select="$db-link"/>
            </xsl:attribute>
            <xsl:text>Server in Somerville</xsl:text>
         </a>
         <xsl:text> </xsl:text>
         <a>
            <xsl:attribute name="href">
               <xsl:text>http://perseus.mpiwg-berlin.mpg.de/cgi-bin/ptext?doc=Perseus:text:1999.05.</xsl:text>
               <xsl:value-of select="$db-link"/>
            </xsl:attribute>
            <xsl:text>Server in Berlin</xsl:text>
         </a>
      </p>
      <p>
         <strong>Bemerkungen: </strong>
         <xsl:value-of select="//t:div[@type = 'commentary' and @subtype = 'general']/t:p"/>
      </p>
      <xsl:if test="//t:div[@type='bibliography' and @subtype='translations']">
         <p>
            <strong>Übersetzungen: </strong>
            <xsl:for-each select="//t:div[@type='bibliography' and @subtype='translations']/t:listBibl">
               <xsl:value-of select="t:head"/>
               <xsl:text> </xsl:text>
               <xsl:for-each select="t:bibl[@type = 'translations']">
                  <xsl:if test="preceding-sibling::t:bibl[@type = 'translations']">
                     <xsl:text>, </xsl:text>
                  </xsl:if>
                  <xsl:value-of select="."/>
               </xsl:for-each>
            </xsl:for-each>
         </p>
      </xsl:if>
      <p>
         <strong>Inhalt: </strong>
         <xsl:for-each select="//t:teiHeader/t:profileDesc//t:keywords/t:term/t:rs[@type = 'textType']">
            <xsl:if test="preceding-sibling::t:rs">
               <xsl:text>, </xsl:text>
            </xsl:if>
            <xsl:value-of select="."/>
         </xsl:for-each>
      </p>
      <xsl:if test="//t:div[@type = 'commentary' and @subtype = 'mentionedDates']//t:date[@type = 'mentioned']">
         <p>
            <strong>
               <xsl:value-of select="//t:div[@type = 'commentary' and @subtype = 'mentionedDates']/t:head"/>
               <xsl:text>: </xsl:text>
            </strong>
            <xsl:for-each select="//t:div[@type = 'commentary' and @subtype = 'mentionedDates']/t:p">
               <xsl:value-of select="."/>
               <xsl:if test="following-sibling::t:p">
                  <xsl:text>; </xsl:text>
               </xsl:if>
            </xsl:for-each>
         </p>
      </xsl:if>

  </xsl:template>

</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-tpl-license.xsl"><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  
  <xsl:template name="license">
      <xsl:apply-templates select="//t:publicationStmt" mode="license"/>
  </xsl:template>
  
  <xsl:template match="t:publicationStmt" mode="license">
      <div id="license">
         <xsl:choose>
            <xsl:when test="p">
               <xsl:if test="contains(t:p/t:ref[@type='license']/@href,'creativecommons')">
                  <img src="http://i.creativecommons.org/l/{substring-after(t:p/t:ref[@type='license']/@href, 'licenses/')}88x31.png" alt="{t:p/t:ref[@type='license']}" align="left"/>
               </xsl:if>
               <xsl:apply-templates/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:if test="contains(t:availability/t:ref[@type='license']/@href,'creativecommons')">
                  <img src="http://i.creativecommons.org/l/{substring-after(t:availability/t:ref[@type='license']/@href, 'licenses/')}88x31.png" alt="{t:availability/t:ref[@type='license']}" align="left"/>
               </xsl:if>
               <xsl:apply-templates select="t:availability"/>
            </xsl:otherwise>
         </xsl:choose>
      </div>
  </xsl:template>
  
  <xsl:template match="t:ref[@type='license']">
      <a rel="license" href="{@href}">
         <xsl:apply-templates/>
      </a>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="htm-tpl-sqbrackets.xsl"><xsl:stylesheet exclude-result-prefixes="xs" version="2.0">
    <xd:doc xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Nov 2, 2011</xd:p>
            <xd:p><xd:b>Author:</xd:b> gbodard</xd:p>
            <xd:p><xd:b>Author:</xd:b> flawrence</xd:p>
            <xd:p><xd:b>Author:</xd:b> rviglianti</xd:p>
            <xd:p/>
        </xd:desc>
    </xd:doc>

    <xsl:template match="comment()" mode="sqbrackets">
        <xsl:sequence select="."/>
    </xsl:template>
    
    <xsl:template match="*" mode="sqbrackets">
        <xsl:element name="{name()}">
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="sqbrackets"/>
        </xsl:element>
    </xsl:template>
    
    <xsl:template match="br" mode="sqbrackets">
        <xsl:sequence select="."/>
    </xsl:template>
    
    <xsl:template match="text()" mode="sqbrackets">
        <xsl:variable name="me" select="."/>
        <xsl:variable name="startspace" select="if (matches(substring(.,1,1),'[\n\r\s\t]')) then ' ' else ''"/>
        <xsl:variable name="endspace" select="if (matches(substring(.,string-length(.)),'[\n\r\s\t]')) then ' ' else ''"/>
        <xsl:variable name="current" select="replace(normalize-space(.), '([^\]])\](\s*)\[([^\[])', '$1$2$3')"/>
        <xsl:variable name="strlength" select="string-length($current)"/>
        <xsl:variable name="firstletter" select="substring($current, 1, 1)"/>
        <xsl:variable name="lastletter" select="substring($current, $strlength)"/>
        
        <xsl:value-of select="$startspace"/>
        
        <xsl:choose>
            <xsl:when test="$firstletter = '[' or $lastletter = ']'">
                
                <xsl:variable name="previous" select="preceding::text()[1]"/>
                <xsl:variable name="after" select="following::text()[1]"/>
                
                <!-- get the first text node before the next br (if this node matches current text node then there is a br between this text node and the next text node so don't strip brackets) -->
                <xsl:variable name="beforenextbr" select="following::br[1]/preceding::text()[1]"/>
                
                <!-- get the first next node following the preceding br (if this node matches current text node then there is a br between this text node and the previous text node so don't strip brackets)-->
                <xsl:variable name="afterprevbr" select="preceding::br[1]/following::text()[1]"/>
                <xsl:variable name="afirstletter" select="substring(normalize-space($after), 1, 1)"/>
                <xsl:variable name="plastletter" select="substring(normalize-space($previous), string-length(normalize-space($previous)))"/>
                                
                <xsl:choose>
                    <xsl:when test="$firstletter = '[' and $lastletter = ']'                          and $plastletter = ']' and $afirstletter = '['                          and generate-id($afterprevbr) != generate-id(.)                          and generate-id($beforenextbr) != generate-id(.)">
                        <xsl:value-of select="substring($current, 2, string-length($current)-2)"/>
                    </xsl:when>
                    <xsl:when test="$plastletter = ']' and $firstletter = '[' and generate-id($afterprevbr) != generate-id(.)">
                        <xsl:value-of select="substring($current, 2)"/>
                    </xsl:when>
                    <xsl:when test="$afirstletter = '[' and $lastletter = ']' and generate-id($beforenextbr) != generate-id(.)">
                        <xsl:value-of select="substring($current, 1, string-length($current)-1)"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$current"/>
                    </xsl:otherwise>
                </xsl:choose>
                
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$current"/>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:value-of select="$endspace"/>
        
    </xsl:template>
    
</xsl:stylesheet></xsl:include>
   
   <!-- named templates for localized layout/structure (aka "metadata") -->
   <xsl:include href="htm-tpl-structure.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for default file structure (aka "metadata" aka "supporting data") -->  
   
  <!-- Specific named templates for HGV, InsLib, RIB, IOSPE, EDH, etc. are found in:
               htm-tpl-struct-hgv.xsl
               htm-tpl-struct-inslib.xsl
               htm-tpl-struct-rib.xsl
               htm-tpl-struct-iospe.xsl
               htm-tpl-struct-edh.xsl
               etc.
  -->
   
   <xsl:template name="london-structure">
      <xsl:call-template name="default-structure"/>
   </xsl:template>
   
   <xsl:template name="default-structure">
      <html>
         <head>
            <title>
               <xsl:call-template name="default-title"/>
            </title>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <!-- Found in htm-tpl-cssandscripts.xsl -->
            <xsl:call-template name="css-script"/>
         </head>
         <body>
           <xsl:call-template name="default-body-structure"/>
         </body>
      </html>
   </xsl:template>

   <xsl:template name="default-body-structure">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <!-- Heading for a ddb style file -->
       <xsl:if test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
         <h1>
            <xsl:choose>
               <xsl:when test="//t:sourceDesc//t:bibl/text()">
                  <xsl:value-of select="//t:sourceDesc//t:bibl"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="//t:idno[@type='filename']"/>
               </xsl:otherwise>
            </xsl:choose>
         </h1>
      </xsl:if>
      
      <!-- Main text output -->
      <xsl:variable name="maintxt">
         <xsl:apply-templates/>
      </xsl:variable>
      <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
      <xsl:variable name="maintxt2">
      <xsl:apply-templates select="$maintxt" mode="sqbrackets"/>
      </xsl:variable>
      <xsl:apply-templates select="$maintxt2" mode="sqbrackets"/>
      
      <!-- Found in htm-tpl-license.xsl -->
      <xsl:call-template name="license"/>
   </xsl:template>

   <xsl:template name="default-title">
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
            <xsl:choose>
               <xsl:when test="//t:sourceDesc//t:bibl/text()">
                  <xsl:value-of select="//t:sourceDesc//t:bibl"/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="//t:idno[@type='filename']"/>
               </xsl:otherwise>
            </xsl:choose>
         </xsl:when>
         <xsl:when test="//t:titleStmt/t:title/text()">
            <xsl:if test="//t:idno[@type='filename']/text()">
               <xsl:value-of select="//t:idno[@type='filename']"/>
               <xsl:text>. </xsl:text>
            </xsl:if>
            <xsl:value-of select="//t:titleStmt/t:title"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>EpiDoc example output, default style</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-dol.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Contains named templates for the DOL file structure -->  

   <xsl:template name="dol-body-structure">
      <p><b>Tablet: </b>
      <xsl:choose>
         <xsl:when test="//t:support/t:p/text()">
            <xsl:apply-templates select="//t:support/t:p" mode="dol-dimensions"/>
         </xsl:when>
         <xsl:when test="//t:support//text()">
            <xsl:apply-templates select="//t:support" mode="dol-dimensions"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b>Dialect: </b>
      <xsl:choose>
         <xsl:when test="//t:layoutDesc/t:layout//text()">
            <xsl:value-of select="//t:layoutDesc/t:layout"/>
         </xsl:when>
         <xsl:otherwise>Unknown.</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b>Alphabet: </b>
      <xsl:if test="//t:handDesc/t:handNote/text()">
         <xsl:value-of select="//t:handDesc/t:handNote"/>
      </xsl:if>
      </p>

      <p><b>Date: </b>
      <xsl:choose>
         <xsl:when test="//t:origin/t:origDate/text()">
            <xsl:value-of select="//t:origin/t:origDate"/>
            <xsl:if test="//t:origin/t:origDate[@type='evidence']">
               <xsl:text>(</xsl:text>
               <xsl:for-each select="tokenize(//t:origin/t:origDate[@evidence],' ')">
                  <xsl:value-of select="translate(.,'-',' ')"/>
                  <xsl:if test="position()!=last()">
                     <xsl:text>, </xsl:text>
                  </xsl:if>
               </xsl:for-each>
               <xsl:text>)</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise>Unknown.</xsl:otherwise>
      </xsl:choose>
      </p>

      <p><b>Findspot: </b>
      <xsl:choose>
         <xsl:when test="//t:provenance[@type='found'][string(translate(normalize-space(.),' ',''))]">
            <xsl:apply-templates select="//t:provenance[@type='found']" mode="dol-placename"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b>Original location: </b>
      <xsl:choose>
         <xsl:when test="//t:origin/t:origPlace/text()">
            <xsl:apply-templates select="//t:origin/t:origPlace" mode="dol-placename"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b>Current location: </b>
      <xsl:choose>
         <xsl:when test="//t:provenance[@type='observed'][string(translate(normalize-space(.),' ',''))]">
            <xsl:apply-templates select="//t:provenance[@type='observed']" mode="dol-placename"/>
            <!-- Named template found below. -->
            <xsl:call-template name="dol-invno"/>
         </xsl:when>
         <xsl:when test="//t:msIdentifier//t:repository[string(translate(normalize-space(.),' ',''))]">
            <xsl:value-of select="//t:msIdentifier//t:repository[1]"/>
            <!-- Named template found below. -->
            <xsl:call-template name="dol-invno"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>
      </p>

      <p>
         <b>Bibliography: </b>
         <xsl:apply-templates select="//t:div[@type='bibliography']/t:p/node()"/>
         <br/>
         <b>Editor: </b>
         <xsl:apply-templates select="//t:editor"/>
         <br/>
         <b>Text constituted from: </b>
         <xsl:apply-templates select="//t:creation"/>
      </p>

      <div id="edition">
         <!-- Edited text output -->
         <xsl:variable name="edtxt">
            <xsl:apply-templates select="//t:div[@type='edition']"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
      </div>

      <div id="apparatus">
         <h4 class="slimmer">Apparatus:</h4>
         <!-- Apparatus text output -->
         <xsl:variable name="apptxt">
            <xsl:apply-templates select="//t:div[@type='apparatus']//t:p"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
      </div>

      <div id="translation">
         <h4 class="slimmer">Translation:</h4>
         <!-- Translation text output -->
         <xsl:variable name="transtxt">
            <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
      </div>

      <div id="commentary">
         <h4 class="slimmer">Commentary:</h4>
         <!-- Commentary text output -->
         <xsl:variable name="commtxt">
            <xsl:apply-templates select="//t:div[@type='commentary']//t:p"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
      </div>

      <p><b>Themes / Keywords: </b>
      <xsl:if test="//t:textClass/t:keywords/t:list/t:item/text()">
         <xsl:value-of select="//t:textClass/t:keywords/t:list/t:item"/>
      </xsl:if>
      </p>
   </xsl:template>

   <!-- Called from htm-tpl-structure.xsl -->
   <xsl:template name="dol-structure">
      <xsl:variable name="title">
         <xsl:call-template name="dol-title"/>
      </xsl:variable>
      
      <html>
         <head>
            <title>
               <xsl:value-of select="$title"/>
            </title>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <!-- Found in htm-tpl-cssandscripts.xsl -->
            <xsl:call-template name="css-script"/>
         </head>
         
         <body>
            <h1>
               <xsl:value-of select="$title"/>
            </h1>
            <xsl:call-template name="dol-body-structure"/>
         </body>
      </html>
   </xsl:template>
   
   <xsl:template match="t:dimensions" mode="dol-dimensions">
      <xsl:if test="text()">
         <xsl:if test="t:width/text()">w: 
            <xsl:value-of select="t:width"/>
            <xsl:if test="t:height/text()">
               <xsl:text> x </xsl:text>
            </xsl:if>
         </xsl:if>
         <xsl:if test="t:height/text()">h: 
            <xsl:value-of select="t:height"/>
         </xsl:if>
         <xsl:if test="t:depth/text()">x d:
            <xsl:value-of select="t:depth"/>
         </xsl:if>
         <xsl:if test="t:dim[@type='diameter']/text()">x diam.:
            <xsl:value-of select="t:dim[@type='diameter']"/>
         </xsl:if>
      </xsl:if>
   </xsl:template>
   
   <xsl:template match="t:placeName|t:rs" mode="dol-placename">
      <xsl:choose>
         <xsl:when test="contains(@ref,'pleiades.stoa.org') or contains(@ref,'geonames.org')">
            <a>
               <xsl:attribute name="href">
                  <xsl:value-of select="@ref"/>
               </xsl:attribute>
               <xsl:apply-templates/>
            </a>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   
   <xsl:template name="dol-invno">
      <xsl:if test="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
         <xsl:text> (Inv. no. </xsl:text>
         <xsl:for-each select="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
            <xsl:value-of select="."/>
            <xsl:if test="position()!=last()">
               <xsl:text>, </xsl:text>
            </xsl:if>
         </xsl:for-each>
         <xsl:text>)</xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template name="dol-title">
      <xsl:choose>
         <xsl:when test="//t:titleStmt/t:title/text() and number(substring(//t:publicationStmt/t:idno[@type='filename']/text(),2,5))">
            <xsl:value-of select="substring(//t:publicationStmt/t:idno[@type='filename'],1,1)"/> 
            <xsl:text>. </xsl:text>
            <xsl:value-of select="number(substring(//t:publicationStmt/t:idno[@type='filename'],2,5)) div 100"/> 
            <xsl:text>. </xsl:text>
            <xsl:value-of select="//t:titleStmt/t:title"/>
         </xsl:when>
         <xsl:when test="//t:titleStmt/t:title/text()">
            <xsl:value-of select="//t:titleStmt/t:title"/>
         </xsl:when>
         <xsl:when test="//t:sourceDesc//t:bibl/text()">
            <xsl:value-of select="//t:sourceDesc//t:bibl"/>
         </xsl:when>
         <xsl:when test="//t:idno[@type='filename']/text()">
            <xsl:value-of select="//t:idno[@type='filename']"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>EpiDoc example output, Dodone Online style</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-eagle.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
	<!-- Contains named templates for default file structure (aka "metadata" aka "supporting data") -->  
	
	<!-- Specific named templates for HGV, InsLib, RIB, IOSPE, EDH, etc. are found in:
               htm-tpl-struct-hgv.xsl
               htm-tpl-struct-inslib.xsl
               htm-tpl-struct-rib.xsl
               htm-tpl-struct-iospe.xsl
               htm-tpl-struct-edh.xsl
               etc.
  -->
	
	
	<xsl:template name="eagle-structure">
		<xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
		<xsl:param name="parm-line-inc" tunnel="yes" required="no" as="xs:double"/>
		<html>
			<head>
				<title>
					<xsl:choose>
						<xsl:when test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
							<xsl:choose>
								<xsl:when test="//t:sourceDesc//t:bibl/text()">
									<xsl:value-of select="//t:sourceDesc//t:bibl"/>
								</xsl:when>
								<xsl:otherwise>
									<xsl:value-of select="//t:idno[@type='filename']"/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:when>
						<xsl:when test="//t:titleStmt/t:title/text()">
							<xsl:if test="//t:idno[@type='filename']/text()">
								<xsl:value-of select="//t:idno[@type='filename']"/>
								<xsl:text>. </xsl:text>
							</xsl:if>
							<xsl:value-of select="//t:titleStmt/t:title"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:text>EpiDoc example output, default style</xsl:text>
						</xsl:otherwise>
					</xsl:choose>
				</title>
				<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
				<!-- Found in htm-tpl-cssandscripts.xsl -->
				<xsl:call-template name="css-script"/>
			</head>
			<body>
				<xsl:call-template name="eagle-body-structure"/>
			</body>
			<eagleinlinetext>
				<xsl:call-template name="eagle-body-structure2"/>
			</eagleinlinetext>
		</html>
	</xsl:template>
	
	<xsl:template name="eagle-body-structure">
	
		<!-- Main text output -->
		<xsl:variable name="maintxt">
			<xsl:apply-templates/>
		</xsl:variable>
		<!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
		<xsl:variable name="maintxt2">
			<xsl:apply-templates select="$maintxt" mode="sqbrackets"/>
		</xsl:variable>
		<xsl:apply-templates select="$maintxt2" mode="sqbrackets"/>
		
		<!-- Found in htm-tpl-license.xsl -->
		<xsl:call-template name="license"/>
	</xsl:template>

	
	
	<xsl:template name="eagle-body-structure2">
		<xsl:variable name="withspaces"><xsl:apply-templates select=".//t:div/t:ab">
			<xsl:with-param name="parm-leiden-style" tunnel="yes">eagletxt</xsl:with-param>
		</xsl:apply-templates></xsl:variable>
		<xsl:variable name="withspaces2"><xsl:apply-templates select="$withspaces" mode="sqbrackets"/></xsl:variable>
		<xsl:value-of select="normalize-space($withspaces2)"/>
	</xsl:template>
	


	
</xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-edak.xsl"><!-- $Id: htm-tpl-struct-edak.xsl 2561 2017-04-04 11:24:24Z gabrielbodard $ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Contains named templates for EDAK file structure -->

   <xsl:template name="edak-body-structure">
      <p><b>Edition: </b>
      <xsl:apply-templates select="//t:div[@type='bibliography']/t:p/node()"/>
      <xsl:if test="//t:creation//text()">
         <br/>
         <b>Text constituted from: </b>
         <xsl:apply-templates select="//t:creation"/>
      </xsl:if>
      </p>

      <p><b>Description: </b>
      <xsl:choose>
         <xsl:when test="//t:support/t:p/text()">
            <xsl:apply-templates select="//t:support/t:p" mode="edak-dimensions"/>
         </xsl:when>
         <xsl:when test="//t:support//text()">
            <xsl:apply-templates select="//t:support" mode="edak-dimensions"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>

      <br/>
      <b>Text: </b>
      <xsl:choose>
         <xsl:when test="//t:layoutDesc/t:layout//text()">
            <xsl:value-of select="//t:layoutDesc/t:layout"/>
         </xsl:when>
         <xsl:otherwise>Unknown.</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b>Letters: </b>
      <xsl:if test="//t:handDesc/t:handNote/text()">
         <xsl:value-of select="//t:handDesc/t:handNote"/>
      </xsl:if>
      </p>

      <p><b>Date: </b>
      <xsl:choose>
         <xsl:when test="//t:origin/t:origDate/text()">
            <xsl:value-of select="//t:origin/t:origDate"/>
            <xsl:if test="//t:origin/t:origDate[@type='evidence']">
               <xsl:text>(</xsl:text>
               <xsl:for-each select="tokenize(//t:origin/t:origDate[@evidence],' ')">
                  <xsl:value-of select="translate(.,'-',' ')"/>
                  <xsl:if test="position()!=last()">
                     <xsl:text>, </xsl:text>
                  </xsl:if>
               </xsl:for-each>
               <xsl:text>)</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise>Unknown.</xsl:otherwise>
      </xsl:choose>
      </p>

      <p><b>Findspot: </b>
      <xsl:choose>
         <xsl:when test="//t:provenance[@type='found'][string(translate(normalize-space(.),' ',''))]">
            <xsl:apply-templates select="//t:provenance[@type='found']" mode="edak-placename"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b>Original location: </b>
      <xsl:choose>
         <xsl:when test="//t:origin/t:origPlace/text()">
            <xsl:apply-templates select="//t:origin/t:origPlace" mode="edak-placename"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b>Last recorded location: </b>
      <xsl:choose>
         <xsl:when test="//t:provenance[@type='observed'][string(translate(normalize-space(.),' ',''))]">
            <xsl:apply-templates select="//t:provenance[@type='observed']" mode="edak-placename"/>
            <!-- Named template found below. -->
            <xsl:call-template name="edak-invno"/>
         </xsl:when>
         <xsl:when test="//t:msIdentifier//t:repository[string(translate(normalize-space(.),' ',''))]">
            <xsl:value-of select="//t:msIdentifier//t:repository[1]"/>
            <!-- Named template found below. -->
            <xsl:call-template name="edak-invno"/>
         </xsl:when>
         <xsl:otherwise>Unknown</xsl:otherwise>
      </xsl:choose>
      </p>

      <div id="edition">
         <p><b>Edition:</b></p>
         <!-- Edited text output -->
         <xsl:variable name="edtxt">
            <xsl:apply-templates select="//t:div[@type='edition']"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
      </div>

      <div id="apparatus">
         <!-- Apparatus text output -->
         <xsl:variable name="apptxt">
            <xsl:apply-templates select="//t:div[@type='apparatus']"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
      </div>

      <div id="translation">
         <h4 class="slimmer">Translation:</h4>
         <!-- Translation text output -->
         <xsl:variable name="transtxt">
            <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
      </div>

      <div id="commentary">
         <h4 class="slimmer">Commentary:</h4>
         <!-- Commentary text output -->
         <xsl:variable name="commtxt">
            <xsl:apply-templates select="//t:div[@type='commentary']//t:p"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
      </div>
   </xsl:template>

   <!-- Called from htm-tpl-structure.xsl -->

   <xsl:template name="edak-structure">
      <xsl:variable name="title">
         <xsl:call-template name="edak-title"/>
      </xsl:variable>

      <html>
         <head>
            <title>
               <xsl:value-of select="$title"/>
            </title>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <!-- Found in htm-tpl-cssandscripts.xsl -->
            <xsl:call-template name="css-script"/>
         </head>

         <body>
            <h1>
               <xsl:value-of select="$title"/>
            </h1>

            <xsl:call-template name="edak-body-structure"/>
         </body>
      </html>
   </xsl:template>

   <xsl:template match="t:dimensions" mode="edak-dimensions">
      <xsl:if test="//text()">
         <xsl:if test="t:width/text()">w: 
            <xsl:value-of select="t:width"/>
            <xsl:if test="t:height/text()">
               <xsl:text> x </xsl:text>
            </xsl:if>
         </xsl:if>
         <xsl:if test="t:height/text()">h: 
            <xsl:value-of select="t:height"/>
         </xsl:if>
         <xsl:if test="t:depth/text()">x d:
            <xsl:value-of select="t:depth"/>
         </xsl:if>
         <xsl:if test="t:dim[@type='diameter']/text()">x diam.:
            <xsl:value-of select="t:dim[@type='diameter']"/>
         </xsl:if>
      </xsl:if>
   </xsl:template>

   <xsl:template match="t:placeName|t:rs" mode="edak-placename">
      <xsl:choose>
         <xsl:when test="contains(@ref,'pleiades.stoa.org') or contains(@ref,'geonames.org')">
            <a>
               <xsl:attribute name="href">
                  <xsl:value-of select="@ref"/>
               </xsl:attribute>
               <xsl:apply-templates/>
            </a>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="edak-invno">
      <xsl:if test="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
         <xsl:text> (Inv. no. </xsl:text>
         <xsl:for-each select="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
            <xsl:value-of select="."/>
            <xsl:if test="position()!=last()">
               <xsl:text>, </xsl:text>
            </xsl:if>
         </xsl:for-each>
         <xsl:text>)</xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template name="edak-title">
      <xsl:choose>
         <xsl:when test="//t:titleStmt/t:title/text() and number(substring(//t:publicationStmt/t:idno[@type='filename']/text(),2,5))">
            <xsl:value-of select="substring(//t:publicationStmt/t:idno[@type='filename'],1,1)"/>
            <xsl:text>. </xsl:text>
            <xsl:value-of select="number(substring(//t:publicationStmt/t:idno[@type='filename'],2,5)) div 100"/>
            <xsl:text>. </xsl:text>
            <xsl:value-of select="//t:titleStmt/t:title"/>
         </xsl:when>
         <xsl:when test="//t:titleStmt/t:title/text()">
            <xsl:value-of select="//t:titleStmt/t:title"/>
         </xsl:when>
         <xsl:when test="//t:sourceDesc//t:bibl/text()">
            <xsl:value-of select="//t:sourceDesc//t:bibl"/>
         </xsl:when>
         <xsl:when test="//t:idno[@type='filename']/text()">
            <xsl:value-of select="//t:idno[@type='filename']"/>
         </xsl:when>
         <xsl:otherwise>
            <xsl:text>EpiDoc example output, edak style</xsl:text>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

</xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-edh.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for EDH file structure (aka "metadata" aka "supporting data") -->  
   
   <!-- Called from htm-tpl-structure.xsl -->
   
   <xsl:template name="edh-structure">
      <xsl:call-template name="default-structure"/>
   </xsl:template>
   
   </xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-hgv.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for HGV file structure (aka "metadata" aka "supporting data") -->  
   
  <!-- Called from htm-tpl-structure.xsl -->
   
   <xsl:template name="hgv-structure">
       <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
       <html>
         <head>
            <title>
               <xsl:choose>
                  <xsl:when test="//t:sourceDesc//t:bibl/text()">
                     <xsl:value-of select="//t:sourceDesc//t:bibl"/>
                  </xsl:when>
                  <xsl:when test="//t:idno[@type='filename']/text()">
                     <xsl:value-of select="//t:idno[@type='filename']"/>
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:text/>
                  </xsl:otherwise>
               </xsl:choose>
            </title>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <!-- Found in htm-tpl-cssandscripts.xsl -->
            <xsl:call-template name="css-script"/>
         </head>
         <body>
            
            <!-- Heading for a ddb style file -->
             <xsl:if test="($parm-leiden-style = 'ddbdp' or $parm-leiden-style = 'sammelbuch')">
               <h1>
                  <xsl:choose>
                     <xsl:when test="//t:sourceDesc//t:bibl/text()">
                        <xsl:value-of select="//t:sourceDesc//t:bibl"/>
                     </xsl:when>
                     <xsl:otherwise>
                        <xsl:value-of select="//t:idno[@type='filename']"/>
                     </xsl:otherwise>
                  </xsl:choose>
               </h1>
            </xsl:if>         
            
            <!-- Main text output -->
            <xsl:apply-templates select="//div[@type='edition']"/>
            
            <!-- Found in htm-tpl-license.xsl -->
            <xsl:call-template name="license"/>
            
         </body>
      </html>
   </xsl:template>
   
   </xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-igcyr.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- 
 WORK IN PROGRESS file structure for IGCYR 
meant to be run in a folder with other data locally referred
  -->

   <!-- Called from htm-tpl-structure.xsl -->

   <xsl:template name="igcyr-structure">
      <xsl:variable name="title">
         <xsl:choose>
            <xsl:when test="//t:titleStmt/t:title/text()">
               <xsl:if test="//t:publicationStmt/t:idno[@type='filename']/text()">
                  <xsl:value-of select="substring(//t:publicationStmt/t:idno[@type='filename'],1,5)"/>
                  <xsl:text> </xsl:text>
                  <xsl:value-of select="number(substring(//t:publicationStmt/t:idno[@type='filename'],6,6)) div 100"/>
                  <xsl:text> </xsl:text>
               </xsl:if>
               <xsl:value-of select="//t:titleStmt/t:title"/>
            </xsl:when>
            <xsl:when test="//t:sourceDesc//t:bibl/text()">
               <xsl:value-of select="//t:sourceDesc//t:bibl"/>
            </xsl:when>
            <xsl:when test="//t:idno[@type='filename']/text()">
               <xsl:value-of select="//t:idno[@type='filename']"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text>EpiDoc example output, InsLib style</xsl:text>
            </xsl:otherwise>
         </xsl:choose>
      </xsl:variable>

      <html>
         <head>
            <title>
               <xsl:value-of select="$title"/>
            </title>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <!-- Found in htm-tpl-cssandscripts.xsl -->
            <xsl:call-template name="css-script"/>
         </head>

         <body>
            <h1>
               <xsl:value-of select="$title"/>
            </h1>

            <div class="sourceDesc">
               <h3>Source Description</h3>
               <b>Support: </b>
               <xsl:choose>
                  <xsl:when test="//t:support/t:p/text()">
                     <xsl:apply-templates select="//t:support/t:p" mode="inslib-dimensions"/>
                  </xsl:when>
                  <xsl:otherwise>Unknown</xsl:otherwise>
               </xsl:choose>
               <br/>
               <b>Leyout: </b>
               <xsl:choose>
                  <xsl:when test="//t:layoutDesc/t:layout//text()">
                     <xsl:value-of select="//t:layoutDesc/t:layout"/>
                  </xsl:when>
                  <xsl:otherwise>Unknown.</xsl:otherwise>
               </xsl:choose>
               <br/>
               <b>Letters: </b>
               <xsl:if test="//t:handDesc/t:handNote/text()">
                  <xsl:value-of select="//t:handDesc/t:handNote"/>
               </xsl:if>
            <br/>
               <b>Origin Place: </b>
               <xsl:choose>
                  <xsl:when test="//t:provenance[@type='found'][string(translate(normalize-space(.),' ',''))]">
                     <xsl:apply-templates select="//t:provenance[@type='found']" mode="inslib-placename"/>
                  </xsl:when>
                  <xsl:otherwise>Unknown</xsl:otherwise>
               </xsl:choose>
               <br/>
                  <b>Date: </b>
                  <xsl:choose>
                     <xsl:when test="//t:origin/t:origDate/text()">
                        <xsl:value-of select="//t:origin/t:origDate"/>
                        <xsl:if test="//t:origin/t:origDate[@type='evidence']">
                           <xsl:text>(</xsl:text>
                           <xsl:for-each select="tokenize(//t:origin/t:origDate[@evidence],' ')">
                              <xsl:value-of select="translate(.,'-',' ')"/>
                              <xsl:if test="position()!=last()">
                                 <xsl:text>, </xsl:text>
                              </xsl:if>
                           </xsl:for-each>
                           <xsl:text>)</xsl:text>
                        </xsl:if>
                     </xsl:when>
                     <xsl:otherwise>Unknown.</xsl:otherwise>
                  </xsl:choose>
               
               <br/>
               <b>Provenance: </b>
               <xsl:choose>
                  <xsl:when test="//t:origin/t:origPlace/text()">
                     <xsl:apply-templates select="//t:origin/t:origPlace" mode="igcyr-placename"/>
                  </xsl:when>
                  <xsl:otherwise>Unknown</xsl:otherwise>
               </xsl:choose>
               <br/>
            </div>
               <div class="physDesc">
                  <h4>Description: </h4>
               <b>Observed: </b>
               <xsl:choose>
                  <xsl:when test="//t:provenance[@type='observed'][string(translate(normalize-space(.),' ',''))]">
                     <xsl:apply-templates select="//t:provenance[@type='observed']" mode="inslib-placename"/>
                     <!-- Named template found below. -->
                     <xsl:call-template name="igcyr-invno"/>
                  </xsl:when>
                  <xsl:when test="//t:msIdentifier//t:repository[string(translate(normalize-space(.),' ',''))]">
                     <xsl:value-of select="//t:msIdentifier//t:repository[1]"/>
                     <!-- Named template found below. -->
                     <xsl:call-template name="igcyr-invno"/>
                  </xsl:when>
                  <xsl:otherwise>Unknown</xsl:otherwise>
               </xsl:choose>
            
            <br/>
               <b>Bibliography: </b>
               <xsl:copy>
                  <xsl:apply-templates select="//t:div[@type='bibliography']//t:p" mode="bibliog"/>        
               </xsl:copy>
               <br/>
               <b>Text constituted from: </b>
               <xsl:apply-templates select="//t:creation"/>
            </div>
            <br/>
            <div id="edition">
              <!-- <p>
                  <b>Edition:</b>
               </p>-->
               <!-- Edited text output -->
               <xsl:variable name="edtxt">
                  <xsl:apply-templates select="//t:div[@type='edition']"/>
               </xsl:variable>
               <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
               <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
            </div>
            <br/>
            <div id="apparatus">
               <!-- Apparatus text output -->
               <xsl:variable name="apptxt">
                  <xsl:apply-templates select="//t:div[@type='apparatus']"/>
               </xsl:variable>
               <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
               <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
            </div>


            <div id="translation">
               <h4 class="slimmer">Translation:</h4>
               <!-- Translation text output -->
               <xsl:variable name="transtxt">
                  <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
               </xsl:variable>
               <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
               <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
            </div>

            <div id="commentary">
               <h4 class="slimmer">Commentary:</h4>
               <!-- Commentary text output -->
               <xsl:variable name="commtxt">
                  <xsl:apply-templates select="//t:div[@type='commentary']//t:p"/>
               </xsl:variable>
               <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
               <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
            </div>
         </body>
      </html>
   </xsl:template>

   <xsl:template match="//t:bibl" mode="bibliog">
   
      <xsl:choose><xsl:when test=".[t:ptr]">
         
         <a href="{concat('../files/Bibliography', ./t:ptr/@target)}">   <xsl:variable name="extendedbib">
            <xsl:variable name="biblentry" select="substring-after(./t:ptr/@target, '#')"/>
            <xsl:for-each select="$biblentry">
               
               <xsl:choose>
                  <xsl:when test="document('Workspace/files/BIBLIOGRAPHY.xml')//t:bibl[@xml:id = $biblentry]">
                     <xsl:for-each select="document('Workspace/files/BIBLIOGRAPHY.xml')//t:bibl[@xml:id = $biblentry]">
                        <xsl:choose><xsl:when test="t:author"><xsl:value-of select="t:author[1]/t:name[@type='surname']"/>
                        <xsl:if test="t:author[2]">
                           <xsl:text>-</xsl:text>
                           <xsl:value-of select="t:author[2]/t:name[@type='surname']"/>
                        </xsl:if></xsl:when>
                        <xsl:when test="t:editor">
                           <xsl:value-of select="t:editor[1]/t:name[@type='surname']"/>
                           <xsl:if test="t:editor[2]">
                              <xsl:text>-</xsl:text>
                              <xsl:value-of select="t:editor[2]/t:name[@type='surname']"/>
                           </xsl:if>
                        </xsl:when></xsl:choose>
                        <xsl:text> </xsl:text><xsl:value-of select="t:date"/>
                     </xsl:for-each>
                     
                  </xsl:when>
                  <xsl:otherwise>
                     <xsl:text> !</xsl:text><xsl:value-of select="$biblentry"/><xsl:text>!</xsl:text>
                  </xsl:otherwise>
               </xsl:choose>
               
            </xsl:for-each>
            
         </xsl:variable>
            
            <xsl:value-of select="$extendedbib"/> <xsl:value-of select="."/>
         </a>
      </xsl:when>
         <xsl:otherwise>
            <xsl:value-of select="."/>
         </xsl:otherwise>
      </xsl:choose>               
   
</xsl:template>
   
   <xsl:template match="t:dimensions" mode="igcyr-dimensions">
      <xsl:if test="text()">
         <xsl:if test="t:width/text()">w: <xsl:value-of select="t:width"/>
            <xsl:if test="t:height/text()">
               <xsl:text> x </xsl:text>
            </xsl:if>
         </xsl:if>
         <xsl:if test="t:height/text()">h: <xsl:value-of select="t:height"/>
         </xsl:if>
         <xsl:if test="t:depth/text()"> x d: <xsl:value-of select="t:depth"/>
         </xsl:if>
         <xsl:if test="t:dim[@type='diameter']/text()"> x diam.: <xsl:value-of select="t:dim[@type='diameter']"/>
         </xsl:if>
      </xsl:if>
   </xsl:template>

   <xsl:template match="t:placeName|t:rs" mode="igcyr-placename">
      <xsl:choose>
         <xsl:when test="contains(@ref,'pleiades.stoa.org') or contains(@ref,'geonames.org')">
            <a>
               <xsl:attribute name="href">
                  <xsl:value-of select="@ref"/>
               </xsl:attribute>
               <xsl:apply-templates/>
            </a>
         </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="igcyr-invno">
      <xsl:if test="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
         <xsl:text> (Inv. no. </xsl:text>
         <xsl:for-each select="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
            <xsl:value-of select="."/>
            <xsl:if test="position()!=last()">
               <xsl:text>, </xsl:text>
            </xsl:if>
         </xsl:for-each>
         <xsl:text>)</xsl:text>
      </xsl:if>
   </xsl:template>
   

   <xsl:template match="t:ref[@type='inscription']">
   <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
   <xsl:choose>
      <xsl:when test="$parm-edn-structure = 'igcyr'">
         
<a href="{concat('Workspace/xml/', ., '.xml')}">
      
      <xsl:text>IGCyr </xsl:text>
      <xsl:value-of select="number(substring(.,6,6)) div 100"/>
   </a>
      </xsl:when>
   </xsl:choose>
</xsl:template>
   
</xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-inslib.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for InsLib file structure (aka "metadata" aka "supporting data") -->  
   
   <!-- Called from htm-tpl-structure.xsl -->

   <xsl:template name="inslib-body-structure">
     <p><b><i18n:text i18n:key="epidoc-xslt-inslib-description">Description</i18n:text>: </b>
     <xsl:choose>
       <xsl:when test="//t:support/t:p/text()">
         <xsl:apply-templates select="//t:support/t:p" mode="inslib-dimensions"/>
       </xsl:when>
       <xsl:when test="//t:support//text()">
         <xsl:apply-templates select="//t:support" mode="inslib-dimensions"/>
       </xsl:when>
       <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-inslib-unknown">Unknown</i18n:text></xsl:otherwise>
     </xsl:choose>

     <br/>
     <b><i18n:text i18n:key="epidoc-xslt-inslib-text">Text</i18n:text>: </b>
     <xsl:choose>
       <xsl:when test="//t:layoutDesc/t:layout//text()">
         <xsl:value-of select="//t:layoutDesc/t:layout"/>
       </xsl:when>
       <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-inslib-unknown">Unknown</i18n:text>.</xsl:otherwise>
     </xsl:choose>
     <br/>
     <b><i18n:text i18n:key="epidoc-xslt-inslib-letters">Letters</i18n:text>: </b>
     <xsl:if test="//t:handDesc/t:handNote/text()">
       <xsl:value-of select="//t:handDesc/t:handNote"/>
     </xsl:if>
     </p>

     <p><b><i18n:text i18n:key="epidoc-xslt-inslib-date">Date</i18n:text>: </b>
     <xsl:choose>
       <xsl:when test="//t:origin/t:origDate/text()">
         <xsl:value-of select="//t:origin/t:origDate"/>
         <xsl:if test="//t:origin/t:origDate[@type='evidence']">
           <xsl:text>(</xsl:text>
           <xsl:for-each select="tokenize(//t:origin/t:origDate[@evidence],' ')">
             <xsl:value-of select="translate(.,'-',' ')"/>
             <xsl:if test="position()!=last()">
               <xsl:text>, </xsl:text>
             </xsl:if>
           </xsl:for-each>
           <xsl:text>)</xsl:text>
         </xsl:if>
       </xsl:when>
       <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-inslib-unknown">Unknown</i18n:text>.</xsl:otherwise>
     </xsl:choose>
     </p>

     <p><b><i18n:text i18n:key="epidoc-xslt-inslib-findspot">Findspot</i18n:text>: </b>
     <xsl:choose>
       <xsl:when test="//t:provenance[@type='found'][string(translate(normalize-space(.),' ',''))]">
         <xsl:apply-templates select="//t:provenance[@type='found']" mode="inslib-placename"/>
       </xsl:when>
       <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-inslib-unknown">Unknown</i18n:text></xsl:otherwise>
     </xsl:choose>
     <br/>
     <b><i18n:text i18n:key="epidoc-xslt-inslib-original-location">Original location</i18n:text>: </b>
     <xsl:choose>
       <xsl:when test="//t:origin/t:origPlace/text()">
         <xsl:apply-templates select="//t:origin/t:origPlace" mode="inslib-placename"/>
       </xsl:when>
       <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-inslib-unknown">Unknown</i18n:text></xsl:otherwise>
     </xsl:choose>
     <br/>
     <b><i18n:text i18n:key="epidoc-xslt-inslib-last-recorded-location">Last recorded location</i18n:text>: </b>
     <xsl:choose>
       <xsl:when test="//t:provenance[@type='observed'][string(translate(normalize-space(.),' ',''))]">
         <xsl:apply-templates select="//t:provenance[@type='observed']" mode="inslib-placename"/>
         <!-- Named template found below. -->
         <xsl:call-template name="inslib-invno"/> 
       </xsl:when>
       <xsl:when test="//t:msIdentifier//t:repository[string(translate(normalize-space(.),' ',''))]">
         <xsl:value-of select="//t:msIdentifier//t:repository[1]"/>
         <!-- Named template found below. -->
         <xsl:call-template name="inslib-invno"/>
       </xsl:when>
       <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-inslib-unknown">Unknown</i18n:text></xsl:otherwise>
     </xsl:choose>
     </p>

     <div class="section-container tabs" data-section="tabs">
       <section>
         <p class="title" data-section-title="data-section-title"><a href="#"><i18n:text i18n:key="epidoc-xslt-inslib-edition">Interpretive</i18n:text></a></p>
         <div class="content" id="edition" data-section-content="data-section-content">
           <!-- Edited text output -->
           <xsl:variable name="edtxt">
             <xsl:apply-templates select="//t:div[@type='edition']">
               <xsl:with-param name="parm-edition-type" select="'interpretive'" tunnel="yes"/>
             </xsl:apply-templates>
           </xsl:variable>
           <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
           <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
         </div>
       </section>
       <section>
         <p class="title" data-section-title="data-section-title"><a href="#"><i18n:text i18n:key="epidoc-xslt-inslib-diplomatic">Diplomatic</i18n:text></a></p>
         <div class="content" id="diplomatic" data-section-content="data-section-content">
           <!-- Edited text output -->
           <xsl:variable name="edtxt">
             <xsl:apply-templates select="//t:div[@type='edition']">
               <xsl:with-param name="parm-edition-type" select="'diplomatic'" tunnel="yes"/>
             </xsl:apply-templates>
           </xsl:variable>
           <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
           <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
         </div>
       </section>
     </div>

     <div id="apparatus">
       <!-- Apparatus text output -->
       <xsl:variable name="apptxt">
         <xsl:apply-templates select="//t:div[@type='apparatus']"/>
       </xsl:variable>
       <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
       <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
     </div>

     <div id="translation">
       <h4 class="slimmer"><i18n:text i18n:key="epidoc-xslt-inslib-translation">Translation</i18n:text>:</h4>
       <!-- Translation text output -->
       <xsl:variable name="transtxt">
         <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
       </xsl:variable>
       <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
       <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
     </div>

     <div id="commentary">
       <h4 class="slimmer"><i18n:text i18n:key="epidoc-xslt-inslib-commentary">Commentary</i18n:text>:</h4>
       <!-- Commentary text output -->
       <xsl:variable name="commtxt">
         <xsl:apply-templates select="//t:div[@type='commentary']//t:p"/>
       </xsl:variable>
       <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
       <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
     </div>

     <p><b><i18n:text i18n:key="epidoc-xslt-inslib-bibliography">Bibliography</i18n:text>: </b>
     <xsl:apply-templates select="//t:div[@type='bibliography']/t:p/node()"/> 
     <br/>
     <b><i18n:text i18n:key="epidoc-xslt-inslib-constituted-from">Text constituted from</i18n:text>: </b>
     <xsl:apply-templates select="//t:creation"/>
     </p>
   </xsl:template>

   <xsl:template name="inslib-structure">
      <xsl:variable name="title">
         <xsl:call-template name="inslib-title"/>
      </xsl:variable>

      <html>
         <head>
            <title>
               <xsl:value-of select="$title"/>
            </title>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <!-- Found in htm-tpl-cssandscripts.xsl -->
            <xsl:call-template name="css-script"/>
         </head>
         <body>
            <h1>
               <xsl:value-of select="$title"/>
            </h1>
            <xsl:call-template name="inslib-body-structure"/>
         </body>
      </html>
   </xsl:template>

   <xsl:template match="t:dimensions" mode="inslib-dimensions">
      <xsl:if test="//text()">
         <xsl:if test="t:width/text()">w: 
            <xsl:value-of select="t:width"/>
            <xsl:if test="t:height/text()">
               <xsl:text> x </xsl:text>
            </xsl:if>
         </xsl:if>
         <xsl:if test="t:height/text()">h: 
            <xsl:value-of select="t:height"/>
         </xsl:if>
         <xsl:if test="t:depth/text()">x d:
            <xsl:value-of select="t:depth"/>
         </xsl:if>
         <xsl:if test="t:dim[@type='diameter']/text()">x diam.:
            <xsl:value-of select="t:dim[@type='diameter']"/>
         </xsl:if>
      </xsl:if>
   </xsl:template>
   
   <xsl:template match="t:placeName|t:rs" mode="inslib-placename">
      <xsl:choose>
         <xsl:when test="contains(@ref,'pleiades.stoa.org') or contains(@ref,'geonames.org')">
            <a>
               <xsl:attribute name="href">
                  <xsl:value-of select="@ref"/>
               </xsl:attribute>
               <xsl:apply-templates/>
            </a>
      </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
   
   <xsl:template name="inslib-invno">
      <xsl:if test="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
         <xsl:text> (Inv. no. </xsl:text>
         <xsl:for-each select="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
            <xsl:value-of select="."/>
            <xsl:if test="position()!=last()">
               <xsl:text>, </xsl:text>
            </xsl:if>
         </xsl:for-each>
         <xsl:text>)</xsl:text>
      </xsl:if>
   </xsl:template>

   <xsl:template name="inslib-title">
     <xsl:choose>
       <xsl:when test="//t:titleStmt/t:title/text() and number(substring(//t:publicationStmt/t:idno[@type='filename']/text(),2,5))">
         <xsl:value-of select="substring(//t:publicationStmt/t:idno[@type='filename'],1,1)"/> 
         <xsl:text>. </xsl:text>
         <xsl:value-of select="number(substring(//t:publicationStmt/t:idno[@type='filename'],2,5)) div 100"/> 
         <xsl:text>. </xsl:text>
         <xsl:value-of select="//t:titleStmt/t:title"/>
       </xsl:when>
       <xsl:when test="//t:titleStmt/t:title/text()">
         <xsl:value-of select="//t:titleStmt/t:title"/>
       </xsl:when>
       <xsl:when test="//t:sourceDesc//t:bibl/text()">
         <xsl:value-of select="//t:sourceDesc//t:bibl"/>
       </xsl:when>
       <xsl:when test="//t:idno[@type='filename']/text()">
         <xsl:value-of select="//t:idno[@type='filename']"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:text>EpiDoc example output, InsLib style</xsl:text>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>

 </xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-iospe.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for IOSPE file structure (aka "metadata" aka "supporting data") -->

  <!-- Called from htm-tpl-structure.xsl -->

  <xsl:template name="iospe-body-structure">
    <div id="stone">
      <h3 class="iospe"><i18n:text i18n:key="epidoc-xslt-iospe-monument">Monument</i18n:text></h3>
      <dl class="iospe">
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-monument-type">Type of monument</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support//t:objectType//text()">
              <xsl:value-of select="//t:support//t:objectType"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-material">Material</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support//t:material//text()">
              <xsl:value-of select="//t:support//t:material"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-description">Description and condition</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support//t:p//text()">
              <xsl:value-of select="//t:support//t:p"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
      </dl>

      <dl class="iospe">
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-find-place">Find place</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:provenance[@type='found']//t:placeName[@type='ancientFindspot']//text()">
              <xsl:value-of select="//t:provenance[@type='found']//t:placeName[@type='ancientFindspot']"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-unknown">Unknown</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-find-circumstances">Find circumstances</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:provenance[@type='found']//t:rs[@type='circumstances']//text()">
              <xsl:value-of select="//t:provenance[@type='found']//t:rs[@type='circumstances']"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-unknown">Unknown</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-find-context">Find context</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:provenance[@type='found']//t:rs[@type='context']//text()">
              <xsl:value-of select="//t:provenance[@type='found']//t:rs[@type='context']"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-unknown">Unknown</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-modern-location">Modern location</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:provenance[@type='observed']//text()">
              <xsl:value-of select="//t:provenance[@type='observed']"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-unknown">Unknown</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-dimensions">Dimensions</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support/t:dimensions//text()[not(normalize-space(.)=' ')]">
              <xsl:if test="//t:support/t:dimensions/t:height/text()[not(normalize-space(.)=' ')]">H. <xsl:value-of select="//t:support/t:dimensions/t:height"/>,</xsl:if>
              <xsl:if test="//t:support/t:dimensions/t:width/text()[not(normalize-space(.)=' ')]">W. <xsl:value-of select="//t:support/t:dimensions/t:width"/>,</xsl:if>
              <xsl:if test="//t:support/t:dimensions/t:depth/text()[not(normalize-space(.)=' ')]">Th. <xsl:value-of select="//t:support/t:dimensions/t:depth"/></xsl:if>
              <xsl:if test="//t:support/t:dimensions/t:dim[@type='diameter']/text()[not(normalize-space(.)=' ')]">, Diam. <xsl:value-of select="//t:support/t:dimensions/t:dim[@type='diameter']"/></xsl:if>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-unknown">Unknown</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-institution-inventory">Institution and inventory</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:msIdentifier//t:repository/text() and //t:msIdentifier//t:idno/text()">
              <xsl:value-of select="//t:msIdentifier//t:repository"/>
              <xsl:value-of select="//t:msIdentifier//t:idno"/>
            </xsl:when>
            <xsl:when test="//t:msIdentifier//t:repository/text()">
              <xsl:value-of select="//t:msIdentifier//t:repository"/>
              <xsl:text>no inv. no.</xsl:text>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-unknown">Unknown</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
      </dl>
    </div>

    <div id="text-field">
      <h3 class="iospe"><i18n:text i18n:key="epidoc-xslt-iospe-inscribed-field">Inscribed field</i18n:text></h3>
      <dl class="iospe">
        <xsl:if test="//t:layout/@ana">
          <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-faces-code">Faces code</i18n:text></dt>
          <dd><xsl:value-of select="//t:layout/@ana"/></dd>
        </xsl:if>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-placement-text">Placement of text</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:layout/text()">
              <xsl:value-of select="//t:layout"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-style-lettering">Style of lettering</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:handNote//text()[not(ancestor::t:height)]">
              <xsl:value-of select="/t:handNote//text()[not(ancestor::t:height)]"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epidoc-xslt-iospe-letterheights">Letterheights</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:handNote//t:height/text()">
              <xsl:value-of select="//t:handNote//t:height"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
      </dl>
    </div>

    <div id="text">
      <h3 class="iospe"><i18n:text i18n:key="epidoc-xslt-iospe-text">Text</i18n:text></h3>
      <dl class="iospe">

        <dt><i18n:text i18n:key="epidoc-xslt-iospe-origin">Origin</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:origin/t:origPlace/text()">
              <xsl:value-of select="//t:origin/t:origPlace"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt><i18n:text i18n:key="epidoc-xslt-iospe-category">Category</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:msContents/t:summary/text()">
              <xsl:value-of select="//t:msContents/t:summary"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt><i18n:text i18n:key="epidoc-xslt-iospe-date">Date</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:origin/t:origDate/text()">
              <xsl:value-of select="//t:origin/t:origDate"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-not-specified">Not specified</i18n:text></xsl:otherwise>
        </xsl:choose></dd>
        <dt><i18n:text i18n:key="epidoc-xslt-iospe-dating-criteria">Dating criteria</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:origin/t:origDate/@evidence">
              <xsl:for-each select="tokenize(//t:origin/t:origDate/@evidence,' ')">
                <xsl:value-of select="translate(.,'-',' ')"/>
                <xsl:if test="position()!=last()">
                  <xsl:text>, </xsl:text>
                </xsl:if>
              </xsl:for-each>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>n/a</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt><i18n:text i18n:key="epidoc-xslt-iospe-editions">Editions</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:body//t:div[@type='bibliography']//text()">
              <xsl:apply-templates select="//t:body//t:div[@type='bibliography']"/>
            </xsl:when>
            <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-iospe-unpublished">Unpublished</i18n:text></xsl:otherwise>
        </xsl:choose></dd>
      </dl>

      <div id="edition" class="iospe">
        <!-- Edited text output -->
        <xsl:variable name="edtxt">
          <xsl:apply-templates select="//t:div[@type='edition']"/>
        </xsl:variable>
        <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
      </div>
      <div id="apparatus" class="iospe">
        <h4 class="iospe"><i18n:text i18n:key="epidoc-xslt-iospe-apparatus">Apparatus</i18n:text></h4>
        <!-- Apparatus text output -->
        <xsl:variable name="apptxt">
          <xsl:apply-templates select="//t:div[@type='apparatus']/t:listApp"/>
        </xsl:variable>
        <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
      </div>
      <div id="translation" class="iospe">
        <h4 class="iospe"><i18n:text i18n:key="epidoc-xslt-iospe-translation">Translation</i18n:text></h4>
        <!-- Translation text output -->
        <xsl:variable name="transtxt">
          <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
        </xsl:variable>
        <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
      </div>
      <div id="commentary" class="iospe">
        <h4 class="iospe"><i18n:text i18n:key="epidoc-xslt-iospe-commentary">Commentary</i18n:text></h4>
        <!-- Commentary text output -->
        <xsl:variable name="commtxt">
          <xsl:apply-templates select="//t:div[@type='commentary']//t:p"/>
        </xsl:variable>
        <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
      </div>
      <div id="images" class="iospe">
        <h4 class="iospe"><i18n:text i18n:key="epidoc-xslt-iospe-images">Images</i18n:text></h4>
        <dl>
          <xsl:for-each select="//t:facsimile//t:graphic">
            <dt width="150" align="left"/>
            <dd>
              <xsl:apply-templates select="."/>
            </dd>
          </xsl:for-each>
        </dl>
      </div>
    </div>
  </xsl:template>

  <xsl:template name="iospe-structure">
    <xsl:variable name="title">
      <xsl:call-template name="iospe-title"/>
    </xsl:variable>
    <html>
      <head>
        <title>
          <xsl:value-of select="$title"/>
        </title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <!-- Found in htm-tpl-cssandscripts.xsl -->
        <xsl:call-template name="css-script"/>
      </head>
      <body>
        <h1>
          <xsl:value-of select="$title"/>
        </h1>
        <xsl:call-template name="iospe-body-structure"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="iospe-title">
    <xsl:choose>
      <xsl:when test="//t:titleStmt/t:title/text() and matches(//t:idno[@type='filename'], '^\d\.\d{1,4}$')">
        <xsl:number value="substring-before(//t:idno[@type='filename'],'.')" format="I"/>
        <xsl:text> </xsl:text>
        <xsl:number value="substring-after(//t:idno[@type='filename'],'.')" format="1"/>
        <xsl:text>. </xsl:text>
        <xsl:if test="string(normalize-space(//t:origPlace[1]))"><xsl:value-of select="normalize-space(//t:origPlace[1])"/>
        <xsl:text>. </xsl:text></xsl:if>
        <xsl:value-of select="//t:titleStmt/t:title[child::text()][1]"/>
        <xsl:if test="not(//t:titleStmt/t:title[child::text()][1][child::t:origDate])">
          <xsl:text>, </xsl:text>
          <xsl:value-of select="//t:origDate[1]"/>
        </xsl:if>
      </xsl:when>
      <xsl:when test="//t:titleStmt/t:title/text()">
        <xsl:value-of select="//t:titleStmt/t:title"/>
      </xsl:when>
      <xsl:when test="//t:sourceDesc//t:bibl/text()">
        <xsl:value-of select="//t:sourceDesc//t:bibl"/>
      </xsl:when>
      <xsl:when test="//t:idno[@type='filename']/text()">
        <xsl:value-of select="//t:idno[@type='filename']"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>EpiDoc example output, IOSPE style</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-rib.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for RIB file structure (aka "metadata" aka "supporting data") -->  
   
   <!-- Called from htm-tpl-structure.xsl -->
   
   <xsl:template name="rib-structure">
      <xsl:call-template name="default-structure"/>
   </xsl:template>
   
   </xsl:stylesheet></xsl:include>
    <xsl:include href="htm-tpl-struct-spes.xsl"><!-- $Id: htm-tpl-struct-spes.xsl 2561 2017-04-04 11:24:24Z gabrielbodard $ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
   <!-- Contains named templates for SPES file structure -->

   <xsl:template name="spes-body-structure">
      <p><b><i18n:text i18n:key="epidoc-xslt-spes-description">Description</i18n:text>: </b>
      <xsl:choose>
         <xsl:when test="//t:support/t:p/text()">
            <xsl:apply-templates select="//t:support/t:p" mode="spes-dimensions"/>
         </xsl:when>
         <xsl:when test="//t:support//text()">
            <xsl:apply-templates select="//t:support" mode="spes-dimensions"/>
         </xsl:when>
         <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-spes-unknown">Unknown</i18n:text></xsl:otherwise>
      </xsl:choose>

      <br/>
      <b><i18n:text i18n:key="epidoc-xslt-spes-text">Text</i18n:text>: </b>
      <xsl:choose>
         <xsl:when test="//t:layoutDesc/t:layout//text()">
            <xsl:value-of select="//t:layoutDesc/t:layout"/>
         </xsl:when>
         <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-spes-unknown">Unknown</i18n:text>.</xsl:otherwise>
      </xsl:choose>
      <br/>
      <b><i18n:text i18n:key="epidoc-xslt-spes-letters">Letters</i18n:text>: </b>
      <xsl:if test="//t:handDesc/t:handNote/text()">
         <xsl:value-of select="//t:handDesc/t:handNote"/>
      </xsl:if>
      </p>

      <p><b><i18n:text i18n:key="epidoc-xslt-spes-date">Date</i18n:text>: </b>
      <xsl:choose>
         <xsl:when test="//t:origin/t:origDate/text()">
            <xsl:value-of select="//t:origin/t:origDate"/>
            <xsl:if test="//t:origin/t:origDate[@type='evidence']">
               <xsl:text>(</xsl:text>
               <xsl:for-each select="tokenize(//t:origin/t:origDate[@evidence],' ')">
                  <xsl:value-of select="translate(.,'-',' ')"/>
                  <xsl:if test="position()!=last()">
                     <xsl:text>, </xsl:text>
                  </xsl:if>
               </xsl:for-each>
               <xsl:text>)</xsl:text>
            </xsl:if>
         </xsl:when>
         <xsl:otherwise><i18n:text i18n:key="epidoc-xslt-spes-unknown">Unknown</i18n:text>.</xsl:otherwise>
      </xsl:choose>
      </p>

      <p>
         <xsl:if test="//t:provenance[@type='found'][string(translate(normalize-space(.),' ',''))]">
            <b><i18n:text i18n:key="epidoc-xslt-spes-findspot">Findspot</i18n:text>: </b>
            <xsl:apply-templates select="//t:provenance[@type='found']" mode="spes-placename"/>
         </xsl:if>

         <xsl:if test="//t:origin/t:origPlace/text()">
            <br/>
            <b><i18n:text i18n:key="epidoc-xslt-spes-original-location">Original location</i18n:text>: </b>
            <xsl:apply-templates select="//t:origin/t:origPlace" mode="spes-placename"/>
         </xsl:if>

         <xsl:if test="//t:provenance[@type='observed'][string(translate(normalize-space(.),' ',''))] or                        //t:msIdentifier//t:repository[string(translate(normalize-space(.),' ',''))]">
            <br/>
            <b><i18n:text i18n:key="epidoc-xslt-spes-last-location">Last recorded location</i18n:text>: </b>
            <xsl:if test="//t:provenance[@type='observed'][string(translate(normalize-space(.),' ',''))]">
               <xsl:apply-templates select="//t:provenance[@type='observed']" mode="spes-placename"/> 
            </xsl:if>
            <xsl:text> </xsl:text>
            <xsl:if test="//t:msIdentifier//t:repository[string(translate(normalize-space(.),' ',''))]">
               <xsl:value-of select="//t:msIdentifier//t:repository[1]"/>
               <xsl:if test="//t:msIdentifier//t:idno[string(translate(normalize-space(.),' ',''))]">
                  <xsl:text> (inv. </xsl:text>
                  <xsl:value-of select="//t:msIdentifier//t:idno[1]"/>
                  <xsl:text>)</xsl:text>
               </xsl:if>
            </xsl:if>
         </xsl:if>
      </p>

      <p><b><i18n:text i18n:key="epidoc-xslt-spes-bibliography">Bibliography</i18n:text>: </b>
      <xsl:apply-templates select="//t:div[@type='bibliography']/t:p/node()"/>
      <br/>
      <b><i18n:text i18n:key="epidoc-xslt-spes-text-constituted">Text constituted from</i18n:text>: </b>
      <xsl:apply-templates select="//t:creation"/>
      </p>

      <div id="edition">
         <p><b><i18n:text i18n:key="epidoc-xslt-spes-edition">Edition</i18n:text>:</b></p>
         <!-- Edited text output -->
         <xsl:variable name="edtxt">
            <xsl:apply-templates select="//t:div[@type='edition']"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
      </div>

      <div id="apparatus">
         <!-- Apparatus text output -->
         <xsl:variable name="apptxt">
            <xsl:apply-templates select="//t:div[@type='apparatus']"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
      </div>

      <div id="translation">
         <h4 class="slimmer"><i18n:text i18n:key="epidoc-xslt-spes-translation">Translation</i18n:text>:</h4>
         <!-- Translation text output -->
         <xsl:variable name="transtxt">
            <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
      </div>

      <div id="commentary">
         <h4 class="slimmer"><i18n:text i18n:key="epidoc-xslt-spes-commentary">Commentary</i18n:text>:</h4>
         <!-- Commentary text output -->
         <xsl:variable name="commtxt">
            <xsl:apply-templates select="//t:div[@type='commentary']//t:p"/>
         </xsl:variable>
         <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
         <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
      </div>
   </xsl:template>

   <!-- Called from htm-tpl-structure.xsl -->

   <xsl:template name="spes-structure">
      <xsl:variable name="title">
         <xsl:call-template name="spes-title"/>
      </xsl:variable>

      <html>
         <head>
            <title>
               <xsl:value-of select="$title"/>
            </title>
            <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
            <!-- Found in htm-tpl-cssandscripts.xsl -->
            <xsl:call-template name="css-script"/>
         </head>

         <body>
            <h1>
               <xsl:value-of select="$title"/>
            </h1>

            <xsl:call-template name="spes-body-structure"/>
         </body>
      </html>
   </xsl:template>

   <xsl:template match="t:dimensions" mode="spes-dimensions">
      <xsl:if test="//text()">
         <xsl:if test="t:width/text()">w: 
            <xsl:value-of select="t:width"/>
            <xsl:if test="t:height/text()">
               <xsl:text> x </xsl:text>
            </xsl:if>
         </xsl:if>
         <xsl:if test="t:height/text()">h: 
            <xsl:value-of select="t:height"/>
         </xsl:if>
         <xsl:if test="t:depth/text()">x d:
            <xsl:value-of select="t:depth"/>
         </xsl:if>
         <xsl:if test="t:dim[@type='diameter']/text()">x diam.:
            <xsl:value-of select="t:dim[@type='diameter']"/>
         </xsl:if>
      </xsl:if>
   </xsl:template>

   <xsl:template match="t:placeName|t:rs" mode="spes-placename">
      <xsl:choose>
         <xsl:when test="contains(@ref,'pleiades.stoa.org') or contains(@ref,'geonames.org')">
            <a>
               <xsl:attribute name="href">
                  <xsl:value-of select="@ref"/>
               </xsl:attribute>
               <xsl:apply-templates/>
            </a>
      </xsl:when>
         <xsl:otherwise>
            <xsl:apply-templates/>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>

   <xsl:template name="spes-title">
         <xsl:choose>
            <xsl:when test="//t:titleStmt/t:title/text() and number(substring(//t:publicationStmt/t:idno[@type='filename']/text(),2,5))">
               <xsl:value-of select="substring(//t:publicationStmt/t:idno[@type='filename'],1,1)"/> 
               <xsl:text>. </xsl:text>
               <xsl:value-of select="number(substring(//t:publicationStmt/t:idno[@type='filename'],2,5)) div 100"/> 
               <xsl:text>. </xsl:text>
               <xsl:value-of select="//t:titleStmt/t:title"/>
            </xsl:when>
            <xsl:when test="//t:titleStmt/t:title/text()">
               <xsl:value-of select="//t:titleStmt/t:title"/>
            </xsl:when>
            <xsl:when test="//t:sourceDesc//t:bibl/text()">
               <xsl:value-of select="//t:sourceDesc//t:bibl"/>
            </xsl:when>
            <xsl:when test="//t:idno[@type='filename']/text()">
               <xsl:value-of select="//t:idno[@type='filename']"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:text>EpiDoc example output, spes style</xsl:text>
            </xsl:otherwise>
         </xsl:choose>
   </xsl:template>

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

   <!-- global named templates with no html, also used by start-txt -->
   <xsl:include href="tpl-certlow.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Called by many different elements -->
  
  <xsl:template name="cert-low">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:if test="@cert='low' and $parm-edition-type != 'diplomatic'">
          <xsl:if test="not($parm-leiden-style = ('london','panciera','iospe') and local-name() = ('ex','supplied'))">
           <xsl:text>(</xsl:text>
        </xsl:if>
        <xsl:text>?</xsl:text>
          <xsl:if test="not($parm-leiden-style = ('london','panciera','iospe') and local-name() = ('ex','supplied'))">
           <xsl:text>)</xsl:text>
        </xsl:if>
      </xsl:if>
  </xsl:template>
  
</xsl:stylesheet></xsl:include>
   <xsl:include href="tpl-text.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">

  <xsl:template match="text()[not(ancestor::t:note)]">
      <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
      <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
      <xsl:choose>
         <!-- strip all spaces and punctuation in diplomatic edition -->
          <xsl:when test="$parm-edition-type = 'diplomatic' and ancestor::t:div[@type='edition'] and not(ancestor::t:head) and not($parm-leiden-style='sigidoc')">
            <xsl:variable name="apos">
               <xsl:text>'</xsl:text>
            </xsl:variable>
             <xsl:value-of select="upper-case(translate(normalize-unicode(translate(translate(translate(.,'ϲ','Ϲ'),$apos,''), '··&#10; ,.;‘’', ''),'NFD'),'̀́̈̓̔͂ͅ',''))"/>
            <!--<xsl:value-of select="translate(translate(translate(.,$apos,''), '··&#xA; ,.;‘’', ''), $all-grc, $grc-upper-strip)"/>-->
             <!-- &#x02bc;&#x02bd;&#x0301;&#x0302;&#x0303;&#x0308;&#x0340;&#x0341;&#x0342;&#x0343;&#x0344;&#x0345; -->
         </xsl:when>
         <xsl:when test="$parm-edition-type = 'diplomatic' and ancestor::t:div[@type='edition'] and not(ancestor::t:head) and $parm-leiden-style = 'sigidoc'">
            <xsl:variable name="apos">
               <xsl:text>'</xsl:text>
            </xsl:variable>
            <xsl:value-of select="."/>
         </xsl:when>
         <!-- omit space between abbreviation and (deleted) "f." or "l." from EDH names mode -->
          <xsl:when test="$parm-leiden-style='edh-names' and              normalize-space(.) = '' and              following-sibling::t:*[1][local-name()='w'][@lemma='filius' or @lemma='libertus' or @lemma='filia' or @lemma='liberta'] and             preceding-sibling::t:*[1][descendant-or-self::t:expan]"/>
         <xsl:otherwise>
            <xsl:if test="matches(., '^\s') and not(matches(., '^\s+$')) and not(preceding-sibling::t:*[1][self::t:lb[@break='no']])">
               <xsl:text> </xsl:text>
            </xsl:if>
            <xsl:choose>
               <xsl:when test="$parm-leiden-style='edh-names'">
                  <xsl:value-of select="."/>
               </xsl:when>
               <xsl:otherwise>
                  <xsl:value-of select="normalize-space(.)"/>
               </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="matches(.,'\s$') and not(following-sibling::t:*[1][self::t:lb[@break='no']])">
               <xsl:text> </xsl:text>
            </xsl:if>
         </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

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



   <!-- HTML FILE -->
   <xsl:template match="/">
      <xsl:choose>
         <xsl:when test="$edn-structure = 'london'">
            <!-- this and other structure templates found in htm-tpl-struct-*.xsl -->
             <xsl:call-template name="london-structure">
                 <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                 <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                 <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                 <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                 <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="$edn-structure = 'hgv'">
             <xsl:call-template name="hgv-structure">
                 <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                 <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                 <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                 <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
            </xsl:call-template>
         </xsl:when>
          <xsl:when test="$edn-structure = 'edak'">
              <xsl:call-template name="edak-structure">
                  <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                  <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                  <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                  <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                  <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                  <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                  <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
              </xsl:call-template>
          </xsl:when>
          <xsl:when test="$edn-structure = 'inslib'">
              <xsl:call-template name="inslib-structure">
                  <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                  <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                  <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                  <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                  <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                  <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                  <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
              </xsl:call-template>
          </xsl:when>
          <xsl:when test="$edn-structure = 'spes'">
              <xsl:call-template name="spes-structure">
                  <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                  <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                  <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                  <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                  <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                  <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                  <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
              </xsl:call-template>
          </xsl:when>
          <xsl:when test="$edn-structure = 'dol'">
              <xsl:call-template name="dol-structure">
                  <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                  <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                  <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                  <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                  <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                  <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                  <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
              </xsl:call-template>
          </xsl:when>
         <xsl:when test="$edn-structure = 'iospe'">
             <xsl:call-template name="iospe-structure">
                 <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                 <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                 <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                 <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
            </xsl:call-template>
         </xsl:when>
         <xsl:when test="$edn-structure = 'ddbdp'">
            <div>
                <xsl:call-template name="default-body-structure">
                    <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                    <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                  <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                  <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                  <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                  <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                    <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                    <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
              </xsl:call-template>
            </div>
         </xsl:when>
        <xsl:when test="$edn-structure='eagle'">
            <xsl:call-template name="eagle-structure">
                <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
                <xsl:with-param name="parm-bib" select="$bibliography" tunnel="yes"/>
                <xsl:with-param name="parm-bibloc" select="$localbibl" tunnel="yes"/>
                <xsl:with-param name="parm-zoteroUorG" select="$ZoteroUorG" tunnel="yes"/>
                <xsl:with-param name="parm-zoteroKey" select="$ZoteroKey" tunnel="yes"/>
                <xsl:with-param name="parm-zoteroNS" select="$ZoteroNS" tunnel="yes"/>
                <xsl:with-param name="parm-zoteroStyle" select="$ZoteroStyle" tunnel="yes"/>
            </xsl:call-template>
        </xsl:when>
          <xsl:when test="$edn-structure='igcyr'">
              <xsl:call-template name="igcyr-structure">
                  <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                  <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                  <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                  <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                  <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                  <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                  <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                  <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
              </xsl:call-template>
          </xsl:when>
          <xsl:otherwise>
             <xsl:call-template name="default-structure">
                 <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
                 <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
                <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
                <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
                <xsl:with-param name="parm-hgv-gloss" select="$hgv-gloss" tunnel="yes"/>
                <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
                <xsl:with-param name="parm-line-inc" select="$line-inc" tunnel="yes" as="xs:double"/>
                 <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
                 <xsl:with-param name="parm-css-loc" select="$css-loc" tunnel="yes"/>
            </xsl:call-template>
         </xsl:otherwise>
      </xsl:choose>
   </xsl:template>



</xsl:stylesheet></xsl:import>
  <xsl:import href="htm-tpl-struct-sigidoc.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:t="http://www.tei-c.org/ns/1.0" xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for IOSPE file structure (aka "metadata" aka "supporting data") -->

  <!-- Called from htm-tpl-structure.xsl -->
  
  <!-- LAST MODIFIED: 2023-03-08 -->

  <xsl:template name="sigidoc-body-structure">
    <xsl:call-template name="navigation"/>
    

      <h6 width="600" align="right" xml:space="preserve">SigiDoc ID: 
        <xsl:choose>
          <xsl:when test="//t:publicationStmt//t:idno[@type='SigiDocID']//text()">
            <xsl:apply-templates select="//t:publicationStmt//t:idno[@type='SigiDocID']"/>
          </xsl:when>
          <xsl:otherwise>―</xsl:otherwise>
        </xsl:choose>
      </h6>
    
    
    <div id="stone">
      <h3 class="iospe"><i18n:text i18n:key="artifact">Artifact</i18n:text></h3>
      <dl class="iospe">
        <dt width="150" align="left"><i18n:text i18n:key="type">Type</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:objectType//t:term//t:seg//text()">
              <xsl:apply-templates select="//t:objectType//t:term//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="general-layout">General layout</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:TEI//t:teiHeader//t:fileDesc//t:sourceDesc//t:msDesc//t:physDesc//t:objectDesc//t:layoutDesc//t:layout[@n='whole']//t:rs[@type='layout']//t:seg">
              <xsl:apply-templates select="//t:TEI//t:teiHeader//t:fileDesc//t:sourceDesc//t:msDesc//t:physDesc//t:objectDesc//t:layoutDesc//t:layout[@n='whole']//t:rs[@type='layout']//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="matrix">Matrix</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:layout[@n='whole']//t:rs[@type='matrix']//t:idno[@type='SigiDoc'][normalize-space(.) != '' and normalize-space(.) != '―']">
              SigiDoc ID: <xsl:apply-templates select="//t:layout[@n='whole']//t:rs[@type='matrix']//t:idno[@type='SigiDoc']"/>
            </xsl:when>
            <xsl:when test="//t:layout[@n='whole']//t:rs[@type='matrix']//t:idno[@type='PBW'][normalize-space(.) != '' and normalize-space(.) != '―']">
              PBW ID: <xsl:apply-templates select="//t:layout[@n='whole']//t:rs[@type='matrix']//t:idno[@type='PBW']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
      </dl>
    </div>
        <div id="stone">
          <h4 class="iospe"><i><i18n:text i18n:key="physical-description">Physical description</i18n:text></i></h4>
          <!-- ************* physical description *************** -->
          <dl class="iospe">
            <dt width="150" align="left"><i18n:text i18n:key="medium">Medium</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:objectType//t:interp[@type='workType']//text()">
              <xsl:apply-templates select="//t:objectType//t:interp[@type='workType']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
            <dt width="150" align="left"><i18n:text i18n:key="material">Material</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support//t:material//t:seg//text()">
              <xsl:apply-templates select="//t:support//t:material//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
            <dt width="150" align="left"><i18n:text i18n:key="shape">Shape</i18n:text></dt>
            <dd>
              <xsl:choose>
                <xsl:when test="//t:layout//t:rs[@type='shape']//t:seg//text()">
                  <xsl:apply-templates select="//t:layout//t:rs[@type='shape']//t:seg"/>
                </xsl:when>
                <xsl:otherwise>―</xsl:otherwise>
              </xsl:choose>
            </dd>
            <dt width="150" align="left"><i18n:text i18n:key="dimensions">Dimensions (mm)</i18n:text></dt>
        <dd>
          <xsl:choose xml:space="preserve">
            <xsl:when test="//t:support/t:dimensions/t:dim[@type='diameter']/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="diameter">Diam. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:dim[@type='diameter']"/>
            </xsl:when>
            <xsl:when test="//t:support/t:dimensions/t:height/text()[not(normalize-space(.)=' ')] and //t:support/t:dimensions/t:width/text()[not(normalize-space(.)=' ')] and //t:support/t:dimensions/t:depth/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="height">H. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:height"/>,
              <i18n:text i18n:key="width">W. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:width"/>,
              <i18n:text i18n:key="thickness">Th. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:depth"/>
            </xsl:when>
            <xsl:when test="//t:support/t:dimensions/t:height/text()[not(normalize-space(.)=' ')] and //t:support/t:dimensions/t:width/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="height">H. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:height"/>,
              <i18n:text i18n:key="width">W. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:width"/>
            </xsl:when>
            <xsl:when test="//t:support/t:dimensions/t:height/text()[not(normalize-space(.)=' ')] and //t:support/t:dimensions/t:depth/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="height">H. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:height"/>,
              <i18n:text i18n:key="thickness">Th. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:depth"/>
            </xsl:when>
            <xsl:when test="//t:support/t:dimensions/t:width/text()[not(normalize-space(.)=' ')] and //t:support/t:dimensions/t:depth/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="width">W. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:width"/>,
              <i18n:text i18n:key="thickness">Th. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:depth"/>
            </xsl:when>
            <xsl:when test="//t:support/t:dimensions/t:height/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="height">H. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:height"/>
            </xsl:when>
            <xsl:when test="//t:support/t:dimensions/t:width/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="width">W. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:width"/>
            </xsl:when>
            <xsl:when test="//t:support/t:dimensions/t:depth/text()[not(normalize-space(.)=' ')]">
              <i18n:text i18n:key="thickness">Th. </i18n:text>
              <xsl:apply-templates select="//t:support/t:dimensions/t:depth"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
            <dt width="150" align="left"><i18n:text i18n:key="weight">Weight (g)</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support//t:measure[@type='weight'][@unit='g']//text()">
              <xsl:apply-templates select="//t:support//t:measure[@type='weight'][@unit='g']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
            <dt width="150" align="left"><i18n:text i18n:key="channel-orientation">Channel orientation (clock)</i18n:text></dt>
            <dd>
              <xsl:choose>
                <xsl:when test="//t:support//t:measure[@type='channelOrient'][@unit='clock']//text()">
                  <xsl:apply-templates select="//t:support//t:measure[@type='channelOrient'][@unit='clock']"/>
                </xsl:when>
                <xsl:otherwise>―</xsl:otherwise>
              </xsl:choose>
            </dd>
            <dt width="150" align="left"><i18n:text i18n:key="axis">Axis (clock)</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support//t:measure[@type='axis'][@unit='clock']//text()">
              <xsl:apply-templates select="//t:support//t:measure[@type='axis'][@unit='clock']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
            <dt width="150" align="left"><i18n:text i18n:key="overstrike-orientation">Overstrike orientation (clock)</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:support//t:measure[@type='overstrikeOrient'][@unit='clock']//text()">
              <xsl:apply-templates select="//t:support//t:measure[@type='overstrikeOrient'][@unit='clock']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
            <dt width="150" align="left"><i18n:text i18n:key="execution">Execution</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:layout//t:rs[@type='execution']//t:seg//text()">
              <xsl:apply-templates select="//t:layout//t:rs[@type='execution']//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
            <dt width="150" align="left"><i18n:text i18n:key="countermark">Countermark</i18n:text></dt>
            <dd>
              <xsl:choose>
                <xsl:when test="//t:support//t:measure[@type='countermark']//text()">
                  <xsl:apply-templates select="//t:support//t:measure[@type='countermark']"/>
                </xsl:when>
                <xsl:otherwise>―</xsl:otherwise>
              </xsl:choose>
            </dd>
            <dt width="150" align="left"><i18n:text i18n:key="condition">Condition</i18n:text></dt>
        <dd>
          <xsl:choose xml:space="preserve">
            <xsl:when test="//t:supportDesc//t:condition">
              <xsl:apply-templates select="//t:supportDesc//t:condition//t:p//text()"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          </dl>
        </div>
        <div id="stone">
          <h4 class="iospe"><i><i18n:text i18n:key="dating">Dating</i18n:text></i></h4><!-- ***********Dating************ -->
        <dl class="iospe">
          <dt width="150" align="left"><i18n:text i18n:key="date">Date</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:origin//t:origDate[@type='analysis']//t:seg/text()">
              <xsl:apply-templates select="//t:origin//t:origDate[@type='analysis']//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="internal-date">Internal date</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:origin//t:origDate[@type='internal']//t:seg/text()">
                <xsl:apply-templates select="//t:origin//t:origDate[@type='internal']//t:seg"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="dating-criteria">Dating criteria</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:origin//t:origDate[@type='analysis']//t:interp[@type='datingCriteria']/text()[not(normalize-space(.)='―') and not(normalize-space(.)='')]">
                <xsl:for-each select="//t:origin//t:origDate[@type='analysis']//t:interp[@type='datingCriteria'][not(normalize-space(.)='―') and not(normalize-space(.)='')]">
                  <xsl:apply-templates select="."/>
                  <xsl:if test="position() != last()">, </xsl:if>
                </xsl:for-each>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="alternative-dating">Alternative dating</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:origin//t:date//t:choice//t:corr[text() and normalize-space(.) != '―' and normalize-space(.) != '']">
                <xsl:apply-templates select="//t:origin//t:date//t:choice//t:corr"/> (<xsl:apply-templates select="//t:origin//t:date//t:choice//t:corr/@resp"/>), <i18n:text i18n:key="alternative-dating-basedon">based on</i18n:text>: <xsl:apply-templates select="//t:origin//t:date//t:interp[@type='datingCriteria']"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
        </dl>
        </div>
        <div id="stone">
          <h4 class="iospe"><i><i18n:text i18n:key="history">History</i18n:text></i></h4><!-- ***********History********* -->
        <dl class="iospe">
          <dt width="150" align="left"><i18n:text i18n:key="seal-category">Category</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:msContents//t:summary[@n='whole']//t:seg//text()">
              <xsl:apply-templates select="//t:msContents//t:summary[@n='whole']//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="issuer">Issuer</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:author//t:roleName//t:seg//text()">
              <xsl:apply-templates select="//t:author//t:roleName//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="issuer-milieu">Issuer's milieu</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:author//t:roleName//t:interp//text()">
              <xsl:apply-templates select="//t:author//t:roleName//t:interp"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="place-origin">Place of origin</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:origPlace//t:seg//t:placeName//text()">
              <xsl:apply-templates select="//t:origPlace//t:seg//t:placeName"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="find-place">Find place</i18n:text></dt>
        <dd>
          <xsl:choose xml:space="preserve">
            <xsl:when test="//t:history//t:provenance[@type='found']//t:placeName[@type='ancientFindspot']/text()[not(normalize-space(.)='―')] and //t:history//t:provenance[@type='found']//t:placeName[@type='modernFindspot']/text()[not(normalize-space(.)='―')]">
              <xsl:apply-templates select="//t:history//t:provenance[@type='found']//t:placeName[@type='ancientFindspot']"/> (<xsl:apply-templates select="//t:history//t:provenance[@type='found']//t:placeName[@type='modernFindspot']"/>)
            </xsl:when>
            <xsl:when test="//t:history//t:provenance[@type='found']//t:placeName[@type='ancientFindspot']/text()[not(normalize-space(.)='―')]">
              <xsl:apply-templates select="//t:history//t:provenance[@type='found']//t:placeName[@type='ancientFindspot']"/>
            </xsl:when>
            <xsl:when test="//t:history//t:provenance[@type='found']//t:placeName[@type='modernFindspot']/text()[not(normalize-space(.)='―')]">
              <xsl:apply-templates select="//t:history//t:provenance[@type='found']//t:placeName[@type='modernFindspot']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="find-date">Find date</i18n:text></dt>
          <dd>
            <xsl:choose xml:space="preserve">
              <xsl:when test="//t:provenance[@type='found']/@when">
                <xsl:apply-templates select="//t:provenance[@type='found']/@when"/>
              </xsl:when>
              <xsl:when test="//t:provenance[@type='found']/@notBefore and //t:provenance[@type='found']/@notAfter">
                <xsl:apply-templates select="//t:provenance[@type='found']/@notBefore"/> - <xsl:apply-templates select="//t:provenance[@type='found']/@notAfter"/>
              </xsl:when>
              <xsl:when test="//t:provenance[@type='found']/@notBefore">
                <i18n:text i18n:key="not-before">Not before</i18n:text> <xsl:apply-templates select="//t:provenance[@type='found']/@notBefore"/>
              </xsl:when>
              <xsl:when test="//t:provenance[@type='found']/@notAfter">
                <i18n:text i18n:key="not-after">Not after</i18n:text> <xsl:apply-templates select="//t:provenance[@type='found']/@notAfter"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="find-circumstances">Find circumstances</i18n:text></dt>
          <dd>
          <xsl:choose>
            <xsl:when test="//t:provenance[@type='found']//t:rs[@type='circumstances']//text()">
              <xsl:apply-templates select="//t:provenance[@type='found']//t:rs[@type='circumstances']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="modern-location">Modern location</i18n:text></dt>
        <dd>
          <xsl:choose xml:space="preserve">
                        <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:settlement//t:seg//text() and //t:sourceDesc//t:msDesc//t:msIdentifier//t:country//t:seg//text()">
                          <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:settlement//t:seg"/>
                          (<xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:country//t:seg"/>) 
                        </xsl:when>
                        <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:settlement//t:seg//text()">
                          <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:settlement//t:seg"/>
                          <xsl:text/>
                        </xsl:when>
                        <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:country//t:seg//text()">
                          <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:country//t:seg"/>
                          <xsl:text/>
                        </xsl:when>
                        <xsl:otherwise>―</xsl:otherwise>
                    </xsl:choose>
        </dd>
          <dt width="150" align="left"><i18n:text i18n:key="institution-repository">Institution and repository</i18n:text></dt>
        <!-- <dd>
            <xsl:choose xml:space="preserve">
                        <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier">
                            <xsl:value-of select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:institution"/>: <xsl:value-of select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:repository"/>, <xsl:value-of select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:collection"/>, No. <xsl:value-of select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:idno"/>  
                        </xsl:when>
                        <xsl:otherwise><i18n:text i18n:key="not-available">Not available</i18n:text></xsl:otherwise>
                    </xsl:choose>
          </dd> -->
          <dd>
            <xsl:choose xml:space="preserve">
              <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:institution/text()[not(normalize-space(.)='―')] and //t:sourceDesc//t:msDesc//t:msIdentifier//t:repository/text()[not(normalize-space(.)='―')]">
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:institution"/>,
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:repository"/>
              </xsl:when>
              <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:institution/text()[not(normalize-space(.)='―')]">
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:institution"/>
              </xsl:when>
              <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:repository/text()[not(normalize-space(.)='―')]">
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:repository"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="collection-inventory">Collection and inventory</i18n:text></dt>
          <dd>
            <xsl:choose xml:space="preserve">
              <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:collection/text()[not(normalize-space(.)='―')] and //t:sourceDesc//t:msDesc//t:msIdentifier//t:idno/text()[not(normalize-space(.)='―')]">
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:collection"/>, 
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:idno"/>
              </xsl:when>
              <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:collection/text()[not(normalize-space(.)='―')]">
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:collection"/>, no inv. no.
              </xsl:when>
              <xsl:when test="//t:sourceDesc//t:msDesc//t:msIdentifier//t:idno/text()[not(normalize-space(.)='―')]">
                <xsl:apply-templates select="//t:sourceDesc//t:msDesc//t:msIdentifier//t:idno"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="acquisition">Acquisition</i18n:text></dt>
          <dd>
            <xsl:choose xml:space="preserve">
              <xsl:when test="//t:acquisition//t:p//text()">
                <xsl:apply-templates select="//t:acquisition//t:p"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="previous-locations">Previous locations</i18n:text></dt>
          <dd>
            <xsl:choose xml:space="preserve">
              <xsl:when test="//t:provenance[@type='transferred']//t:p//text()">
                <xsl:apply-templates select="//t:provenance[@type='transferred']//t:p"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="modern-observations">Modern observations</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:provenance[@type='observed']//t:p//text() and //t:provenance[@type='not-observed']//t:p//text()">
                <xsl:apply-templates select="//t:provenance[@type='observed']//t:p"/>
                <xsl:apply-templates select="//t:provenance[@type='not-observed']//t:p"/>
              </xsl:when>
              <xsl:when test="//t:provenance[@type='observed']//t:p//text()">
                <xsl:apply-templates select="//t:provenance[@type='observed']//t:p"/>
              </xsl:when>
              <xsl:when test="//t:provenance[@type='not-observed']//t:p//text()">
                <xsl:apply-templates select="//t:provenance[@type='not-observed']//t:p"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
        </dl>
        </div>
        
      <div id="text-field">
        <h3 class="iospe"><i18n:text i18n:key="field-obverse">Obverse</i18n:text></h3>
        <!-- *******inscribed field - obverse *********** -->
        <dl class="iospe"> 
          <dt width="150" align="left"><i18n:text i18n:key="languages">Language(s)</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:msContents//t:textLang[@n='r']//t:seg//text()">
                <xsl:apply-templates select="//t:msContents//t:textLang[@n='r']//t:seg"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="layout-field">Layout of field</i18n:text></dt>
          <dd>
            <xsl:choose xml:space="preserve">
                        <xsl:when test="//t:layoutDesc//t:layout[@n='r']">
                            <xsl:apply-templates select="//t:layoutDesc//t:layout[@n='r']//t:p"/>
                        </xsl:when>
                        <xsl:otherwise>―</xsl:otherwise>
                    </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="field-dimensions">Field's dimensions (mm)</i18n:text></dt>
          <dd>
            <xsl:choose xml:space="preserve">
              <xsl:when test="//t:layout[@n='r']/t:dimensions/t:dim[@type='diameter'][text() and normalize-space(.) != '―' and normalize-space(.) != '']">
                <i18n:text i18n:key="diameter">Diam. </i18n:text>
                <xsl:apply-templates select="//t:layout[@n='r']/t:dimensions/t:dim[@type='diameter']"/>
              </xsl:when>
              <xsl:when test="//t:layout[@n='r']/t:dimensions/t:height[text() and normalize-space(.) != '―' and normalize-space(.) != ''] and //t:layout[@n='r']/t:dimensions/t:width[text() and normalize-space(.) != '―' and normalize-space(.) != '']">
                <i18n:text i18n:key="height">H. </i18n:text>
                <xsl:apply-templates select="//t:layout[@n='r']/t:dimensions/t:height"/>,
                <i18n:text i18n:key="width">W. </i18n:text>
                <xsl:apply-templates select="//t:layout[@n='r']/t:dimensions/t:width"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="matrix">Matrix</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:origin//t:origDate[@type='analysis']//t:interp[@type='datingCriteria'][normalize-space(.) != '' and normalize-space(.) != '―']">
                <xsl:apply-templates select="//t:origin//t:origDate[@type='analysis']//t:interp[@type='datingCriteria']"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="iconography">Iconography</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:figure//t:figDesc[@n='r']//text()">
                <xsl:apply-templates select="//t:figure//t:figDesc[@n='r']"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="decoration">Decoration</i18n:text></dt>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:figure//t:figDesc[@n='decoR']//text()">
                <xsl:apply-templates select="//t:figure//t:figDesc[@n='decoR']"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <dt width="150" align="left"><i18n:text i18n:key="epigraphy">Epigraphy</i18n:text></dt>
          <dd id="epigraphy">
            <xsl:choose> <!--cambiare @n='whole' in 'r' e 'v'-->
              <xsl:when test="//t:handDesc//t:handNote[@n='r']//t:seg//text()">
                <xsl:apply-templates select="//t:handDesc//t:handNote[@n='r']//t:seg"/>
              </xsl:when>
              <xsl:otherwise>―</xsl:otherwise>
            </xsl:choose>
          </dd>
          <!-- dating for assembled seals not included yet -->
        </dl>
      </div>

    <dl class="iospe"/><!-- don't touch this! -->
      
    <div id="text-field">
      <h3 class="iospe"><i18n:text i18n:key="field-reverse">Reverse</i18n:text></h3><!-- *******inscribed field - reverse *********** -->
      <dl class="iospe"> 
        <dt width="150" align="left"><i18n:text i18n:key="languages">Language(s)</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:msContents//t:textLang[@n='v']//t:seg//text()">
              <xsl:apply-templates select="//t:msContents//t:textLang[@n='v']//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="layout-field">Layout of field</i18n:text></dt>
        <dd>
          <xsl:choose xml:space="preserve">
                        <xsl:when test="//t:layoutDesc//t:layout[@n='v']">
                            <xsl:apply-templates select="//t:layoutDesc//t:layout[@n='v']//t:p"/>
                        </xsl:when>
                        <xsl:otherwise>―</xsl:otherwise>
                    </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="field-dimensions">Field's dimensions (mm)</i18n:text></dt>
        <dd>
          <xsl:choose xml:space="preserve">
            <xsl:when test="//t:layout[@n='r']/t:dimensions/t:dim[@type='diameter'][text() and normalize-space(.) != '―' and normalize-space(.) != '']">
              <i18n:text i18n:key="diameter">Diam. </i18n:text>
              <xsl:apply-templates select="//t:layout[@n='r']/t:dimensions/t:dim[@type='diameter']"/>
            </xsl:when>
            <xsl:when test="//t:layout[@n='r']/t:dimensions/t:height[text() and normalize-space(.) != '―' and normalize-space(.) != ''] and //t:layout[@n='r']/t:dimensions/t:width[text() and normalize-space(.) != '―' and normalize-space(.) != '']">
              <i18n:text i18n:key="height">H. </i18n:text>
              <xsl:apply-templates select="//t:layout[@n='r']/t:dimensions/t:height"/>,
              <i18n:text i18n:key="width">W. </i18n:text>
              <xsl:apply-templates select="//t:layout[@n='r']/t:dimensions/t:width"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="matrix">Matrix</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:origin//t:date//t:choice//t:corr[normalize-space(.) != '' and normalize-space(.) != '―']">
              <xsl:apply-templates select="//t:origin//t:date//t:choice//t:corr"/> (<xsl:apply-templates select="//t:origin//t:date//t:choice//t:corr/@resp"/>), <i18n:text i18n:key="alternative-dating-basedon">based on</i18n:text>: <xsl:apply-templates select="//t:origin//t:date//t:interp[@type='datingCriteria']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="iconography">Iconography</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:figure//t:figDesc[@n='v']//text()">
              <xsl:apply-templates select="//t:figure//t:figDesc[@n='v']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="decoration">Decoration</i18n:text></dt>
        <dd>
          <xsl:choose>
            <xsl:when test="//t:figure//t:figDesc[@n='decoV']//text()">
              <xsl:apply-templates select="//t:figure//t:figDesc[@n='decoV']"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="epigraphy">Epigraphy</i18n:text></dt>
        <dd id="epigraphy">
          <xsl:choose>
            <xsl:when test="//t:handDesc//t:handNote[@n='v']//t:seg//text()">
              <xsl:apply-templates select="//t:handDesc//t:handNote[@n='v']//t:seg"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <!-- dating for assembled seals -->
      </dl>
    </div>
    <dl class="iospe"><!-- don't touch this! --></dl>
    <div id="text">
      <!--<h3 class="iospe"><i18n:text i18n:key="text">Text</i18n:text></h3>-->
      <div id="images"><!-- ************************* IMAGES ************************************ -->
        <h4 class="iospe"><i><i18n:text i18n:key="images">Images</i18n:text></i></h4>
        <dl class="box">
          <xsl:for-each select="//t:facsimile//t:surface[@type='obverse' or @n='r']//t:graphic">
            <dd>
              <xsl:apply-templates select="."/>
            </dd>
          </xsl:for-each>
          <dt width="150">
            <xsl:value-of select="//t:facsimile//t:surface[@type='obverse' or @n='r']//t:graphic//t:desc"/>
          </dt>
        </dl>
        <dl class="box">
          <xsl:for-each select="//t:facsimile//t:surface[@type='reverse' or @n='v']//t:graphic">
            <dd>
              <xsl:apply-templates select="."/>
            </dd>
          </xsl:for-each>
          <dt width="150">
            <xsl:value-of select="//t:facsimile//t:surface[@type='reverse' or @n='v']//t:graphic//t:desc"/>
          </dt>
        </dl>
        
        <!-- alternative (without captions) -->
        
        <!--<dl class="box">
          <dt width="150"/>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:facsimile//t:surface[@type='obverse']//t:graphic">
                <xsl:apply-templates select="//t:facsimile//t:surface[@type='obverse']//t:graphic"/>
              </xsl:when>
              <xsl:otherwise><i18n:text>No images available</i18n:text></xsl:otherwise>
            </xsl:choose>
          </dd>
        </dl>
        <dl class="box">
          <dt width="150"/>
          <dd>
            <xsl:choose>
              <xsl:when test="//t:facsimile//t:surface[@type='reverse']//t:graphic">
                <xsl:apply-templates select="//t:facsimile//t:surface[@type='reverse']//t:graphic"/>
              </xsl:when>
              <xsl:otherwise><i18n:text>No images available</i18n:text></xsl:otherwise>
            </xsl:choose>
          </dd>
        </dl>-->

<!-- deprecated solution, with table -->
        
        <!--<table border="1">
          <tr>
            <td align="center">
              <dl>
                <xsl:for-each select="//t:facsimile//t:surface[@type='obverse']//t:graphic">
                <dt width="150" align="left"></dt>
                  <dd>
                    <xsl:apply-templates select="." />
                  </dd>
                </xsl:for-each>
              </dl>
            </td>
            <td align="center">
              <dl>
                <xsl:for-each select="//t:facsimile//t:surface[@type='reverse']//t:graphic">
                  <dt width="150" align="left"></dt>
                  <dd>
                    <xsl:apply-templates select="." />
                  </dd>
                </xsl:for-each>
              </dl>
            </td>
          </tr>
          <tr>
            <th>
              <xsl:choose>
                <xsl:when test="//t:facsimile//t:surface[@type='obverse']//t:graphic//t:desc//text()">
                  <xsl:apply-templates select="//t:facsimile//t:surface[@type='obverse']//t:graphic//t:desc"/>
                </xsl:when>
                <xsl:otherwise></xsl:otherwise>
              </xsl:choose>
            </th>
            <th>
              <xsl:choose>
                <xsl:when test="//t:facsimile//t:surface[@type='reverse']//t:graphic//t:desc//text()">
                  <xsl:apply-templates select="//t:facsimile//t:surface[@type='reverse']//t:graphic//t:desc"/>
                </xsl:when>
                <xsl:otherwise></xsl:otherwise>
              </xsl:choose>
            </th>
          </tr>
        </table>-->
      </div>

      <h4 class="iospe"><i><i18n:text i18n:key="edition">Edition</i18n:text></i></h4>
      <div class="section-container tabs" data-section="tabs">
        <section>
          <p class="title" data-section-title="data-section-title"><a href="#"><i18n:text i18n:key="interpretive">Interpretive</i18n:text></a></p>
          <div class="content" id="edition" data-section-content="data-section-content">
            <!-- Edited text output -->
            <xsl:variable name="edtxt">
              <xsl:apply-templates select="//t:div[@type='edition'][@subtype='editorial']">
                <xsl:with-param name="parm-edition-type" select="'interpretive'" tunnel="yes"/>
              </xsl:apply-templates>
            </xsl:variable>
            <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
            <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
          </div>
        </section>
        <section>
          <p class="title" data-section-title="data-section-title"><a href="#"><i18n:text i18n:key="diplomatic">Diplomatic</i18n:text></a></p>
          <div class="content" id="diplomatic" data-section-content="data-section-content">
            <!-- Edited text output -->
            <xsl:variable name="edtxt">
              <xsl:apply-templates select="//t:div[@type='edition'][@subtype='diplomatic']">
                <xsl:with-param name="parm-edition-type" select="'diplomatic'" tunnel="yes"/>
              </xsl:apply-templates>
            </xsl:variable>
            <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
            <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
          </div>
        </section>
      </div>
      <div id="apparatus" class="iospe">
        <h4 class="iospe"><i18n:text i18n:key="apparatus">Apparatus</i18n:text></h4>
        <!-- Apparatus text output -->
        <xsl:variable name="apptxt">
          <xsl:apply-templates select="//t:div[@type='apparatus']/t:listApp"/>
        </xsl:variable>
        <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
      </div>
      
      <div id="translation">
        <h4 class="iospe"><i><i18n:text i18n:key="legend-translation">Legend and Translation</i18n:text></i></h4>
        <!-- Translation text output -->
        <xsl:variable name="transtxt">
          <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
        </xsl:variable>
        <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
      </div>
      
      <div id="bibliography"> <!--is a div here necessary?????-->
        <h4 class="iospe"><i18n:text i18n:key="references">References</i18n:text></h4>
      <dl class="iospe">  
        <dt width="150" align="left"><i18n:text i18n:key="editions"><i>Edition(s)</i></i18n:text></dt>
        <dd id="biblioEditions">
          <xsl:choose>
            <xsl:when test="//t:body//t:div[@type='bibliography'][@subtype='edition']/t:p/node()">
              <xsl:apply-templates select="//t:body//t:div[@type='bibliography'][@subtype='edition']/t:p/node()"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
        <!--<dt width="150" align="left"><i18n:text i18n:key="commentary-edition">Commentary on edition(s)</i18n:text></dt>
        <dd id="biblioCommEditions">
          <xsl:choose>
            <xsl:when test="//t:body//t:div[@type='bibliography'][@subtype='discussionCurrent']/t:p/node()">
              <xsl:apply-templates select="//t:body//t:div[@type='bibliography'][@subtype='discussionCurrent']/t:p/node()"/>
            </xsl:when>
            <xsl:otherwise><i><i18n:text i18n:key="none">None</i18n:text></i></xsl:otherwise>
          </xsl:choose>
        </dd>-->
        <dt width="150" align="left"><i18n:text i18n:key="parallels"><i>Parallel(s)</i></i18n:text></dt>
        <dd id="biblioParallels">
          <xsl:choose>
            <xsl:when test="//t:body//t:div[@type='bibliography'][@subtype='parallels']/t:p/node()">
              <xsl:apply-templates select="//t:body//t:div[@type='bibliography'][@subtype='parallels']/t:p/node()"/>
            </xsl:when>
            <xsl:otherwise><i><i18n:text i18n:key="no-parallels-known">No parallels known</i18n:text></i></xsl:otherwise>
          </xsl:choose>
        </dd>
        <dt width="150" align="left"><i18n:text i18n:key="further-references"><i>Further references</i></i18n:text></dt>
        <dd id="biblioCommParallels">
          <xsl:choose> <!--da cambiare i subtype-->
            <xsl:when test="//t:body//t:div[@type='bibliography'][@subtype='discussion']/t:p/node()">
              <xsl:apply-templates select="//t:body//t:div[@type='bibliography'][@subtype='discussion']/t:p/node()"/>
            </xsl:when>
            <xsl:otherwise>―</xsl:otherwise>
          </xsl:choose>
        </dd>
      </dl>
      </div>
      
      <div id="commentary">
        <h4 class="iospe"><i><i18n:text i18n:key="commentary">Commentary</i18n:text></i></h4>
        <!-- Commentary text output -->
        <xsl:variable name="commtxt">
          <xsl:apply-templates select="//t:div[@type='commentary'][@subtype='text']//t:p"/>
        </xsl:variable>
        <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
      </div>
      
      <!-- ************** FOOTNOTES ***************** -->
      <div class="fnseparator"/>
      <div id="footnotes">
        <h4 class="iospe" id="notes"><i18n:text i18n:key="footnotes">Footnotes</i18n:text></h4>
        <xsl:choose>
          <xsl:when test="//t:div[@type='commentary'][@subtype='footnotes']//t:p">
            <xsl:apply-templates select="//t:div[@type='commentary'][@subtype='footnotes']//t:p"/>
          </xsl:when>
          <xsl:otherwise>―</xsl:otherwise>
        </xsl:choose>
      </div>
      
    </div>
  </xsl:template>

  <xsl:template name="sigidoc-structure">
    <xsl:variable name="title">
      <xsl:call-template name="iospe-title"/>
    </xsl:variable>
    <html>
      <head>
        <title>
          <xsl:value-of select="$title"/>
        </title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
        <!-- Found in htm-tpl-cssandscripts.xsl -->
        <xsl:call-template name="css-script"/>
      </head>
      <body>
        <h1>
          <xsl:value-of select="$title"/>
        </h1>
        <xsl:call-template name="iospe-body-structure"/>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="sigidoc-title">
    <xsl:choose>
      <xsl:when test="//t:titleStmt/t:title/text() and matches(//t:idno[@type='filename'], '^\d\.\d{1,4}$')">
        <xsl:number value="substring-before(//t:idno[@type='filename'],'.')" format="I"/>
        <xsl:text> </xsl:text>
        <xsl:number value="substring-after(//t:idno[@type='filename'],'.')" format="1"/>
        <xsl:text>. </xsl:text>
        <xsl:if test="string(normalize-space(//t:origPlace[1]))"><xsl:value-of select="normalize-space(//t:origPlace[1])"/>
        <xsl:text>. </xsl:text></xsl:if>
        <xsl:value-of select="//t:titleStmt/t:title[child::text()][1]"/>
        <xsl:if test="not(//t:titleStmt/t:title[child::text()][1][child::t:origDate])">
          <xsl:text>, </xsl:text>
          <xsl:value-of select="//t:origDate[1]"/>
        </xsl:if>
      </xsl:when>
      <xsl:when test="//t:titleStmt/t:title/text()">
        <xsl:value-of select="//t:titleStmt/t:title"/>
      </xsl:when>
      <xsl:when test="//t:sourceDesc//t:bibl/text()">
        <xsl:value-of select="//t:sourceDesc//t:bibl"/>
      </xsl:when>
      <xsl:when test="//t:idno[@type='filename']/text()">
        <xsl:value-of select="//t:idno[@type='filename']"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>EpiDoc example output, SigiDoc style</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="t:placeName"><!-- don't add @mode!!! -->
    <xsl:choose>
      <xsl:when test="contains(@ref,'pleiades.stoa.org') or contains(@ref,'geonames.org') or contains(@ref,'slsgazetteer.org')">
        <a>
          <xsl:attribute name="href">
            <xsl:value-of select="@ref"/>
          </xsl:attribute>
          <xsl:attribute name="target">_blank</xsl:attribute>
          <xsl:apply-templates/>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
  <xsl:template match="t:ref"><!-- for external (not <placeName/>) and internal links -->
    <a>
      <xsl:attribute name="href">
        <xsl:value-of select="@target"/>
      </xsl:attribute>
      <xsl:attribute name="target">_blank</xsl:attribute>
      <xsl:apply-templates/>
    </a>
  </xsl:template>
  
  <xsl:template match="t:idno[@type='PBW']"><!-- pointing to the boulloterion ID page on the PBW -->
    <a>
      <xsl:attribute name="href">
        <xsl:value-of select="@corresp"/>
      </xsl:attribute>
      <xsl:attribute name="target">_blank</xsl:attribute>
      <xsl:apply-templates/>
    </a>
  </xsl:template>
  
  <xsl:template match="t:ptr[@target]">
    <xsl:variable name="bibl-ref" select="@target"/>
    <xsl:variable name="bibl" select="document(concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/bibliography.xml'))//t:bibl[@xml:id=$bibl-ref][not(@sameAs)]"/>
    <a>
      <xsl:attribute name="href">
        <xsl:text>../concordance/bibliography/</xsl:text>
        <xsl:value-of select="$bibl-ref"/>
        <xsl:text>.html</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="target">_blank</xsl:attribute>
      <xsl:choose>
        <xsl:when test="$bibl//t:bibl[@type='abbrev']">
          <xsl:apply-templates select="$bibl//t:bibl[@type='abbrev'][1]"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="$bibl"/>
        </xsl:otherwise>
      </xsl:choose>
    </a>
  </xsl:template>
  
  <!-- arrows pointing to previous/next seal: from "Cretan Inscriptions" project -->
  <xsl:template name="navigation">
    <xsl:if test="doc-available(concat('file:',system-property('user.dir'),'/all_seals.xml')) = fn:true()">
      <xsl:variable name="filename"><xsl:value-of select="//t:idno[@type='sequence']"/></xsl:variable>
      <xsl:variable name="list" select="document(concat('file:',system-property('user.dir'),'/all_seals.xml'))//t:list"/>
      <xsl:variable name="prev" select="$list/t:item[@sortKey=$filename]/preceding-sibling::t:item[1]/@n"/>
      <xsl:variable name="next" select="$list/t:item[@sortKey=$filename]/following-sibling::t:item[1]/@n"/>
      
      <div class="row">
        <div class="large-12 columns">
          <ul class="pagination left">
            <xsl:if test="$prev">
              <li class="arrow">
                <a>
                  <xsl:attribute name="href">
                    <xsl:text>./</xsl:text>
                    <xsl:value-of select="$prev"/>
                    <xsl:text>.html</xsl:text>
                  </xsl:attribute>
                  <i18n:text i18n:key="arrow-left"><xsl:text>⇐ previous</xsl:text></i18n:text>
                </a>
              </li>
            </xsl:if>
            
            <xsl:if test="$next">
              <li class="arrow">
                <a>
                  <xsl:attribute name="href">
                    <xsl:text>./</xsl:text>
                    <xsl:value-of select="$next"/>
                    <xsl:text>.html</xsl:text>
                  </xsl:attribute>
                  <i18n:text i18n:key="arrow-right"><xsl:text>next ⇒</xsl:text></i18n:text>
                </a>
              </li>
            </xsl:if>
          </ul>
        </div>
      </div>
    </xsl:if>
  </xsl:template>
  
</xsl:stylesheet></xsl:import>
  
</xsl:stylesheet></xsl:import><xsl:import xmlns:i18n="http://apache.org/cocoon/i18n/2.1" 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 xmlns:i18n="http://apache.org/cocoon/i18n/2.1" 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 xmlns:i18n="http://apache.org/cocoon/i18n/2.1" href="cocoon://_internal/url/reverse.xsl"><xsl:stylesheet 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-map'"><xsl:text>/</xsl:text><xsl:value-of select="$parameters[2-1]"/><xsl:text>/map/</xsl:text></xsl:when><xsl:when test="$match-id = 'local-about'"><xsl:text>/</xsl:text><xsl:value-of select="$parameters[2-1]"/><xsl:text>/about/</xsl:text></xsl:when><xsl:when test="$match-id = 'local-about-page'"><xsl:text>/</xsl:text><xsl:value-of select="$parameters[2-1]"/><xsl:text>/about/</xsl:text><xsl:value-of select="$parameters[3-1]"/><xsl:text>/</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>/seals/</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>/seals/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>/seals/</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>/seals/</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:param name="filename"/><xsl:param name="edition-type"/><xsl:param name="edn-structure"/><xsl:param name="external-app-style"/><xsl:param name="image-loc"/><xsl:param name="internal-app-style"/><xsl:param name="leiden-style"/><xsl:param name="line-inc"/><xsl:param name="verse-lines"/><xsl:variable name="title">
    <xsl:call-template name="inslib-title"/>
  </xsl:variable><xsl:template match="/">

  

  
    

  
  
  
  
  
  
  
  
  

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

  
    

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

  <!-- Imports the menu stylesheet -->
  

  

  
    <html xmlns:i18n="http://apache.org/cocoon/i18n/2.1" 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>
            
      SigiDoc:
      <xsl:value-of select="$title"/>
    
          </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/epidoc/global.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"/>
          
    
          
            <script src="{$kiln:assets-path}/foundation/js/vendor/custom.modernizr.js"> </script>
            <script src="{$kiln:assets-path}/scripts/footnotes.js"> </script>
            <script src="{$kiln:assets-path}/scripts/cookieinfo.min.js" type="text/javascript" id="cookieinfo"/>
          
          
        </head>
      
      
        <body>
          
            <div id="header-logos" style="display: flex; justify-content: space-between; align-items: center; padding: 1rem 2rem; background-color: rgb(210, 94, 55); min-height: 120px;">
              <div class="text-left" style="flex: 1; display: flex; justify-content: flex-start;">
                <a href="/">
                  <img src="{$kiln:assets-path}/images/DigiSigiCorpLogoTransparent.png" alt="SigiDoc" style="max-height: 5em; height: auto; width: auto;"/>
                </a>
              </div>
              <div class="text-center" style="flex: 1; display: flex; justify-content: center;">
                <img src="{$kiln:assets-path}/images/Logo_NAIM_transparent.png" alt="NAIM" style="max-height: 5em; height: auto; width: auto;"/>
              </div>
              <div class="text-right" style="flex: 1; display: flex; justify-content: flex-end;">
                <img src="{$kiln:assets-path}/images/logo_Balgaristika_transparent.png" alt="Balgaristika" style="max-height: 5em; height: auto; width: auto;"/>
              </div>
            </div>
            <nav class="top-bar">
              
                <ul class="title-area">
                  <li class="name">
                    <a href="{kiln:url-for-match('local-language-home-page', ($language), 0)}">Home</a>
                  </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:value-of select="$title"/>

      <div class="export-seal">
        Export in
        <a href="{kiln:url-for-match('local-epidoc-display-xml', ($language, $filename), 0)}"> XML</a>
        |
        <a href="javascript:window.print()">PDF</a>
      </div>
    
                </h1>
              </div>
            </div>
          
          
            <main>
              
      <div class="row">
        <div class="large-12 columns">
          <!-- Set an appropriate context node for xsl:apply-templates
               within the EpiDoc XSLT. -->
          <xsl:for-each select="aggregation/tei:*">
            <xsl:call-template name="inslib-body-structure">
              <xsl:with-param name="parm-edition-type" select="$edition-type" tunnel="yes"/>
              <xsl:with-param name="parm-edn-structure" select="$edn-structure" tunnel="yes"/>
              <xsl:with-param name="parm-external-app-style" select="$external-app-style" tunnel="yes"/>
              <xsl:with-param name="parm-image-loc" select="$image-loc" tunnel="yes"/>
              <xsl:with-param name="parm-internal-app-style" select="$internal-app-style" tunnel="yes"/>
              <xsl:with-param name="parm-leiden-style" select="$leiden-style" tunnel="yes"/>
              <xsl:with-param name="parm-line-inc" select="number($line-inc)" tunnel="yes" as="xs:double"/>
              <xsl:with-param name="parm-verse-lines" select="$verse-lines" tunnel="yes"/>
            </xsl:call-template>
          </xsl:for-each>
        </div>
      </div>
      
    
            </main>
          
          
            <footer>
              <div id="footer-content">
                <div class="footer-left">
                  <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" rel="noopener">
                    <img alt="CC BY NC SA" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png"/>
                  </a>
                </div>
                <div class="footer-center">
                  <a href="https://github.com/SigiDoc" target="_blank" rel="noopener">SigiDoc</a>
                </div>
                <div class="footer-right">
                  <a href="https://www.codecrew.io/" target="_blank" rel="noopener">
                    <img alt="CodeCrew" src="{$kiln:assets-path}/images/CodeCrewLogo.png"/>
                  </a>
                </div>
              </div>
            </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>
          
        </body>
      
    </html>
  

  

  

  

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