<xsl:stylesheet
  version="3.0"
  exclude-result-prefixes="#all"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
  xmlns:dbk="http://docbook.org/ns/docbook"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:html="http://www.w3.org/1999/xhtml"
  xmlns:rng="http://relaxng.org/ns/structure/1.0"
  xpath-default-namespace="http://www.tei-c.org/ns/1.0"
  xmlns:teix="http://www.tei-c.org/ns/Examples"
  xmlns:tei="http://www.tei-c.org/ns/1.0"
  xmlns:xd="http://www.pnp-software.com/XSLTdoc"
  xmlns:xhtml="http://www.w3.org/1999/xhtml"
  xmlns:xlink="http://www.w3.org/1999/xlink"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:import href="http://www.tei-c.org/release/xml/tei/stylesheet/odds/odd2html.xsl"/>
  <xsl:import href="http://www.tei-c.org/release/xml/tei/stylesheet/odds/guidelines.xsl"/>
  <xsl:output method="xhtml" html-version="5"/>

  <xsl:strip-space elements="tei:additional tei:address tei:adminInfo
                             tei:altGrp tei:altIdentifier tei:analytic
                             tei:app tei:appInfo tei:application
                             tei:arc tei:argument tei:attDef
                             tei:attList tei:availability tei:back
                             tei:biblFull tei:biblStruct tei:bicond
                             tei:binding tei:bindingDesc tei:body
                             tei:broadcast tei:cRefPattern tei:calendar
                             tei:calendarDesc tei:castGroup
                             tei:castList tei:category tei:certainty
                             tei:char tei:charDecl tei:charProp
                             tei:choice tei:cit tei:classDecl
                             tei:classSpec tei:classes tei:climate
                             tei:cond tei:constraintSpec tei:correction
                             tei:custodialHist tei:decoDesc
                             tei:dimensions tei:div tei:div1 tei:div2
                             tei:div3 tei:div4 tei:div5 tei:div6
                             tei:div7 tei:divGen tei:docTitle tei:eLeaf
                             tei:eTree tei:editionStmt
                             tei:editorialDecl tei:elementSpec
                             tei:encodingDesc tei:entry tei:epigraph
                             tei:epilogue tei:equipment tei:event
                             tei:exemplum tei:fDecl tei:fLib
                             tei:facsimile tei:figure tei:fileDesc
                             tei:floatingText tei:forest tei:front
                             tei:fs tei:fsConstraints tei:fsDecl
                             tei:fsdDecl tei:fvLib tei:gap tei:glyph
                             tei:graph tei:graphic tei:group
                             tei:handDesc tei:handNotes tei:history
                             tei:hom tei:hyphenation tei:iNode tei:if
                             tei:imprint tei:incident tei:index
                             tei:interpGrp tei:interpretation tei:join
                             tei:joinGrp tei:keywords tei:kinesic
                             tei:langKnowledge tei:langUsage
                             tei:layoutDesc tei:leaf tei:lg tei:linkGrp
                             tei:list tei:listBibl tei:listChange
                             tei:listEvent tei:listForest tei:listNym
                             tei:listOrg tei:listPerson tei:listPlace
                             tei:listRef tei:listRelation
                             tei:listTranspose tei:listWit tei:location
                             tei:locusGrp tei:macroSpec tei:metDecl
                             tei:moduleRef tei:moduleSpec tei:monogr
                             tei:msContents tei:msDesc tei:msIdentifier
                             tei:msItem tei:msItemStruct tei:msPart
                             tei:namespace tei:node tei:normalization
                             tei:notatedMusic tei:notesStmt tei:nym
                             tei:objectDesc tei:org tei:particDesc
                             tei:performance tei:person tei:personGrp
                             tei:physDesc tei:place tei:population
                             tei:postscript tei:precision
                             tei:profileDesc tei:projectDesc
                             tei:prologue tei:publicationStmt
                             tei:quotation tei:rdgGrp tei:recordHist
                             tei:recording tei:recordingStmt
                             tei:refsDecl tei:relatedItem tei:relation
                             tei:relationGrp tei:remarks tei:respStmt
                             tei:respons tei:revisionDesc tei:root
                             tei:row tei:samplingDecl tei:schemaSpec
                             tei:scriptDesc tei:scriptStmt tei:seal
                             tei:sealDesc tei:segmentation
                             tei:seriesStmt tei:set tei:setting
                             tei:settingDesc tei:sourceDesc
                             tei:sourceDoc tei:sp tei:spGrp tei:space
                             tei:spanGrp tei:specGrp tei:specList
                             tei:state tei:stdVals tei:subst
                             tei:substJoin tei:superEntry
                             tei:supportDesc tei:surface tei:surfaceGrp
                             tei:table tei:tagsDecl tei:taxonomy
                             tei:teiCorpus tei:teiHeader tei:terrain
                             tei:text tei:textClass tei:textDesc
                             tei:timeline tei:titlePage tei:titleStmt
                             tei:trait tei:transpose tei:tree
                             tei:triangle tei:typeDesc tei:vAlt
                             tei:vColl tei:vDefault tei:vLabel
                             tei:vMerge tei:vNot tei:vRange tei:valItem
                             tei:valList tei:vocal"/>

  <xsl:key name="IDS" match="*[@xml:id]" use="@xml:id"/>
  <xsl:param name="googleAnalytics"></xsl:param>
  <xsl:param name="pageLayout">Complex</xsl:param>
  <xsl:param name="lang"/>
  <xsl:param name="doclang"/>
  <xsl:param name="STDOUT">false</xsl:param>
  <xsl:param name="splitLevel">0</xsl:param>
  <xsl:param name="footnoteFile">false</xsl:param>
  <xsl:param name="auto">false</xsl:param>
  <xsl:param name="numberFrontHeadings">true</xsl:param>
  <xsl:param name="splitBackmatter">true</xsl:param>
  <xsl:param name="splitFrontmatter">true</xsl:param>
  <xsl:param name="displayMode">both</xsl:param>
  <xsl:param name="feedbackURL">https://tei-c.org/about/contact/</xsl:param>
  <xsl:param name="homeLabel">TEI P5 Guidelines</xsl:param>
  <xsl:param name="homeWords">TEI P5</xsl:param>
  <xsl:param name="institution">Text Encoding Initiative</xsl:param>
  <xsl:param name="linkPanel">false</xsl:param>
  <xsl:param name="outputDir">Guidelines</xsl:param>
  <xsl:param name="cssFile">guidelines.css</xsl:param>
  <xsl:param name="cssSecondaryFile">odd.css</xsl:param>
  <xsl:param name="cssPrintFile">guidelines-print.css</xsl:param>
  <xsl:param name="teiWeb"></xsl:param>
  <xsl:param name="divOffset">2</xsl:param>
  <xsl:param name="verboseSpecDesc">false</xsl:param>

  <xsl:template match="/">

    <xsl:result-document
      html-version="{$htmlVersion}"
      normalization-form="{$normalizationForm}"
      encoding="{$outputEncoding}"
      method="{$outputMethod}"
      omit-xml-declaration="{$omitXMLDeclaration}"
      href="{$outputDir}/TitlePageRecto.html" >
      <html>
        <xsl:comment>THIS IS A GENERATED FILE. DO NOT EDIT (97) </xsl:comment>
        <head>
          <title>
            <xsl:value-of select="tei:generateTitle(.)"/>
          </title>
          <xsl:choose>
            <xsl:when test="$cssFile = ''"/>
            <xsl:when test="$cssFileInclude='true'">
              <style>
                <include href="{$cssFile}" parse="text" xmlns="http://www.w3.org/2001/XInclude"/>
              </style>
            </xsl:when>
            <xsl:otherwise>
              <link href="{$cssFile}" rel="stylesheet"
                    type="text/css"/>
            </xsl:otherwise>
          </xsl:choose>
          <xsl:if test="not($cssSecondaryFile = '')">
            <link href="{$cssSecondaryFile}" rel="stylesheet"
                  type="text/css"/>
          </xsl:if>
          <xsl:call-template name="metaHTML">
            <xsl:with-param name="title"
                            select="string-join(tei:generateTitle(.),'')"/>
          </xsl:call-template>
          <xsl:call-template name="javascriptHook"/>
        </head>
        <body id="TOP">
          <xsl:call-template name="bodyHook"/>
          <div id="onecol" class="main-content">
            <xsl:apply-templates select="/TEI/text/front/titlePage/*"/>
          </div>
          <xsl:call-template name="stdfooter"/>
        </body>
      </html>
    </xsl:result-document>    
    <xsl:apply-imports/>
    <xsl:for-each select="key('ELEMENTDOCS',1)">
      <xsl:variable name="me" select="@ident"/>
      <xsl:variable name="mychapter" select="ancestor::div[last()]/@xml:id"/>
      <xsl:variable name="langs">
        <xsl:value-of select="concat(normalize-space(tei:generateDocumentationLang(.)),' ')"/>
      </xsl:variable>
      <xsl:result-document       
        html-version="{$htmlVersion}"
        normalization-form="{$normalizationForm}"
        encoding="{$outputEncoding}"
        method="{$outputMethod}"
        omit-xml-declaration="{$omitXMLDeclaration}"
        href="{$outputDir}/examples-{$me}.html">
        <html>
          <xsl:comment>THIS IS A GENERATED FILE. DO NOT EDIT (98) </xsl:comment>
          <head>
            <title>
              <xsl:sequence select="tei:i18n('Example')"/>
              <xsl:text>: &lt;</xsl:text>
              <xsl:value-of select="$me"/>
              <xsl:text>&gt; </xsl:text>
              <xsl:sequence select="tei:makeGloss(.,$langs)"/>
            </title>
            <link href="{$cssFile}" rel="stylesheet" type="text/css"/>
            <xsl:if test="not($cssSecondaryFile = '')">
              <link href="{$cssSecondaryFile}" rel="stylesheet"
                    type="text/css"/>
            </xsl:if>
            <meta
                content="Text Encoding Initiative Consortium XSLT stylesheets"
                name="generator"/>
          <xsl:call-template name="metaHTML">
            <xsl:with-param name="title">
                <xsl:sequence select="tei:i18n('Example')"/>
                <xsl:text>: </xsl:text>
                <xsl:value-of select="$me"/>
                <xsl:text> </xsl:text>
                <xsl:sequence select="tei:makeGloss(.,$langs)"/>
            </xsl:with-param>
          </xsl:call-template>
            <xsl:call-template name="includeJavascript"/>
            <xsl:call-template name="javascriptHook"/>
          </head>
          <body id="TOP">
            <xsl:call-template name="bodyHook"/>
            <div class="main-content">
              <xsl:call-template name="startDivHook"/>
              <h3>
                <xsl:sequence select="tei:i18n('Example')||': '"/>
                <a href="ref-{$me}.html">
                  <xsl:value-of select="'&lt;'||$me||'&gt;'"/>
                </a>
                <xsl:sequence select="string-join( '&#x20;', tei:makeGloss(.,$langs) )"/>
              </h3>
              <p>These search results reproduce every example of the
              use of <xsl:text>&lt;</xsl:text>
              <xsl:value-of select="$me"/>
              <xsl:text>&gt;</xsl:text> in the Guidelines, including all localised
              and translated versions. In some cases, the examples have been drawn
              from discussion of other elements in the Guidelines and illustrating
              the use of <xsl:text>&lt;</xsl:text>
              <xsl:value-of select="$me"/>
              <xsl:text>&gt;</xsl:text>
              is not the main 
              focus of the passage in question. In other cases, examples may be direct 
              translations of each other, and hence identical from the perspective of 
              their encoding.</p>             
                <xsl:for-each
                    select="/TEI/text/body/div[@xml:id=$mychapter]">
                  <xsl:if test="count(key('EXAMPLES',concat(@xml:id,$me)))&gt;0">
                    <ul>
                      <li>
                        <b>
                          <a href="#{@xml:id}">
                            <xsl:call-template name="header"/> <em> (defining module)</em>
                          </a>
                        </b>
                      </li>
                    </ul>
                  </xsl:if>
                </xsl:for-each>
              <xsl:variable name="items">
                <xsl:for-each
                    select="/TEI/text/body/div[not(@xml:id=$mychapter)]">
                  <xsl:if test="count(key('EXAMPLES',concat(@xml:id,$me)))&gt;0">
                    <li>
                      <a href="#{@xml:id}">
                        <xsl:call-template name="header"/>
                        <xsl:if test="./ancestor::*/@module = $me/ancestor::*/@module">
                          <em>(defining module)</em>
                        </xsl:if>
                      </a>
                    </li>
                  </xsl:if>
                </xsl:for-each>
              </xsl:variable>
              <xsl:if test="count($items/html:li)&gt;0">
                <ul>
                  <xsl:copy-of select="$items/html:li"/>
                </ul>
              </xsl:if>
              <xsl:for-each
                  select="/TEI/text/body/div[@xml:id=$mychapter]">
                <xsl:if
                    test="count(key('EXAMPLES',concat(@xml:id,$me)))&gt;0">
                  <xsl:call-template name="showExamplesFromDiv">
                    <xsl:with-param name="me" select="$me"/>
                  </xsl:call-template>
                </xsl:if>
              </xsl:for-each>
              <xsl:for-each
                  select="/TEI/text/body/div[not(@xml:id=$mychapter)]">
                <xsl:if
                    test="count(key('EXAMPLES',concat(@xml:id,$me)))&gt;0">
                  <xsl:call-template name="showExamplesFromDiv">
                    <xsl:with-param name="me" select="$me"/>
                  </xsl:call-template>
                </xsl:if>
              </xsl:for-each>
            </div>
            <xsl:call-template name="stdfooter">
              <xsl:with-param name="file">
                <xsl:text>examples-</xsl:text>
                <xsl:value-of select="$me"/>
              </xsl:with-param>
            </xsl:call-template>
          </body>
        </html>
      </xsl:result-document>
    </xsl:for-each>
  </xsl:template>

  <xsl:template name="showExamplesFromDiv">
    <xsl:param name="me"/>
    <h4 id="{@xml:id}">
      <xsl:call-template name="header"/>
    </h4>
    <xsl:for-each select="key('EXAMPLES',concat(@xml:id,$me))">
      <xsl:variable name="pos">
        <xsl:number level="any" from="teix:egXML"/>
      </xsl:variable>
      <xsl:if test="number($pos)=1 or ($me='egXML' and
                    number($pos)=2)">
        <hr/>
        <p>
          <xsl:variable name="exemplumLang" select="tei:checkLang(ancestor::exemplum/@xml:lang)"/>
          <xsl:choose>
            <xsl:when test="ancestor::elementSpec">
              <a
                  href="../../{$exemplumLang}/html/ref-{ancestor::elementSpec/@ident}.html">
                <xsl:text>&lt;</xsl:text>
                <xsl:value-of
                    select="ancestor::elementSpec/@ident"/>
                <xsl:text>&gt;</xsl:text>
              </a>
              <xsl:if test="$exemplumLang ne $doclang">
                <xsl:sequence select="'&#x20;('||$exemplumLang||')'"/>
              </xsl:if>
            </xsl:when>
            <xsl:when test="ancestor::classSpec">
              <a
                  href="../../{$exemplumLang}/html/ref-{ancestor::classSpec/@ident}.html">
                <xsl:value-of
                    select="ancestor::classSpec/@ident"/>
              </a>
              <xsl:if test="$exemplumLang ne $doclang">
                <xsl:sequence select="'&#x20;('||$exemplumLang||')'"/>
              </xsl:if>
            </xsl:when>
            <xsl:otherwise>
              <xsl:for-each select="ancestor::div[@xml:id and head][1]">
                <a>
                  <xsl:attribute name="href">
                    <xsl:apply-templates select="." mode="generateLink"/>
                  </xsl:attribute>
                  <xsl:call-template name="header"/>
                </a>
              </xsl:for-each>
            </xsl:otherwise>
          </xsl:choose>
        </p>
        <xsl:apply-templates select="ancestor::teix:egXML">
          <xsl:with-param name="simple" select="'false'"/>
          <xsl:with-param name="highlight"><xsl:value-of select="$me"/></xsl:with-param>
        </xsl:apply-templates>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  

  <xsl:template name="startDivHook">
    <xsl:if
      test="not(parent::div) or not(local-name(preceding::*[1])='head')">
      <div>
        <xsl:choose>
        <xsl:when test="not(parent::div) and child::div">
          <xsl:attribute name="class">
            <xsl:text>miniTOC miniTOC_left</xsl:text>
          </xsl:attribute>
          <xsl:call-template name="subtoc"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="class">
            <xsl:text>miniTOC miniTOC_right</xsl:text>
          </xsl:attribute>
        </xsl:otherwise>
        </xsl:choose>
        <ul class="subtoc">
          <li class="subtoc"><xsl:call-template name="previousLink"/></li>
          <li class="subtoc"><xsl:call-template name="nextLink"/></li>
          <li class="subtoc"><a class="navigation" href="index.html">
          <xsl:sequence select="tei:i18n('homeWord')"/>
          </a> </li>
          <xsl:choose>
              <xsl:when test="self::elementSpec">
                <li class="subtoc">
                <a class="navigation" href="REF-ELEMENTS.html">
                  <xsl:call-template name="showHead">
                    <xsl:with-param name="ID">
                      <xsl:text>REF-ELEMENTS</xsl:text>
                    </xsl:with-param>
                  </xsl:call-template>
                </a>
                </li>
            </xsl:when>
              <xsl:when test="self::classSpec[@type='model']">
                <li class="subtoc">
                <a class="navigation" href="REF-CLASSES-MODEL.html">
                  <xsl:call-template name="showHead">
                    <xsl:with-param name="ID">
                      <xsl:text>REF-CLASSES-MODEL</xsl:text>
                    </xsl:with-param>
                  </xsl:call-template>
                </a>
                </li>
            </xsl:when>
              <xsl:when test="self::classSpec[@type='atts']">
                <li class="subtoc">
                <a class="navigation" href="REF-CLASSES-ATTS.html">
                <xsl:call-template name="showHead">
                  <xsl:with-param name="ID">
                    <xsl:text>REF-CLASSES-ATTS</xsl:text>
                  </xsl:with-param>
                </xsl:call-template>
                </a>
                </li>
            </xsl:when>
              <xsl:when test="self::macroSpec">
                <li class="subtoc">
                <a class="navigation" href="REF-MACROS.html">
                  <xsl:call-template name="showHead">
                    <xsl:with-param name="ID">
                      <xsl:text>REF-MACROS</xsl:text>
                    </xsl:with-param>
                  </xsl:call-template>
                </a>
                </li>
            </xsl:when>
            <xsl:otherwise>
              <!--
              <xsl:for-each select="ancestor::div">
                <div>
                  <xsl:attribute name="style">
                    <xsl:text>margin-left:</xsl:text>
                    <xsl:value-of select="count(ancestor::div) + 1"/>
                    <xsl:text>em;</xsl:text>
                  </xsl:attribute>
                  <xsl:text>&#x21B3;</xsl:text>
                <a class="UP">
                  <xsl:attribute name="href">
                    <xsl:apply-templates mode="generateLink"
                                         select="."/>
                  </xsl:attribute>
                  <xsl:call-template name="headerLink">
                    <xsl:with-param name="minimal"
                                    select="$minimalCrossRef"/>
                  </xsl:call-template>
                </a>
                </div>
              </xsl:for-each>
              -->
            </xsl:otherwise>
          </xsl:choose>

        </ul>
      </div>
    </xsl:if>
  </xsl:template>


  <xsl:template name="mainPage">
    <xsl:param name="currentID"/>
    <div id="onecol" class="main-content">
      <xsl:choose>
        <xsl:when test="not($currentID='')">
          <xsl:call-template name="mainFrame">
            <xsl:with-param name="currentID" select="$currentID"/>
            <xsl:with-param name="minimal">true</xsl:with-param>
          </xsl:call-template>
          <xsl:call-template name="partialFootNotes">
            <xsl:with-param name="currentID" select="$currentID"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="mainTOC"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="stdfooter">
        <xsl:with-param name="file" select="if (string-length($currentID) gt 0) then $currentID else 'index'"/>
      </xsl:call-template>
    </div>
  </xsl:template>





  <xsl:template name="mainTOC">
    <xsl:param name="force"/>
        
        
<!-- MDH 2013-06: changes for new TOC page layout.      -->
        
        <p class="lang_links"> 
                [<a href="../../en/html/index.html">English</a>] 
                [<a href="../../de/html/index.html">Deutsch</a>] 
                [<a href="../../es/html/index.html">Español</a>] 
                [<a href="../../it/html/index.html">Italiano</a>] 
                [<a href="../../fr/html/index.html">Français</a>] 
                [<a href="../../ja/html/index.html">日本語</a>]
                [<a href="../../ko/html/index.html">한국어</a>] 
                [<a href="../../zh-TW/html/index.html">中文</a>] 
                
                <br/>
                
                <a href="../../en/Guidelines.pdf" class="ebookLink">
                        <img src="icons/e-book-icons/mdh_pdf_doc_32x32.png" width="32" height="32" 
                                alt="PDF version for downloading and printing."
                                title="PDF version for downloading and printing."/>
                </a>
                <a href="../../en/Guidelines.epub" class="ebookLink">
                        <img src="icons/e-book-icons/mdh_epub_doc_32x32.png" width="32" height="32" 
                                alt="ePub version for mobile devices."
                                title="ePub version for mobile devices."/>
                </a>
        </p>
        
        <div class="col_left">
                <div class="toc_front">
                        <h3>
                                <xsl:sequence select="tei:i18n('Front Matter')"/>
                        </h3>
                        <ul class="toc{$force} toc_front">
                                <li>
                                        <a href="TitlePageRecto.html">
                                                <xsl:sequence select="tei:i18n('title')"/>
                                        </a>
                                </li>
                                <xsl:for-each
                                        select="ancestor-or-self::TEI/text/front">
                                        <xsl:if test="div">
                                                <xsl:apply-templates mode="maketoc" select="div">
                                                        <xsl:with-param name="forcedepth" select="$force"/>
                                                </xsl:apply-templates>
                                        </xsl:if>
                                </xsl:for-each>
                        </ul>
                </div>
                
                <div class="toc_back">
                        <h3>
                                <xsl:sequence select="tei:i18n('Back Matter')"/>
                        </h3>
                        <xsl:for-each
                                select="ancestor-or-self::TEI/text/back">
                                <xsl:if test="div">
                                        <ul class="toc{$force} toc_back">
                                                <xsl:apply-templates mode="maketoc"
                                                        select="div">
                                                        <xsl:with-param name="forcedepth" select="$force"/>
                                                </xsl:apply-templates>
                                        </ul>
                                </xsl:if>
                        </xsl:for-each>
                </div>
                
                
        </div>
        
        <div class="col_centre">
                
                <div class="toc_body">
                        <h3>
                                <xsl:sequence select="tei:i18n('Text body')"/>
                        </h3>
                        <xsl:for-each
                                select="ancestor-or-self::TEI/text/body">
                                <xsl:if          test="div">
                                        <ul class="toc{$force}  toc_body">
                                                <xsl:apply-templates mode="maketoc"
                                                        select="div">
                                                        <xsl:with-param name="forcedepth" select="$force"/>
                                                </xsl:apply-templates>
                                        </ul>
                                </xsl:if>
                        </xsl:for-each>
                </div>
                
        </div>
        
        <div class="col_right">
                <div>
                        <h3>TEI sourcecode</h3>
                        <ul>
                          <li>
                            <a href="https://github.com/TEIC/TEI">TEI GitHub Repository</a>
                          </li>
                          <li>
                            <a href="https://github.com/TEIC/TEI/blob/dev/Documents/Git-README.md">Notes on using Git to edit the Guidelines.</a>
                          </li>
                          <li>
                            <a href="https://github.com/TEIC/TEI/issues">Bug Reports, Feature Requests, etc.</a>
                          </li>
                        </ul>
                </div>
        </div>
    

  </xsl:template>



  <xsl:template match="divGen[@type='toc']"/>

  <xsl:template name="javascriptHook">
    <script type="text/javascript" src="popupFootnotes.js"/>
    <xsl:comment>CAMPAIGN JS</xsl:comment>
    <script type="text/javascript">
      document.addEventListener("DOMContentLoaded", function() {
      var relaxBtns = document.querySelectorAll(".displayRelaxButton");
      if (relaxBtns) {
        relaxBtns.forEach(function(btn) {
          btn.onclick = function() {
            var rngs = btn.parentElement.querySelectorAll('.RNG_XML');
            var rncs = btn.parentElement.querySelectorAll('.RNG_Compact');
            if (rngs) {
              rngs.forEach(function(rng) {
                rng.style.display = getComputedStyle(rng).display === "none" ? "block" : "none";
              })
            }
            if (rncs) {
              rncs.forEach(function(rnc) {
                rnc.style.display = getComputedStyle(rnc).display === "none" ? "block" : "none";
              })
            }
          }
        })
      }
      var showHides = document.querySelectorAll(".tocTree .showhide");
      if (showHides) {
        showHides.forEach(function(btn) {
          btn.onclick = function() {
            btn.querySelectorAll(".tocShow,.tocHide").forEach(function(toc) {
              toc.style.display = getComputedStyle(toc).display === "none" ? "inline" : "none";
            })
            btn.parentElement.querySelectorAll("ul.continuedtoc").forEach(function(ul) {
              ul.style.display = getComputedStyle(ul).display === "none" ? "block" : "none";
            })
          }
        })
      }
    })
    </script>
    <script type="text/javascript">
      document.addEventListener("DOMContentLoaded", function() {
        const location = window.location.pathname.replace(/.*\/ref-(.*).html/, '$1.xml');
        const outDateTr = document.querySelector('.outOfDateTranslation')
        if (outDateTr) {
          const link = document.createElement('a');
          link.href = `https://translate.tei-c.org/translate.html?edit=${location}`;
          
          const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
          svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
          svg.setAttribute("width", "16");
          svg.setAttribute("height", "16");
          svg.setAttribute("fill", "currentColor");
          svg.setAttribute("aria-label", "Translation out of date.");
          svg.setAttribute("viewBox", "0 0 16 16");
          svg.setAttribute("style", "position:absolute; top:2px; right:2px; color:red");
          
          const title = document.createElementNS("http://www.w3.org/2000/svg", "title");
          title.textContent = "Translation out of date.";
          svg.appendChild(title);
          
          const path1 = document.createElementNS("http://www.w3.org/2000/svg", "path");
          path1.setAttribute("d", "M6.146 7.146a.5.5 0 0 1 .708 0L8 8.293l1.146-1.147a.5.5 0 1 1 .708.708L8.707 9l1.147 1.146a.5.5 0 0 1-.708.708L8 9.707l-1.146 1.147a.5.5 0 0 1-.708-.708L7.293 9 6.146 7.854a.5.5 0 0 1 0-.708z");
          
          const path2 = document.createElementNS("http://www.w3.org/2000/svg", "path");
          path2.setAttribute("d", "M3.5 0a.5.5 0 0 1 .5.5V1h8V.5a.5.5 0 0 1 1 0V1h1a2 2 0 0 1 2 2v11a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2V3a2 2 0 0 1 2-2h1V.5a.5.5 0 0 1 .5-.5zM1 4v10a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V4H1z");
          
          svg.appendChild(path1);
          svg.appendChild(path2);
          
          link.appendChild(svg);
          outDateTr.appendChild(link);
        }
      });
    </script>
    <script src="https://tei-c.org/js/main.js"></script>

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

  </xsl:template>
  
  <xsl:template name="bodyHook">
    <div id="container">
      <xsl:if test="not($googleAnalytics='')">
        <xsl:copy-of select="doc('nav.html')"/>
      </xsl:if>
    </div>
    
    <div class="mainhead">
      <h1>TEI: <xsl:sequence select="tei:i18n('GuidelinesTEI')"/></h1>
      <p><xsl:value-of select="/TEI/teiHeader/fileDesc/editionStmt/edition"/></p>
    </div>
  </xsl:template>

  <xsl:template name="bodyEndHook">
    <div class="container">
      <footer class="py-3 my-4">
        <ul class="nav justify-content-center border-top pb-3 mb-3">
          <li class="nav-item"><a href="#" class="nav-link px-2 text-body-secondary">Home</a></li>
          <li class="nav-item"><a href="/about/code-of-conduct/" class="nav-link px-2 text-body-secondary">Code of Conduct</a></li>
          <li class="nav-item"><a href="/about/contact/" class="nav-link px-2 text-body-secondary">Contact Us</a></li>
        </ul>
        <p class="text-center text-body-secondary">
          <img src="emblem_color_dark.png" alt="TEI Emblem" width="40"/> © 2025 TEI Consortium — Hosted by <a href="https://www.huma-num.fr/" class="text-body-secondary">
            <img src="logo-petit-hn-rvb-1.png" alt="Hosted by Huma-Num" width="50"/>
          </a>
        </p>
      </footer>
    </div>
  </xsl:template>

  <xsl:template name="calculateFigureNumber">
    <xsl:choose>
      <xsl:when test="ancestor::front">
        <xsl:sequence select="tei:i18n('figureWord')"/>
        <xsl:text> </xsl:text>
        <xsl:number count="figure[head]" from="div[parent::front]" level="any"/>
        <xsl:for-each select="ancestor::div[parent::front]">
          <xsl:number/>
        </xsl:for-each>
        <xsl:text>.</xsl:text>
      </xsl:when>
      <xsl:when test="ancestor::back">
        <xsl:sequence select="tei:i18n('figureWord')"/>
        <xsl:text> </xsl:text>
        <xsl:for-each select="ancestor::div[parent::back]">
          <xsl:number/>
        </xsl:for-each>
        <xsl:text>.</xsl:text>
        <xsl:number count="figure[head]" from="div[parent::back]" level="any"/>
      </xsl:when>
      <xsl:when test="ancestor::body">
        <xsl:sequence select="tei:i18n('figureWord')"/>
        <xsl:text> </xsl:text>
        <xsl:for-each select="ancestor::div[parent::body]">
          <xsl:number/>
        </xsl:for-each>
        <xsl:text>.</xsl:text>
        <xsl:number count="figure[head]" from="div[parent::body]" level="any"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>



  <xsl:function name="tei:escapeChars" as="xs:string">
    <xsl:param name="letters"/>
    <xsl:param name="context"/>
    <xsl:value-of select="normalize-unicode($letters,'NFC')"/>
  </xsl:function>


  <xsl:template name="myi18n">
    <xsl:param name="word"/>
    <xsl:choose>
      <xsl:when test="$word eq 'defaultValValidUntil'">
        <xsl:text>The value will no longer be a default after</xsl:text>
      </xsl:when>
      <xsl:when test="$word='validuntil'">
        <xsl:text>This feature will be withdrawn after</xsl:text>
      </xsl:when>
      <xsl:when test="$word='previousWord'">
        <span class="icon">
          <xsl:text>« </xsl:text>
        </span>
      </xsl:when>
      <xsl:when test="$word='upWord'">
        <span class="icon">
          <xsl:text>↑ </xsl:text>
        </span>
      </xsl:when>
      <xsl:when test="$word='nextWord'">
        <span class="icon">
          <xsl:text>» </xsl:text>
        </span>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
  
  <xsl:function name="tei:checkLang" as="xs:string">
    <xsl:param name="lang"/>
      <xsl:sequence select="if
                            ($lang=('de','en','es','fr','it','ko','zh-TW'))
                            then $lang else 'en'"/>
  </xsl:function>

  <xsl:template match="*" mode="copyhtml">
    <xsl:copy>
      <xsl:apply-templates select="@*|*|processing-instruction()|comment()|text()" mode="copyhtml"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="comment()|@*|processing-instruction()|text()" mode="copyhtml">
    <xsl:copy-of select="."/>
  </xsl:template>

  <xsl:template match="a/@href"  mode="copyhtml">
    <xsl:attribute name="href">
      <xsl:if test="starts-with(.,'/')">
        <xsl:text>https://www.tei-c.org</xsl:text>
      </xsl:if>
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>

</xsl:stylesheet>
