<?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 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="glyph-variant"
                                select="document($param-file)//parameter[name = 'glyph-variant']/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">
      	<!-- transfers the  @xml:lang attribute of the ab element to the textpart-->
      	<!-- a div[@type='textpart'] is created for each ab element, independant of the textpart / ab hierarchical structure -->
      	
      	<!-- Found in htm-tpl-lang.xsl -->
      	<xsl:call-template name="attr-lang"/>
                           <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', 'dclp','sammelbuch'))                   and descendant::t:lb[last()][contains(@style, 'text-direction:l-to-r') or @rend='left-to-right']">
                                 <xsl:text>  →</xsl:text>
                              </xsl:if>
                              <xsl:if test="not($parm-leiden-style=('ddbdp','dclp','sammelbuch'))                   and descendant::t:lb[last()][contains(@style, 'text-direction:r-to-l') or @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:param name="location" 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">
                                       <xsl:choose>
                                          <xsl:when test="$location = 'apparatus'">apparatus</xsl:when>
                                          <xsl:otherwise>text</xsl:otherwise>
                                       </xsl:choose>
                                    </xsl:with-param>
                                 </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','dclp','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','dclp','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:param name="parm-apparatus-style" tunnel="yes" required="no"/>
                              <xsl:param name="location" tunnel="yes" required="no"/>
                              <xsl:if test="$parm-apparatus-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">
                                          <xsl:choose>
                                             <xsl:when test="$location = 'apparatus'">apparatus</xsl:when>
                                             <xsl:otherwise>text</xsl:otherwise>
                                          </xsl:choose>
                                       </xsl:with-param>
                                    </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','dclp','sammelbuch')) and @rend='slashes'">
                                    <xsl:apply-templates/>
                                 </xsl:when>
                                 <xsl:when test="($parm-leiden-style = ('ddbdp','dclp','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:param name="location" tunnel="yes" required="no"/>
                        <xsl:apply-imports/>
                     </xsl:template>


                     <xsl:template match="t:add">
                        <xsl:param name="location" tunnel="yes" required="no"/>
                        <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
                        <xsl:choose>
                           <xsl:when test="($parm-leiden-style = ('ddbdp','dclp','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:param name="location" tunnel="yes" required="no"/>
                        <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:param name="location" 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>
                                                <xsl:text>Other reading</xsl: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','dclp','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','dclp','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','dclp')">
                                       <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','dclp')">
                                       <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: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','dclp','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>

                        <!-- Custodial events here -->
      <!-- first get the value of the columns @corresp -->
      <xsl:variable name="corresp" select="@corresp"/>
                        <!-- then find each custEvent with a matching @corresp value -->

      <xsl:variable name="div-n" select="@n"/>
                        <xsl:variable name="div-subtype" select="@subtype"/>
                        <xsl:for-each select="//t:idno[@xml:id = (tokenize(replace($corresp,'#',''),' '))]">
                           <span class="corresp idno">
                              <xsl:value-of select="."/>
                           </span>
                           <br/>
                        </xsl:for-each>
                        <xsl:for-each select="//t:custEvent[@corresp = (tokenize($corresp,' '))]">
         
                           <span class="custevent" id="ce{$div-loc}{$div-n}">

               <!-- type of event -->
               <xsl:variable name="type-string">
                                 <xsl:choose>
                                    <xsl:when test="@type='MSI'">
                                       <xsl:text>Multi-spectral image captured</xsl:text>
                                    </xsl:when>
                                    <xsl:otherwise>
                                       <xsl:value-of select="concat(upper-case(substring(@type, 1, 1)), substring(@type, 2))"/>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </xsl:variable>
                              <xsl:choose>
                                 <xsl:when test="t:graphic[@url]">
                                    <xsl:variable name="gtype">
                                       <xsl:choose>
                                          <xsl:when test="@type = 'sketched'">scan of sketch</xsl:when>
                                          <xsl:when test="@type = 'imaged'">digital photograph</xsl:when>
                                          <xsl:when test="@type = 'engraved'">scan of engraving</xsl:when>
                                          <xsl:when test="@type='MSI'">multi-spectral image</xsl:when>
                                          <xsl:otherwise>
                                             <xsl:value-of select="@type"/>
                                             <xsl:message>WARNING (<xsl:value-of select="//t:idno[@type='dclp']"/>): unexpected type value for custodial event: <xsl:value-of select="@type"/>
                                             </xsl:message>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                    </xsl:variable>
                                    <a href="{t:graphic/@url}" title="{$gtype} of {$div-subtype} {$div-n}">
                                       <xsl:value-of select="$type-string"/>
                                    </a>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:value-of select="$type-string"/>
                                 </xsl:otherwise>
                              </xsl:choose>
               
                              <!-- date of event -->
               <xsl:if test="@when">
                                 <xsl:text> </xsl:text>
                                 <xsl:value-of select="@when"/>
                              </xsl:if>
                              <xsl:if test="@from and @to">
                                 <xsl:text> </xsl:text>
                                 <xsl:value-of select="@from"/>-<xsl:value-of select="@to"/>
                              </xsl:if>
               
                              <!-- responsible individual -->               
               <xsl:text> by </xsl:text>
                              <xsl:choose>
                                 <xsl:when test="t:forename or t:surname">
                                    <xsl:value-of select="t:forename"/>
                                    <xsl:if test="t:forename and t:surname">
                                       <xsl:text> </xsl:text>
                                    </xsl:if>
                                    <xsl:value-of select="t:surname"/>
                                 </xsl:when>
                                 <xsl:otherwise> [unidentified responsible individual] </xsl:otherwise>
                              </xsl:choose>
               
                           </span>
                           <br/>
                        </xsl:for-each>

                        <br/>
                        <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 xmlns:fn="http://www.w3.org/2005/xpath-functions" 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'">
                                 <xsl:text>not collated</xsl: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:for-each select="$final_printing_sources/t:ref">
                           <xsl:if test="position()=1">
                              <xsl:text> </xsl:text>
                           </xsl:if>
                           <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"/>
                        <xsl:param name="parm-edn-structure" 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[@loc]) or @loc != preceding-sibling::t:app[1]/@loc)"> <!-- edited for IAph to display t:app[not(@loc)] on a separate line -->
        <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 or not(@loc)"> <!-- edited for IAph to display t:app[not(@loc)] on a separate line -->
        <br/>
                           </xsl:when>
                           <xsl:when test="following-sibling::t:app">
                              <xsl:choose>
                                 <xsl:when test="$parm-edn-structure='inslib' or $parm-edn-structure='sample'">
                                    <xsl:text> || </xsl:text>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:text>; </xsl:text>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </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:if test="@resp">
                           <xsl:apply-templates select="@resp"/>
                        </xsl:if>
                        <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:if test="@resp">
                           <xsl:apply-templates select="@resp"/>
                        </xsl:if>
                        <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:rdg/@resp|t:div[@type = 'apparatus']//t:lem/@resp">
                        <xsl:param name="parm-external-app-style" tunnel="yes" required="no"/>
                        <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
                        <xsl:variable name="biblio" select="tokenize(substring-after(., '#'), ' #')"/>
                        <xsl:choose>
                           <xsl:when test="$parm-edn-structure='inslib' or $parm-edn-structure='sample'">
                              <xsl:for-each select="$biblio">
                                 <xsl:variable name="bib" select="normalize-space(.)"/>
                                 <!-- if you are running this template outside EFES, change the path to the bibliography authority list accordingly -->
          <xsl:variable name="bibliography-al"
                                               select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/bibliography.xml')"/>
                                 <xsl:variable name="bibl"
                                               select="document($bibliography-al)//t:bibl[@xml:id=$bib][not(@sameAs)]"/>
                                 <xsl:if test="position()=1">
                                    <xsl:text> </xsl:text>
                                 </xsl:if>
                                 <xsl:choose>
                                    <xsl:when test="doc-available($bibliography-al) = fn:true() and $bibl">
                                       <a href="../concordance/bibliography/{$bib}.html" target="_blank">
                                          <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:choose>
                                                   <xsl:when test="$bibl//t:*[@type='abbrev']">
                                                      <xsl:apply-templates select="$bibl//t:*[@type='abbrev']"/>
                                                   </xsl:when>
                                                   <xsl:when test="$bibl[ancestor::t:div[@xml:id='authored_editions']]">
                                                      <xsl:for-each select="$bibl//t:name[@type='surname'][not(parent::*/preceding-sibling::t:title)]">
                                                         <xsl:apply-templates select="."/>
                                                         <xsl:if test="position()!=last()"> – </xsl:if>
                                                      </xsl:for-each>
                                                      <xsl:text> </xsl:text>
                                                      <xsl:apply-templates select="$bibl//t:date"/>
                                                   </xsl:when>
                                                   <xsl:when test="$bibl[ancestor::t:div[@xml:id='series_collections']]">
                                                      <i>
                                                         <xsl:value-of select="$bibl/@xml:id"/>
                                                      </i>
                                                   </xsl:when>
                                                   <xsl:otherwise>
                                                      <xsl:value-of select="$bib"/>
                                                   </xsl:otherwise>
                                                </xsl:choose>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </a>
                                    </xsl:when>
                                    <xsl:otherwise>
                                       <xsl:value-of select="$bib"/>
                                    </xsl:otherwise>
                                 </xsl:choose>
                                 <xsl:if test="position()!=last()">
                                    <xsl:text>, </xsl:text>
                                 </xsl:if>
                              </xsl:for-each>
                           </xsl:when>
                           <xsl:otherwise/>
                        </xsl:choose>
                     </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)}">
                           <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"
                                   mode="#default inslib-dimensions inslib-placename sample-dimensions creta">
                        <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
                        <xsl:choose>
                           <xsl:when test="$parm-edn-structure='inslib' or $parm-edn-structure='sample' or $parm-edn-structure='creta'">
                              <span class="lang">
                    <!-- Found in htm-tpl-lang.xsl -->
                    <xsl:call-template name="attr-lang"/>
                                 <xsl:choose>
                                    <xsl:when test="@xml:lang='grc'">
                                       <xsl:apply-templates/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                       <i>
                                          <xsl:apply-templates/>
                                       </i>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </span>
                           </xsl:when>
                           <xsl:otherwise>
                              <span class="lang">
                    <!-- Found in htm-tpl-lang.xsl -->
                    <xsl:call-template name="attr-lang"/>
                                 <xsl:apply-templates/>
                              </span>
                           </xsl:otherwise>
                        </xsl:choose>
                     </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','dclp','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"
                                        xmlns:fn="http://www.w3.org/2005/xpath-functions"
                                        exclude-result-prefixes="t EDF"
                                        version="2.0">
   <!-- Templates imported by [htm|txt]-teig.xsl -->

   <xsl:template name="lb-dash">
      <!-- function EDF:f-wwrap declared in functions.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:param name="parm-edition-type" tunnel="yes" required="no"/>
                              <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
                              <xsl:param name="parm-glyph-variant" tunnel="yes" required="no"/>
      
                              <xsl:choose>
         <!-- **** TEMPORARY FIX FOR INSLIB TEMPLATE **** -->
         <xsl:when test="$parm-edn-structure='inslib'">
                                    <xsl:variable name="symbol" select="substring-after(@ref,'#')"/>
                                    <!-- if you are running this template outside EFES, change the path to the symbols authority list accordingly -->
            <xsl:variable name="symbols-al"
                                                  select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/symbols.xml')"/>
                                    <xsl:choose>
                                       <xsl:when test="doc-available($symbols-al) = fn:true() and document($symbols-al)//t:glyph[@xml:id=$symbol]">
                                          <xsl:variable name="symbol-id" select="document($symbols-al)//t:glyph[@xml:id=$symbol]"/>
                                          <xsl:choose>
                                             <xsl:when test="$parm-edition-type='diplomatic' and $symbol-id//t:charProp[descendant::t:localName='glyph-display']//t:value">
                                                <xsl:value-of select="$symbol-id//t:charProp[descendant::t:localName='glyph-display']//t:value"/>
                                             </xsl:when>
                                             <xsl:otherwise>
                                                <xsl:value-of select="$symbol-id//t:charProp[descendant::t:localName='text-display']//t:value"/>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:choose>
                                             <xsl:when test="@ref">
                                                <xsl:value-of select="@ref"/>
                                             </xsl:when>
                                             <xsl:when test="ancestor::t:num and @type='acrophonic'">
                                                <xsl:value-of select="upper-case(.)"/>
                                             </xsl:when>
                                             <xsl:when test="ancestor::t:num and @type='alphabetic' and $parm-edition-type='interpretive'">
                                                <xsl:value-of select="lower-case(.)"/>
                                                <xsl:text>´</xsl:text>
                                             </xsl:when>
                                             <xsl:when test="ancestor::t:num and @type='alphabetic' and $parm-edition-type='diplomatic'">
                                                <xsl:value-of select="upper-case(.)"/>
                                             </xsl:when>
                                             <xsl:otherwise>
                                                <xsl:value-of select="."/>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:when>
                                 <!-- **** TEMPORARY FIX FOR INSLIB TEMPLATE - END **** -->
         <!--         if text-display set, give priority to the content of g, if any-->
         <xsl:when test="$parm-glyph-variant = 'text-display'">
                                    <xsl:choose>
                                       <xsl:when test="text()">
                                          <xsl:value-of select="."/>
                                       </xsl:when>
                                       <xsl:otherwise>
                  <!--                  because the value is alternative to project specific lists, this will use defaults.-->
                  <xsl:call-template name="chardecl">
                                             <xsl:with-param name="g" select="."/>
                                          </xsl:call-template>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:when>
                                 <!--         <g>§</g>-->
         <xsl:when test="not(@ref) and not(@type)">
                                    <xsl:choose>
                                       <xsl:when test="text()">
                                          <xsl:value-of select="."/>
                                       </xsl:when>
                                       <xsl:otherwise>unspecified</xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:call-template name="chardecl">
                                       <xsl:with-param name="g" select="."/>
                                    </xsl:call-template>
                                 </xsl:otherwise>
                              </xsl:choose>
      
                           </xsl:template>

                           <xsl:template name="chardecl">
                              <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
                              <xsl:param name="parm-edition-type" tunnel="yes" required="no"/>
                              <xsl:param name="parm-glyph-variant" tunnel="yes" required="no"/>
   
                              <xsl:param name="g"/>
   
                              <!--      stores the chardecl: if locally included, uses that one, otherways uses the common one, i.e. local definitions override -->
   <xsl:variable name="chardecl"
                                            select="if (//t:charDecl) then //t:charDecl else doc('charDecl.xml')"/>
                              <xsl:variable name="glyphID" select="EDF:refID(current()/@ref)"/>
                              <xsl:choose>
                                 <xsl:when test="starts-with($parm-leiden-style, 'edh')"/>
      
                                 <!--     if there is ref AND there actually is a glyph in the list with that id, then check what to print from the values in that glyph-->
      <xsl:when test="starts-with(@ref,'#') and $chardecl//t:glyph[@xml:id=$glyphID]">
                                    <xsl:for-each select="$chardecl//t:glyph[@xml:id=$glyphID]">
                                       <xsl:choose>
                                          <xsl:when test="$parm-edition-type='diplomatic'">
                                             <xsl:variable name="glyphDiplomatic" select="concat($parm-glyph-variant, '-diplomatic')"/>
                                             <xsl:choose>
                                                <xsl:when test="t:mapping[@type=$glyphDiplomatic]">
                                                   <xsl:value-of select="t:mapping[@type=$glyphDiplomatic]"/>
                                                   <xsl:call-template name="g-unclear-symbol"/>
                                                </xsl:when>
                                                <xsl:when test="t:mapping[@type=$parm-glyph-variant]">
                                                   <xsl:value-of select="t:mapping[@type=$parm-glyph-variant]"/>
                                                   <xsl:call-template name="g-unclear-symbol"/>
                                                </xsl:when>
                                                <!--                        no fallback, it will produce nothing in a diplomatic edition unless specified by the glyph-variant -->
                  </xsl:choose>
                                          </xsl:when>
                                          <xsl:when test="t:mapping[@type=$parm-glyph-variant]">
                                             <xsl:value-of select="t:mapping[@type=$parm-glyph-variant]"/>
                                             <xsl:call-template name="g-unclear-symbol"/>
                                          </xsl:when>
                                          <xsl:otherwise>
                                             <xsl:value-of select="t:mapping[@type='standard']"/>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                    </xsl:for-each>
                                 </xsl:when>
      
                                 <!--         If there is a ref, but it does not start with #, it should be another URI,
         which is assumed to be like https://example.com/myCharDeclFile.xml#glyphID or
         ../../myCharDeclFile.xml#glyphID -->
      
      <xsl:when test="@ref">
         <!--            ref may be a full string, or rather use a prefix, declared in prefixDecl, the xml:id assigned to the glyph may be thus without anchor, and needs to be reconstructed before-->
         <xsl:variable name="parsedRef" select="EDF:refParser(@ref, //t:listPrefixDef)"/>
         
                                    <xsl:variable name="externalCharDecl" select="substring-before($parsedRef, '#')"/>
                                    <xsl:choose>
                                       <xsl:when test="doc-available($externalCharDecl)">
                                          <xsl:variable name="externalCharDecldoc" select="doc($externalCharDecl)"/>
                                          <xsl:choose>
                                             <xsl:when test="$externalCharDecldoc//t:glyph[@xml:id=$glyphID]">
                                                <xsl:for-each select="$externalCharDecldoc//t:glyph[@xml:id=$glyphID]">
                  <!--               do not assume localName values are like in parameter, only print the standard -->
                  <xsl:value-of select="t:mapping[@type='standard']"/>
                                                </xsl:for-each>  
                                             </xsl:when>
                                             <xsl:otherwise>
               <!--               <xsl:message>I did not match a glyph</xsl:message>-->
               <!--                  if the linked charDecl does not actually have that ID for a glyph element, then return the value of the id-->
               <xsl:value-of select="if(contains($parsedRef, '#')) then substring-after($parsedRef,'#') else if(contains($parsedRef, ':')) then substring-after($parsedRef,':')  else $parsedRef "/>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:message>The XSLT could not locate <xsl:value-of select="@ref"/>.</xsl:message>
                                          <xsl:value-of select="@ref"/>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:when>
      
                                 <xsl:otherwise>
                                    <xsl:value-of select="@type"/>
                                    <xsl:call-template name="g-unclear-string"/>
                                 </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>𐆖</xsl:text>
                                          <xsl:call-template name="g-unclear-symbol"/>
                                       </xsl:when>
                                       <xsl:when test="@type='drachma'">
                                          <xsl:text>𐅵</xsl:text>
                                          <xsl:call-template name="g-unclear-symbol"/>
                                       </xsl:when>
                                       <xsl:when test="@type='sestercius'">
                                          <xsl:text>𐆘</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>𐆖</xsl:text>
                  <xsl:call-template name="g-unclear-symbol"/>
               </xsl:when>
               <xsl:when test="@type='sestercius'">
                  <xsl:text>𐆘</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:param name="location" tunnel="yes" required="no"/>
                              <xsl:choose>
                                 <xsl:when test="@type='apostrophe' or @type='diastole'">
                                    <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='diple-obelismene'">
                                    <xsl:text>⤚</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='diple-periestigmene'">
                                    <xsl:text>⸖</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='parens-punctuation-closing'">
                                    <xsl:text>)</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='parens-punctuation-opening'">
                                    <xsl:text>(</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='downwards-ancora'">
                                    <xsl:text>⸔</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='upwards-ancora'">
                                    <xsl:text>⸕</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='antisigma'">
                                    <xsl:text>ͻ</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='antisigma-periestigmene'">
                                    <xsl:text>ͽ</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='hypodiastole'">
                                    <xsl:text>⸒</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='swungdash'">
                                    <xsl:text>⁓</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='tetrapunct'">
                                    <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='tetrapunct'">
                                    <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='diple-obelismene'">
                                    <xsl:text>⤚</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='diple-periestigmene'">
                                    <xsl:text>⸖</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='parens-punctuation-closing'">
                                    <xsl:text>)</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='parens-punctuation-opening'">
                                    <xsl:text>(</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='downwards-ancora'">
                                    <xsl:text>⸔</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='upwards-ancora'">
                                    <xsl:text>⸕</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='antisigma'">
                                    <xsl:text>ͻ</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='antisigma-periestigmene'">
                                    <xsl:text>ͽ</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='hypodiastole'">
                                    <xsl:text>⸒</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='swungdash'">
                                    <xsl:text>⁓</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='tetrapunct'">
                                    <xsl:text>⁞</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='dotted-obelos'">
                                    <xsl:text>⸓</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='obelos'">
                                    <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='diple'">
                                    <xsl:text>›</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='asteriskos'">
                                    <xsl:text>※</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='low-punctus'">
                                    <xsl:text>.</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='high-punctus'">
                                    <xsl:text>˙</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='chi-periestigmenon'">
                                    <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 + change from https://sourceforge.net/p/epidoc/code/2532/ -->
         <xsl:otherwise>
                                    <xsl:text> ((</xsl:text>
                                    <xsl:value-of select="@type"/>
                                    <xsl:call-template name="g-unclear-string"/>
                                    <xsl:text>)) </xsl: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>𐆛</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>𐆘</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>

                           <!-- creta specific template -->
   <xsl:template name="g-creta">
                              <xsl:choose>
                                 <xsl:when test="@type='dipunct'">
                                    <xsl:text>∶</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='tripunct'">
                                    <xsl:text>⋮</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='|'">
                                    <xsl:text>|</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='middot'">
                                    <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='year'">
                                    <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='stauros'">
                                    <xsl:text>†</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='swastika'">
                                    <xsl:text>卐</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='palmula'">
                                    <xsl:text>⸙</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='⧖'">
                                    <xsl:text>⧖</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:when test="@type='⨇'">
                                    <xsl:text>⨇</xsl:text>
                                    <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='ligo'">
                                    <xsl:text>(ligo)</xsl:text>
                                    <xsl:call-template name="g-unclear-symbol"/>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:value-of select="@type"/>
                                    <xsl:call-template name="g-unclear-string"/>
                                 </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:param name="parm-edn-structure" tunnel="yes" required="no"/>
                        <xsl:param name="location" 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')"/>
                           <xsl:when test="($parm-leiden-style = ('ddbdp','dclp','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:when test="$parm-edn-structure='inslib' and (starts-with(ancestor::t:TEI//t:publicationStmt/t:idno[@type='filename']/text(), 'IGCyr') or starts-with(ancestor::t:TEI//t:publicationStmt/t:idno[@type='filename']/text(), 'GVCyr'))">
                              <xsl:apply-imports/>
                           </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','dclp','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: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'">
                                    <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','dclp','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']">
                              <xsl:param name="location" tunnel="yes" required="no"/>
                              <!-- 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']]) and not($location = 'apparatus')">
                                 <xsl:call-template name="extent-string"/>
                              </xsl:if>
      
                              <!-- Apparatus display suppress  @extent='unknown' in apparatus TODO: possibly need to add: and not(self::t:gap[@reason='illegible'][@extent='unknown'])
       -->
      <xsl:if test="$location = 'apparatus'  and not(preceding::node()[1][self::text()][normalize-space(.)=''][preceding-sibling::node()[1][self::t:gap[@reason='illegible']]]) and not(preceding-sibling::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','dclp','sammelbuch') and @unit = 'line' and @extent = 'unknown'"/>
                                 <xsl:when test="$parm-leiden-style = 'panceira' 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 with @reason='lost' and @extent='unknown' 
            -->
            <xsl:if test="                (                not(preceding::node()[1][self::text()][normalize-space(.)=''][preceding-sibling::node()[1][self::t:gap[@reason='lost'][@extent='unknown']]])                and not(preceding::node()[1][self::t:gap[@reason='lost'][@extent='unknown']])                )                 or not(self::t:gap[@reason='lost'][@extent='unknown'])">
                                       <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','dclp','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','dclp','sammelbuch') and @unit = 'line' and @extent = 'unknown'"/>
                                 <xsl:when test="$parm-leiden-style = 'panceira' 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:param name="parm-edn-structure" tunnel="yes" required="no"/> 
                              <!-- added for creta -->
      <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','dclp','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','dclp','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-edn-structure = 'creta'"> <!-- added for creta -->
                  <xsl:text>- - -</xsl:text>
                                       </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; 1 and @precision='low')">
                                          <xsl:choose>
                                             <xsl:when test="$parm-leiden-style = ('ddbdp','dclp','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','dclp','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','dclp','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','dclp','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')">
                                          <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')">
                                          <xsl:text>c. </xsl:text>
                                          <xsl:value-of select="@atLeast"/>
                                          <xsl:text> - </xsl:text>
                                          <xsl:value-of select="@atMost"/>
                                       </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','dclp','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)">
                                          <xsl:text>------</xsl:text>
                                       </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','dclp','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','dclp','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','dclp','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','dclp')">
                              <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 -->

    <!-- Add ligature combining characaters to given text -->
    <xsl:template name="ligaturizeText">
                              <xsl:param name="textLigaturize"/>
                              <xsl:analyze-string select="$textLigaturize" regex="\p{{L}}"> <!-- select letters only (will omit combining chars) -->
            <xsl:matching-substring>
                                    <xsl:choose>
                                       <xsl:when test="position()=1"> <!-- skip first ligatured char -->
                        <xsl:value-of select="."/>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:text>͡</xsl:text> 
                                          <!-- emit ligature combining char -->
                        <xsl:value-of select="."/>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </xsl:matching-substring>
                                 <xsl:non-matching-substring>
                                    <xsl:value-of select="."/>
                                 </xsl:non-matching-substring>
                              </xsl:analyze-string>
                           </xsl:template>

                           <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-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:param name="location" tunnel="yes" required="no"/>

                              <!-- This is necessary when <hi> content is embedded within <orig> mark-up or has embedded mark-up within.
             Without it, <orig> text may be reduced to lowercase, or embedded mark-up will be ignored. -->
        <xsl:variable name="text-content">
                                 <xsl:choose>
                                    <xsl:when test="ancestor::t:orig[not(ancestor::t:choice)]">
                                       <xsl:variable name="processedChars">
                                          <xsl:apply-templates select="./*|text()"/>
                                       </xsl:variable>
                                       <xsl:value-of select="translate($processedChars, $all-grc, $grc-upper-strip)"/>
                                    </xsl:when>
                                    <xsl:otherwise>
                                       <xsl:apply-templates select="./*|text()"/>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </xsl:variable>

                              <xsl:choose>
                                 <xsl:when test="@rend='ligature' and not($parm-edn-structure='inslib')">
                                    <xsl:choose>
                                       <xsl:when test="$parm-leiden-style='seg'">
                                          <xsl:if test="string-length(normalize-space(.))=2">
                                             <xsl:text>͜</xsl:text>
                                          </xsl:if>
                                       </xsl:when>
                                       <xsl:otherwise>
                        <!-- Combining char (x0361) will only render ligature line over two chars. For ligatures of >=3 chars, keep adding ligature marks -->
                        <!-- Combining characters for half-marks are: COMBINING LIGATURE LEFT HALF (U+FE20), COMBINING LIGATURE RIGHT HALF (U+FE21),
                           and COMBINING CONJOINING MACRON (U+FE26) -->
                        <!-- Also need to modify so that elements within <hi rend="ligature"> are rendered, e.g., reversed E. See RIB 1911 for example. -->
                        <!-- pro-process text content first, so formatting (e.g., underdots for unclear chars) gets applied before ligature marks -->
                        <xsl:variable name="preprocessed">
                                             <xsl:value-of select="normalize-space($text-content)"/>
                                          </xsl:variable>
                                          <xsl:call-template name="ligaturizeText">
                                             <xsl:with-param name="textLigaturize" select="$preprocessed"/>
                                          </xsl:call-template>
                                       </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">
                                                <xsl:choose>
                                                   <xsl:when test="$location = 'apparatus'">apparatus</xsl:when>
                                                   <xsl:otherwise>text</xsl:otherwise>
                                                </xsl:choose>
                                             </xsl:with-param>
                                          </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:param name="parm-edn-structure" 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:variable name="xmlid" select="@xml:id"/>
                              <xsl:variable name="prevLig"
                                            select="ancestor::t:w/preceding-sibling::t:w[1]/descendant::t:*[@rend and @xml:id]"/>
                              <xsl:variable name="nextLig"
                                            select="ancestor::t:w/following-sibling::t:w[1]/descendant::t:*[@rend and @xml:id]"/>
                              <xsl:element name="span">
                                 <xsl:choose>
                                    <xsl:when test="$parm-leiden-style=('petrae','iospe')">
                                       <xsl:attribute name="class">petraeligature</xsl:attribute>
                                    </xsl:when>
                                    <xsl:when test="$parm-edn-structure = 'inslib' and not($xmlid)">
                                       <xsl:attribute name="class">inslibligature</xsl:attribute>
                                    </xsl:when>
                                    <xsl:when test="$parm-edn-structure = 'inslib' and $xmlid">
                                       <xsl:choose>
                                          <xsl:when test="$nextLig and not($prevLig)">
                                             <xsl:attribute name="class">inslibligatureI</xsl:attribute>
                                          </xsl:when>
                                          <xsl:when test="$prevLig and $nextLig">
                                             <xsl:attribute name="class">inslibligatureM</xsl:attribute>
                                          </xsl:when>
                                          <xsl:when test="$prevLig and not($nextLig)">
                                             <xsl:attribute name="class">inslibligatureF</xsl:attribute>
                                          </xsl:when>
                                          <xsl:otherwise>
                                             <xsl:attribute name="class">ligature</xsl:attribute>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                    </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='inverted'                                                   -->
          <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
          <xsl:when test="@rend='inverted'">
                              <xsl:element name="span">
                                 <xsl:attribute name="class">inverted</xsl:attribute>
                                 <xsl:attribute name="title">inverted: <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','dclp','sammelbuch')">
                                    <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','dclp','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','dclp','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','dclp','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" tunnel="yes" required="no"/>
        
                        <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>
                        <!--    edh web  -->
                        <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>
                                    <!--    *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])"/>
                                    <!-- TODO: The following two are in contention -->
                        <xsl:when test="($parm-leiden-style = 'ddbdp' and ((not(ancestor::*[name() = 'TEI'])) or $location='apparatus')) or ($parm-edn-structure='inslib' and ancestor::t:div[@type='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 functions.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>
                                
                              <!-- print arrows right of line if R2L or explicitly L2R -->
                <!-- arrows after final line handled in htm-teiab.xsl and htm-teilgandl.xsl -->
                <xsl:if test="                     not($parm-leiden-style = ('ddbdp','dclp', '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', 'dclp','sammelbuch'))                     and not(position() = 1)                     and preceding::t:lb[1][@rend = 'right-to-left']">
                                 <xsl:text>  ←</xsl:text>
                              </xsl:if>
                
                              <xsl:if test="$parm-edn-structure='inslib' and ancestor::t:l/preceding::t:l[1]//t:lb[last()][@rend = 'left-to-right']">
                                 <xsl:text>  →</xsl:text>
                              </xsl:if>
                              <xsl:if test="$parm-edn-structure='inslib' and ancestor::t:l/preceding::t:l[1]//t:lb[last()][@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>
                                    <xsl:if test="@rend">
                                       <span>
                                          <xsl:if test="@rend">
                                             <xsl:attribute name="class">
                                                <xsl:value-of select="concat('lb ',@rend)"/>
                                             </xsl:attribute>
                                          </xsl:if>
                                          <xsl:choose>
                                             <xsl:when test="@rend='inverse'">(inverse) </xsl:when>
                                             <xsl:when test="@rend='perpendicular'">(perpendicular) </xsl:when>
                                          </xsl:choose>
                                       </span>                     
                                    </xsl:if>
                                    <!-- for the first lb in a div, create an empty anchor instead of a line-break -->
                    </xsl:when>
                                 <!-- Commented out, causes incorrect formatting. '|' should only appear in apparatus. See: https://github.com/DCLP/dclpxsltbox/issues/119 TODO: Investigate. Canceled comment (HAC)
                    -->
                    <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','dclp') and ((not(ancestor::*[name() = 'TEI'])) or $location='apparatus')) or ($parm-edn-structure='inslib' and ancestor::t:div[@type='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:if test="@rend">
                                       <span>
                                          <xsl:if test="@rend">
                                             <xsl:attribute name="class">
                                                <xsl:value-of select="concat('lb ',@rend)"/>
                                             </xsl:attribute>
                                          </xsl:if>
                                          <xsl:choose>
                                             <xsl:when test="@rend='inverse'">(inverse) </xsl:when>
                                             <xsl:when test="@rend='perpendicular'">(perpendicular) </xsl:when>
                                          </xsl:choose>
                                       </span>                     
                                    </xsl:if>
                                 </xsl:otherwise>
                              </xsl:choose>
                              <xsl:choose>
                                 <xsl:when test="$location = 'apparatus'"/>
                                 <xsl:when test="not(number(@n)) and ($parm-leiden-style = ('ddbdp','dclp','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','dclp','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','dclp') 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','dclp') 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','dclp','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:param name="parm-edn-structure" 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:when test="$parm-edn-structure='inslib' and following-sibling::t:lg">
                              <div class="textpart no-space">
               <!-- Found in htm-tpl-lang.xsl -->
               <xsl:call-template name="attr-lang"/>
                                 <xsl:apply-templates/>
                              </div>
                           </xsl:when>
                           <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:param name="parm-edn-structure" 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/>
                              <!-- if final lb in l is L2R or R2L, then print arrow here -->
            <xsl:if test="$parm-edn-structure='inslib' and not(following-sibling::t:l) and descendant::t:lb[last()][@rend='left-to-right']">
                                 <xsl:text>  →</xsl:text>
                              </xsl:if>
                              <xsl:if test="$parm-edn-structure='inslib' and not(following-sibling::t:l) and descendant::t:lb[last()][@rend='right-to-left']">
                                 <xsl:text>  ←</xsl:text>
                              </xsl:if>
                           </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:param name="parm-edn-structure" tunnel="yes" required="no"/>
                        <xsl:choose>
                           <xsl:when test="($parm-leiden-style = ('ddbdp','dclp','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','dclp','sammelbuch') or $parm-edn-structure='inslib')">
                              <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'">
                  <!--         imported change  from https://sourceforge.net/p/epidoc/code/2602/-->
                  <!-- Added to controll '-' when there is a milestone@rend='paragraphos' followed by a lb@break='no' see: https://github.com/DCLP/dclpxsltbox/issues/52-->
                 <xsl:if test="following-sibling::node()[not(self::text()                      and normalize-space(self::text())='')][1]/self::t:lb[@break='no']                      and not(preceding-sibling::*[1][self::t:supplied[@reason='lost']])">-</xsl:if>
                                    <xsl:if test="not(parent::t:supplied) and not($parm-edn-structure='inslib')">
                                       <br/>
                                    </xsl:if>
                                    <xsl:text>——</xsl:text>
                                 </xsl:when>
                                 <xsl:when test="@rend = 'diple-obelismene' and @unit='undefined'">
                  <!-- <xsl:message><xsl:text>    </xsl:text>paragraphos!</xsl:message> -->
                  <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>&gt;---</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>
   
                     <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>

                  </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"
                                  xmlns:fn="http://www.w3.org/2005/xpath-functions"
                                  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, ./t:ptr/@target)         else          ./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+&#34;key&#34;:\s&#34;)(.+)&#34;">
								                                  <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+&#34;citation&#34;:\s&#34;&lt;span&gt;)(.+)(&lt;/span&gt;&#34;)">
											                                        <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: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:template match="t:ptr[@target]">
		                      <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
		                      <xsl:choose>
			                        <xsl:when test="$parm-edn-structure='inslib' or $parm-edn-structure='sample'">
			 <!-- if you are running this template outside EFES, change the path to the bibliography authority list accordingly -->
				<xsl:variable name="bibliography-al"
                                            select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/bibliography.xml')"/>
				                          <xsl:variable name="bibl-ref" select="translate(@target, '#', '')"/>
				                          <xsl:choose>
				                             <xsl:when test="doc-available($bibliography-al) = fn:true()">
				                                <xsl:variable name="bibl"
                                                  select="document($bibliography-al)//t:bibl[@xml:id=$bibl-ref][not(@sameAs)]"/>
				                                <a href="../concordance/bibliography/{$bibl-ref}.html" target="_blank">
				                                   <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:choose>
							                                         <xsl:when test="$bibl[ancestor::t:div[@xml:id='authored_editions']]">
								                                           <xsl:for-each select="$bibl//t:name[@type='surname'][not(parent::*/preceding-sibling::t:title)]">
									                                             <xsl:apply-templates select="."/>
									                                             <xsl:if test="position()!=last()"> – </xsl:if>
								                                           </xsl:for-each>
								                                           <xsl:text> </xsl:text>
								                                           <xsl:apply-templates select="$bibl//t:date"/>
							                                         </xsl:when>
							                                         <xsl:when test="$bibl[ancestor::t:div[@xml:id='series_collections']]">
								                                           <i>
                                                      <xsl:value-of select="$bibl/@xml:id"/>
                                                   </i>
							                                         </xsl:when>
						                                       </xsl:choose>
					                                     </xsl:otherwise>
				                                   </xsl:choose>
				                                </a>
				                             </xsl:when>
				                             <xsl:otherwise>
				                                <xsl:value-of select="$bibl-ref"/>
				                             </xsl:otherwise>
				                          </xsl:choose>
			                        </xsl:when>
			                        <xsl:otherwise>
				                          <xsl:apply-templates/>
			                        </xsl:otherwise>
		                      </xsl:choose>
	                    </xsl:template>
	
	                    <xsl:template match="t:title[not(ancestor::t:titleStmt)]"
                                   mode="#default inslib-dimensions inslib-placename sample-dimensions creta">
		                      <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
		                      <xsl:choose>
			                        <xsl:when test="$parm-edn-structure='inslib' or $parm-edn-structure='sample' or $parm-edn-structure='creta'">
				                          <i>
                                 <xsl:apply-templates/>
                              </i>
			                        </xsl:when>
			                        <xsl:otherwise>
				                          <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:param name="parm-edn-structure" tunnel="yes" required="no"/>
                              <xsl:choose>
                                 <xsl:when test="not(child::t:* or child::text())"/>
                                 <xsl:when test="$parm-leiden-style = ('ddbdp','dclp','sammelbuch') and $parm-edn-structure!='inslib'">
                                    <xsl:apply-templates/>
                                    <xsl:if test="@rend='tick'">
                                       <xsl:text>´</xsl:text>
                                    </xsl:if>
                                 </xsl:when>
                                 <xsl:when test="$parm-edn-structure!='inslib' and $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','dclp','sammelbuch')              and string(.)">
                              <span>
                                 <xsl:attribute name="title">
                                    <xsl:choose>
                                       <xsl:when test="contains(@value,'/') or @type='fraction'">
                                          <xsl:text>fraction</xsl:text>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:text>number</xsl: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">
                        <xsl:param name="parm-leiden-style" tunnel="yes" required="no"/>
                        <xsl:choose>
                           <xsl:when test="$parm-leiden-style = 'dclp'">⎣<xsl:apply-templates/>⎦</xsl:when>
                           <xsl:otherwise>
                              <span class="underline">
                                 <xsl:apply-templates/>
                              </span>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:template>
    
                     <xsl:template name="supplied-previouseditor">
                        <span class="underline">
                           <xsl:apply-templates/>
                        </span>
                     </xsl:template>

                     <xsl:template name="supplied-subaudible">
                        <xsl:text>(</xsl:text>
                        <em>
                           <xsl:text>scil.</xsl:text>
                        </em>
                        <xsl:text> </xsl:text>
                        <xsl:apply-templates/>
                        <xsl:call-template name="cert-low"/>
                        <xsl:text>)</xsl:text>
                     </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','dclp','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"
                                   mode="#default inslib-dimensions inslib-placename sample-dimensions">
                        <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
                        <xsl:choose>
                           <xsl:when test="$parm-edn-structure='inslib' or $parm-edn-structure='sample'">
                              <xsl:choose>
                                 <xsl:when test="starts-with(@target, 'iAph') and not(node())"> <!-- this is the approach used in IAph -->
                  <a href="{@target}.html" target="_blank">
                                       <xsl:number value="number(substring(@target, 5, 2))" format="1"/>
                                       <xsl:text>.</xsl:text>
                                       <xsl:number value="number(substring(@target, 7, 4))" format="1"/>
                                    </a> 
                                 </xsl:when>
                                 <xsl:when test="@target">
                                    <a href="{@target}" target="_blank">
                                       <xsl:apply-templates/>
                                    </a>
                                 </xsl:when>
                                 <xsl:when test="@corresp and not(@target)">
                                    <a href="{@corresp}" target="_blank">
                                       <xsl:apply-templates/>
                                    </a>
                                 </xsl:when>
                                 <xsl:when test="@type='inscription' and @n and not(@target) and not(@corresp)">
                                    <a href="{@n}.html" target="_blank">
                                       <xsl:apply-templates/>
                                    </a>
                                 </xsl:when>
                                 <xsl:when test="@type='inscription' and not(@n) and not(@target) and not(@corresp)">
                                    <a target="_blank" href="{lower-case(translate(string(.), ' ', ''))}.html">
                                       <xsl:apply-templates/>
                                    </a>
                                 </xsl:when>
                              </xsl:choose>
                           </xsl:when>
                           <xsl:otherwise>
                              <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: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','dclp','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','dclp','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','dclp','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:value-of></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:param name="location" tunnel="yes" required="no"/>
                        <!--   This causes an error missing ' for which read ' in apparatus title, need to investigate. TODO: follow up
         -->
       <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">
                                 <xsl:choose>
                                    <xsl:when test="$location = 'apparatus'">apparatus</xsl:when>
                                    <xsl:otherwise>text</xsl:otherwise>
                                 </xsl:choose>
                              </xsl:with-param>
                           </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','dclp','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|t:facsimile"/>
  
                  </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' or @unit='fragment']">
     <!-- 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-apparatus-style" tunnel="yes" required="no"/>
                        <xsl:param name="location" tunnel="yes" required="no"/>
                        <xsl:if test="$parm-apparatus-style = 'ddbdp'">
      <!-- Adds links/indication to apparatus - found in [htm|txt]-tpl-apparatus -->
         <xsl:call-template name="app-link">
                              <xsl:with-param name="location">
                                 <xsl:choose>
                                    <xsl:when test="$location = 'apparatus'">apparatus</xsl:when>
                                    <xsl:otherwise>text</xsl:otherwise>
                                 </xsl:choose>
                              </xsl:with-param>
                           </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" priority="1">
                        <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="parent::t:choice">
                              <xsl:choose>
                                 <xsl:when test="$parm-leiden-style='medcyprus' and $parm-edition-type!='diplomatic'"/>
                                 <xsl:otherwise>
                                    <xsl:apply-templates/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:variable name="origChildren">
                                 <xsl:apply-templates/>                    
                              </xsl:variable>
                              <!-- Emit all uppercase characters for all text children of t:orig -->
                <xsl:value-of select="upper-case(translate(normalize-unicode(translate($origChildren,'ϲ','Ϲ'),'NFD'),'̀́̈̓̔͂ͅ',''))"/>
                           </xsl:otherwise>
                        </xsl:choose>
                     </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'">
               <!-- Ignore -->
           </xsl:when>
                           <xsl:otherwise>
                              <xsl:apply-templates/>
                              <xsl:if test="$parm-leiden-style = ('ddbdp','dclp')">
                   <!-- 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"/>
                     <!-- reg is currently not displayed in text in any Leiden-style
          (except "iospe", see under orig, above) -->
   
</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','dclp','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','dclp','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','dclp','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>

                     <!-- creta specific template -->
   <xsl:template match="t:corr">
                        <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/>
                        <xsl:if test="$parm-edn-structure = 'creta'">
                           <xsl:text>⟨</xsl:text>
                           <xsl:apply-templates/>
                           <xsl:text>⟩</xsl:text>
                        </xsl:if>
                     </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"/>
                        <xsl:param name="parm-edn-structure" tunnel="yes" required="no"/> 
                        <!-- added for creta -->
      <!-- function EDF:f-wwrap declared in functions.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','dclp','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:when test="($parm-edn-structure = 'creta')"> <!-- added for creta -->
                  <xsl:choose>
                                       <xsl:when test="@unit='character'">
                                          <xsl:choose>
                                             <xsl:when test="@quantity='1'">
                                                <i>v</i>
                                             </xsl:when>
                                             <xsl:when test="@quantity='2'">
                                                <i>vv</i>
                                             </xsl:when>
                                             <xsl:when test="@quantity='3'">
                                                <i>vvv</i>
                                             </xsl:when>
                                             <xsl:otherwise>
                                                <i>vac.</i>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </xsl:when>
                                       <xsl:when test="@unit='line'">
                                          <i>vacat</i>
                                       </xsl:when>                
                                    </xsl:choose>
                                    <xsl:if test="@cert='low'">
                                       <i>?</i>
                                    </xsl:if>
                                 </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','dclp','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','dclp','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: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 functions.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','dclp') 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>
            <!-- Found in [htm|txt]-teisupplied.xsl -->
            <xsl:call-template name="supplied-subaudible"/>
                           </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 = 'apograph'">
                              <xsl:text>⌈</xsl:text>
                              <xsl:apply-templates/>
                              <xsl:call-template name="cert-low"/>
                              <xsl:text>⌉</xsl:text>
                           </xsl:when>
                           <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: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','dclp','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($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-link-back'"/>
                                    </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>
                                       <!-- Parse app content to include html elements see: https://github.com/DCLP/dclpxsltbox/issues/137 -->
               <xsl:call-template name="parse-app-parts">
                                          <xsl:with-param name="part" select="$part1"/>
                                       </xsl:call-template>
                                       <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:call-template name="parse-app-parts">
                                          <xsl:with-param name="part" select="$part3"/>
                                       </xsl:call-template>
                                    </xsl:when>
                                    <!-- hi -->
            <xsl:when test="local-name() = 'hi'">
                                       <xsl:call-template name="hirend"/>
                                    </xsl:when>

                                    <!-- g -->
            <xsl:when test="local-name() = 'g'">
                                       <xsl:call-template name="grend"/>
                                    </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>

                           <!-- Parse app content to include html elements see: https://github.com/DCLP/dclpxsltbox/issues/137 -->
   <xsl:template name="parse-app-parts">
                              <xsl:param name="part" xml:space="preserve"/>
                              <xsl:choose>
                                 <xsl:when test="matches(normalize-space($part),'FNORD(\S)*')">
                                    <xsl:value-of select="normalize-space(replace(replace($part, 'FNORD(\S)*', ''), '\(\*\)', ''))"/>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:for-each select="$part/node() | $part/text()">
                                       <xsl:choose>
                                          <xsl:when test="matches(normalize-space(.),'FNORD(\S)*')">
                                             <xsl:value-of select="normalize-space(replace(replace(., 'FNORD(\S)*', ''), '\(\*\)', ''))"/>
                                          </xsl:when>
                                          <xsl:when test="position() = last()">
                                             <xsl:for-each select=".">
                                                <xsl:choose>
                                                   <xsl:when test="self::text()">
                                                      <xsl:choose>
                                                         <xsl:when test="position() = last()">
                                                            <xsl:value-of select="replace(.,'\s+$','')"/>
                                                         </xsl:when>
                                                         <xsl:otherwise>
                                                            <xsl:copy xml:space="preserve"/>
                                                         </xsl:otherwise>
                                                      </xsl:choose>
                                                   </xsl:when>
                                                   <xsl:when test="name(.)='span'">
                                                      <xsl:element name="{name(.)}">
                                                         <xsl:copy-of select="@*"/>
                                                         <xsl:call-template name="parse-app-parts">
                                                            <xsl:with-param name="part" select="." xml:space="preserve"/>
                                                         </xsl:call-template>
                                                      </xsl:element>
                                                   </xsl:when>
                                                   <xsl:otherwise>
                                                      <xsl:call-template name="parse-app-parts">
                                                         <xsl:with-param name="part" select="." xml:space="preserve"/>
                                                      </xsl:call-template>
                                                   </xsl:otherwise>
                                                </xsl:choose>
                                             </xsl:for-each>
                                          </xsl:when>
                                          <xsl:when test="name(.)='span'">
                                             <xsl:element name="{name(.)}">
                                                <xsl:copy-of select="@*"/>
                                                <xsl:call-template name="parse-app-parts">
                                                   <xsl:with-param name="part" select="." xml:space="preserve"/>
                                                </xsl:call-template>
                                             </xsl:element>
                                          </xsl:when>
                                          <xsl:when test="self::text()">
                                             <xsl:copy xml:space="preserve"/>
                                          </xsl:when>
                                          <xsl:otherwise>
                                             <xsl:call-template name="parse-app-parts">
                                                <xsl:with-param name="part" select="." xml:space="preserve"/>
                                             </xsl:call-template>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                    </xsl:for-each>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </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'" tunnel="yes"/>
                                    </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'" tunnel="yes"/>
                                          </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'" tunnel="yes"/>
                                          </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'" tunnel="yes"/>
                                          </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'" tunnel="yes"/>
                                          </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'" tunnel="yes"/>
                                    </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'" tunnel="yes"/>
                                    </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'" tunnel="yes"/>
                                    </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="location" tunnel="yes" required="no"/>
                              <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="location" select="'apparatus'" tunnel="yes"/>
                                          <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:with-param name="location" select="'apparatus'" tunnel="yes"/>
                                    </xsl:apply-templates>
                                    <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="location" select="'apparatus'" tunnel="yes"/>
                                       <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:with-param name="location" select="'apparatus'" tunnel="yes"/>
                                          </xsl:apply-templates>
                                       </xsl:if>
                                       <xsl:apply-templates select=".">
                                          <xsl:with-param name="location" select="'apparatus'" tunnel="yes"/>
                                       </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:with-param name="location" select="'apparatus'" tunnel="yes"/>
                                                   </xsl:apply-templates>
                                                </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>
                                 <!-- Special handling for t:orig -->
         <xsl:when test="$step[self::t:orig[parent::t:choice]]">
                                    <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: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:with-param name="location" select="'apparatus'" tunnel="yes"/>
                                             </xsl:apply-templates>
                                          </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:with-param name="location" select="'apparatus'" tunnel="yes"/>
                                             </xsl:apply-templates>
                                          </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:variable name="str">
                                                   <xsl:choose>
                                                      <xsl:when test="$step[self::t:hi]">   
                                                         <xsl:call-template name="hirend_print"/>
                                                      </xsl:when>
                                                      <xsl:otherwise>
                                                         <xsl:call-template name="trans-string">
                                                            <xsl:with-param name="trans-text">
                                                               <xsl:apply-templates select="$step"/>
                                                            </xsl:with-param>
                                                         </xsl:call-template>
                                                      </xsl:otherwise>
                                                   </xsl:choose>
                                                </xsl:variable>
                                                <xsl:value-of select="$str"/>
                                             </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::*/preceding-sibling::node()[1]"/>
                                          </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::*/following-sibling::node()[1]"/>
                                       </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="grend">
                              <xsl:param name="gcontext" select="'yes'"/>
      
                              <xsl:if test="$gcontext != '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::*/preceding-sibling::node()[1]"/>
                                          </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(replace($text-before,'’|''',''))"/>
                              </xsl:if>
                              <xsl:apply-templates select=".">
                                 <xsl:with-param name="location" select="'apparatus'" tunnel="yes"/>
                              </xsl:apply-templates>
                              <xsl:if test="$gcontext != 'no'">
                                 <xsl:choose>
                                    <xsl:when test="not(following-sibling::node()[1])">
                                       <xsl:call-template name="recurse_forward">
                                          <xsl:with-param name="step" select="parent::*/following-sibling::node()[1]"/>
                                       </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 -->
      <!-- TODO: This is not really the locus for the fix, but this is what flagged for me that nested <hi>
           is a thing, and I'm not sure I agree with it. -->
      <xsl:choose>
                                 <xsl:when test="@rend = 'diaeresis'">
                                    <xsl:choose>
                                       <xsl:when test="child::t:hi[@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:text>́</xsl:text>
                                          <xsl:if test="t:gap[@reason='lost']">
                                             <xsl:text>]</xsl:text>
                                          </xsl:if>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <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:otherwise>
                                    </xsl:choose>
                                 </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:choose>
                                       <xsl:when test="child::t:hi[@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:text>́</xsl:text>
                                          <xsl:if test="t:gap[@reason='lost']">
                                             <xsl:text>]</xsl:text>
                                          </xsl:if>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <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:otherwise>
                                    </xsl:choose>
                                 </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="location" tunnel="yes" required="no"/>
                              <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:with-param name="location" select="'apparatus'" tunnel="yes"/>
                              </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="location" select="'apparatus'" tunnel="yes"/>
                                 <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="replace(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:g[@type='apostrophe'] |          .//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">
                              <xsl:variable name="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:g[@type='apostrophe'] |                   .//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']]                   or ancestor::t:hi)] |                   .//t:del[@rend='slashes' or @rend='cross-strokes'] | .//t:milestone[@rend = 'box']">
                                    <app>
                     <!-- 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>
                                    </app>
                                 </xsl:for-each>
                              </xsl:variable>
                              <!-- XSL for-each-group effectively suppresses any duplicate apparatus generated due to sibling triggers.   -->
            <xsl:for-each-group select="$apparatus/*:app" group-by=".">
                                 <xsl:copy-of select="node()"/>
                              </xsl:for-each-group>
                           </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-link-back'">
                              <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: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:if>
                     </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:variable name="lang">
                           <xsl:value-of select="ancestor-or-self::t:*[@xml:lang][1]/@xml:lang"/>
                        </xsl:variable>
                        <xsl:if test="ancestor-or-self::t:*[@xml:lang]">
                           <xsl:attribute name="lang">
                              <xsl:value-of select="$lang"/>
                           </xsl:attribute>
                        </xsl:if>
                        <xsl:if test="$lang = ('ar','he','syc','syr')">
                           <xsl:attribute name="dir">rtl</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="ignorableThingsBetweenAdjacentBrackets">
                           <regexselectors>
<!--                space-->
                <selector>\s</selector>
                              <!--              keraia  -->
                <selector>´</selector>
                              <!--                editorial comma-->
                <selector>,</selector>
                              <!--                add another one below if something else 
                    needs to be ignored when removing adjacent ][ -->
            </regexselectors>
                        </xsl:variable>
                        <xsl:variable name="closingadjacentbrackettypes">
                           <closingbrackets>
<!--                supplied, square bracket must be escaped for regex-->
                <bracket>\]</bracket>
                              <!--                del-->
                <bracket>⟧</bracket>
                           </closingbrackets>
                        </xsl:variable>
                        <xsl:variable name="openingadjacentbrackettypes">
                           <closingbrackets>
                <!--                supplied, square bracket must be escaped for regex-->
                <bracket>\[</bracket>
                              <!--                del-->
                <bracket>⟦</bracket>
                           </closingbrackets>
                        </xsl:variable>
                        <xsl:variable name="regex"
                                      select="concat('([^\]])[',string-join($closingadjacentbrackettypes//text(),''),']([',string-join($ignorableThingsBetweenAdjacentBrackets//text(),''),']*)[',string-join($openingadjacentbrackettypes//text(),''),']([^\[])')"/>
        
                        <xsl:variable name="current" select="replace(normalize-space(.), $regex, '$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','dclp','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','dclp','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-creta.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:fn="http://www.w3.org/2005/xpath-functions" exclude-result-prefixes="t"
                                  version="2.0">
  <!-- Contains named templates for creta file structure (aka "metadata" aka "supporting data") -->  
  <!-- Called from htm-tpl-structure.xsl -->
  
  <xsl:template name="creta-title">
                        <xsl:value-of select="//t:idno[@type='filename']"/>
                     </xsl:template>
  
                     <xsl:template name="creta-structure">
                        <xsl:variable name="title">
                           <xsl:call-template name="creta-title"/>
                        </xsl:variable>
                        <html>
                           <head>
                              <title>
                                 <xsl:value-of select="$title"/>
                              </title>
                              <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
                              <xsl:call-template name="css-script"/> 
                              <!-- Found in htm-tpl-cssandscripts.xsl -->
      </head>
                           <body>
                              <h1>
                                 <xsl:call-template name="creta-title"/>
                              </h1>
                              <xsl:call-template name="creta-body-structure"/>
                           </body>
                        </html>
                     </xsl:template>
  
                     <xsl:template name="creta-body-structure">
                        <xsl:call-template name="creta-navigation"/>
                        <div id="creta-inscription-body" class="creta">
                           <div id="title" class="creta">
                              <h1>
                                 <xsl:if test="//t:idno[@type='projectNo']/text()">
                                    <xsl:value-of select="number(//t:idno[@type='projectNo'])"/>. </xsl:if>
                                 <xsl:apply-templates select="//t:titleStmt/t:title"/>
                              </h1>
                           </div>
      
      
                           <div id="descriptive_lemma" class="creta">
                              <p>
                                 <b>Tipologia documentaria: </b> 
                                 <xsl:choose>
                                    <xsl:when test="//t:msContents/t:summary">
                                       <xsl:apply-templates select="//t:msContents/t:summary"/>
                                    </xsl:when>
                                    <xsl:otherwise>?</xsl:otherwise>
                                 </xsl:choose>
                              </p>
        
                              <p>
                                 <b>Supporto: </b> 
                                 <xsl:choose>
                                    <xsl:when test="//t:support">
                                       <xsl:apply-templates select="//t:support"/>
                                    </xsl:when>
                                    <xsl:otherwise>?</xsl:otherwise>
                                 </xsl:choose>
                              </p>
        
                              <xsl:if test="//t:layoutDesc/t:layout//text()">
                                 <p>
                                    <b>Disposizione del testo: </b> 
                                    <xsl:value-of select="//t:layoutDesc/t:layout"/>
                                 </p>
                              </xsl:if>
        
                              <xsl:if test="//t:handDesc/t:handNote//text()">
                                 <p>
                                    <b>Scrittura: </b>
                                    <xsl:choose>
                                       <xsl:when test="//t:handDesc/t:handNote/t:p/text()">
                                          <xsl:value-of select="//t:handDesc/t:handNote/t:p"/>
                                          <xsl:if test="//t:handDesc/t:handNote/t:height/text()">; h. <xsl:value-of select="//t:handDesc/t:handNote/t:height"/>
                                          </xsl:if>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:if test="//t:handDesc/t:handNote/t:height">h. <xsl:value-of select="//t:handDesc/t:handNote/t:height"/>
                                          </xsl:if>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </p>
                              </xsl:if>
        
                              <p>
                                 <b>Datazione: </b> 
                                 <xsl:choose>
                                    <xsl:when test="//t:origin/t:origDate/text()">
                                       <xsl:value-of select="//t:origin/t:origDate"/>
                                    </xsl:when>
                                    <xsl:otherwise>?</xsl:otherwise>
                                 </xsl:choose>
                              </p>
        
                              <p>
                                 <b>Provenienza: </b> 
                                 <xsl:choose>
                                    <xsl:when test="//t:origin/t:origPlace">
                                       <xsl:apply-templates select="//t:origin/t:origPlace"/>
                                    </xsl:when>
                                    <xsl:otherwise>?</xsl:otherwise>
                                 </xsl:choose>
                              </p>
        
                              <xsl:if test="//t:provenance[@type='found']">
                                 <p>
                                    <b>Luogo di ritrovamento: </b> 
                                    <xsl:apply-templates select="//t:provenance[@type='found']"/>
                                 </p>
                              </xsl:if>
        
                              <p>
                                 <b>Collocazione attuale: </b> 
                                 <xsl:choose>
                                    <xsl:when test="//t:msIdentifier//t:repository">
                                       <xsl:apply-templates select="//t:msIdentifier//t:repository"/>
                                       <xsl:if test="//t:idno[@type='invNo'][string(translate(normalize-space(.),' ',''))]">
                                          <xsl:text> (n. inv. </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:when>
                                    <xsl:otherwise>?</xsl:otherwise>
                                 </xsl:choose>
                              </p>
                           </div>
      
      
                           <div id="bibliography" class="creta">
                              <xsl:apply-templates mode="creta" select="//t:div[@type='bibliography']/t:p"/>
                           </div>
      
      
                           <div id="edition" class="creta">
                              <xsl:variable name="edtxt">
                                 <xsl:apply-templates select="//t:div[@type='edition']">
                                    <xsl:with-param name="parm-edition-type" tunnel="yes">
                                       <xsl:text>interpretive</xsl:text>
                                    </xsl:with-param>
                                    <xsl:with-param name="parm-verse-lines" tunnel="yes">
                                       <xsl:text>off</xsl:text>
                                    </xsl:with-param>
                                    <xsl:with-param name="parm-line-inc" tunnel="yes">
                                       <xsl:text>5</xsl:text>
                                    </xsl:with-param>
                                 </xsl:apply-templates>
                              </xsl:variable>
                              <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
                           </div>
      
      
                           <xsl:if test="//t:div[@type='apparatus']">
                              <div id="apparatus" class="creta">
                                 <xsl:variable name="apptxt">
                                    <xsl:apply-templates select="//t:div[@type='apparatus']//t:p"/>
                                 </xsl:variable>
                                 <xsl:apply-templates select="$apptxt" mode="sqbrackets"/>
                              </div>
                           </xsl:if>
      
      
                           <xsl:if test="//t:div[@type='translation']">
                              <div id="translation" class="creta">
                                 <xsl:variable name="transtxt">
                                    <xsl:apply-templates select="//t:div[@type='translation']//t:p"/>
                                 </xsl:variable>
                                 <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
                              </div>
                           </xsl:if>
      
      
                           <div id="commentary" class="creta">
                              <xsl:variable name="commtxt">
                                 <xsl:apply-templates mode="creta" 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>
                     </xsl:template> 
  
                     <!-- links to external resources in bibliography  -->
  <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='phi']">
    ➚<a target="_blank" href="http://epigraphy.packhum.org/text/{@target}">PHI</a>
                     </xsl:template>
                     <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='aio']">
    ➚<a target="_blank" href="https://www.atticinscriptions.com/inscription/{@target}">AIO</a>
                     </xsl:template>
                     <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='seg']">
    ➚<a target="_blank" href="http://dx.doi.org/10.1163/1874-6772_seg_{@target}">SEG</a>
                     </xsl:template>
                     <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='cgrn']">
    ➚<a target="_blank" href="http://cgrn.ulg.ac.be/file/{@target}">CGRN</a>
                     </xsl:template>
                     <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='thetima']">
    ➚<a target="_blank"
                           href="http://ancdialects.greek-language.gr/inscriptions/{@target}">ΘΕΤΙΜΑ</a>
                     </xsl:template>
                     <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='axon']">
    ➚<a target="_blank"
                           href="https://mizar.unive.it/axon/public/axon/anteprima/anteprima/idSchede/{@target}">Axon</a>
                     </xsl:template>
                     <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='poinikastas']">
    ➚<a target="_blank"
                           href="http://poinikastas.csad.ox.ac.uk/search-browse.shtml{@target}">Poinikastas</a>
                     </xsl:template>
                     <xsl:template mode="creta"
                                   match="t:div[@type='bibliography']/t:p/t:bibl/t:ptr[@target][@type='ela']">
    ➚<a target="_blank"
                           href="http://www.epigraphiclandscape.unito.it/index.php/browse/{@target}">ELA</a>
                     </xsl:template>
  
                     <!-- links to full bibliographic references -->
  <xsl:template mode="creta"
                                   match="t:div[@type='bibliography' or @type='commentary']/t:p/t:bibl/t:ref[@target]">
                        <a target="_blank"
                           href="../texts/bibliografia.html#{substring-after(@target,'#')}"
                           class="link">
                           <xsl:apply-templates mode="creta"/>
                        </a>
                     </xsl:template>
  
                     <!-- links to inscriptions and literary sources in the commentary -->
  <xsl:template mode="creta" match="t:div[@type='commentary']/t:p/t:ref[@target][@type='ins']">
                        <a target="_blank" href="./{substring-after(@target,'#')}.html">
                           <xsl:apply-templates mode="creta"/>
                        </a>
                     </xsl:template>
  
                     <xsl:template mode="creta" match="t:div[@type='commentary']/t:p/t:ref[@target][@type='lit']">
                        <a target="_blank"
                           href="../texts/fonti_letterarie.html{substring-after(@target, '#')}">
                           <xsl:apply-templates mode="creta"/>
                        </a>
                     </xsl:template>
  
                     <!-- links to institution sections in the commentary -->
  <xsl:template mode="creta" match="t:div[@type='commentary']/t:p/t:ref[@target][@type='inst']">
                        <a target="_blank" href="../texts/istituzioni.html{@target}">
                           <xsl:apply-templates mode="creta"/>
                        </a>
                     </xsl:template>
  
  
                     <!-- bold chosen edition in bibliography  -->
  <xsl:template mode="creta" match="t:bibl[@type='main_edition']">
                        <strong>
                           <xsl:apply-templates mode="creta"/>
                        </strong>
                     </xsl:template>
  
                     <!-- p in bibliography, commentary, translation -->
  <xsl:template mode="creta"
                                   match="t:div[@type='bibliography' or @type='commentary' or @type='translation']/t:p">
                        <p>
                           <xsl:apply-templates mode="creta"/>
                        </p>
                     </xsl:template>
  
                     <!-- emph in bibliography and commentary -->
  <xsl:template mode="creta"
                                   match="t:div[@type='bibliography' or @type='commentary']/t:p//t:emph">
                        <strong>
                           <xsl:apply-templates/>
                        </strong>
                     </xsl:template>
  
                     <!-- apices in bibliography, commentary, apparatus -->
  <xsl:template mode="creta"
                                   match="t:div[@type='bibliography' or @type='commentary' or @type='apparatus']//t:hi[@rend='superscript']">
                        <sup>
                           <xsl:apply-templates/>
                        </sup>
                     </xsl:template>
  
                     <!-- arrows pointing to previous/next inscription -->
  <xsl:template name="creta-navigation">
                        <xsl:if test="doc-available(concat('file:',system-property('user.dir'),'/all_inscriptions.xml')) = fn:true()">
                           <xsl:variable name="filename">
                              <xsl:value-of select="//t:idno[@type='projectNo']"/>
                           </xsl:variable>
                           <xsl:variable name="list"
                                         select="document(concat('file:',system-property('user.dir'),'/all_inscriptions.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 href="./{$prev}.html">
                                             <xsl:text>«</xsl:text>
                                          </a>
                                       </li>
                                    </xsl:if>
            
                                    <xsl:if test="$next">
                                       <li class="arrow">
                                          <a href="./{$next}.html">
                                             <xsl:text>»</xsl:text>
                                          </a>
                                       </li>
                                    </xsl:if>
                                 </ul>
                              </div>
                           </div>
                        </xsl:if>
                     </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-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-inslib.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1"
                                  xmlns:fn="http://www.w3.org/2005/xpath-functions"
                                  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:variable name="inslib-corpus"> <!-- used for InsLib projects and IAph -->
    <xsl:choose>
                           <xsl:when test="starts-with(//t:publicationStmt/t:idno[@type='filename']/text(), 'IRT')">IRT</xsl:when>
                           <xsl:when test="starts-with(//t:publicationStmt/t:idno[@type='filename']/text(), 'IGCyr') or starts-with(//t:publicationStmt/t:idno[@type='filename']/text(), 'GVCyr')">IGCyr</xsl:when>
                           <xsl:when test="number(substring(//t:publicationStmt/t:idno[@type='filename']/text(),2,5))">IRCyr</xsl:when>
                           <xsl:when test="starts-with(//t:publicationStmt/t:idno[@type='filename']/text(), 'iAph')">IAph</xsl:when>
                        </xsl:choose>
                     </xsl:variable>
  
                     <xsl:template name="inslib-body-structure">
                        <div id="full-edition">
                           <div id="edition-text">
                              <xsl:call-template name="inslib-navigation"/>
                              <xsl:if test="$inslib-corpus='IGCyr'">
                                 <p>EpiDoc XML: 
            <a target="_blank"
                                       href="{lower-case(string(//t:publicationStmt//t:idno[@type='filename']))}.xml">
                                       <xsl:value-of select="//t:publicationStmt//t:idno[@type='filename']"/>
                                    </a>
                                    <xsl:if test="//t:publicationStmt//t:idno[@type='TM']">
                                       <br/>Trismegistos ID: 
              <a target="_blank"
                                          href="https://www.trismegistos.org/text/{//t:publicationStmt//t:idno[@type='TM']}">
                                          <xsl:value-of select="//t:publicationStmt//t:idno[@type='TM']"/>
                                       </a>
                                    </xsl:if>
                                 </p>
                              </xsl:if>
        
                              <xsl:if test="$inslib-corpus='IGCyr'">
                                 <h3>Source description</h3>
                              </xsl:if>
                              <div id="source-description">
                                 <xsl:if test="//t:support">
                                    <p>
                                       <b>
                                          <xsl:value-of select="if ($inslib-corpus='IGCyr') then 'Support: ' else 'Description: '"/>
                                       </b>
                                       <xsl:choose>
                                          <xsl:when test="//t:support/t:p/node()">
                                             <xsl:apply-templates select="//t:support/t:p/node()" mode="inslib-dimensions"/>
                                          </xsl:when>
                                          <xsl:when test="//t:support//node()">
                                             <xsl:apply-templates select="//t:support" mode="inslib-dimensions"/>
                                          </xsl:when>
                                          <xsl:otherwise>Unknown</xsl:otherwise>
                                       </xsl:choose>
                                    </p>
                                 </xsl:if>
          
                                 <xsl:if test="//t:layoutDesc">
                                    <p>
                                       <b>
                                          <xsl:value-of select="if ($inslib-corpus='IGCyr') then 'Layout: ' else 'Text: '"/>
                                       </b>
                                       <xsl:choose>
                                          <xsl:when test="//t:layoutDesc/t:layout//node()">
                                             <xsl:apply-templates select="//t:layoutDesc/t:layout" mode="inslib-dimensions"/>
                                          </xsl:when>
                                          <xsl:otherwise>Unknown.</xsl:otherwise>
                                       </xsl:choose>
                                    </p>
                                 </xsl:if>
          
                                 <xsl:if test="//t:handDesc">
                                    <p>
                                       <b>Letters: </b>
                                       <xsl:if test="//t:handDesc/t:handNote/node()">
                                          <xsl:apply-templates select="//t:handDesc/t:handNote"/>
                                       </xsl:if>
                                    </p>
                                 </xsl:if>
          
                                 <xsl:if test="//t:origDate">
                                    <p>
                                       <b>Date: </b>
                                       <xsl:choose>
                                          <xsl:when test="//t:origin/t:origDate/node()">
                                             <xsl:for-each select="//t:origin/t:origDate">
                                                <xsl:apply-templates select="."/>
                                                <xsl:if test="./@evidence">
                                                   <xsl:text> (</xsl:text>
                                                   <xsl:for-each select="tokenize(./@evidence,' ')">
                                                      <xsl:value-of select="translate(translate(.,'-',' '),',','')"/>
                                                      <xsl:if test="position()!=last()">
                                                         <xsl:text>, </xsl:text>
                                                      </xsl:if>
                                                   </xsl:for-each>
                                                   <xsl:text>)</xsl:text>
                                                   <xsl:if test="position()!=last()">
                                                      <xsl:text>; </xsl:text>
                                                   </xsl:if>
                                                </xsl:if>
                                             </xsl:for-each>
                                          </xsl:when>
                                          <xsl:otherwise>Unknown.</xsl:otherwise>
                                       </xsl:choose>
                                    </p>
                                 </xsl:if>
          
                                 <xsl:if test="//t:provenance">
                                    <p>
                                       <b>Findspot: </b>
                                       <xsl:choose>
                                          <xsl:when test="//t:provenance[@type='found'][string(translate(normalize-space(.),' ',''))]">
                                             <xsl:choose>
                                                <xsl:when test="//t:provenance[@type='found']//t:p">
                                                   <xsl:apply-templates select="//t:provenance[@type='found']//t:p/node()" mode="inslib-placename"/> 
                                                </xsl:when>
                                                <xsl:otherwise>
                                                   <xsl:apply-templates select="//t:provenance[@type='found']" mode="inslib-placename"/>
                                                </xsl:otherwise>
                                             </xsl:choose>
                                          </xsl:when>
                                          <xsl:otherwise>Unknown</xsl:otherwise>
                                       </xsl:choose>
                                    </p>
                                 </xsl:if>
          
                                 <xsl:if test="//t:origPlace">
                                    <p>
                                       <b>
                                          <xsl:value-of select="if ($inslib-corpus='IGCyr') then 'Place of origin: ' else 'Original location: '"/>
                                       </b>
                                       <xsl:choose>
                                          <xsl:when test="//t:origin/t:origPlace/node()">
                                             <xsl:apply-templates select="//t:origin/t:origPlace" mode="inslib-placename"/>
                                          </xsl:when>
                                          <xsl:otherwise>Unknown</xsl:otherwise>
                                       </xsl:choose>
                                    </p>
                                 </xsl:if>
          
                                 <xsl:if test="//t:provenance[@type!='found']//text()|//t:repository//text()">
                                    <p>
                                       <b>Last recorded location: </b>
                                       <xsl:if test="//t:repository and $inslib-corpus='IGCyr'">
                                          <xsl:apply-templates select="//t:repository" mode="inslib-placename"/>
                                          <!-- Named template found below. -->
                <xsl:call-template name="inslib-invno"/>
                                          <xsl:text>. </xsl:text>
                                       </xsl:if>
                                       <xsl:for-each select="//t:provenance[@type!='found']">
                                          <xsl:apply-templates mode="inslib-placename"/>
                                          <xsl:if test="position()!=last()">
                                             <xsl:text> </xsl:text>
                                          </xsl:if>
                                       </xsl:for-each>
                                       <xsl:if test="$inslib-corpus!='IGCyr'">
                                          <xsl:if test="//t:repository[@ref] and not(//t:provenance[@type='observed'])">
                                             <xsl:apply-templates select="//t:repository[@ref][1]" mode="inslib-placename"/>
                                          </xsl:if>
                                          <!-- Named template found below. -->
                <xsl:call-template name="inslib-invno"/>
                                       </xsl:if>
                                    </p>
                                 </xsl:if>
          
                                 <xsl:if test="//t:creation and $inslib-corpus='IGCyr'">
                                    <p>
                                       <b>Text constituted from: </b>
                                       <xsl:apply-templates select="//t:creation"/>
                                    </p>
                                 </xsl:if>
                              </div>
        
                              <xsl:if test="//t:div[@type='bibliography'] and $inslib-corpus='IGCyr'">
                                 <h3>Bibliography</h3>
                                 <p>
                                    <xsl:apply-templates select="//t:div[@type='bibliography']/t:p/node()"/>
                                 </p>
                              </xsl:if>
        
                              <xsl:if test="//t:div[@type='edition']">
                                 <xsl:if test="$inslib-corpus='IGCyr'">
                                    <h3>Text</h3>
                                 </xsl:if>
                                 <div class="section-container tabs" data-section="tabs">
                                    <section>
                                       <p class="title" data-section-title="data-section-title">
                                          <a href="#">Interpretive</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>
                                    <xsl:if test="$inslib-corpus='IGCyr' and //t:l">
                                       <section>
                                          <p class="title" data-section-title="data-section-title">
                                             <a href="#">Metrical</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:with-param name="parm-verse-lines" select="'on'" tunnel="yes"/>
                                                </xsl:apply-templates>
                                             </xsl:variable>
                                             <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
                  <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
                                          </div>
                                       </section>
                                    </xsl:if>
                                    <section>
                                       <p class="title" data-section-title="data-section-title">
                                          <a href="#">Diplomatic</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>
                              </xsl:if>
        
                              <xsl:if test="//t:div[@type='apparatus']//node()">
                                 <div id="apparatus">
                                    <xsl:if test="$inslib-corpus='IGCyr'">
                                       <h3>Apparatus</h3>
                                    </xsl:if>
                                    <!-- 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>
                              </xsl:if>
        
                              <xsl:if test="//t:div[@type='translation']//t:p//node()">
                                 <div id="translation">
                                    <xsl:variable name="editor" select="//t:teiHeader/t:fileDesc/t:titleStmt/t:editor"/>
                                    <xsl:for-each select="//t:div[@type='translation'][not(descendant::t:div[@type='translation'])]">
                                       <h3>
                                          <xsl:variable name="transl_lang">
                                             <xsl:choose>
                                                <xsl:when test="@xml:lang='en'">English</xsl:when>
                                                <xsl:when test="@xml:lang='fr'">French</xsl:when>
                                                <xsl:when test="@xml:lang='it'">Italian</xsl:when>
                                                <xsl:when test="@xml:lang='de'">German</xsl:when>
                                                <xsl:when test="@xml:lang='la'">Latin</xsl:when>
                                                <xsl:when test="@xml:lang='ar'">Arabic</xsl:when>
                                                <!-- add here any needed language -->
                  </xsl:choose>
                                          </xsl:variable>
                                          <xsl:choose>
                                             <xsl:when test="$transl_lang!=''">
                                                <xsl:value-of select="$transl_lang"/>
                                                <xsl:text> translation</xsl:text>
                                             </xsl:when>
                                             <xsl:otherwise>
                                                <xsl:text>Translation</xsl:text>
                                                <xsl:if test="@xml:lang">
                                                   <xsl:text> (</xsl:text>
                                                   <xsl:value-of select="@xml:lang"/>
                                                   <xsl:text>)</xsl:text>
                                                </xsl:if>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                       </h3>
                                       <xsl:if test="@source">
                                          <xsl:variable name="source-id" select="substring-after(@source, '#')"/>
                                          <p>
                                             <xsl:text>Translation source: </xsl:text> 
                                             <!-- if you are running this template outside EFES, change the path to the bibliography authority list accordingly -->
                  <xsl:variable name="bibliography-al"
                                                           select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/bibliography.xml')"/>
                                             <xsl:choose>
                                                <xsl:when test="doc-available($bibliography-al) = fn:true() and document($bibliography-al)//t:bibl[@xml:id=$source-id][not(@sameAs)]">
                                                   <xsl:variable name="source"
                                                                 select="document($bibliography-al)//t:bibl[@xml:id=$source-id][not(@sameAs)]"/>
                                                   <a href="{concat('../concordance/bibliography/',$source-id,'.html')}"
                                                      target="_blank">
                                                      <xsl:choose>
                                                         <xsl:when test="$source//t:bibl[@type='abbrev']">
                                                            <xsl:apply-templates select="$source//t:bibl[@type='abbrev'][1]"/>
                                                         </xsl:when>
                                                         <xsl:otherwise>
                                                            <xsl:choose>
                                                               <xsl:when test="$source[ancestor::t:div[@xml:id='authored_editions']] and $inslib-corpus='IGCyr'">
                                                                  <xsl:for-each select="$source//t:name[@type='surname'][not(parent::*/preceding-sibling::t:title)]">
                                                                     <xsl:apply-templates select="."/>
                                                                     <xsl:if test="position()!=last()"> – </xsl:if>
                                                                  </xsl:for-each>
                                                                  <xsl:text> </xsl:text>
                                                                  <xsl:apply-templates select="$source//t:date"/>
                                                               </xsl:when>
                                                               <xsl:when test="$source[ancestor::t:div[@xml:id='series_collections']] and $inslib-corpus='IGCyr'">
                                                                  <i>
                                                                     <xsl:value-of select="$source/@xml:id"/>
                                                                  </i>
                                                               </xsl:when>
                                                               <xsl:otherwise>
                                                                  <xsl:apply-templates select="$source-id"/>
                                                               </xsl:otherwise>
                                                            </xsl:choose>
                                                         </xsl:otherwise>
                                                      </xsl:choose>
                                                   </a>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                   <xsl:value-of select="$source-id"/>
                                                </xsl:otherwise>
                                             </xsl:choose>
                                          </p>
                                       </xsl:if>
                                       <xsl:if test="@resp">
                                          <xsl:variable name="resp-id" select="substring-after(@resp, '#')"/>
                                          <xsl:variable name="resp" select="$editor[@xml:id=$resp-id]"/>
                                          <p>
                                             <xsl:text>Translation by: </xsl:text> 
                                             <xsl:choose>
                                                <xsl:when test="$resp">
                                                   <xsl:value-of select="$resp"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                   <xsl:value-of select="$resp-id"/> 
                                                </xsl:otherwise>
                                             </xsl:choose>
                                          </p>
                                       </xsl:if>
                                       <!-- Translation text output -->
              <xsl:variable name="transtxt">
                                          <xsl:for-each select=".//t:p">
                                             <xsl:choose>
                                                <xsl:when test="ancestor::t:div[@xml:lang='ar']">
                                                   <p class="rtl">
                                                      <xsl:apply-templates select="node()"/>
                                                   </p>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                   <p>
                                                      <xsl:apply-templates select="node()"/>
                                                   </p>
                                                </xsl:otherwise>
                                             </xsl:choose>
                                          </xsl:for-each>
                                       </xsl:variable>
                                       <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
              <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
                                    </xsl:for-each>
                                 </div>
                              </xsl:if>
        
                              <xsl:if test="//t:div[@type='commentary']//t:p//node() and not(contains(//t:div[@type='commentary'][1]/t:p[1], 'No comment'))">
                                 <div id="commentary">
                                    <h3>Commentary</h3>
                                    <!-- 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:if>
        
                              <xsl:if test="//t:div[@type='bibliography'] and $inslib-corpus='IAph'">
                                 <h3>Bibliography</h3>
                                 <xsl:for-each select="//t:div[@type='bibliography']">
                                    <p>
                                       <xsl:if test="@subtype='transcription'">
                                          <b>Transcription: </b>
                                       </xsl:if>
                                       <xsl:if test="@subtype='publication'">
                                          <b>Publication: </b>
                                       </xsl:if>
                                       <xsl:apply-templates select="t:p/node()"/>
                                    </p>
                                 </xsl:for-each>
                              </xsl:if>
        
                              <xsl:if test="//t:div[@type='bibliography'] and $inslib-corpus!=('IGCyr') and $inslib-corpus!=('IAph')">
                                 <p>
                                    <b>Bibliography: </b>
                                    <xsl:apply-templates select="//t:div[@type='bibliography']/t:p/node()"/>
            
                                    <xsl:if test="//t:creation and $inslib-corpus='IRCyr'">
                                       <br/>
                                       <b>Text constituted from: </b>
                                       <xsl:apply-templates select="//t:creation"/>
                                    </xsl:if>
                                 </p>
                              </xsl:if>
        
                              <xsl:if test="$inslib-corpus='IGCyr'">
                                 <div id="license">
                                    <xsl:apply-templates select="//t:availability"/>
                                 </div>
                              </xsl:if>
                           </div>
      
                           <div id="edition-images-maps">
                              <xsl:if test="//t:facsimile">
                                 <div id="images">
                                    <h3>Images</h3>
                                    <xsl:choose>
                                       <xsl:when test="//t:facsimile//t:graphic">
                                          <xsl:for-each select="//t:facsimile//t:graphic">
                                             <div class="embedded_image">
                                                <xsl:choose>
                                                   <xsl:when test="contains(@url,'http')">
                                                      <a href="{@url}" target="_blank">
                                                         <img src="{@url}" style="max-height:200px"/>
                                                      </a>
                                                   </xsl:when>
                                                   <xsl:otherwise>
                                                      <xsl:apply-templates select="."/>
                                                   </xsl:otherwise>
                                                </xsl:choose>
                                                <p style="margin-top:5px">
                                                   <strong>
                                                      <xsl:text>Fig. </xsl:text>
                                                      <xsl:number value="position()" format="1"/>
                                                   </strong>
                                                   <xsl:if test="t:desc">
                                                      <xsl:text>. </xsl:text>
                                                      <xsl:apply-templates select="t:desc"/>
                                                   </xsl:if>
                                                </p>
                                             </div>
                                          </xsl:for-each>
                                       </xsl:when>
                                       <xsl:otherwise>
                                          <xsl:for-each select="//t:facsimile[not(//t:graphic)]">
                                             <p>None available.</p>
                                          </xsl:for-each>
                                       </xsl:otherwise>
                                    </xsl:choose>
                                 </div>
                              </xsl:if>
          
                              <xsl:if test="$inslib-corpus='IGCyr'">
          <!-- if you are running this template outside EFES, change the path to the places authority list accordingly -->
          <xsl:if test="doc-available(concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/places.xml')) = fn:true()">
                                    <div id="maps">
                                       <h3>Maps</h3>
                                       <div class="row map_box">
                                          <div id="specific_map" class="map inscription_map"/>
                                          <xsl:variable name="place-name"
                                                        select="//t:provenance[@type='found'][1]//t:p[1]//t:placeName[@type='ancientFindspot'][1]"/>
                                          <xsl:variable name="place-id"
                                                        select="//t:provenance[@type='found'][1]//t:p[1]//t:placeName[@type='ancientFindspot'][1]/@key"/>
                                          <xsl:variable name="places-al"
                                                        select="document(concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/places.xml'))//t:place[descendant::t:placeName=$place-name][1]"/>
                                          <xsl:variable name="counter" select="$places-al//t:note[@type='total_inscriptions']"/>
                                          <xsl:variable name="points"
                                                        select="concat(string-join($place-name, ''), '#', string-join($counter, '') ,'@', substring-after(string-join($place-id, ''), 'slsgazetteer.org/'))"/>
                                          <script type="text/javascript">
                  var points = {"<xsl:value-of select="$points"/>": "<xsl:value-of select="$places-al//t:geo"/>"};
                </script>
                                          <script type="text/javascript" src="../../assets/scripts/maps.js"/>
                                          <script type="text/javascript">
                  var mymap = L.map('specific_map', { center: [32, 22], zoom: 6, fullscreenControl: true, layers: layers });
                  L.control.layers(baseMaps, overlayMaps).addTo(mymap);
                  L.control.scale().addTo(mymap);
                  L.Control.geocoder().addTo(mymap);
                  toggle_places.addTo(mymap); 
                </script>
                                       </div>
              
                                       <div id="specific_archaeo_map" class="map">
                                          <xsl:variable name="findspot"
                                                        select="string-join(//t:provenance[@type='found']//t:placeName, '')"/>
                                          <xsl:variable name="findspot-rs"
                                                        select="lower-case(string-join(//t:provenance[@type='found']//t:rs, ' '))"/>
                                          <xsl:if test="contains($findspot, 'Apollonia')">
                                             <xsl:call-template name="inslib-map">
                                                <xsl:with-param name="map_name" select="'map_Apollonia'"/>
                                             </xsl:call-template>
                                          </xsl:if>
                                          <xsl:if test="contains($findspot, 'Berenike')">
                                             <xsl:call-template name="inslib-map">
                                                <xsl:with-param name="map_name" select="'map_Berenike'"/>
                                             </xsl:call-template>
                                          </xsl:if>
                                          <xsl:if test="$findspot='Cyrene'">
                                             <xsl:call-template name="inslib-map">
                                                <xsl:with-param name="map_name" select="'map_Cyrene_general_plan'"/>
                                             </xsl:call-template>
                                             <xsl:if test="contains($findspot-rs, 'agora')">
                                                <xsl:call-template name="inslib-map">
                                                   <xsl:with-param name="map_name" select="'map_Cyrene_agora'"/>
                                                </xsl:call-template>
                                             </xsl:if>
                                             <xsl:if test="contains($findspot-rs, 'central quarter')">
                                                <xsl:call-template name="inslib-map">
                                                   <xsl:with-param name="map_name" select="'map_Cyrene_central_quarter'"/>
                                                </xsl:call-template>
                                             </xsl:if>
                                             <xsl:if test="contains($findspot-rs, 'north necropolis')">
                                                <xsl:call-template name="inslib-map">
                                                   <xsl:with-param name="map_name" select="'map_Cyrene_north_necropolis'"/>
                                                </xsl:call-template>
                                             </xsl:if>
                                             <xsl:if test="contains($findspot-rs, 'of apollo')">
                                                <xsl:call-template name="inslib-map">
                                                   <xsl:with-param name="map_name" select="'map_Cyrene_sanctuary_of_Apollo'"/>
                                                </xsl:call-template>
                                             </xsl:if>
                                          </xsl:if>
                                          <xsl:if test="contains($findspot, 'Euesperides')">
                                             <xsl:call-template name="inslib-map">
                                                <xsl:with-param name="map_name" select="'map_Euesperides'"/>
                                             </xsl:call-template>
                                          </xsl:if>
                                          <xsl:if test="contains($findspot, 'Ptolemais')">
                                             <xsl:call-template name="inslib-map">
                                                <xsl:with-param name="map_name" select="'map_Ptolemais_inner'"/>
                                             </xsl:call-template>
                                             <xsl:call-template name="inslib-map">
                                                <xsl:with-param name="map_name" select="'map_Ptolemais_outer'"/>
                                             </xsl:call-template>
                                          </xsl:if>
                                          <xsl:if test="contains($findspot, 'Taucheira')">
                                             <xsl:call-template name="inslib-map">
                                                <xsl:with-param name="map_name" select="'map_Tocra'"/>
                                             </xsl:call-template>
                                          </xsl:if>
                                       </div>
                                    </div>
                                 </xsl:if>
                              </xsl:if>
                           </div>
                        </div>
                     </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 name="inslib-invno">
                        <xsl:if test="//t:idno[ancestor::t:msIdentifier][translate(normalize-space(string(.)),' ','')!='']">
                           <xsl:value-of select="if ($inslib-corpus='IGCyr') then ', ' else ' (Inv. no. '"/>
                           <xsl:for-each select="//t:idno[ancestor::t:msIdentifier][translate(normalize-space(string(.)),' ','')!='']">
                              <xsl:value-of select="."/>
                              <xsl:if test="position()!=last()">
                                 <xsl:text>, </xsl:text>
                              </xsl:if>
                           </xsl:for-each>
                           <xsl:if test="$inslib-corpus!='IGCyr'">
                              <xsl:text>)</xsl:text>
                           </xsl:if>
                        </xsl:if>
                     </xsl:template>
  
                     <xsl:template name="inslib-map">
                        <xsl:param name="map_name"/>
                        <!-- if you are running this template outside EFES, change the path to the images folder accordingly -->
    <xsl:variable name="images"
                                      select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/images/')"/>
                        <div id="{$map_name}" class="archaeo_map">
                           <h4>
                              <xsl:value-of select="translate(replace($map_name, 'map_', ''), '_', ' ')"/>
                           </h4>
                           <p>
                              <a href="../texts/{$map_name}.html">
                                 <img alt="image" class="image" src="/images/{$map_name}.png"/>
                              </a>
                           </p>
                        </div>
                     </xsl:template>
  
                     <xsl:template name="inslib-title">
                        <xsl:choose>
                           <xsl:when test="//t:titleStmt/t:title and $inslib-corpus='IRT'">
                              <xsl:value-of select="substring-after(//t:publicationStmt/t:idno[@type='filename']/text(),'IRT')"/>
                              <xsl:text>. </xsl:text>
                              <xsl:apply-templates select="//t:titleStmt/t:title"/>
                           </xsl:when>
                           <xsl:when test="//t:titleStmt/t:title and $inslib-corpus='IGCyr'">
                              <xsl:apply-templates select="//t:titleStmt/t:title"/>
                           </xsl:when>
                           <xsl:when test="//t:titleStmt/t:title and $inslib-corpus='IRCyr'">
                              <xsl:value-of select="//t:publicationStmt/t:idno[@type='filename']/text()"/>
                              <xsl:text>. </xsl:text>
                              <xsl:apply-templates select="//t:titleStmt/t:title"/>
                           </xsl:when>
                           <xsl:when test="//t:titleStmt/t:title and $inslib-corpus='IAph'">
                              <xsl:number value="number(substring(//t:publicationStmt/t:idno[@type='filename']/text(), 5, 2))"
                                          format="1"/>
                              <xsl:text>.</xsl:text>
                              <xsl:number value="number(substring(//t:publicationStmt/t:idno[@type='filename']/text(), 7, 4))"
                                          format="1"/>
                              <xsl:text>. </xsl:text>
                              <xsl:apply-templates select="//t:titleStmt/t:title"/>
                           </xsl:when>
                           <xsl:when test="//t:titleStmt/t:title/node()">
                              <xsl:apply-templates select="//t:titleStmt/t:title"/>
                           </xsl:when>
                           <xsl:when test="//t:sourceDesc//t:bibl/node()">
                              <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:template match="t:dimensions" mode="inslib-dimensions">
                        <xsl:if test="//text()">
                           <xsl:if test="t:width/text()">
                              <xsl:text>w: </xsl:text>
                              <xsl:value-of select="t:width"/>
                              <xsl:if test="t:height/text() | t:depth/text() | t:dim[@type='diameter']/text()">
                                 <xsl:text> × </xsl:text>
                              </xsl:if>
                           </xsl:if>
                           <xsl:if test="t:height/text()">
                              <xsl:text>h: </xsl:text>
                              <xsl:value-of select="t:height"/>
                              <xsl:if test="t:depth/text() | t:dim[@type='diameter']/text()">
                                 <xsl:text> × </xsl:text>
                              </xsl:if>
                           </xsl:if>
                           <xsl:if test="t:depth/text()">
                              <xsl:text>d: </xsl:text>
                              <xsl:value-of select="t:depth"/>
                              <xsl:if test="t:dim[@type='diameter']/text()">
                                 <xsl:text> × </xsl:text>
                              </xsl:if>
                           </xsl:if>
                           <xsl:if test="t:dim[@type='diameter']/text()">
                              <xsl:text>diam: </xsl:text>
                              <xsl:value-of select="t:dim[@type='diameter']"/>
                           </xsl:if>
                        </xsl:if>
                     </xsl:template>
  
                     <xsl:template match="t:placeName|t:rs|t:repository" mode="inslib-placename">
                        <xsl:variable name="ref-id" select="substring-after(@ref, '#')"/>
                        <!-- if you are running this template outside EFES, change the path to the institutions authority list accordingly -->
    <xsl:variable name="institutions-list"
                                      select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/institution.xml')"/>
                        <xsl:variable name="findspots-list"
                                      select="concat('file:',system-property('user.dir'),'/webapps/ROOT/content/xml/authority/findspot.xml')"/>
                        <xsl:choose>
                           <xsl:when test="contains(@ref,'institution.xml') and doc-available($institutions-list) = fn:true() and document($institutions-list)//t:place[@xml:id=$ref-id]//t:idno[1]">
                              <a target="_blank"
                                 href="{document($institutions-list)//t:place[@xml:id=$ref-id][1]//t:idno[1]}">
                                 <xsl:apply-templates/>
                              </a>
                           </xsl:when>
                           <xsl:when test="starts-with(@ref, 'http') and starts-with(@key, 'http')">
                              <a href="{@ref}" target="_blank">
                                 <xsl:apply-templates/>
                              </a>
                              <a target="_blank" href="{@key}"> ➚</a>
                           </xsl:when>
                           <xsl:when test="starts-with(@ref, 'http') and not(starts-with(@key, 'http'))">
                              <a href="{@ref}" target="_blank">
                                 <xsl:apply-templates/>
                              </a>
                           </xsl:when>
                           <xsl:when test="starts-with(@key, 'http') and not(starts-with(@ref, 'http'))">
                              <a href="{@key}" target="_blank">
                                 <xsl:apply-templates/>
                              </a>
                           </xsl:when>
                           <xsl:when test="starts-with(@ref, '#') and doc-available($findspots-list) = fn:true() and document($findspots-list)//t:place[@xml:id=$ref-id]//t:idno">
                              <a target="_blank"
                                 href="{document($findspots-list)//t:place[@xml:id=$ref-id][1]//t:idno[1]}">
                                 <xsl:apply-templates/>
                              </a>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:apply-templates/>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:template>
  
                     <xsl:template name="inslib-navigation">
    <!-- if you are running this template outside EFES, change the path to the inscriptions list accordingly -->
    <xsl:if test="doc-available(concat('file:',system-property('user.dir'),'/webapps/ROOT/content/lists/all_inscriptions.xml')) = fn:true()">
                           <xsl:variable name="list"
                                         select="document(concat('file:',system-property('user.dir'),'/webapps/ROOT/content/lists/all_inscriptions.xml'))//t:list"/>
                           <xsl:variable name="filename">
                              <xsl:value-of select="lower-case(string(//t:idno[@type='filename'][1]))"/>
                           </xsl:variable>
                           <xsl:variable name="prev"
                                         select="$list/t:item[substring-before(lower-case(@n),'.xml')=$filename][1]/preceding-sibling::t:item[1]/substring-before(@n,'.xml')"/>
                           <xsl:variable name="next"
                                         select="$list/t:item[substring-before(lower-case(@n),'.xml')=$filename][1]/following-sibling::t:item[1]/substring-before(@n,'.xml')"/>
      
                           <div class="row">
                              <div class="large-12 columns">
                                 <ul class="pagination">
                                    <xsl:if test="$prev">
                                       <li class="arrow">
                                          <a href="./{$prev}.html">« Previous</a>
                                       </li>
                                    </xsl:if>
                                    <xsl:if test="$next">
                                       <li class="arrow">
                                          <a href="./{$next}.html">Next »</a>
                                       </li>
                                    </xsl:if>
                                 </ul>
                              </div>
                           </div>
                        </xsl:if>
                     </xsl:template>
  
                  </xsl:stylesheet>
               </xsl:include>
               <xsl:include href="htm-tpl-struct-iospe.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1" 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>
                     </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-sample.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1" exclude-result-prefixes="t"
                                  version="2.0">
  <!-- Contains named templates for sample file structure -->  
  <!-- Called from htm-tpl-structure.xsl -->
  
  <xsl:template name="sample-title">
                        <xsl:choose>
                           <xsl:when test="//t:titleStmt/t:title//text() and //t:publicationStmt/t:idno[@type='filename']/text()">
                              <xsl:value-of select="//t:publicationStmt/t:idno[@type='filename']"/> 
                              <xsl:text>. </xsl:text>
                              <xsl:apply-templates select="//t:titleStmt/t:title"/>
                           </xsl:when>
                           <xsl:when test="//t:titleStmt/t:title//text()">
                              <xsl:apply-templates select="//t:titleStmt/t:title"/>
                           </xsl:when>
                           <xsl:when test="//t:sourceDesc//t:bibl//text()">
                              <xsl:apply-templates 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, sample style</xsl:text>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:template>
  
                     <xsl:template name="sample-structure">
                        <xsl:variable name="title">
                           <xsl:call-template name="sample-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="sample-body-structure"/>
                           </body>
                        </html>
                     </xsl:template>
  
                     <xsl:template name="sample-body-structure">
                        <div id="metadata">
                           <xsl:if test="//t:support//t:p//text() or //t:support/t:rs[not(@type='decoration')]//text()">
                              <p>
                                 <b>Description: </b>
                                 <xsl:apply-templates select="//t:support/t:p" mode="sample-dimensions"/>
                                 <xsl:text> </xsl:text>
                                 <xsl:for-each select="//t:support/t:rs[not(@type='decoration')]">
                                    <xsl:apply-templates select="." mode="sample-dimensions"/>
                                    <xsl:if test="position()!=last()">
                                       <xsl:text>; </xsl:text>
                                    </xsl:if>
                                 </xsl:for-each>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:support/t:material//text()">
                              <p>
                                 <b>Material: </b>
                                 <xsl:apply-templates select="//t:support/t:material"/>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:support/t:objectType//text()">
                              <p>
                                 <b>Object type: </b>
                                 <xsl:apply-templates select="//t:support/t:objectType"/>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:support/t:dimensions//text()">
                              <p>
                                 <b>Dimensions: </b>
                                 <xsl:apply-templates select="//t:support/t:dimensions" mode="sample-dimensions"/>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:decoDesc//text() or //t:support/t:rs[@type='decoration']">
                              <p>
                                 <b>Decoration: </b>
                                 <xsl:apply-templates select="//t:decoDesc"/>
                                 <xsl:text> </xsl:text>
                                 <xsl:apply-templates select="//t:support/t:rs[@type='decoration']"/>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:supportDesc//t:condition//text()">
                              <p>
                                 <b>Condition: </b>
                                 <xsl:value-of select="//t:supportDesc//t:condition"/>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:layoutDesc/t:layout//text()">
                              <p>
                                 <b>Text: </b>
                                 <xsl:apply-templates select="//t:layoutDesc/t:layout" mode="sample-dimensions"/>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:handDesc//text()">
                              <p>
                                 <b>Letters: </b>
                                 <xsl:apply-templates select="//t:handDesc"/>
                              </p>
                           </xsl:if>
      
                           <p>
                              <b>Date: </b>
                              <xsl:choose>
                                 <xsl:when test="//t:origin/t:origDate//text()">
                                    <xsl:apply-templates select="//t:origin/t:origDate"/>
                                    <xsl:if test="//t:origin/t:origDate[@evidence]">
                                       <xsl:text> (</xsl:text>
                                       <xsl:for-each select="tokenize(//t:origin/t:origDate/@evidence,' ')">
                                          <xsl:value-of select="translate(translate(.,'-',' '),',','')"/>
                                          <xsl:if test="position()!=last()">
                                             <xsl:text>, </xsl:text>
                                          </xsl:if>
                                       </xsl:for-each>
                                       <xsl:text>)</xsl:text>
                                    </xsl:if>
                                 </xsl:when>
                                 <xsl:when test="//t:origin/t:date//text()">
                                    <xsl:apply-templates select="//t:origin/t:date"/>
                                    <xsl:if test="//t:origin/t:date[@evidence]">
                                       <xsl:text> (</xsl:text>
                                       <xsl:for-each select="tokenize(//t:origin/t:date/@evidence,' ')">
                                          <xsl:value-of select="translate(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']//text()">
                                    <xsl:apply-templates select="//t:provenance[@type='found']"/>
                                 </xsl:when>
                                 <xsl:otherwise>Unknown</xsl:otherwise>
                              </xsl:choose>
                           </p>
      
                           <p>
                              <b>Original location: </b>
                              <xsl:choose>
                                 <xsl:when test="//t:origin/t:origPlace//text()">
                                    <xsl:apply-templates select="//t:origin/t:origPlace"/>
                                 </xsl:when>
                                 <xsl:when test="//t:origin/t:placeName//text()">
                                    <xsl:apply-templates select="//t:origin/t:placeName"/>
                                 </xsl:when>
                                 <xsl:otherwise>Unknown</xsl:otherwise>
                              </xsl:choose>
                           </p>
      
                           <p>
                              <b>Current repository: </b>
                              <xsl:choose>
                                 <xsl:when test="//t:msIdentifier//t:repository//text()">
                                    <xsl:for-each select="//t:msIdentifier//t:repository">
                                       <xsl:if test="preceding-sibling::t:*[not(self::t:idno)][not(self::t:altIdentifier)]">
                                          <xsl:for-each select="preceding-sibling::t:*[not(self::t:idno)][not(self::t:altIdentifier)]">
                                             <xsl:apply-templates select="."/>
                                             <xsl:text> </xsl:text>
                                          </xsl:for-each>
                                       </xsl:if>
                                       <xsl:if test="following-sibling::t:*[not(self::t:idno)][not(self::t:altIdentifier)]">
                                          <xsl:for-each select="following-sibling::t:*[not(self::t:idno)][not(self::t:altIdentifier)]">
                                             <xsl:apply-templates select="."/>
                                             <xsl:text> </xsl:text>
                                          </xsl:for-each>
                                       </xsl:if>
                                       <xsl:apply-templates select="."/>
                                       <xsl:if test="following-sibling::t:idno">
                                          <xsl:text> (inv. no. </xsl:text>
                                          <xsl:for-each select="following-sibling::t:idno">
                                             <xsl:apply-templates select="."/>
                                             <xsl:if test="position()!=last()">
                                                <xsl:text>, </xsl:text>
                                             </xsl:if>
                                          </xsl:for-each>
                                          <xsl:text>)</xsl:text>
                                       </xsl:if>
                                       <xsl:if test="position()!=last()">
                                          <xsl:text>, </xsl:text>
                                       </xsl:if>
                                    </xsl:for-each>
                                 </xsl:when>
                                 <xsl:when test="//t:msIdentifier//t:msName//text()">
                                    <xsl:for-each select="//t:msIdentifier//t:msName">
                                       <xsl:apply-templates select="."/>
                                       <xsl:if test="position()!=last()">
                                          <xsl:text>, </xsl:text>
                                       </xsl:if>
                                    </xsl:for-each>
                                 </xsl:when>
                                 <xsl:otherwise>Unknown</xsl:otherwise>
                              </xsl:choose>
                           </p>
      
                           <xsl:if test="//t:provenance[@type='observed' or @type='not-observed' or @type='transferred']//text()">
                              <p>
                                 <b>Last recorded location(s): </b>
                                 <xsl:for-each select="//t:provenance[@type='observed' or @type='not-observed' or @type='transferred']">
                                    <xsl:apply-templates select="."/>
                                    <xsl:if test="position()!=last()">
                                       <xsl:text> </xsl:text>
                                    </xsl:if>
                                 </xsl:for-each>
                              </p>
                           </xsl:if>
      
                           <p>
                              <b>Text type: </b>
                              <xsl:choose>
                                 <xsl:when test="//t:textClass//t:keywords//t:term[@type='textType']">
                                    <xsl:apply-templates select="//t:textClass//t:keywords//t:term[@type='textType']"/>
                                    <xsl:text> </xsl:text>
                                 </xsl:when>
                                 <xsl:when test="//t:teiHeader//t:rs[@type='textType']">
                                    <xsl:apply-templates select="//t:teiHeader//t:rs[@type='textType']"/>
                                    <xsl:text> </xsl:text>
                                 </xsl:when>
                                 <xsl:when test="//t:msContents//t:summary[@corresp]">
                                    <xsl:apply-templates select="//t:msContents//t:summary[@corresp]"/>
                                    <xsl:text> </xsl:text>
                                 </xsl:when>
                                 <xsl:when test="//t:textClass//t:keywords//t:term[not(@type='textType')]">
                                    <xsl:apply-templates select="//t:textClass//t:keywords//t:term[not(@type='textType')]"/>
                                    <xsl:text> </xsl:text>
                                 </xsl:when>
                                 <xsl:when test="//t:msDesc//t:msItem[@class]">
                                    <xsl:value-of select="//t:msDesc//t:msItem/@class"/>
                                 </xsl:when>
                                 <xsl:otherwise>Unknown</xsl:otherwise>
                              </xsl:choose>
                           </p>
      
                           <xsl:if test="//t:msDesc/t:msContents/t:msItem/t:p//text() or //t:msContents//t:summary//text()">
                              <p>
                                 <b>Summary: </b>
                                 <xsl:choose>
                                    <xsl:when test="//t:msDesc/t:msContents/t:msItem/t:p">
                                       <xsl:value-of select="//t:msDesc/t:msContents/t:msItem/t:p"/>
                                    </xsl:when>
                                    <xsl:when test="//t:msContents//t:summary">
                                       <xsl:apply-templates select="//t:msContents//t:summary"/>
                                    </xsl:when>
                                 </xsl:choose>
                              </p>
                           </xsl:if>
      
                           <!--<xsl:if test="//t:textClass//t:keywords//text()">
        <p><b>Keywords: </b>
          <xsl:apply-templates select="//t:textClass//t:keywords"/>
        </p>
      </xsl:if>-->
    </div>
    
                        <div id="file_metadata">
                           <xsl:if test="//t:titleStmt//t:editor//text()">
                              <p>
                                 <b>Editor(s): </b>
                                 <xsl:for-each select="//t:editor">
                                    <xsl:apply-templates select="."/>
                                    <xsl:if test="@role">
                                       <xsl:text> (</xsl:text>
                                       <xsl:value-of select="@role"/>
                                       <xsl:text>)</xsl:text>
                                    </xsl:if>
                                    <xsl:if test="position()!=last()">
                                       <xsl:text>, </xsl:text>
                                    </xsl:if>
                                 </xsl:for-each>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:revisionDesc//t:change">
                              <p>
                                 <b>Changes history: </b>
                                 <xsl:for-each select="//t:change">
                                    <xsl:value-of select="@when"/>
                                    <xsl:text> </xsl:text>
                                    <xsl:value-of select="@who"/>
                                    <xsl:text> </xsl:text>
                                    <xsl:value-of select="."/>
                                    <xsl:if test="position()!=last()">
                                       <xsl:text>; </xsl:text>
                                    </xsl:if>
                                 </xsl:for-each>
                              </p>
                           </xsl:if>
      
                           <xsl:if test="//t:publicationStmt[descendant::t:*[not(self::t:idno)]//text()]">
                              <p>
                                 <b>Publication details: </b>
                                 <xsl:for-each select="//t:publicationStmt/t:*[not(self::t:idno)] ">
                                    <xsl:apply-templates select="."/>
                                    <xsl:if test="position()!=last()">
                                       <xsl:text>; </xsl:text>
                                    </xsl:if>
                                 </xsl:for-each>
                              </p>
                           </xsl:if>
                        </div>
    
                        <div class="section-container tabs" data-section="tabs">
                           <section>
                              <p class="title" data-section-title="data-section-title">
                                 <a href="#">Interpretive</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="#">Diplomatic</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>
    
                        <xsl:if test="//t:div[@type='apparatus']//text()">
                           <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>
                        </xsl:if>
    
                        <xsl:if test="//t:div[@type='translation']//text()">
                           <div id="translation">
        <!-- Translation text output -->
        <xsl:variable name="transtxt">
                                 <xsl:for-each select="//t:div[@type='translation']">
                                    <h3>Translation
              <xsl:if test="@xml:lang">
                                          <xsl:text> (</xsl:text>
                                          <xsl:choose>
                                             <xsl:when test="@xml:lang='en'">
                                                <xsl:text>English</xsl:text>
                                             </xsl:when>
                                             <xsl:when test="@xml:lang='fr'">
                                                <xsl:text>French</xsl:text>
                                             </xsl:when>
                                             <xsl:when test="@xml:lang='it'">
                                                <xsl:text>Italian</xsl:text>
                                             </xsl:when>
                                             <xsl:when test="@xml:lang='de'">
                                                <xsl:text>German</xsl:text>
                                             </xsl:when>
                                             <xsl:when test="@xml:lang='ru'">
                                                <xsl:text>Russian</xsl:text>
                                             </xsl:when>
                                             <xsl:when test="@xml:lang='ar'">
                                                <xsl:text>Arabic</xsl:text>
                                             </xsl:when>
                                             <xsl:when test="@xml:lang='es'">
                                                <xsl:text>Spanish</xsl:text>
                                             </xsl:when>
                                             <xsl:otherwise>
                                                <xsl:value-of select="@xml:lang"/>
                                             </xsl:otherwise>
                                          </xsl:choose>
                                          <xsl:text>)</xsl:text>
                                       </xsl:if>
                                    </h3>
                                    <xsl:if test="@resp">
                                       <p>
                                          <xsl:text>Translation by </xsl:text>
                                          <xsl:value-of select="translate(@resp, '#', '')"/>
                                       </p>
                                    </xsl:if>
                                    <xsl:if test="@source">
                                       <p>
                                          <xsl:text>Translation from </xsl:text>
                                          <xsl:value-of select="translate(@source, '#', '')"/>
                                       </p>
                                    </xsl:if>
                                    <xsl:apply-templates select="descendant::t:p|descendant::t:ab"/>
                                 </xsl:for-each>
                              </xsl:variable>
                              <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$transtxt" mode="sqbrackets"/>
                           </div>
                        </xsl:if>
    
                        <xsl:if test="//t:div[@type='commentary']//text()">
                           <div id="commentary">
        <!-- Commentary text output -->
        <xsl:variable name="commtxt">
                                 <xsl:for-each select="//t:div[@type='commentary']">
                                    <h3>Commentary
              <xsl:if test="@subtype">
                                          <xsl:text> (</xsl:text>
                                          <xsl:value-of select="@subtype"/>
                                          <xsl:text>)</xsl:text>
                                       </xsl:if>
                                    </h3>
                                    <xsl:apply-templates select="descendant::t:p"/>
                                 </xsl:for-each>
                              </xsl:variable>
                              <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$commtxt" mode="sqbrackets"/>
                           </div>
                        </xsl:if>
    
                        <xsl:if test="//t:div[@type='bibliography']//text() or //t:teiHeader//t:listBibl//text()">
                           <div id="bibliography">
                              <xsl:for-each select="//t:div[@type='bibliography']">
                                 <h3>Bibliography
          <xsl:if test="@subtype">
                                       <xsl:text> (</xsl:text>
                                       <xsl:value-of select="@subtype"/>
                                       <xsl:text>)</xsl:text>
                                    </xsl:if>
                                 </h3>
                                 <xsl:apply-templates select="descendant::t:p"/>
                                 <xsl:apply-templates select="descendant::t:listBibl"/>
                              </xsl:for-each>

                              <xsl:for-each select="//t:teiHeader//t:listBibl">
                                 <h3>Bibliography
            <xsl:if test="@type">
                                       <xsl:text> (</xsl:text>
                                       <xsl:value-of select="@type"/>
                                       <xsl:text>)</xsl:text>
                                    </xsl:if>
                                 </h3>
                                 <p>
                                    <xsl:apply-templates select="descendant::t:bibl"/>
                                 </p>
                              </xsl:for-each>
      
                              <xsl:if test="//t:creation//text()">
                                 <p>
                                    <b>Text constituted from: </b>
                                    <xsl:apply-templates select="//t:creation"/>
                                 </p>
                              </xsl:if>
                           </div>
                        </xsl:if>
    
                        <xsl:if test="//t:facsimile">
                           <div id="images">
                              <h3>Images</h3>
                              <xsl:choose>
                                 <xsl:when test="//t:facsimile//t:graphic">
                                    <xsl:for-each select="//t:facsimile//t:graphic">
                                       <span> </span>
                                       <xsl:choose>
                                          <xsl:when test="contains(@url,'http')">
                                             <a target="_blank" href="{@url}">[Open image]</a>
                                          </xsl:when>
                                          <xsl:otherwise>
                                             <xsl:apply-templates select="."/>
                                          </xsl:otherwise>
                                       </xsl:choose>
                                       <xsl:text> </xsl:text>
                                       <span> </span>
                                       <strong>
                                          <xsl:text>Fig. </xsl:text>
                                          <xsl:number value="position()" format="1"/>
                                       </strong>
                                       <xsl:text>. </xsl:text>
                                       <xsl:if test="ancestor::t:surface[@n]">
                                          <xsl:text>Surface </xsl:text>
                                          <xsl:value-of select="ancestor::t:surface/@n"/>
                                          <xsl:text>. </xsl:text>
                                       </xsl:if>
                                       <xsl:if test="ancestor::t:surface[child::t:desc]">
                                          <xsl:apply-templates select="ancestor::t:surface/t:desc"/>
                                          <xsl:text>. </xsl:text>
                                       </xsl:if>
                                       <xsl:if test="t:desc">
                                          <xsl:apply-templates select="t:desc"/>
                                       </xsl:if>
                                       <br/>
                                       <br/>
                                    </xsl:for-each>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:for-each select="//t:facsimile[not(//t:graphic)]">
                                       <p>None available.</p>
                                    </xsl:for-each>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </div>
                        </xsl:if>
                     </xsl:template>
  
                     <!-- dimensions -->
  <xsl:template match="t:dimensions" mode="sample-dimensions">
                        <xsl:if test="@type">
                           <xsl:value-of select="@type"/>
                           <xsl:text>: </xsl:text>
                        </xsl:if>
                        <xsl:if test="//text()">
                           <xsl:if test="t:width/text()">
                              <xsl:text>w </xsl:text>
                              <xsl:value-of select="t:width"/>
                              <xsl:if test="t:width[@unit]">
                                 <xsl:text> </xsl:text>
                                 <xsl:value-of select="t:width/@unit"/>
                              </xsl:if>
                              <xsl:if test="t:height/text()">
                                 <xsl:text> x </xsl:text>
                              </xsl:if>
                           </xsl:if>
                           <xsl:if test="t:height/text()">
                              <xsl:text>h </xsl:text>
                              <xsl:value-of select="t:height"/>
                              <xsl:if test="t:height[@unit]">
                                 <xsl:text> </xsl:text>
                                 <xsl:value-of select="t:height/@unit"/>
                              </xsl:if>
                           </xsl:if>
                           <xsl:if test="t:depth/text()">
                              <xsl:text> x d </xsl:text>
                              <xsl:value-of select="t:depth"/>
                              <xsl:if test="t:depth[@unit]">
                                 <xsl:text> </xsl:text>
                                 <xsl:value-of select="t:depth/@unit"/>
                              </xsl:if>
                           </xsl:if>
                           <xsl:if test="t:dim[@type='diameter']/text()">
                              <xsl:text> x diam. </xsl:text>
                              <xsl:value-of select="t:dim[@type='diameter']"/>
                              <xsl:if test="t:dim[@type='diameter'][@unit]">
                                 <xsl:text> </xsl:text>
                                 <xsl:value-of select="t:dim[@type='diameter']/@unit"/>
                              </xsl:if>
                           </xsl:if>
                           <xsl:if test="@unit">
                              <xsl:text> </xsl:text>
                              <xsl:value-of select="@unit"/>
                           </xsl:if>
                           <xsl:text> </xsl:text>
                        </xsl:if>
                     </xsl:template>
  
                     <!-- uncomment the following template to activate external links in @ref -->
    <!--<xsl:template priority="10" match="t:*[starts-with(@ref, 'http')]">
      <a href="{@ref}" target="_blank"><xsl:apply-templates/></a>
    </xsl:template>-->
  
</xsl:stylesheet>
               </xsl:include>
               <xsl:include href="htm-tpl-struct-sigidoc.xsl"><!-- $Id$ --><xsl:stylesheet exclude-result-prefixes="t" version="2.0">
  <!-- Contains named templates for sigidoc file structure (aka "metadata" aka "supporting data") -->

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

  <xsl:template name="sigidoc-body-structure">
                        <div id="stone">
                           <h3 class="sigidoc">Object</h3>
                           <dl class="sigidoc">
                              <dt width="150" align="left">Physical description</dt>
        
                              <!-- e.g. fragmented seal, seal inscripted on two sides -->
        
        <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:support//t:objectType//text()">
                                       <xsl:value-of select="//t:support//t:objectType"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">Material</dt>
        
                              <!-- lead, gold, silver -->
        
        <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:support//t:material//text()">
                                       <xsl:value-of select="//t:support//t:material"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">Description and condition</dt>
                              <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:support//t:p//text()">
                                       <xsl:value-of select="//t:support//t:p"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>

                           <dl class="sigidoc">
                              <dt width="150" align="left">Find place</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>Unknown</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">Find circumstances</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>Unknown</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">Find context</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>Unknown</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
        
                              <dt width="150" align="left">Current location</dt>
        
                              <!-- country, city, institution, repository, collection, accession number --> 
          
        <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:provenance[@type='observed']//text()">
                                       <xsl:value-of select="//t:provenance[@type='observed']"/>
                                    </xsl:when>
                                    <xsl:otherwise>Unknown</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">Dimensions (mm)</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>Unknown</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
      
                              <dt width="150" align="left">Weight (gr)</dt>
        
                              <dt width="150" align="left">Institution and inventory</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>Unknown</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>
                        </div>

                        <div id="text-field">
                           <h3 class="sigidoc">Inscribed field</h3>
                           <dl class="sigidoc">
                              <xsl:if test="//t:layout/@ana">
                                 <dt width="150" align="left">Faces code</dt>
                                 <dd>
                                    <xsl:value-of select="//t:layout/@ana"/>
                                 </dd>
                              </xsl:if>
                              <dt width="150" align="left">Placement of text</dt>
                              <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:layout/text()">
                                       <xsl:value-of select="//t:layout"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">Style of lettering</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>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">Letterheights</dt>
                              <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:handNote//t:height/text()">
                                       <xsl:value-of select="//t:handNote//t:height"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>
                        </div>

                        <div id="text">
                           <h3 class="sigidoc">Text</h3>
                           <dl class="sigidoc">

                              <dt>Origin</dt>
                              <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:origin/t:origPlace/text()">
                                       <xsl:value-of select="//t:origin/t:origPlace"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt>Category</dt>
                              <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:msContents/t:summary/text()">
                                       <xsl:value-of select="//t:msContents/t:summary"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt>Date</dt>
                              <dd>
                                 <xsl:choose>
                                    <xsl:when test="//t:origin/t:origDate/text()">
                                       <xsl:value-of select="//t:origin/t:origDate"/>
                                    </xsl:when>
                                    <xsl:otherwise>Not specified</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt>Dating criteria</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>Editions</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>Unpublished</xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>

                           <div id="sigidoc-text" class="sigidoc">
                              <div id="edition">
                                 <p>
                                    <b>Interpretive edition:</b>
                                 </p>
                                 <!-- Edited text output -->
          <xsl:variable name="edtxt">
                                    <xsl:apply-templates select="//t:div[@type='edition']">
                                       <xsl:with-param name="parm-edition-type" tunnel="yes" select="'interpretive'"/>
                                       <xsl:with-param name="parm-verse-lines" tunnel="yes" select="'no'"/>
                                    </xsl:apply-templates>
                                 </xsl:variable>
                                 <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
          <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
                              </div>
        
                              <xsl:if test="//t:div[@type='edition']//t:lg">
                                 <div id="verse">
                                    <p>
                                       <b>Verse edition:</b>
                                    </p>
                                    <!-- Edited text output -->
            <xsl:variable name="edtxt">
                                       <xsl:apply-templates select="//t:div[@type='edition']">
                                          <xsl:with-param name="parm-edition-type" tunnel="yes" select="'interpretive'"/>
                                          <xsl:with-param name="parm-verse-lines" tunnel="yes" select="'yes'"/>
                                       </xsl:apply-templates>
                                    </xsl:variable>
                                    <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
            <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
                                 </div>
                              </xsl:if>
        
                              <div id="diplomatic">
                                 <p>
                                    <b>Diplomatic edition:</b>
                                 </p>
                                 <!-- Edited text output -->
          <xsl:variable name="edtxt">
                                    <xsl:apply-templates select="//t:div[@type='edition']">
                                       <xsl:with-param name="parm-edition-type" tunnel="yes" select="'diplomatic'"/>
                                       <xsl:with-param name="parm-verse-lines" tunnel="yes" select="'no'"/>
                                    </xsl:apply-templates>
                                 </xsl:variable>
                                 <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
          <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
                              </div>
                           </div>
      
                           <div id="apparatus" class="sigidoc">
                              <h4 class="sigidoc">Apparatus</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="sigidoc">
                              <h4 class="sigidoc">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" class="sigidoc">
                              <h4 class="sigidoc">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>
                        </div>
                     </xsl:template>

                     <xsl:template name="sigidoc-structure">
                        <xsl:variable name="title">
                           <xsl:call-template name="sigidoc-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="sigidoc-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:stylesheet>
               </xsl:include>
               <xsl:include href="htm-tpl-struct-ecg.xsl"><!-- $Id$ --><xsl:stylesheet xmlns:i18n="http://apache.org/cocoon/i18n/2.1" exclude-result-prefixes="t"
                                  version="2.0">
  <!-- Contains named templates for ecg file structure (aka "metadata" aka "supporting data") -->

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

  <xsl:template name="ecg-body-structure">
                        <div id="stone">
                           <h3 class="ecg">
                              <i18n:text i18n:key="epidoc-xslt-ecg-monument">Monument</i18n:text>
                           </h3>
                           <dl class="ecg">
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>

                           <dl class="ecg">
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-unknown">Unknown</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-unknown">Unknown</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-unknown">Unknown</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-unknown">Unknown</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-unknown">Unknown</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-unknown">Unknown</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>
                        </div>

                        <div id="text-field">
                           <h3 class="ecg">
                              <i18n:text i18n:key="epidoc-xslt-ecg-inscribed-field">Inscribed field</i18n:text>
                           </h3>
                           <dl class="ecg">
                              <xsl:if test="//t:layout/@ana">
                                 <dt width="150" align="left">
                                    <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt width="150" align="left">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>
                        </div>

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

                              <dt>
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt>
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt>
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-not-specified">Not specified</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                              <dt>
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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-ecg-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-ecg-unpublished">Unpublished</i18n:text>
                                    </xsl:otherwise>
                                 </xsl:choose>
                              </dd>
                           </dl>

                           <div id="edition" class="ecg">
        <!-- Edited text output -->


        <xsl:variable name="edtxt">
                                 <xsl:apply-templates select="//t:div[@type='edition']">
                                    <xsl:with-param name="parm-edition-type" tunnel="yes">
                                       <xsl:text>inetrpretative</xsl:text>
                                    </xsl:with-param>
                                    <xsl:with-param name="parm-verse-lines" tunnel="yes">
                                       <xsl:text>off</xsl:text>
                                    </xsl:with-param>
                                 </xsl:apply-templates>
                              </xsl:variable>
                              <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
                           </div>
      
                           <div id="diplomatic">

        <!-- Edited text output -->
        <xsl:variable name="edtxt">
                                 <xsl:apply-templates select="//t:div[@type='edition']">
                                    <xsl:with-param name="parm-edition-type" tunnel="yes">
                                       <xsl:text>diplomatic</xsl:text>
                                    </xsl:with-param>
                                    <xsl:with-param name="parm-verse-lines" tunnel="yes">
                                       <xsl:text>off</xsl:text>
                                    </xsl:with-param>
                                 </xsl:apply-templates>
                              </xsl:variable>
                              <!-- Moded templates found in htm-tpl-sqbrackets.xsl -->
        <xsl:apply-templates select="$edtxt" mode="sqbrackets"/>
                           </div>


                           <div id="apparatus" class="ecg">
                              <h4 class="ecg">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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="ecg">
                              <h4 class="ecg">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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="ecg">
                              <h4 class="ecg">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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="ecg">
                              <h4 class="ecg">
                                 <i18n:text i18n:key="epidoc-xslt-ecg-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="ecg-structure">
                        <xsl:variable name="title">
                           <xsl:call-template name="ecg-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="ecg-body-structure"/>
                           </body>
                        </html>
                     </xsl:template>

                     <xsl:template name="ecg-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, ecg 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 -->
         
         <!-- Georgian Alphabet in diplomatic edition-->
         
         <xsl:when test="$parm-edition-type = 'diplomatic' and ancestor::t:div[@type='edition'] and not(ancestor::t:head)             and ancestor-or-self::t:*[@xml:lang][1][@xml:lang='ka']">
                              <xsl:value-of select="translate(.,'აბგდევზჱთიკლმნჲოპჟრსტჳუფქღყშჩცძწჭხჴჯჰჵ','ႠႡႢႣႤႥႦჁႧႨႩႪႫႬჂႭႮႯႰႱႲჃႳႴႵႶႷႸႹႺႻႼႽႾჄႿჀჅ')"/>
                           </xsl:when>
         
                           <!-- Armenian Alphabet  -->
         
         <xsl:when test="$parm-edition-type = 'diplomatic' and ancestor::t:div[@type='edition'] and not(ancestor::t:head)             and ancestor-or-self::t:*[@xml:lang][1][@xml:lang='hy']">
                              <xsl:value-of select="translate(.,'աբգդեզէըթժիլխծկհձղճմյնշոչպջռսվտրցւփք','ԱԲԳԴԵԶԷԸԹԺԻԼԽԾԿՀՁՂՃՄՅՆՇՈՉՊՋՌՍՎՏՐՑՒՓՔ')"/>
                           </xsl:when> 
         
                           <xsl:when test="$parm-edition-type = 'diplomatic' and ancestor::t:div[@type='edition'] and not(ancestor::t:head)">
                              <xsl:variable name="apos">
                                 <xsl:text>'</xsl:text>
                              </xsl:variable>
                              <xsl:value-of select="upper-case(translate(normalize-unicode(translate(translate(translate(.,'ϲ','Ϲ'),$apos,''), '··&#xA; ,.;‘’', ''),'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>
                           <!-- 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>
               <xsl:include href="functions.xsl">
                  <xsl:stylesheet xmlns:EDF="http://epidoc.sourceforge.net/ns/functions"
                                  exclude-result-prefixes="xs"
                                  version="2.0">
    
                     <xsl:function name="EDF:refParser">
                        <xsl:param name="ref"/>
                        <xsl:param name="listPrefixDef"/>
                        <xsl:choose>
                           <xsl:when test="starts-with($ref, 'http')">
                              <xsl:value-of select="$ref"/>
                           </xsl:when>
                           <xsl:when test="contains($ref, ':')">
                              <xsl:variable name="prefix" select="substring-before($ref,':')"/>
                              <xsl:variable name="pdef" select="$listPrefixDef//t:prefixDef[@ident=$prefix]"/>
                              <xsl:choose>
                                 <xsl:when test="$pdef">
                                    <xsl:value-of select="replace(substring-after($ref, ':'), $pdef/@matchPattern, $pdef/@replacementPattern)"/>
                                 </xsl:when>
                                 <xsl:otherwise>
                                    <xsl:value-of select="concat('no matching prefix ',$prefix, ' found for ', $ref)"/>
                                 </xsl:otherwise>
                              </xsl:choose>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:value-of select="$ref"/>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:function>
   
                     <xsl:function name="EDF:refID">
                        <xsl:param name="ref"/>
                        <xsl:choose>
                           <xsl:when test="contains($ref, '#')">
                              <xsl:value-of select="substring-after($ref,'#')"/>
                           </xsl:when>
                           <xsl:when test="contains($ref, ':')">
                              <xsl:value-of select="substring-after($ref,':')"/>
                           </xsl:when>
                           <xsl:otherwise>
                              <xsl:value-of select="$ref"/>
                           </xsl:otherwise>
                        </xsl:choose>
                     </xsl:function>

                     <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>
                           <!--      imported change    https://sourceforge.net/p/epidoc/code/2602/-->
            <!-- Added to controll '-' when there is a milestone@rend='paragraphos' followed by a lb@break='no' see: https://github.com/DCLP/dclpxsltbox/issues/52-->
            <xsl:when test="$ww-context/following-sibling::node()[1][(local-name()='milestone' and (@rend='paragraphos'))                 or normalize-space(.)='' and following-sibling::node()[1][local-name()='milestone' and (@rend='paragraphos')]                 and $ww-context/following-sibling::node()[2][(local-name()='lb' and (@break='no' or @type='inWord'))                 or normalize-space(.)='' and following-sibling::node()[2][local-name()='lb' and (@break='no' or @type='inWord')]]]">
                              <xsl:value-of select="true()"/>
                           </xsl:when>
                           <!-- Added to controll '-' when there is a milestone@rend='paragraphos' followed by a lb@break='no' see: https://github.com/DCLP/dclpxsltbox/issues/52 -->
            <xsl:when test="$ww-context/following-sibling::node()[1][(local-name()='milestone' and (@rend='paragraphos'))                 or normalize-space(.)='' and following-sibling::node()[1][local-name()='milestone' and (@rend='paragraphos')]                 and $ww-context/following-sibling::node()[2][(local-name()='lb' and (@break='no' or @type='inWord'))                 or normalize-space(.)='' and following-sibling::node()[2][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: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 = '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: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 = '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 = 'sample'">
                        <xsl:call-template name="sample-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 = 'sigidoc'">
                        <xsl:call-template name="sigidoc-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 = 'ecg'">
                        <div>
                           <xsl:call-template name="ecg-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 = 'creta'">
                        <div>
                           <xsl:call-template name="creta-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: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:with-param name="parm-glyph-variant" select="$glyph-variant" tunnel="yes"/>
                        </xsl:call-template>
                     </xsl:otherwise>
                  </xsl:choose>
               </xsl:template>

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

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

  <xsl:param name="language"/>

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  

  
    

  
  
  
  
  
  
  
  
  

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

  
    

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

  <!-- Imports the menu stylesheet -->
  

  

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

  

  

  

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