<?xml version="1.0" encoding="UTF-8"?>
<!--

<h1>TEI » HTML (<a href="http://subversion.cru.fr/diple/trunk/transform/tei_html.xsl">tei_html.xsl</a>)</h1>

© 2010–2011, <a href="http://www.enc.sorbonne.fr/">École nationale des chartes</a>, licence  <a href="http://www.cecill.info/licences/Licence_CeCILL-C_V1-fr.html">CeCILL-C</a>/<a href="http://www.gnu.org/licenses/lgpl.html">LGPL</a>
<ul>
  <li>[VJ] <a onmouseover="this.href='mailto'+'\x3A'+'vincent.jolivet'+'\x40'+'diple.net'">Vincent Jolivet</a></li>
  <li>[FG] <a onmouseover="this.href='mailto'+'\x3A'+'frederic.glorieux'+'\x40'+'diple.net'">Frédéric Glorieux</a></li>
</ul>

<p>
Cette transformation XSLT 1.0 (compatible navigateurs, PHP, Python, Java…) 
transforme du TEI en HTML5.
Les auteurs ne s'engagent pas à supporter les 600 éléments TEI.
Cette feuille prend en charge <a href="http://www.tei-c.org/Guidelines/Customization/Lite/">TEI lite</a>
et les éléments TEI documentés dans les <a href="./../schema/">schémas</a> de cette installation.
</p>
<p>
Alternative : les transformations de Sebastian Rahtz <a href="http://www.tei-c.org/Tools/Stylesheets/">tei-c.org/Tools/Stylesheets/</a>
sont officiellement ditribuées par le consortium TEI, cependant ce développement est en XSLT 2.0 (java requis).
</p>
-->
<xsl:transform 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:tei="http://www.tei-c.org/ns/1.0" 
  xmlns:html="http://www.w3.org/1999/xhtml"
  version="1.1" 
  exclude-result-prefixes="tei html"
>
  <!-- Des modèles valables pour tous schémas -->
  <xsl:import href="diple.xsl"/>
  <!-- Sortie texte brut, notamment pour des titres de table des matières -->
  <xsl:import href="tei_txt.xsl"/>
<!--
La méthode de sortie est xml, pour faire du xhtml.
epub requiert du xhtml strict,
  
L'utilisation des attributs 
    doctype-public="-//W3C//DTD XHTML 1.1//EN"
    doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
est contraignante, difficile à surcharger par les transformations qui veulent une
absence de déclaration de DTD.
-->
  <xsl:output 
    encoding="UTF-8" 
    indent="yes" 
    method="xml"
  />
  <!--
  <xsl:strip-space elements="*"/>
  -->
  <!-- Un titre. -->
  <xsl:param name="corpusTitle">
    <xsl:choose>
      <xsl:when test="/*/tei:text/tei:group/tei:head">
        <xsl:value-of select="/*/tei:text/tei:group/tei:head"/>
      </xsl:when>
      <xsl:when test="/*/tei:text/tei:body/tei:head">
        <xsl:value-of select="/*/tei:text/tei:body/tei:head"/>
      </xsl:when>
      <!-- prendre le dernier titre du header, ?? règle bizarre [FG 2010-07] -->
      <xsl:when test="/*/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title">
        <xsl:value-of select="/*/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title[not(following-sibling::tei:title)]"/>
      </xsl:when>
    </xsl:choose>
  </xsl:param>
  <!-- Fichier de messages pour étiquettes générées. -->
  <xsl:param name="messages">tei.rdfs</xsl:param>
  <!-- Majuscules, pour conversions. -->
  <xsl:variable name="caps">ABCDEFGHIJKLMNOPQRSTUVWXYZÆŒÇÀÁÂÃÄÅÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝ.</xsl:variable>
  <!-- Minuscules, pour conversions -->
  <xsl:variable name="mins">abcdefghijklmnopqrstuvwxyzæœçàáâãäåèéêëìíîïòóôõöùúûüý</xsl:variable>
  <!-- Pour normaliser des clés. -->
  <xsl:variable name="iso">ABCDEFGHIJKLMNOPQRSTUVWXYZÀÂÄÉÈÊÏÎÔÖÛÜÇàâäéèêëïîöôüû</xsl:variable>
  <xsl:variable name="min">abcdefghijklmnopqrstuvwxyzaaaeeeiioouucaaaeeeeiioouu</xsl:variable>
  <!-- Éléments uniques dans un fichier, identifiés par leur nom, liste séparée d'espaces. -->
  <xsl:variable name="els-unique"> TEI teiHeader revisionDesc samplingDecl projectDesc editorialDecl sourceDesc </xsl:variable>
  <!-- Langue des messages (pour l'instant seul fr est implémenté) -->
  <xsl:param name="lang">fr</xsl:param>
  <!-- notes d'apparat critique ? -->
  <xsl:param name="app" select="boolean(//tei:app)"/>
  <!-- à surcharger -->
  <xsl:key name="split" match="/" use="'root'"/>
  <!-- 
<h2>Métadonnées</h2>
  -->
  <!-- 
<h3>teiHeader</h3>
  -->
  <!-- Bloc de métadonnées -->
  <xsl:template match="tei:teiHeader">
    <xsl:if test="normalize-space(.) != ''">
      <header>
        <xsl:call-template name="atts"/>
        <!-- Ne pas procéder  revisionDesc ici -->
        <xsl:apply-templates select="tei:fileDesc | tei:encodingDesc | tei:profileDesc"/>
      </header>
    </xsl:if>
  </xsl:template>
  <!-- Réordonner le bloc de description du fichier -->
  <xsl:template match="tei:fileDesc">
    <section>
      <xsl:call-template name="atts"/>
      <!-- Envoyer la page de titre -->
      <xsl:apply-templates select="tei:titleStmt"/>
      <!-- Envoyer les informations éditoriales -->
      <xsl:apply-templates select="tei:publicationStmt"/>
      <!-- Retenir le reste qui pourra être repris dans les blocs plus haut -->
    </section>
  </xsl:template>
  <!-- Bloc de publication, réordonné -->
  <xsl:template match="tei:publicationStmt">
    <section>
      <xsl:call-template name="atts"/>
      <!-- 1) ligne bibliographique -->
      <p>
        <xsl:apply-templates select=".." mode="bibl"/>
      </p>
      <!-- 3) source -->
      <xsl:apply-templates select="../tei:sourceDesc"/>
      <!-- 2) taille -->
      <xsl:apply-templates select="../tei:extent"/>
      <!-- 4) éditeur -->
      <xsl:apply-templates select="tei:publisher"/>
      <xsl:apply-templates select="tei:address"/>
      <!-- 5) licence -->
      <xsl:apply-templates select="tei:availability"/>
    </section>
  </xsl:template>
  <!-- Section avec titre prédéfini -->
  <xsl:template match="tei:encodingDesc"/>
  <xsl:template match=" tei:projectDesc | tei:samplingDecl | tei:editorialDecl | tei:availability ">
    <section>
      <xsl:call-template name="atts"/>
      <xsl:variable name="label">
        <xsl:call-template name="label"/>
      </xsl:variable>
      <xsl:if test="string($label) != '' and string($label) != local-name()">
        <legend class="{local-name()}">
          <xsl:value-of select="$label"/>
        </legend>
      </xsl:if>
      <xsl:apply-templates/>
    </section>
  </xsl:template>
  <!-- éléments teiHeader retenus -->
  <xsl:template match="tei:charDecl | tei:langUsage | tei:catRef"/>
  <!-- Ligne avec intitulé -->
  <xsl:template match="tei:sourceDesc">
    <p>
      <xsl:call-template name="atts"/>
      <xsl:variable name="label">
        <xsl:call-template name="label"/>
      </xsl:variable>
      <xsl:if test="string($label) != ''">
        <legend>
          <xsl:value-of select="$label"/>
        </legend>
        <xsl:text> : </xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
    </p>
  </xsl:template>
  <!-- Éléments avec intitulé -->
  <xsl:template match="tei:fileDesc/tei:titleStmt/tei:funder | tei:fileDesc/tei:titleStmt/tei:edition | tei:fileDesc/tei:titleStmt/tei:extent">
    <div>
      <xsl:call-template name="atts"/>
      <xsl:variable name="label">
        <xsl:call-template name="label"/>
      </xsl:variable>
      <xsl:if test="string($label) != ''">
        <legend><xsl:value-of select="$label"/></legend>
        <xsl:text> : </xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  <!-- directeur de la publication et contributeurs -->
  <xsl:template match="tei:fileDesc/tei:titleStmt/tei:principal[position() != 1]"/>
  <xsl:template match="tei:fileDesc/tei:titleStmt/tei:principal[1]">
    <div>
      <xsl:call-template name="atts"/>
      <xsl:variable name="label">
        <xsl:call-template name="label"/>
      </xsl:variable>
      <xsl:if test="string($label) != ''">
        <legend><xsl:value-of select="$label"/></legend>
        <xsl:text> : </xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
      <xsl:for-each select="following-sibling::tei:principal">
        <xsl:choose>
          <xsl:when test="following-sibling::tei:principal">, </xsl:when>
          <xsl:otherwise>
            <xsl:text> </xsl:text>
            <xsl:call-template name="label">
              <xsl:with-param name="id">and</xsl:with-param>
            </xsl:call-template>
            <xsl:text> </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:apply-templates/>        
      </xsl:for-each>
    </div>
  </xsl:template>
  <!-- -->
  <xsl:template match="tei:fileDesc/tei:titleStmt/tei:editor"/>
  <xsl:template match="tei:fileDesc/tei:titleStmt/tei:editor[1]">
    <div>
      <xsl:choose>
        <xsl:when test="../tei:principal">
          <xsl:call-template name="label">
            <xsl:with-param name="id">with</xsl:with-param>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="label">
            <xsl:with-param name="id">editor</xsl:with-param>
          </xsl:call-template>
          <xsl:text> :</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:for-each select="../tei:editor">
        <xsl:choose>
          <xsl:when test="position() = 1">
            <xsl:text> </xsl:text>
          </xsl:when>         
          <xsl:when test="position() = last()">
            <xsl:text> </xsl:text>
            <xsl:call-template name="label">
              <xsl:with-param name="id">and</xsl:with-param>
            </xsl:call-template>
            <xsl:text> </xsl:text>
          </xsl:when>
          <xsl:otherwise>, </xsl:otherwise>
        </xsl:choose>
        <xsl:apply-templates/>
      </xsl:for-each>
    </div>
  </xsl:template>
  <!-- Réordonner la page de titre du fichier -->
  <xsl:template match="tei:fileDesc/tei:titleStmt">
    <header>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates select="tei:title | tei:author | tei:editor | tei:funder | tei:meeting | tei:principal | tei:sponsor"/>
      <!-- Ramener une description du projet ? -->
      <xsl:apply-templates select="../../tei:encodingDesc/tei:projectDesc"/>
      <!-- Ramener une description de l'édition -->
      <xsl:apply-templates select="../tei:editionStmt"/>
      <!-- procéder les autres éléments -->
      <xsl:apply-templates select="tei:respStmt"/>
      <!-- Histoire des modifications (si pas public, mettre display none en CSS) -->
      <xsl:apply-templates select="/*/tei:teiHeader/tei:revisionDesc"/>
    </header>
  </xsl:template>
<xsl:template match="tei:docAuthor">
    <xsl:if test=". != ''">
      <span>
        <xsl:call-template name="atts"/>
        <xsl:apply-templates/>
      </span>
    </xsl:if>
  </xsl:template>

  <!-- Champs blocs  -->
  <xsl:template match=" 
  tei:addrLine | tei:docTitle | tei:docImprint | tei:docEdition
| tei:editionStmt | tei:keywords | tei:profileDesc | tei:textClass
">
    <xsl:if test=". != ''">
      <div>
        <xsl:call-template name="atts"/>
        <xsl:apply-templates/>
      </div>
    </xsl:if>
  </xsl:template>
  <xsl:template match="tei:teiHeader" mode="title">
    <xsl:apply-templates select="tei:fileDesc/tei:titleStmt" mode="txt"/>
  </xsl:template>
  <xsl:template match="tei:fileDesc/tei:titleStmt" mode="txt">
    <xsl:choose>
      <xsl:when test="tei:author">
        <xsl:apply-templates select="tei:author" mode="txt"/>
        <xsl:text> ; </xsl:text>
      </xsl:when>
    </xsl:choose>
    <xsl:apply-templates select="tei:title" mode="txt"/>
  </xsl:template>
  <!-- Titres obtenus depuis diple.rdfs -->
  <xsl:template match="tei:publicationStmt | tei:titleStmt" mode="title">
    <xsl:call-template name="label"/>
  </xsl:template>

  
  <!--
 <h2>Blocs</h2>
  -->
<!--
<h3>Sections</h3>
  -->
  <!-- Sections avec notes, procéder le contenu de la section, puis les notes.
La logique est surchargées pour le split (notes au bas de chaque page internet).
Une version précédente de la logique cherchait à automatiser la distribution des 
notes par section. Ne pas réessayer, inutilement compliqué, et ne s'adapte pas 
à tous les cas possibles de division des pages. Ici, notes pour introduction générale, 
annexes, corps, et textes 
  -->
  <xsl:template match="tei:text">
    <xsl:param name="notes" select="parent::tei:group"/>
    <article>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
      <!-- Actes, procéder les notes par textes -->
      <xsl:if test="$notes">
        <xsl:call-template name="notes"/>
      </xsl:if>
    </article>
  </xsl:template>
  <xsl:template match="tei:front">
    <xsl:param name="notes" select="not(ancestor::tei:group)"/>
    <header>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
      <xsl:if test="$notes">
        <xsl:call-template name="notes"/>
      </xsl:if>
    </header>
  </xsl:template>
  <xsl:template match="tei:back">
    <xsl:param name="notes" select="not(ancestor::tei:group)"/>
    <footer>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
      <xsl:if test="$notes">
        <xsl:call-template name="notes"/>
      </xsl:if>
    </footer>
  </xsl:template>
  <xsl:template match="tei:body">
    <xsl:param name="notes" select="not(ancestor::tei:group)"/>
    <div>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
      <xsl:if test="$notes">
        <xsl:call-template name="notes"/>
      </xsl:if>
    </div>
  </xsl:template>
  <!--
    TODO ? notes dans les groupes ?
  <xsl:template match="tei:text/tei:group">
    <section>
      <xsl:call-template name="atts"/>
      <xsl:comment>
        <xsl:call-template name="path"/>
      </xsl:comment>
      <xsl:apply-templates/>
      <xsl:call-template name="notes">
        <xsl:with-param name="texte" select=".//*[not()]"/>
      </xsl:call-template>
    </section>
  </xsl:template>
  -->
  <!-- Sections -->
  <xsl:template match="tei:group | tei:div | tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 | tei:prologue | tei:epilogue">
    <section>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </section>
  </xsl:template>
  <xsl:template match="tei:floatingText">
    <aside>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </aside>
  </xsl:template>
  <!-- Divisions qui ne sont pas des sections -->
  <xsl:template match="tei:argument ">
    <xsl:if test=". != ''">
      <div>
        <xsl:call-template name="atts"/>
        <xsl:apply-templates/>
      </div>
    </xsl:if>
  </xsl:template>
  <!-- Cartouche d'entête d'acte -->
  <xsl:template match="tei:group/tei:text/tei:front ">
    <header>
      <xsl:call-template name="atts"/>
      <!--
          <xsl:choose>
            <xsl:when test="../@n">
              <xsl:value-of select="../@n"/>
            </xsl:when>
            <xsl:when test="tei:titlePart[starts-with(@type, 'num')]">
              <xsl:value-of select="tei:titlePart[starts-with(@type, 'num')]"/>
            </xsl:when>
          </xsl:choose>
        -->
        <xsl:apply-templates/>
        <!-- VJ : inscire la mention "D'après témoin" -->
        <xsl:apply-templates select=".//tei:witness[@ana='edited']" mode="according"/>
    </header>
  </xsl:template>
  <!-- Traverser la racine sans laisser de trace (~html:body) -->
  <xsl:template match="/*">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Éléments coupés de la sortie, ou à implémenter -->
  <xsl:template match="tei:divGen "/>
  <!--
<h3>Titres</h3>

  -->
  <!-- Titre en entête -->
  <xsl:template match="tei:titleStmt/tei:title">
    <h1>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </h1>
  </xsl:template>
  <!-- Page de titre -->
  <xsl:template match="tei:titlePage">
    <header>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </header>
  </xsl:template>
  <!-- <h[1-6]> titres avec niveaux hiérarchiques génériques selon le nombre d'ancêtres -->
  <xsl:template match="tei:head">
    
    <xsl:variable name="niv" select="count(ancestor::tei:*)"/>
    <xsl:variable name="name">
      <xsl:choose>
        <xsl:when test="normalize-space(.) = ''"/>
        <xsl:when test="parent::tei:front | parent::tei:text | parent::tei:back ">h1</xsl:when>
        <xsl:when test="$niv &lt; 3">h1</xsl:when>
        <xsl:when test="$niv &gt; 7">h6</xsl:when>
        <xsl:otherwise>h<xsl:value-of select="$niv -2"/></xsl:otherwise>
      </xsl:choose>      
    </xsl:variable>
    <xsl:if test="$name != ''">
      <xsl:element name="{$name}">
        <xsl:call-template name="atts"/>
        <xsl:apply-templates/>
        <!-- Ce lien pour  pour connaître l'id de partie pose pb à l'autotoc 
        <a class="bookmark" style="display:none">
          <xsl:attribute name="href">
            <xsl:call-template name="href"/>
          </xsl:attribute>
          <xsl:text>¶</xsl:text>
        </a>
        -->
      </xsl:element>
    </xsl:if>
  </xsl:template>
  <!-- Autres titres -->
  <xsl:template match="tei:titlePart">
    <h1>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </h1>
  </xsl:template>

  <!--
<h3>Paragraphes</h3>
  -->
  <!-- Blocs paragraphes (ne contenant pas de paragraphes) -->
  <xsl:template match="tei:byline | tei:caption | tei:dateline | tei:desc | tei:imprimatur | tei:p | tei:signed | tei:salute | tei:trailer">
    <p>
      <xsl:call-template name="atts"/>
      <xsl:if test="@n">
        <small class="n">
          <xsl:text>[</xsl:text>
          <xsl:value-of select="@n"/>
          <xsl:text>]</xsl:text>
        </small>
        <xsl:text> </xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
    </p>
  </xsl:template>
  <!-- Bloc cité -->
  <xsl:template match="tei:cit | tei:quote | tei:epigraph">
    <blockquote>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </blockquote>
  </xsl:template>
  <xsl:template match="tei:cit/tei:quote" priority="5">
    <q>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </q>
  </xsl:template>
  <xsl:template match="tei:address">
    <address>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </address>
  </xsl:template>
  <!-- Bloc de texte préformaté -->
  <xsl:template match="tei:eg">
    <pre>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </pre>
  </xsl:template>
  <!-- Ne pas sortir les saut de ligne dans du texte préformaté -->
  <xsl:template match="tei:eg/tei:lb"/>

  <!--
<h3>Listes</h3>



-->
  <!-- Différentes listes, avec prise en charge xhtml correcte des titres (inclus dans un blockquote)  -->
  <xsl:template match="tei:list | tei:listWit | tei:listBibl | tei:recordHist">
    <xsl:variable name="el">
      <xsl:choose>
        <xsl:when test="contains(' ordered ol Décimale ', concat(' ', @type, ' ')) ">ol</xsl:when>
        <xsl:otherwise>ul</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:choose>
      <!-- liste titrée à mettre dans un conteneur-->
      <xsl:when test="tei:head">
        <div class="{local-name()}">
          <xsl:apply-templates select="tei:head"/>
          <xsl:element name="{$el}">
            <xsl:call-template name="atts"/>
            <xsl:apply-templates select="*[local-name() != 'head']"/>
          </xsl:element>
        </div>
      </xsl:when>
      <xsl:otherwise>
        <xsl:element name="{$el}">
          <xsl:call-template name="atts"/>
          <xsl:apply-templates/>
        </xsl:element>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- Pseudo-listes  -->
  <xsl:template match="tei:respStmt">
    <xsl:variable name="name" select="name()"/>
    <!-- Plus de 2 item du même nom, voir s'il y a un titre dans le fichier de messages -->
    <xsl:if test="../*[name() = $name][2] and count(../*[name() = $name][1]|.) = 1">
      <xsl:variable name="label">
        <xsl:call-template name="label"/>
      </xsl:variable>
      <xsl:if test="string($label) != ''">
        <legend class="{local-name()}"><xsl:value-of select="$label"/></legend>
      </xsl:if>
    </xsl:if>
    <div>
      <xsl:call-template name="atts"/>
      <xsl:if test="*/@from|*/@to">
        <xsl:text>(</xsl:text>
        <xsl:value-of select="*/@from"/>
        <xsl:text> — </xsl:text>
        <xsl:value-of select="*/@to"/>
        <xsl:text>) </xsl:text>
      </xsl:if>
      <xsl:for-each select="*">
        <xsl:apply-templates select="."/>
        <xsl:choose>
          <xsl:when test="position() = last()">
            <xsl:call-template name="dot"/>
          </xsl:when>
          <xsl:when test="position()=1 and following-sibling::*"> : </xsl:when>
          <xsl:otherwise> ; </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </div>
  </xsl:template>
  <xsl:template match="tei:resp">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Liste de type index -->
  <xsl:template match="tei:list[@type='index']">
    <div>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates select="tei:head"/>
      <!-- s'il n'y a pas de division spéciale, barre de lettres -->
      <xsl:choose>
        <xsl:when test="not(tei:list)">
          <div class="alpha">
            <xsl:call-template name="alpha_href"/>
          </div>
        </xsl:when>
      </xsl:choose>
      <ul class="index">
        <xsl:apply-templates select="*[local-name() != 'head']"/>
      </ul>
    </div>
  </xsl:template>
  <!-- Barre de lettres, supposée appelée dans le contexte d'un index à plat -->
  <xsl:template name="alpha_href">
    <!-- Préfixe de l'identifiant -->
    <xsl:param name="prefix" select="concat(@xml:id, '.')"/>
    <xsl:param name="alpha">abcdefghijklmnopqrstuvwxyz</xsl:param>
    <xsl:choose>
      <!-- ne pas oublier de stopper à temps -->
      <xsl:when test="$alpha =''"/>
      <xsl:otherwise>
        <xsl:variable name="lettre" select="substring($alpha, 1, 1)"/>
        <!-- tester si la lettre existe avant de l'écrire -->
        <xsl:if test="*[translate(substring(., 1, 1), $iso, $min) = $lettre]">
          <xsl:if test="$lettre != 'a'"> </xsl:if><!-- pas d'espace insécable -->
          <a href="#{$prefix}{$lettre}" target="_self">
            <xsl:value-of select="translate ( $lettre, $min, $iso)"/>
          </a>
        </xsl:if>
        <xsl:call-template name="alpha_href">
          <xsl:with-param name="alpha" select="substring($alpha, 2)"/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- Titre d'une liste -->
  <xsl:template match="tei:list/tei:head">
    <legend class="list">
      <xsl:apply-templates/>
    </legend>
  </xsl:template>
  <!-- <item>, item de liste -->
  <xsl:template match="tei:item">
    <li>
      <xsl:call-template name="atts"/>
      <!-- Si index, rajouter une ancre -->
      <xsl:if test="../@type='index' and not(../tei:list)">
        <xsl:variable name="lettre" select="translate(substring(., 1, 1), $iso, $min)"/>
        <xsl:if test="translate(substring(preceding-sibling::tei:item, 1, 1), $iso, $min) != $lettre">
          <a name="{../@xml:id}.{$lettre}">
            <xsl:comment></xsl:comment>
          </a>
        </xsl:if>
      </xsl:if>
      <xsl:apply-templates/>
    </li>
  </xsl:template>
  <!-- Listes de termes -->
  <xsl:template match="tei:list[@type='gloss' or tei:label]">
    <xsl:choose>
      <!-- liste titrée à mettre dans un conteneur-->
      <xsl:when test="tei:head">
        <div class="{local-name()}">
          <xsl:apply-templates select="tei:head"/>
          <dl class="dl">
            <xsl:call-template name="atts"/>
            <xsl:apply-templates select="*[local-name() != 'head']"/>
          </dl>
        </div>
      </xsl:when>
      <xsl:otherwise>
        <dl>
          <xsl:call-template name="atts">
            <xsl:with-param name="class">dl</xsl:with-param>
          </xsl:call-template>
          <xsl:apply-templates/>
        </dl>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>
  <xsl:template match="tei:list[@type='gloss' or tei:label]/tei:label">
    <dt>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </dt>
  </xsl:template>
  <xsl:template match="tei:list[@type='gloss' or tei:label]/tei:item">
    <dd>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </dd>
  </xsl:template>
  <!-- Le calendrier des modifications et passer dans dans une page credits -->
  <xsl:template match="tei:revisionDesc">
    <table>
      <xsl:call-template name="atts">
        <xsl:with-param name="class">data</xsl:with-param>  
      </xsl:call-template>
      <caption>
        <xsl:call-template name="label"/>
      </caption>
      <xsl:apply-templates/>
    </table>
  </xsl:template> 
  <!-- Liste spéciale, journal des modifications  -->
  <xsl:template match="tei:change">
    <tr>
      <xsl:call-template name="atts"/>
      <td>
        <xsl:value-of select="@when"/>
      </td>
      <td>
        <xsl:call-template name="anchors">
          <xsl:with-param name="att">who</xsl:with-param>
        </xsl:call-template>
      </td>
      <td>
        <xsl:apply-templates/>
      </td>
    </tr>
  </xsl:template>
  <!--
Tables
 - - -
  -->
  <!-- table  -->
  <xsl:template match="tei:table">
    <table>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </table>
  </xsl:template>
  <xsl:template match="tei:table/tei:head">
    <caption>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </caption>
  </xsl:template>
  <!-- ligne -->
  <xsl:template match="tei:row">
    <xsl:if test="@role='label'">
      <tr>
        <td colspan="{count(*)}">&#160;</td>
      </tr>
    </xsl:if>
    <tr>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </tr>
  </xsl:template>
  <!-- Cellule  -->
  <xsl:template match="tei:cell">
    <xsl:variable name="el">
      <xsl:choose>
        <xsl:when test="@role='label'">th</xsl:when>
        <xsl:when test="../@role='label'">th</xsl:when>
        <xsl:otherwise>td</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:element name="{$el}">
      <xsl:call-template name="atts"/>
      <xsl:if test="@rows &gt; 1">
        <xsl:attribute name="rowspan">
          <xsl:value-of select="@rows"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:if test="@cols &gt; 1">
        <xsl:attribute name="colspan">
          <xsl:value-of select="@cols"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

  <!-- vers, strophe -->
  <xsl:template match="tei:lg[tei:lg]">
    <div>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  <xsl:template match="tei:lg">
    <div>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  <!-- ligne (ex : vers) -->
  <xsl:template match="tei:l">
    <div>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </div>
  </xsl:template>
  <!-- ligne vide, probablement utilisée pour espacement -->
  <xsl:template match="tei:l[not(text())]">
    <br/>
  </xsl:template>

  <!--
<h2>Caractères</h2>

<p>Balises de niveau mot, à l'intérieur d'un paragraphe.</p>

<h3>HTML</h3>

  -->
  <!-- <hi>, mise en forme typo générique -->
  <xsl:template match="tei:hi">
    <xsl:choose>
      <xsl:when test="normalize-space(.) =''"/>
      <!-- si @rend est un nom d'élément HTML -->
      <xsl:when test="contains( ' i b s u em strong tt big small strike sub sup ', concat(' ', @rend, ' '))">
        <xsl:element name="{@rend}">
          <xsl:if test="@type">
            <xsl:attribute name="class">
              <xsl:value-of select="@type"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:apply-templates/>
        </xsl:element>
      </xsl:when>
      <xsl:when test="starts-with(@rend, 'it')">
        <i>
          <xsl:apply-templates/>
        </i>
      </xsl:when>
      <!-- surlignages venus de la transformation ODT -->
      <xsl:when test="@rend='bg'">
        <span class="bg" style="background-color:#{@n};">
          <xsl:apply-templates/>
        </span>
      </xsl:when>
      <xsl:when test="@rend='col'">
        <span class="col" style="color:#{@n};">
          <xsl:apply-templates/>
        </span>
      </xsl:when>
      <!-- sinon appeler le span général -->
      <xsl:otherwise>
        <xsl:call-template name="span"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- HTML5, “identifiant” -->
  <xsl:template match="tei:ident">
    <b>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </b>
  </xsl:template>
  <!-- Venu du traitement de texte -->
  <xsl:template match="tei:head/tei:ident">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Venu du plus profond du traitement de texte -->
  <xsl:template match="tei:head/tei:hi[@rend='u'] | tei:head/tei:title[@rend='u']">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- <gloss>, définition -->
  <xsl:template match="tei:gloss">
    <dfn>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </dfn>
  </xsl:template>
  <!-- Texte cité en cours de ligne, les guillemets ne sont pas ajoutés ici (ex de pb <lg>) -->
  <xsl:template match="tei:q | tei:p//tei:quote | tei:said">
    <q>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </q>
  </xsl:template>
  <!-- <code>, code en police à chasse fixe -->
  <xsl:template match="tei:code">
    <code>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </code>
  </xsl:template>
  <!-- <eg>, exemple en ligne -->
  <xsl:template match="tei:p/tei:eg">
    <samp>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </samp>
  </xsl:template>
  <!-- <num>, nombres, utile pour les chiffres romains -->
  <xsl:template match="tei:num">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  <!-- <label> -->
  <xsl:template match="tei:label">
    <label>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </label>
  </xsl:template>
  <!-- Saut de ligne -->
  <xsl:template match="tei:lb">
    <br/>
    <xsl:if test="@n">
      <small class="lb">
        <xsl:value-of select="@n"/>
      </small>
      <xsl:text> </xsl:text>
    </xsl:if>
  </xsl:template>
  <!-- Césure, traverser sans trace -->
  <xsl:template match="tei:caes">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Saut de colonne, affiché -->
  <xsl:template match="tei:cb">
    <xsl:if test="@n and @n != ''">
      <i class="cb"> (<xsl:value-of select="@n"/>) </i>
    </xsl:if>
  </xsl:template>
  <!-- Saut de page, si saut de colonne, surcharger -->
  <xsl:template match="tei:pb">
    <xsl:choose>
      <xsl:when test="@ana">
        <span class="pb">[<xsl:value-of select="@ana"/>]</span>
      </xsl:when>
      <!-- ex: 16v -->
      <xsl:when test="@n != ''  and translate(substring(@n,1,1), '0123456789.', '') = ''">
        <span class="pb">[fol. <xsl:value-of select="@n"/>] </span>
      </xsl:when>
      <xsl:when test="@n != ''">
        <span class="pb">[<xsl:value-of select="@n"/>]</span>
      </xsl:when>
      <xsl:otherwise/>      
    </xsl:choose>
  </xsl:template>
    <!-- bloc hors flux -->
  <xsl:template match="tei:fw">
    <xsl:if test=". != ''">
      <small>
        <xsl:call-template name="atts"/>
        <xsl:apply-templates/>
      </small>
    </xsl:if>
  </xsl:template>
  <!-- Italique fonctionnelle -->
  <xsl:template match="tei:distinct | tei:emph | tei:mentioned | tei:sic | tei:soCalled ">
    <em>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </em>
  </xsl:template>
  <!-- <span class="..."/>, segment générique sans mise en forme particulière -->
  <xsl:template match="tei:phr " name="span">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  <!-- Traverser sans trace html -->
  <xsl:template match="tei:s | tei:seg | tei:imprint |  tei:pubPlace | tei:glyph ">
    <!-- dates, mieux employer les attributs ? -->
    <xsl:apply-templates/>
  </xsl:template>
  <!-- dates -->
  <xsl:template match="tei:date | tei:docDate | tei:origDate">
    <time>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </time>
  </xsl:template>
  <!-- caractère particulier, par exemple lettrine -->
  <xsl:template match="tei:c">
    <b>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </b>
  </xsl:template>
  <!-- 
<h3>Liens</h3>
  -->
  <!-- Liens par défaut, généralement à surcharger selon les corpus, en fonction de la façon découper les fichiers -->
  <xsl:template match="tei:ref">
    <a>
      <xsl:call-template name="atts"/>
      <xsl:choose>
        <xsl:when test=". != ''">
          <xsl:apply-templates/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="anchors">
            <xsl:with-param name="anchors" select="@target"/>
          </xsl:call-template>
        </xsl:otherwise>
      </xsl:choose>
    </a>
  </xsl:template>
  <!-- email -->
  <xsl:template match="tei:email">
    <xsl:variable name="string">
      <xsl:value-of select="substring-before(., '@')"/>
      <xsl:text>'+'\x40'+'</xsl:text>
      <xsl:value-of select="substring-after(., '@')"/>
    </xsl:variable>
    <a>
      <xsl:call-template name="atts"/>
      <xsl:attribute name="onmouseover">if(this.ok) return; this.innerHTML='<xsl:value-of select="$string"/>'; this.href='mailto:<xsl:value-of select="$string"/>'; this.ok=true; </xsl:attribute>
      <xsl:call-template name="label"/>
    </a>
  </xsl:template>
  <!-- Pointeur sans label -->
  <xsl:template match="tei:ptr">
    <a>
      <xsl:call-template name="atts"/>
      <xsl:value-of select="@target"/>
    </a>
  </xsl:template>
  <!-- Quelque chose à faire ? 

<figure>
  <graphic url="../../../../elec/conferences/src/knoch-mund/olgiati.png"/>
  <head>© Mirta Olgiati</head>
</figure>
  
<figure class="right">
  <a href="ferri/grande/Ill_2_Grillando.jpg"><img src="ferri/petite/Ill_2_Grillando.jpg" height="155" width="250"></a>
  <figcaption style="width: 250px;">
    <a href="ferri/grande/Ill_2_Grillando.jpg"><img src="theme/img/agrandir.png" title="agrandir"></a>
    [ill. 1] Paolo Grillando, Tractat[um] de hereticis et sortilegijs…, Lyon, 1536 [page de titre]. Cornell Library, Division of Rare Books and Manuscripts, Witchcraft BF1565 G85 1536.
    </figcaption>
</figure>
      
  -->
  <xsl:template match="tei:figure">
    <figure>
      <xsl:apply-templates/>  
    </figure>
  </xsl:template>
  <xsl:template match="tei:figure/tei:head">
    <figcaption>
      <xsl:apply-templates/>  
    </figcaption>
  </xsl:template>
  <!-- Images, TODO @alt -->
  <xsl:template match="tei:graphic">
    <img src="{@url}" alt="{normalize-space(.)}">
      <xsl:if test="@rend">
        <xsl:attribute name="align">
          <xsl:copy-of select="@rend"/>
        </xsl:attribute>
      </xsl:if>
    </img>
  </xsl:template>
  <!-- <w>, mot, avec possible définition -->
  <xsl:template match="tei:w">
    <xsl:variable name="def" select="key('id', substring(@lemmaRef, 2))"/>
    <xsl:choose>
      <!--  Particulier à MontFerrand, à sortir ? -->
      <xsl:when test="$def">
        <a>
          <xsl:call-template name="atts"/>
          <xsl:attribute name="title">
            <xsl:for-each select="$def/ancestor-or-self::tei:entry[1]//tei:def">
              <xsl:value-of select="normalize-space(.)"/>
              <xsl:choose>
                <xsl:when test="position() != last()"> ; </xsl:when>
                <xsl:otherwise>.</xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>
          </xsl:attribute>
          <xsl:apply-templates/>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates/>
      </xsl:otherwise>
    </xsl:choose>    
  </xsl:template>

  <!--
<h3>Bibliographie</h3>

  -->
  <xsl:template match="tei:bibl | tei:biblFull | tei:biblStruct | tei:msDesc | tei:msPart | tei:witness">
    <xsl:variable name="el">
      <xsl:choose>
        <!-- Référence bibliograhique affichée comme bloc -->
        <xsl:when test="parent::tei:div or parent::tei:div0 or parent::tei:div1 or parent::tei:div2 or parent::tei:div3 or parent::tei:div4 or parent::tei:div5 or parent::tei:div6 or parent::tei:div7 or parent::tei:accMat">div</xsl:when>
        <xsl:when test="parent::tei:listWit or parent::tei:listBibl">li</xsl:when>
        <xsl:otherwise>span</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:element name="{$el}">
      <xsl:call-template name="atts"/>
      <xsl:if test="@n">
        <small class="n">
          <xsl:value-of select="@n"/>
        </small>
        <xsl:text> </xsl:text>
      </xsl:if>
      <xsl:if test="@xml:id">
        <i>
          <xsl:call-template name="witid"/>
        </i>
        <xsl:text> </xsl:text>
      </xsl:if>
      <xsl:choose>
        <xsl:when test="self::tei:biblStruct">
          <xsl:for-each select="*">
            <xsl:apply-templates select="."/>
            <xsl:choose>
              <xsl:when test="position()=last()">.</xsl:when>
              <xsl:otherwise>. </xsl:otherwise>
            </xsl:choose>            
          </xsl:for-each>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:element>
  </xsl:template>
  <!-- Traverser sans trace -->
  <xsl:template match="tei:monogr | tei:analytic">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Manuscript ou imprimé, notamment appelé comme témoin -->
  <xsl:template match="tei:msDesc | tei:bibl" mode="a">
    <a class="{local-name()}">
      <xsl:attribute name="href">
        <xsl:call-template name="href"/>
      </xsl:attribute>
      <xsl:variable name="title">
        <xsl:apply-templates/>
      </xsl:variable>
      <xsl:attribute name="title">
        <xsl:value-of select="normalize-space($title)"/>
      </xsl:attribute>
      <xsl:choose>
        <xsl:when test="@xml:id">
          <xsl:call-template name="witid"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="label"/>
        </xsl:otherwise>
      </xsl:choose>      
    </a>
  </xsl:template>
  <!-- Présentation d'identifiants de témoins -->
  <xsl:template name="witid">
    <xsl:param name="s" select="@xml:id"/>
    <xsl:choose>
      <xsl:when test="normalize-space($s)=''"/>
      <xsl:when test="contains($s, '_') or contains($s, '.')">
        <xsl:value-of select="."/>
      </xsl:when>
      <!-- Si patron normalisé d'identifiant pour édition -->
      <xsl:when test="starts-with($s, 'ed') and translate(substring($s,3), '0123456789 ', '')=''">
        <xsl:text>éd. </xsl:text>
        <xsl:value-of select="normalize-space(substring($s,3))"/>
      </xsl:when>
      <xsl:when test="translate(substring($s, 1, 1), 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', '') =''">
        <xsl:value-of select="substring($s, 1, 1)"/>
        <xsl:call-template name="witid">
          <xsl:with-param name="s" select="substring($s, 2)"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <sup>
          <xsl:value-of select="$s"/>
        </sup>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="tei:title">
    <cite>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </cite>
  </xsl:template>
  <xsl:template match="tei:p//tei:cit">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:for-each select="*">
        <xsl:if test="position() != 1">
          <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:apply-templates select="."/>
      </xsl:for-each>
    </span>
  </xsl:template>
  <!-- titre avec une URI pas loin -->
  <xsl:template match="tei:title[../tei:idno[@type='URI']]">
    <a href="{../tei:idno[@type='URI']}">
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </a>
  </xsl:template>
  <!-- na pas sortir l'URI -->
  <xsl:template match="tei:idno[@type='URI'][../tei:title]" priority="5"/>
  <!-- numéro de volume -->
  <xsl:template match="tei:idno[@type]">
    <xsl:call-template name="label">
      <xsl:with-param name="id" select="@type"/>
    </xsl:call-template>
    <xsl:value-of select="."/>
  </xsl:template>
  <!-- identifiant bibliographique -->
  <xsl:template match="tei:idno | tei:altIdentifier">
      <xsl:choose>
        <xsl:when test="starts-with('http', .)">
          <a>
            <xsl:call-template name="atts"/>
            <xsl:attribute name="href">
              <xsl:value-of select="."/>
            </xsl:attribute>
            <xsl:apply-templates/>
          </a>
        </xsl:when>
        <xsl:otherwise>
          <span>
            <xsl:call-template name="atts"/>
            <xsl:apply-templates/>
          </span>
        </xsl:otherwise>
      </xsl:choose>
   </xsl:template>
  <xsl:template match="tei:author | tei:biblScope | tei:collation | tei:collection | tei:dim | tei:editor | tei:edition | tei:extent | tei:funder | tei:publisher | tei:biblFull/tei:titleStmt/tei:title | tei:stamp">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  <!-- div -->
  <xsl:template match="tei:accMat | tei:additional | tei:additions | tei:adminInfo | tei:binding | tei:bindingDesc | tei:condition | tei:history | tei:objectDesc | tei:origin | tei:provenance | tei:physDesc | tei:source | tei:support | tei:supportDesc | tei:surrogates | tei:biblFull/tei:titleStmt">
    <xsl:if test=". != ''">
      <div>
        <xsl:call-template name="atts"/>
        <xsl:apply-templates/>
      </div>
    </xsl:if>
  </xsl:template>
  <xsl:template match="tei:handDesc">
    <ul>
      <xsl:for-each select="*">
        <li>
          <xsl:call-template name="atts"/>
          <xsl:if test="@xml:id">
            <small class="id">[<xsl:value-of select="@xml:id"/>]</small>
            <xsl:text> </xsl:text>
          </xsl:if>
          <xsl:apply-templates/>
        </li>
      </xsl:for-each>
    </ul>
  </xsl:template>
  <xsl:template match="tei:dimensions">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:variable name="label">
        <xsl:call-template name="label">
          <xsl:with-param name="id">
            <xsl:value-of select="@type"/>
          </xsl:with-param>
        </xsl:call-template>
      </xsl:variable>
      <xsl:if test="$label != ''">
        <xsl:value-of select="translate(substring($label, 1, 1), $mins, $caps)"/>
        <xsl:value-of select="substring($label, 2)"/>
        <xsl:text> : </xsl:text>
      </xsl:if>
      <xsl:for-each select="*">
        <xsl:apply-templates select="."/>
        <xsl:choose>
          <xsl:when test="position() =last()"/>
          <xsl:otherwise> x </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
      <xsl:if test="@unit">
        <xsl:text> </xsl:text>
        <xsl:value-of select="@unit"/>
      </xsl:if>
      <xsl:text>.</xsl:text>
    </span>
  </xsl:template>
  <xsl:template match="tei:layout">
    <div>
      <xsl:call-template name="atts"/>
      <xsl:choose>
        <xsl:when test="@columns and number(@columns) &gt; 1">
          &lt;TODO&gt;
        </xsl:when>
        <xsl:when test="@ruledLines">
          <xsl:value-of select="@ruledLines"/>
          <xsl:text> </xsl:text>
          <xsl:call-template name="label">
            <xsl:with-param name="id">ruledLines</xsl:with-param>
          </xsl:call-template>
          <xsl:text>, </xsl:text>
          <xsl:value-of select="@writtenLines"/>
          <xsl:call-template name="label">
            <xsl:with-param name="id">writtenLines</xsl:with-param>
          </xsl:call-template>
          <xsl:text>, </xsl:text>
        </xsl:when>
        <xsl:when test="@writtenLines">
          <xsl:value-of select="@writtenLines"/>
          <xsl:text> </xsl:text>
          <xsl:call-template name="label">
            <xsl:with-param name="id">lines</xsl:with-param>
          </xsl:call-template>
          <xsl:text>, </xsl:text>
        </xsl:when>
      </xsl:choose>
      <xsl:variable name="text">
        <xsl:apply-templates/>
      </xsl:variable>
      <xsl:copy-of select="$text"/>
      <xsl:if test="translate(substring(normalize-space($text), string-length(normalize-space($text))), '.?!', '') != ''">.</xsl:if>
    </div>
  </xsl:template>
  <!-- Traverser -->
  <xsl:template match="tei:height | tei:width | tei:layoutDesc ">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- span -->
  <xsl:template match="tei:institution | tei:locus | tei:repository | tei:settlement ">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  <xsl:template match="tei:msIdentifier">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:for-each select="*">
        <xsl:apply-templates select="."/>
        <xsl:choose>
          <xsl:when test="position() = last()">. </xsl:when>
          <xsl:otherwise>
            <xsl:text>, </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </span>
  </xsl:template>
  <!-- Indication du témoin édité (mention "D'après...") -->
  <xsl:template match="tei:witness[@ana='edited']" mode="according">
    <div class="according">
      <xsl:text>D'après </xsl:text>
      <xsl:value-of select="@n"/>
      <xsl:text>.</xsl:text>
    </div>
  </xsl:template>
    <!-- Affichage de n° de témoin -->
  <xsl:template match="tei:witness" mode="a">
    <a class="wit">
      <xsl:attribute name="href">
        <xsl:call-template name="href"/>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:value-of select="normalize-space(.)"/>
      </xsl:attribute>
      <xsl:apply-templates select="." mode="label"/>
    </a>
  </xsl:template>
  <!-- Lien vers un groupe de témoins -->
  <xsl:template match="tei:listWit" mode="a">
    <a class="wit">
      <xsl:attribute name="href">
        <xsl:call-template name="href"/>
      </xsl:attribute>
      <xsl:for-each select="tei:witness">
        <xsl:apply-templates select="." mode="label"/>
        <xsl:choose>
          <xsl:when test="position() = last()">.</xsl:when>
          <xsl:otherwise>, </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </a>
  </xsl:template>
  <!-- Dans un tableau de la tradition, un témoin peut être identifié avec  -->
  <xsl:template match="tei:witness" mode="label">
    <xsl:choose>
      <xsl:when test="tei:label">
        <xsl:apply-templates select="tei:label/node()"/>
      </xsl:when>
      <xsl:when test="@n">
        <xsl:value-of select="@n"/>
      </xsl:when>
      <xsl:when test="@xml:id">
        <xsl:value-of select="@xml:id"/>
      </xsl:when>
    </xsl:choose>
  </xsl:template>
  <!--
<h3>Indexables</h3>
  -->
  <xsl:template match="tei:term">
    <dfn>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </dfn>
  </xsl:template>
  <!-- Par défaut, le contenu de <index> est supposé affichable -->
  <xsl:template match="tei:index">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Termes avec possible forme normale en @rend -->
  <xsl:template match="tei:addName | tei:affiliation | tei:country | tei:foreign | tei:forename | tei:geogName | tei:name | tei:origPlace | tei:orgName | tei:persName | tei:placeName | tei:repository | tei:roleName | tei:rs | tei:settlement | tei:surname">
    <xsl:choose>
      <!-- Un identifiant, lien vers l'entrée d'index -->
      <xsl:when test="@ref and substring(@ref,1,1)='#'">
        <a>
          <xsl:for-each select="key('id', substring(@ref, 2))[1]">
            <xsl:attribute name="href">
              <xsl:call-template name="href"/>
            </xsl:attribute>
            <xsl:attribute name="title">
              <xsl:apply-templates select="." mode="txt"/>
            </xsl:attribute>
          </xsl:for-each>
          <xsl:choose>
            <xsl:when test="self::tei:persName">
              <xsl:attribute name="property">dbo:person</xsl:attribute>
            </xsl:when>
            <xsl:when test="self::tei:placeName">
              <xsl:attribute name="property">dbo:place</xsl:attribute>
            </xsl:when>
          </xsl:choose>
          <xsl:call-template name="atts"/>
          <xsl:apply-templates/>
        </a>
      </xsl:when>
      <xsl:otherwise>
        <span>
          <xsl:choose>
            <xsl:when test="self::tei:persName">
              <xsl:attribute name="property">dbo:person</xsl:attribute>
            </xsl:when>
            <xsl:when test="self::tei:placeName">
              <xsl:attribute name="property">dbo:place</xsl:attribute>
            </xsl:when>
          </xsl:choose>
          <xsl:call-template name="atts"/>
          <xsl:apply-templates/>
        </span>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  
<!--
<h2>Notes</h2>


<h3>Notes de bas de page</h3>

-->
  <!--
Pour afficher des notes en fin de section.

Ce template est plus long que le texte lui-même.
  -->
  <xsl:template name="notes">
    <!-- Les enfants dont on peut explorer les notes -->
    <xsl:param name="text" select="*"/>
    <xsl:variable name="notes">
      <xsl:if test="$app">
        <xsl:variable name="apparatus">
          <xsl:for-each select="$text // tei:app">
            <xsl:variable name="html">
              <xsl:call-template name="fn"/>
            </xsl:variable>
            <xsl:if test="$html != ''">
              <xsl:call-template name="note_retour"/>
              <xsl:copy-of select="$html"/>
              <!-- regarder si la ligne est déjà ponctuée avant d'ajouter un point -->
              <xsl:choose>
                <!-- Déja ponctué -->
                <xsl:when test="translate(substring($html, string-length($html)), ',;.', '') = ''">
                  <xsl:text> </xsl:text>
                </xsl:when>
                <xsl:otherwise>. </xsl:otherwise>
              </xsl:choose>
            </xsl:if>
          </xsl:for-each>
        </xsl:variable>
        <xsl:if test="$apparatus != ''">
          <p class="apparatus">
            <xsl:copy-of select="$apparatus"/>
          </p>
        </xsl:if>
      </xsl:if>
       <!-- notes avec numérotation dans le texte, trier par type -->
      <xsl:for-each select="$text //tei:*[@rend='note']">
        <xsl:sort select="local-name()"/>
        <xsl:call-template name="fn"/>
      </xsl:for-each>
      <!-- notes numérotées par attribut @n, trier, attention à lettres et chiffres -->
      <xsl:for-each select="$text //tei:note[@n]">
        <xsl:sort select="@n" data-type="number"/>
        <xsl:call-template name="fn"/>
      </xsl:for-each>
      <!-- notes à numéroter automatiquement -->
      <xsl:for-each select="$text // tei:note[not(@n)]">
        <xsl:call-template name="fn"/>
      </xsl:for-each>
      <!-- Référence bibliographique de citation numérotée, enfant direct, dans un paragraphe, mais pas dans un div -->
      <xsl:for-each select="$text //tei:cit[@n]">
        <xsl:sort select="@n" data-type="number"/>
        <xsl:call-template name="fn"/>
      </xsl:for-each>
    </xsl:variable>
    <xsl:if test="$notes != ''">
      <div class="notes">
        <hr width="15%" align="left"/>
        <xsl:copy-of select="$notes"/>
      </div>
    </xsl:if>
  </xsl:template>
  <!-- section de notes déjà inscrite dans la source -->
  <xsl:template match="tei:div[@type='notes']">
      <div class="notes">
        <hr width="15%" align="left"/>
        <xsl:apply-templates/>
      </div>
  </xsl:template>
  <!-- Note, ancre courante (sauf si enfant direct d'un div) -->
  <xsl:template match="tei:note | tei:*[@rend='note']">
    <xsl:call-template name="note_appel"/>
  </xsl:template>
  <!-- Note, appel sous forme de lien -->
  <xsl:template match="tei:ref[@type='note']">
    <xsl:call-template name="note_appel"/>
  </xsl:template>
  <!-- Note, appel et lien vers le texte -->
  <xsl:template name="note_appel">
    <xsl:variable name="n">
      <xsl:call-template name="n"/>
    </xsl:variable>
    <xsl:variable name="id">
      <xsl:call-template name="id">
      </xsl:call-template>
	<xsl:text>_</xsl:text>
    </xsl:variable>
    <!-- TODO, multi cibles -->
    <xsl:variable name="target">
      <xsl:choose>
        <xsl:when test="@target">
          <xsl:value-of select="substring-before(concat(@target, ' '), ' ')"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>#</xsl:text>
          <xsl:call-template name="id"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <a class="refnote" href="{$target}" id="{$id}">
      <xsl:if test="self::tei:note">
        <xsl:variable name="title">
          <xsl:apply-templates select="." mode="fn"/>
        </xsl:variable>
        <xsl:attribute name="title">
          <xsl:value-of select="normalize-space($title)"/>
        </xsl:attribute>
      </xsl:if>
      <xsl:value-of select="$n"/>
    </a>
  </xsl:template>
  <!-- Note, texte, fonctionne pour note courante ou déportée -->
  <xsl:template name="note_texte">
    <xsl:text>
    </xsl:text>
    <div class="note">
        <!-- identifiant de la note -->
      <xsl:attribute name="id">
        <xsl:call-template name="id"/>
      </xsl:attribute>
      <xsl:choose>
        <!-- si la note est une suite de paragraphes, intégrer l'appel de note dans le premier paragraphe -->
        <xsl:when test="* and not(*[local-name() != 'p'])"><!-- not(text()[. != '']) and  -->
          <xsl:for-each select="*">
            <p>
              <xsl:choose>
                <xsl:when test="position() = 1">
                  <xsl:for-each select="..">
                    <xsl:call-template name="note_retour"/>
                  </xsl:for-each>
                  <xsl:text> </xsl:text>
                </xsl:when>
              </xsl:choose>
              <xsl:apply-templates/>
            </p>
          </xsl:for-each>
          <xsl:if test="@ana">
            <xsl:text> </xsl:text>
            <i>
              <xsl:value-of select="@ana"/>
            </i>
            <xsl:text>.</xsl:text>
          </xsl:if>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="note_retour"/>
          <xsl:text> </xsl:text>
          <xsl:apply-templates/>
          <xsl:if test="@ana">
            <xsl:text> </xsl:text>
            <i>
              <xsl:value-of select="@ana"/>
            </i>
            <xsl:text>.</xsl:text>
          </xsl:if>
        </xsl:otherwise>
      </xsl:choose>
    </div>
  </xsl:template>
  <!-- Note, retour à l'ancre, TODO retour à une note multiplement appelée -->
  <xsl:template name="note_retour">
    <a class="note">
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="@target">
            <xsl:value-of select="substring-before(concat(@target, ' '), ' ')"/>
          </xsl:when>
          <xsl:otherwise>
            <!-- identifiant de l'ancre -->
            <xsl:text>#</xsl:text>
            <xsl:call-template name="id">
              <xsl:with-param name="suffix">_</xsl:with-param>
            </xsl:call-template>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="id">
        <xsl:call-template name="id"/>
      </xsl:attribute>
      <xsl:call-template name="n"/>
    </a>
  </xsl:template>
  <!-- Le template principal affichant des notes hors flux -->
  <xsl:template match="node()" mode="fn" name="fn">
    <xsl:choose>
      <!-- ne pas sortir en bas de page les notes blocs -->
      <xsl:when test="parent::tei:div or parent::tei:front or parent::tei:app"/>
      <xsl:when test="self::tei:note">
        <xsl:call-template name="note_texte"/>
      </xsl:when>
      <xsl:when test="self::tei:app[@rend='table']"/>
      <!-- Variante, en note de bas de page -->
      <xsl:when test="self::tei:app">
        <span>
          <xsl:call-template name="atts"/>
          <xsl:text> </xsl:text>
          <xsl:apply-templates select="tei:rdg | tei:note | tei:witDetail"/>
        </span>
      </xsl:when>
        <!-- Note normalisée pour ajout -->
      <xsl:when test="self::tei:supplied">
        <!-- Pas besoin de rappel pour note en contexte 
        <xsl:choose>
          <xsl:when test="local-name(..)='w'">
            <xsl:apply-templates select=".." mode="title"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:apply-templates mode="title"/>
          </xsl:otherwise>
        </xsl:choose>
        -->
        <xsl:if test="@source">
          <xsl:text> </xsl:text>
          <i>
            <xsl:call-template name="anchors">
              <xsl:with-param name="anchors" select="@source"/>
            </xsl:call-template>
          </i>
        </xsl:if>
        <xsl:if test="@reason">
          <xsl:text> </xsl:text>
          <i>
            <xsl:call-template name="label">
              <xsl:with-param name="id" select="@reason"/>
            </xsl:call-template>
          </i>
        </xsl:if>
        <xsl:choose>
          <xsl:when test="local-name(..)='w'">
            <xsl:text> [ </xsl:text>
            <xsl:apply-templates/>
          </xsl:when>
        </xsl:choose>
      </xsl:when>
      <!-- Note normalisée pour correction -->
      <xsl:when test="self::tei:choice">
        <!-- pas de rappel de la forme corrigée 
        <xsl:apply-templates select="tei:corr/node() | tei:expan/node() | tei:reg/node()"/>
        <xsl:text> </xsl:text>
        -->
        <xsl:choose>
          <xsl:when test="tei:corr/@source">
            <i>
              <xsl:call-template name="anchors">
                <xsl:with-param name="anchors" select="tei:corr/@source"/>
              </xsl:call-template>
            </i>
            <xsl:text> [ </xsl:text>
          </xsl:when>
          <xsl:otherwise> [ </xsl:otherwise>
        </xsl:choose>
        <xsl:apply-templates select="tei:sic/node() | tei:abbr/node() | tei:orig/node()"/>
      </xsl:when>
      <!-- chroniques latines, citations numérotées -->
      <xsl:when test="self::tei:cit[@n]">
        <xsl:text>
        </xsl:text>
        <div>
          <xsl:call-template name="atts"/>
          <xsl:call-template name="note_retour"/>
          <xsl:text> </xsl:text>
          <xsl:apply-templates select="tei:bibl"/>
        </div>
      </xsl:when>
      <!-- entité nommée avec référence note -->
      <xsl:when test="@ref and substring(@ref,1,1)='#'">
        <xsl:variable name="note" select="key('id', substring(@ref, 2))"/>
        <xsl:if test="$note">
          <xsl:apply-templates select="$note" mode="txt"/>
        </xsl:if>
      </xsl:when>
    </xsl:choose>    
  </xsl:template>
  <!-- Citations numérotées, la référence apparaît en note de bas de page, une animation permet de la mettre en valeur -->
  <xsl:template match="tei:p//tei:cit[@n]">
    <span>
      <xsl:call-template name="atts">
        <xsl:with-param name="class">cit_n</xsl:with-param>  
      </xsl:call-template>
      <xsl:for-each select="*">
        <xsl:choose>
          <xsl:when test="self::tei:bibl"/>
          <xsl:otherwise>
            <xsl:text> </xsl:text>
            <xsl:apply-templates select="."/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
      <xsl:variable name="id">
        <xsl:call-template name="id"/>
      </xsl:variable>
      <a class="refnote" href="#{$id}" id="_{$id}">
        <!-- xsl:attribute name="onclick">if(this.cloc) {this.parentNode.className='cit_n'; this.cloc=null; } else { this.cloc=true;  this.parentNode.className='cit_n_bibl'}; return true;</xsl:attribute -->
        <xsl:attribute name="onmouseover">this.parentNode.className='cit_n_bibl'</xsl:attribute>
        <xsl:attribute name="onmouseout">this.parentNode.className='cit_n'</xsl:attribute>
        <xsl:value-of select="@n"/>
      </a>
      <span class="listBibl">
        <xsl:apply-templates select="tei:bibl"/>
      </span>
    </span>
  </xsl:template>
  <!-- Note sans appel -->
  <xsl:template match="tei:div/tei:note | tei:front/tei:note">
    <xsl:choose>
      <xsl:when test="not(tei:p|tei:div)">
        <p>
          <xsl:call-template name="atts"/>
          <xsl:apply-templates/>
        </p>
      </xsl:when>
      <xsl:otherwise>
        <div>
          <xsl:call-template name="atts"/>
          <xsl:apply-templates/>
        </div>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- Note, texte, pour les notes déportée -->
  <xsl:template match="tei:div[@type='notes']/tei:note" priority="5">
    <xsl:call-template name="note_texte"/>
  </xsl:template>
  <!--
<h3>Apparat critique</h3>
  -->
  <!-- Variante normale, traitement dynamique -->
  <xsl:template match="tei:app">
    <xsl:variable name="el">
      <xsl:choose>
        <xsl:when test="tei:p">div</xsl:when>
        <xsl:otherwise>span</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:element name="{$el}">
      <xsl:attribute name="id">
        <xsl:call-template name="id">
          <xsl:with-param name="suffix">_</xsl:with-param>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:attribute name="class">app</xsl:attribute>
      <xsl:attribute name="onmouseover">this.className='apprdg'</xsl:attribute>
      <xsl:attribute name="onmouseout">if(!this.cloc) this.className='app'</xsl:attribute>
      <xsl:attribute name="onclick">if(this.cloc) {this.className='app'; this.cloc=null; } else { this.cloc=true;  this.className='apprdg'}; return true;</xsl:attribute>
      <!-- ajouts et omissions -->
      <xsl:apply-templates select="tei:lem"/>
      <xsl:call-template name="note_appel"/>
      <span class="rdgList">
        <xsl:text> </xsl:text>
        <xsl:apply-templates select="tei:rdg | tei:witDetail | tei:note"/>
        <xsl:text> </xsl:text>
      </span>
    </xsl:element>
  </xsl:template>
  <!-- version de base de la variante -->
  <xsl:template match="tei:lem">
    <xsl:variable name="prev" select="normalize-space(../preceding-sibling::node()[1])"/>
    <!-- généralement, un espace avant, sauf si apostrophe -->
    <xsl:if test="translate (substring($prev, string-length($prev)), concat($apos, '’'), '') != ''">
      <xsl:text> </xsl:text>
    </xsl:if>
    <span>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </span>
  </xsl:template>
  <!-- Autre leçon -->
  <xsl:template match="tei:rdg | tei:witDetail">
    <xsl:choose>
      <!-- même leçon que le précédent -->
      <xsl:when test=" . = preceding-sibling::tei:rdg">, </xsl:when>
      <xsl:when test="preceding-sibling::tei:rdg"> ; </xsl:when>
    </xsl:choose>
    <span>
      <xsl:call-template name="atts"/>
      <!-- si même leçon que la précédente, pas la pein de la copier -->
      <xsl:choose>
        <xsl:when test=". = preceding-sibling::tei:rdg"/>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:call-template name="anchors"/>
      <xsl:choose>
        <!-- Mot clé, chercher un intitulé -->
        <xsl:when test="@cause and normalize-space(@cause) != ''">
          <xsl:text> </xsl:text>
          <i>
            <xsl:call-template name="label">
              <xsl:with-param name="id" select="@cause"/>
            </xsl:call-template>
          </i>
        </xsl:when>
        <!-- texte libre -->
        <xsl:when test="@hand|@place and normalize-space(@hand|@place) != ''">
          <xsl:text> </xsl:text>
          <i>
            <xsl:value-of select="@hand|@place"/>
          </i>
        </xsl:when>
        <!-- suivant identique, lui laisser l'intitulé automatique -->
        <xsl:when test=" . = following-sibling::tei:rdg"/>
        <!-- Rien en principal, c'est une addition -->
        <xsl:when test="../lem = ''">
          <xsl:text> </xsl:text>
          <i>
            <xsl:call-template name="label">
              <xsl:with-param name="id">add</xsl:with-param>
            </xsl:call-template>
           </i>
        </xsl:when>
        <!-- Rien à ajouter, c'est une omission -->
        <xsl:when test=". = ''">
          <xsl:text> </xsl:text>
          <i>
            <xsl:call-template name="label">
              <xsl:with-param name="id">omit</xsl:with-param>
            </xsl:call-template>
          </i>
        </xsl:when>
      </xsl:choose>
    </span>
  </xsl:template>
  <!-- abbréviation, avec possible forme normale -->
  <xsl:template match="tei:abbr">
    <abbr>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </abbr>
  </xsl:template>
  <!-- expansion signalée en cours de texte -->
  <xsl:template match="tei:expan">
    <xsl:text>[</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>]</xsl:text>
  </xsl:template>
  <!-- développement silencieux d’abréviation -->
  <xsl:template match="tei:ex">
    <ins>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </ins>
  </xsl:template>
  <!-- Texte ajouté -->
  <xsl:template match="tei:choice/tei:supplied">
    <ins>
      <xsl:choose>
        <xsl:when test="@source">
          <xsl:call-template name="atts">
            <xsl:with-param name="class">tipshow</xsl:with-param>
          </xsl:call-template>
          <small class="tip">
            <xsl:call-template name="fn"/>
          </small>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="atts"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:text>[</xsl:text>
      <xsl:apply-templates/>
      <xsl:text>]</xsl:text>
    </ins>
  </xsl:template>
  <xsl:template match="tei:supplied">
    <xsl:text>[</xsl:text>
    <xsl:apply-templates/>
    <xsl:text>]</xsl:text>
  </xsl:template>
  <!-- @source pour attribut title -->
  <xsl:template match="@source" mode="title">
    <xsl:text> : </xsl:text>
    <xsl:call-template name="anchors">
      <xsl:with-param name="anchors" select="."/>
    </xsl:call-template>
  </xsl:template>
  <!-- @reason pour attribut title -->
  <xsl:template match="@reason" mode="title">
    <xsl:text>, </xsl:text>
    <xsl:value-of select="."/>
  </xsl:template>
  <!-- Insertions -->
  <xsl:template match="tei:add">
    <ins>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </ins>
  </xsl:template>
  <!-- Suppressions -->
  <xsl:template match="tei:del">
    <del>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
      <xsl:if test="@ana">
        <xsl:text> [</xsl:text>
        <xsl:call-template name="label">
          <xsl:with-param name="id" select="@ana"/>
        </xsl:call-template>
        <xsl:text>]</xsl:text>
      </xsl:if>
    </del>
  </xsl:template>
  <!-- Alternative, conserver les espacements (faut-il un conteneur ?) -->
  <xsl:template match="tei:choice">
    <span>
      <xsl:choose>
        <xsl:when test="*/@source">
          <xsl:call-template name="atts">
            <xsl:with-param name="class">tipshow</xsl:with-param>
          </xsl:call-template>
          <small class="tip">
            <xsl:call-template name="fn"/>
          </small>
        </xsl:when>
        <xsl:otherwise>
          <xsl:call-template name="atts"/>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:apply-templates select="*"/>
    </span>
  </xsl:template>

  <!-- Correction -->
  <xsl:template match="tei:choice/tei:corr | tei:choice/tei:reg | tei:choice[tei:abbr]/tei:expan">
    <ins>
      <xsl:call-template name="atts"/>
      <xsl:if test="preceding-sibling::*">
        <xsl:text> </xsl:text>
      </xsl:if>
      <xsl:apply-templates/>
    </ins>
  </xsl:template>
  <xsl:template match="tei:choice/tei:sic | tei:choice/tei:abbr | tei:choice/tei:orig">
    <del>
      <xsl:call-template name="atts"/>
      <!-- Espace avant un mot ? attention si l'alternative est au milieu d'un mot -->
      <xsl:apply-templates/>
    </del>
  </xsl:template>
  
  <!-- (?) -->
  <xsl:template match="tei:interp">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </span>
  </xsl:template>

  <xsl:template match="tei:unclear">
    <xsl:apply-templates/>
    <xsl:text> [?] </xsl:text>
  </xsl:template>

  <xsl:template match="tei:gap">
    <span class="gap">
      <xsl:attribute name="title">
        <xsl:call-template name="label">
          <xsl:with-param name="id">gap</xsl:with-param>
        </xsl:call-template>
        <xsl:if test="@extent">
          <xsl:text> : </xsl:text>
          <xsl:value-of select="@extent"/>
          <xsl:text> </xsl:text>
          <xsl:call-template name="label">
            <xsl:with-param name="id">chars</xsl:with-param>
          </xsl:call-template>
        </xsl:if>
      </xsl:attribute>
      <xsl:text>[</xsl:text>
      <xsl:choose>
        <xsl:when test="@extent and not(text())">
          <xsl:value-of select="substring('........................................................................................................', 1, @extent)"/>
        </xsl:when>
        <xsl:when test="@reason">
          <xsl:call-template name="label">
            <xsl:with-param name="id" select="@reason"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:when test=". != ''">
          <xsl:apply-templates/>
        </xsl:when>
        <xsl:otherwise>…</xsl:otherwise>
      </xsl:choose>
      <xsl:text>]</xsl:text>
    </span>
  </xsl:template>
  <!-- Commentaire libre dans une note d'apparat critique. -->
  <xsl:template match="tei:app/tei:note">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Dommage -->
  <xsl:template match="tei:damage">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:text>[</xsl:text>
      <xsl:apply-templates/>
      <xsl:text>]</xsl:text>
    </span>
  </xsl:template>
  <!-- Supposant que cela contient des espaces insécables -->
  <xsl:template match="tei:space">
    <xsl:apply-templates/>
  </xsl:template>
  <!-- Conteneur de variantes importantes -->
  <xsl:template match="tei:app[@rend='table']">
    <table>
      <xsl:call-template name="atts"/>
      <!-- afficher l'intitulé de witness -->
      <xsl:for-each select="*[. != '']">
        <xsl:variable name="pos">
          <xsl:number/>
        </xsl:variable>
        <th width="{floor(100 div count(../tei:rdg|../tei:lem))} %">
          <xsl:call-template name="anchors">
            <xsl:with-param name="att">wit</xsl:with-param>
          </xsl:call-template>
        </th>
      </xsl:for-each>
      <tr>
        <xsl:for-each select="*[. != '']">
          <td valign="top">
            <xsl:choose>
              <xsl:when test="position()=1">
                <xsl:call-template name="atts">
                  <xsl:with-param name="class">first</xsl:with-param>
                </xsl:call-template>
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="atts">
                  <xsl:with-param name="class">more</xsl:with-param>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
            <xsl:apply-templates/>
          </td>
        </xsl:for-each>
      </tr>
    </table>
  </xsl:template>
  <!-- Boucler sur une liste d'ancre en attribut afin d'en afficher quelque chose -->
  <xsl:template name="anchors">
    <!-- nom de l'attribut sur lequel boucler (permet aussi d'adapter le comportement) -->
    <xsl:param name="att">wit</xsl:param>
    <!-- valeur initiale d'attribut à reprendre -->
    <xsl:param name="anchors" select="normalize-space(@*[name()=$att])"/>
    <xsl:variable name="id" select="
      substring-before(
          concat($anchors, ' ') , ' '
      )"/>
    <!-- le n° de témoin -->
    <xsl:choose>
      <!-- plus rien à afficher -->
      <xsl:when test="normalize-space($anchors) = ''"/>
      <!-- code qui n'est pas une ancre (serait-ce un lien ?) -->
      <xsl:when test="not(starts-with($anchors, '#'))">
        <xsl:text> </xsl:text>
        <i class="{$att}">
          <xsl:value-of select="$id"/>
        </i>
      </xsl:when>
      <!-- l'ancre répond, faire afficher un lien -->
      <xsl:when test="key('id', substring-after($id, '#'))">
        <xsl:text> </xsl:text>
        <xsl:apply-templates select="key('id', substring-after($id, '#'))" mode="a"/>
      </xsl:when>
      <!-- ancre absente dans le document -->
      <xsl:otherwise>
        <xsl:text> </xsl:text>
        <i class="{$att}">
          <xsl:value-of select="substring-after($id, '#')"/>
        </i>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:variable name="suivant" select="substring-after($anchors, ' ')"/>
    <xsl:if test="$suivant != ''">
      <xsl:text> </xsl:text>
      <xsl:call-template name="anchors">
        <xsl:with-param name="anchors" select="$suivant"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>
  
  

  <!--
<h2>Modes</h2>

<p>
Un mode permet de parcourir l'arbre du document source afin d'en extraire
d'autres informations que le parcours par défaut. Dans le traitement de documents écrits,
les modes sont souvent utilisés pour extraire une table des matières, des index,
ou les notes qui courrent dans le texte. Nous utilisons aussi les modes pour des vues alternatives sur certains
noeuds, par exemple un identifiant, un titre court (label), ou un lien. Cette syntaxe permet
d'employer toute la souplesse de l'héritage et la surcharge en XSLT.
Il est apparu que certains processeurs XSLT (essentiellemen xsltproc) ont pu être peu performants
sur ces écritures, il en reste parfois des “modes” implémentés sous forme de templates nommés,
qui énumère des conditions sous forme d'une chaîne d'alternatives (choose/when+).
</p>
  -->
  <!--
<h3>Atributs</h3>

<p>
Un traitement centralisé des attributs TEI permet d'assurer la régularité de certains
attributs HTML, notamment les règles de construction d'identifants, ou de classe CSS.
</p>
  -->
  <!-- @*, template généralement appelé à l'ouverture de tout élément HTML
permettant de régler différents comportements par défaut.
PERF
  -->
  <xsl:template name="atts">
    <!-- permet d'ajouter une classe CSS spécifique à la suite des automatiques -->
    <xsl:param name="class"/>
    <!-- comportement par défaut d'attribution d'une classe CSS -->
    <xsl:call-template name="class">
      <xsl:with-param name="class" select="$class"/>
    </xsl:call-template>
    <!-- identification obligatoire pour certains éléments -->
    <xsl:choose>
      <xsl:when test="@id">
        <xsl:attribute name="id">
          <xsl:value-of select="@id"/>
        </xsl:attribute>
      </xsl:when>
      <xsl:when test="@xml:id">
        <xsl:attribute name="id">
          <xsl:value-of select="@xml:id"/>
        </xsl:attribute>
      </xsl:when>
      <xsl:when test="self::tei:div or self::tei:div0 or self::tei:div1 or self::tei:div2 or self::tei:div3 or self::tei:div4 or self::tei:div5 or self::tei:div6 or self::tei:div7 or self::tei:group or self::tei:text  or contains($els-unique, concat(' ', local-name(), ' '))">
        <xsl:attribute name="id">
          <xsl:call-template name="id"/>
        </xsl:attribute>
      </xsl:when>
      <xsl:when test="generate-id(..) = generate-id(/*/tei:text)">
        <xsl:attribute name="id">
          <xsl:call-template name="id"/>
        </xsl:attribute>
      </xsl:when>
    </xsl:choose>
    <!-- Procéder les autres attributs -->
    <xsl:apply-templates select="@*"/>
  </xsl:template>
  <!-- Attribut class interprété de différents attributs TEI -->
  <xsl:template name="class">
    <xsl:param name="class"/>
    <!-- si @rend est utilisé comme forme régulière, ne pas l'utiliser comme nom de classe -->
    <xsl:variable name="value">
      <!-- nom de l'élément lorsqu'il n'a pas d'équivalent direct en HTML -->
      <xsl:if test="not(contains( ' abbr add cell code del eg emph item list p q ref row table ' , concat(' ', local-name(), ' ')))">
        <xsl:value-of select="local-name()"/>
      </xsl:if>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@type"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@role"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@ana"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@place"/>
      <!-- la langue comme classe -->
      <xsl:text> </xsl:text>
      <xsl:value-of select="@xml:lang"/>
      <!-- valeur passée en paramètre -->
      <xsl:text> </xsl:text>
      <xsl:value-of select="$class"/>
      <xsl:text> </xsl:text>
      <xsl:value-of select="@rend"/>
    </xsl:variable>
    <xsl:variable name="norm" select="normalize-space($value)"/>
    <xsl:if test="$norm != ''">
      <xsl:attribute name="class">
        <xsl:value-of select="$norm"/>
      </xsl:attribute>
    </xsl:if>
  </xsl:template>
  <!-- @tei:*, par défaut, intercepter les attributs -->
  <xsl:template match="tei:*/@*" priority="-2"/>
  <!-- Attribut de liage  -->
  <xsl:template match="@ref | @target | @lemmaRef" name="ref">
    <xsl:param name="path" select="."/>
    <xsl:choose>
      <!-- Que faire avec witDetail/@target ? -->
      <xsl:when test="../@wit"/>
      <!-- cache mail -->
      <xsl:when test="contains($path, '@')">
        <xsl:attribute name="href">
        </xsl:attribute>
        <xsl:attribute name="onmouseover">
          <xsl:text>this.href='mailto:</xsl:text>
          <xsl:value-of select="substring-before($path, '@')"/>
          <xsl:text>'+'\x40'+'</xsl:text>
          <xsl:value-of select="substring-after($path, '@')"/>
          <xsl:text>'</xsl:text>
        </xsl:attribute>
      </xsl:when>
      <!-- lien interne à une ancre du fichier XML, déléguer au split -->
      <xsl:when test="starts-with($path, '#')">
        <xsl:variable name="target" select="key('id', substring($path, 2))"/>
        <!-- perf mode href ? -->
        <xsl:for-each select="$target[1]">
          <xsl:attribute name="href">
            <xsl:call-template name="href"/>
          </xsl:attribute>
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="href">
          <xsl:value-of select="$path"/>
        </xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- mode href par défaut, des identifiants -->
  <xsl:template match="node()" mode="href"/>
  <xsl:template match="tei:*" mode="href" name="href">
    <xsl:text>#</xsl:text>
    <xsl:choose>
      <xsl:when test="@xml:id">
        <xsl:value-of select="@xml:id"/>
      </xsl:when>
      <xsl:when test="@id">
        <xsl:value-of select="@id"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="id"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- @id, @lang, réécriture de certains attributs standard pour xhtml -->
  <xsl:template match="@xml:lang | @xml:id | @id">
    <xsl:attribute name="{local-name(.)}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <!-- @xml:*, attributs à recopier à l'identique -->
  <xsl:template match="@xml:base">
    <xsl:copy-of select="."/>
  </xsl:template>
  <!-- @html:*, copier les attributs xhtml -->
  <xsl:template match="@*[ namespace-uri(.) = 'http://www.w3.org/1999/xhtml']">
    <xsl:attribute name="{local-name(.)}">
      <xsl:value-of select="."/>
    </xsl:attribute>
  </xsl:template>
  <!-- <html:*> Recopier tout ce qui est html -->
  <xsl:template match="html:*">
    <xsl:element name="{local-name()}">
      <xsl:copy-of select="@*"/>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

<!--
<h3>mode="n" (numéro)</h3>

<p>
Beaucoup de composants d'un texte peuvent être identifiés par un numéro notamment
les différents types de notes (apparat critique, glose historique, philologique…), ou les sections hiérarchiques.
Un tel numéro peut etre très utile pour 
</p>

-->
  <!-- Numéro élément, priorité aux indications de l'auteur (en général) -->
  <xsl:template match="node()" mode="n" name="n">
    <xsl:variable name="id" select="translate((@xml:id | @id), 'abcdefghijklmnopqrstuvwxyz', '')"/>
    <!-- PERF -->
    <xsl:choose>
      <xsl:when test="@n">
        <xsl:value-of select="@n"/>
      </xsl:when>
      <!-- numérotation hiérarchique des sections -->
      <xsl:when test="self::tei:div">
        <xsl:number level="multiple" format="1.1"/>
      </xsl:when>
      <xsl:when test="self::tei:div0 or self::tei:div1 or self::tei:div2 or self::tei:div3 or self::tei:div4 or self::tei:div5 or self::tei:div6 or self::tei:div7">
        <xsl:number count="tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7" level="multiple" format="1.1"/>
      </xsl:when>
      <xsl:when test="number($id)">
        <xsl:value-of select="$id"/>
      </xsl:when>
      <!-- textes non identifiés (ou numérotés) -->
      <xsl:when test="self::tei:text and ancestor::tei:group">
        <xsl:number level="any" from="tei:text/tei:group"/>
      </xsl:when>
      <!-- Split, à tester -->
      <xsl:when test="ancestor::*[key('split', generate-id())]">
        <xsl:choose>
          <!-- PERF tei:note[not(@n) and not(ancestor::tei:app)] -->
          <xsl:when test="self::tei:note">
            <xsl:number count="tei:note[not(@n) and not(ancestor::tei:app)]" level="any" from="*[key('split', generate-id())]"/> 
          </xsl:when>
          <xsl:when test="self::tei:app">
            <xsl:number count="tei:app" format="a" level="any" from="*[key('split', generate-id())]"/> 
          </xsl:when>
          <xsl:otherwise>
            <xsl:number level="any" from="*[key('split', generate-id())]"/> 
          </xsl:otherwise>
        </xsl:choose>
      </xsl:when>
      <!-- Numérotation automatique des notes de commentaire dans un groupe de texte -->
      <xsl:when test="self::tei:note and ancestor::tei:group">
        <xsl:number count="tei:note[not(@n) and not(ancestor::tei:app)]" level="any" from="tei:text"/> 
      </xsl:when>
      <!-- Numérotation automatique des notes d'apparat dans un groupe de textes -->
      <xsl:when test="self::tei:app and ancestor::tei:group">
        <xsl:number count="tei:app" format="a" level="any" from="tei:text"/> 
      </xsl:when>
      <xsl:when test="self::tei:app">
        <xsl:number count="tei:app[not(@n)]" format="a" level="any" from="tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 | tei:div | tei:front | tei:back | tei:text"/>
      </xsl:when>
      <!-- VJ: ttes le notes sauf les notes libres d'apparat critique (app) -->
      <xsl:when test="self::tei:note">
        <xsl:number count="tei:note[not(@n) and local-name(parent::node()) != 'app']" level="any" from="tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 | tei:div | tei:front | tei:back | tei:text"/> 
      </xsl:when>
      <!-- Renvoi à une note -->
      <xsl:when test="self::tei:ref[@type='note']">
        <xsl:for-each select="key('id', substring-after(@target, '#'))[1]">
          <xsl:call-template name="n"/>
        </xsl:for-each>
      </xsl:when>
      <!-- Par défaut, un  élément est numéroté en ordre séquentiel dans le document, en distinguant cependant texte et paratexte-->
      <xsl:otherwise>
        <xsl:number level="any" from="/*/tei:text/tei:body | /*/tei:text/tei:front | /*/tei:text/tei:back"/>
      </xsl:otherwise>
    </xsl:choose>    
  </xsl:template>
<!--
<h3>mode="id" (identifiant)</h3>

<p>
Mode permettant d'associer un identifiant unique dans le contexte d'un document,
notamment pour établir cible et source de liens.
</p>
-->
  <!-- Identifiant, @xml:id automatique si pas d'attribut. Paramètres de préfixe et de suffixe servent parfois,
  par exemple pour distinguer l'identifiant d'une note, ou de son appel. 
  PERF
  -->
  <xsl:template match="*" mode="id" name="id">
    <xsl:param name="prefix"/>
    <xsl:param name="suffix"/>
    <xsl:value-of select="$prefix"/>
    <xsl:choose>
      <xsl:when test="@xml:id">
        <xsl:value-of select="@xml:id"/>
      </xsl:when>
      <xsl:when test="@id">
        <xsl:value-of select="@id"/>
      </xsl:when>
      <!-- hiérarchie simple de div  -->
      <xsl:when test="self::tei:div and not(ancestor::tei:group)">
        <xsl:if test="$bookId != ''">
          <xsl:value-of select="$bookId"/>
          <xsl:text>_</xsl:text>        
        </xsl:if>
        <xsl:if test="ancestor::tei:front">front-</xsl:if>
        <xsl:if test="ancestor::tei:back">back-</xsl:if>
        <xsl:number count="tei:div"  level="multiple" format="1-1"/>
      </xsl:when>
      <!-- Recherche d'un index -->
      <xsl:when test="/tei:TEI/tei:text/tei:front and count(.|/tei:TEI/tei:text/tei:front)=1">index</xsl:when>
      <xsl:when test="not(/tei:TEI/tei:text/tei:front) and count(.|/tei:TEI/tei:text/tei:group|/tei:TEI/tei:text/tei:body)=1">index</xsl:when>
      <!-- éléments hauts -->
      <xsl:when test="count(.. | /*) = 1">
        <xsl:if test="$bookId != ''">
          <xsl:value-of select="$bookId"/>
          <xsl:text>_</xsl:text>        
        </xsl:if>
        <xsl:value-of select="local-name()"/>
      </xsl:when>
      <!-- groupe de textes -->
      <xsl:when test="self::tei:group">
        <xsl:if test="$bookId != ''">
          <xsl:value-of select="$bookId"/>
          <xsl:text>_</xsl:text>        
        </xsl:if>
        <xsl:value-of select="local-name()"/>
        <xsl:number level="multiple" from="/*/tei:text/tei:group" format="-1-1"/>
      </xsl:when>
      <xsl:when test="true()">
        <xsl:if test="$bookId != ''">
          <xsl:value-of select="$bookId"/>
          <xsl:text>_</xsl:text>        
        </xsl:if>
        <xsl:value-of select="local-name()"/>
        <xsl:call-template name="n"/>
      </xsl:when>
      <!-- numérotation des notes, préfixées par la section -->
      <xsl:when test="self::tei:note or self::tei:app or self::tei:cit[@n]">
        <xsl:choose>
          <xsl:when test="ancestor::*[@xml:id]">
            <xsl:value-of select="ancestor::*[@xml:id][1]/@xml:id"/>
            <xsl:text>-</xsl:text>
          </xsl:when>
          <xsl:when test="ancestor::tei:text[parent::tei:group]">
            <xsl:for-each select="ancestor::tei:text[1]">
              <xsl:call-template name="n"/>
            </xsl:for-each>
            <xsl:text>-</xsl:text>
          </xsl:when>
          <xsl:when test="ancestor::*[key('split', generate-id())]">
            <xsl:for-each select="ancestor::*[key('split', generate-id())][1]">
              <xsl:call-template name="id"/>
            </xsl:for-each>
            <xsl:text>-</xsl:text>
          </xsl:when>
        </xsl:choose>        
        <xsl:text>fn</xsl:text>
        <xsl:variable name="n">
          <xsl:call-template name="n"/>
        </xsl:variable>
        <xsl:value-of select="translate($n, '()-', '')"/>
      </xsl:when>
      <!-- Où ?
      <xsl:when test="@n and ancestor::*[@xml:id][local-name() != local-name(/*)]">
        <xsl:value-of select="ancestor::*[@xml:id][1]/@xml:id"/>
        <xsl:text>-</xsl:text>
        <xsl:value-of select="@n"/>
      </xsl:when>
      -->
      <!-- lien vers une ancre -->
      <xsl:when test="starts-with(@target, '#') and not(contains(@target, ' '))">
        <xsl:value-of select="substring(@target, 2)"/>
      </xsl:when>
      <!-- éléments uniques identifiables par leur nom -->
      <xsl:when test="contains($els-unique, concat(' ', local-name(), ' '))">
        <xsl:if test="$bookId != ''">
          <xsl:value-of select="$bookId"/>
          <xsl:text>_</xsl:text>        
        </xsl:if>
        <xsl:value-of select="local-name()"/>
      </xsl:when>
      <!-- Mauvaise solution par défaut -->
      <xsl:otherwise>
        <xsl:value-of select="generate-id()"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:value-of select="$suffix"/>
  </xsl:template>

  <!--
<h3>mode="a" (lien html)</h3>

<p>
Générer un lien html &lt;a href="href" title="title">label&lt;/a> pour un élément, notamment pour une table des matières,
mais aussi pour le liage dans l'apparat critique. Ce mode fait usage des modes :
</p>
<ul>
  <li>“label” : titre court pour l'intitulé du lien</li>
  <li>“title” : titre long pour une bulle surgissante</li>
  <li>“href” : lien URI relatif fonctionnant dans le contexte de la publication (en un ou plusieurs fichiers)</li>
</ul>
  -->
  <!-- Par défaut, le mode lien ne produit rien et alerte d'un manque dans la sortie. -->
  <xsl:template match="node()" mode="a">
    <b style="color:red;">&lt;<xsl:value-of select="name()"/> mode="a"&gt;</b>
  </xsl:template>
  <!-- section, liées sur leur titres  -->
  <xsl:template match="tei:group | tei:text | tei:front | tei:body | tei:back | tei:div | tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 " mode="a">
    <xsl:param name="class"/>
    <a>
      <xsl:attribute name="href">
        <xsl:call-template name="href"/>
      </xsl:attribute>
      <xsl:if test="$class">
        <xsl:attribute name="class">
          <xsl:value-of select="$class"/>
        </xsl:attribute>
      </xsl:if>
      <!-- titre long -->
      <xsl:variable name="title">
        <xsl:apply-templates select="." mode="title"/>
      </xsl:variable>
      <!-- titre court -->
      <xsl:variable name="label">
        <xsl:apply-templates select="." mode="label"/>
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="normalize-space($label)=''">
          <xsl:copy-of select="$title"/>
        </xsl:when>
        <xsl:when test="normalize-space($title)=''">
          <xsl:copy-of select="$label"/>
        </xsl:when>
        <xsl:when test="$title = $label">
          <xsl:copy-of select="$label"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="title">
            <xsl:value-of select="normalize-space($title)"/>
          </xsl:attribute>
          <xsl:copy-of select="$label"/>
        </xsl:otherwise>
      </xsl:choose>
      <!-- compte d'items -->
      <xsl:if test="self::tei:group">
        <xsl:text> </xsl:text>
        <small>
          <xsl:text>(</xsl:text>
          <xsl:value-of select="count(.//tei:text)"/>
          <xsl:text>)</xsl:text>
        </small>
      </xsl:if>
    </a>
  </xsl:template>
  <!-- affichage de noms avec initiales (par ex resp) -->
  <xsl:template match="tei:principal" mode="a">
    <a class="resp">
      <xsl:attribute name="href">
        <xsl:call-template name="href"/>
      </xsl:attribute>
      <xsl:attribute name="title">
        <xsl:value-of select="normalize-space(.)"/>
      </xsl:attribute>
      <xsl:value-of select="@xml:id | @id"/>
    </a>
  </xsl:template>
  <!-- Liens courts vers un nom -->
  <xsl:template match="tei:name[@xml:id]" mode="a">
    <a href="#{@xml:id}">
      <xsl:variable name="text">
        <xsl:apply-templates select="text()"/>
      </xsl:variable>
      <xsl:choose>
        <xsl:when test="tei:addName|tei:forename|tei:surname">
          <xsl:apply-templates select="tei:addName|tei:forename|tei:surname"/>
        </xsl:when>
        <xsl:when test="normalize-space($text) != ''">
          <xsl:value-of select="normalize-space($text)"/>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates/>
        </xsl:otherwise>
      </xsl:choose>
    </a>
  </xsl:template>

  <!--
<h3>mode="title" (titre long)</h3>

<p>
Ce mode permet de traverser un arbre jusqu'à trouver un élément satisfaisant pour le titrer (souvent <head>).
Une fois cet elément trouvé, le contenu est procédé en mode texte afin de passer les notes,
résoudre les césures, ou les alternatives éditoriales.
</p>
  -->
  <!-- mode titre, par défaut, traverser sans trace -->
  <xsl:template match="*" mode="title" priority="-1">
    <xsl:variable name="label">
      <xsl:call-template name="label"/>
    </xsl:variable>
    <xsl:if test="$label != local-name()">
      <xsl:value-of select="$label"/>
      <xsl:text>. </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="/*/tei:teiHeader" mode="title"/>
  </xsl:template> 
  <!-- Appeler ce template pour avoir un titre de section -->
  <xsl:template match="tei:back | tei:body | tei:div | tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 | tei:front | tei:group | tei:TEI | tei:text | tei:titlePage" name="title" mode="title">
    <!-- Numérotation construite (?) -->
    <xsl:choose>
      <xsl:when test="tei:head">
        <xsl:apply-templates select="tei:head[1]" mode="title"/>
      </xsl:when>
      <xsl:when test="tei:titlePage">
        <xsl:apply-templates select="tei:titlePage" mode="title"/>
      </xsl:when>
      <xsl:when test="tei:docTitle">
        <xsl:apply-templates select="tei:docTitle[1]" mode="title"/>
      </xsl:when>
      <!-- la date est comme un titre (ex, acte) -->
      <xsl:when test="tei:docDate">
        <xsl:apply-templates select="tei:docDate[1]" mode="title"/>
      </xsl:when>
      <xsl:when test="tei:front">
        <xsl:apply-templates select="tei:front" mode="title"/>
      </xsl:when>
      <!-- Après front, supposé plus affichable qu'un teiHeader -->
      <xsl:when test="tei:teiHeader">
        <xsl:apply-templates select="tei:teiHeader" mode="title"/>
      </xsl:when>
      <!-- Groupement de sections dont le titre est porté par la première ?? -->
      <!-- ex: body/div0 -->
      <xsl:when test="count(*) =1">
        <xsl:apply-templates select="*" mode="title"/>
      </xsl:when>
      <!--
      <xsl:when test="tei:div[1]/tei:head">
        <xsl:apply-templates select="tei:div[1]" mode="title"/>
      </xsl:when>
      -->
      <xsl:when test="@n">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="@n"/>
        <xsl:text>] </xsl:text>
      </xsl:when>
      <xsl:when test="@type">
        <xsl:text>[</xsl:text>
        <xsl:value-of select="@type"/>
        <xsl:text>]</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>[</xsl:text>
        <xsl:call-template name="n"/>
        <xsl:text>] </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- par défaut le mode title fait comme le mode texte, à l'exception de certains inlines -->
  <xsl:template match="*" mode="title">
    <xsl:apply-templates select="." mode="txt"/>
  </xsl:template>
  <!-- Garder de la typo de base dans les titres -->
  <xsl:template match="tei:emph | tei:hi | tei:name | tei:num" mode="title">
    <xsl:apply-templates select="."/>
  </xsl:template>
  <!-- Surcharger ici le mode txt qui pour un titre insère des marqueur wiki -->
  <xsl:template match="tei:head | tei:docTitle | tei:docDate  | tei:title" mode="title">
    <xsl:apply-templates mode="title"/>
  </xsl:template>
  <!-- titre dans un front -->
  <xsl:template match="tei:titlePart" mode="title">
    <xsl:apply-templates mode="title"/>
    <xsl:choose>
      <xsl:when test="following-sibling::tei:titlePart">&#160;: </xsl:when>
    </xsl:choose>
  </xsl:template>

  <!-- Créer un titre hiérarchique pour <title> dans un <head> -->
  <xsl:template name="titleBranch">
    <xsl:variable name="titleBranch">
      <xsl:for-each select="ancestor-or-self::*">
        <xsl:sort order="descending" select="position()"/>
        <xsl:variable name="branch">
          <xsl:apply-templates select="." mode="title"/>
        </xsl:variable>
        <xsl:variable name="branchNorm" select="normalize-space($branch)"/>
        <xsl:choose>
          <!-- ramasser le teiHeader (?) -->
          <xsl:when test="self::tei:TEI"/>
          <!-- titre fabriqué, passer -->
          <xsl:when test="contains($branchNorm, '[')"/>
          <!-- déjà ponctué, ne rien faire -->
          <xsl:when test="contains(';.,', substring($branchNorm, string-length($branchNorm)) )">
            <xsl:value-of select="$branchNorm"/>
            <xsl:text> </xsl:text>
          </xsl:when>
          <xsl:when test="position() = last()">
            <xsl:value-of select="$branchNorm"/>
            <xsl:text>.</xsl:text>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$branchNorm"/>
            <xsl:text>. </xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="normalize-space($titleBranch) = ''">
        <xsl:value-of select="$corpusTitle"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="normalize-space($titleBranch)"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template match="*" mode="label">
    <xsl:apply-templates select="." mode="title"/>
  </xsl:template>

  <!-- Interpréter des attributs de datation comme une chaîne de texte -->
  <xsl:template match="tei:date" mode="label">
    <xsl:if test="@cert">~</xsl:if>
    <xsl:if test="@scope">~</xsl:if>
    <xsl:variable name="notBefore">
      <xsl:value-of select="substring(@notBefore, 1, 4)"/>
    </xsl:variable>
    <xsl:variable name="notAfter">
      <xsl:value-of select="substring(@notAfter, 1, 4)"/>
    </xsl:variable>
    <xsl:variable name="when">
      <xsl:value-of select="substring(@when, 1, 4)"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="$when != ''">
        <xsl:value-of select="number($when)"/>
      </xsl:when>
      <xsl:when test="$notAfter = $notBefore and $notAfter != ''">
        <xsl:value-of select="number($notAfter)"/>
      </xsl:when>
      <xsl:when test="@notBefore and @notAfter">
        <xsl:value-of select="number($notBefore)"/>
        <xsl:text>–</xsl:text>
        <xsl:value-of select="number($notAfter)"/>
      </xsl:when>
      <xsl:when test="@notBefore">
        <xsl:value-of select="number($notBefore)"/>
        <xsl:text>–…</xsl:text>
      </xsl:when>
      <xsl:when test="@notAfter">
        <xsl:text>…–</xsl:text>
        <xsl:value-of select="number($notAfter)"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="."/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!--
<h3>mode="ul" (arbre de matières)</h3>

<p>
Le mode table des matières génère une liste hiérarchique (html : ul/li+/ul*)
<p>
-->
  <!-- mode table des matières (ul), par défaut, tout retenir -->
  <xsl:template match="node()" mode="ul"/>
  <!-- racines, traverser -->
  <xsl:template match="/* | /*/tei:text" mode="ul">
    <xsl:apply-templates mode="ul"/>
  </xsl:template>
  <xsl:template match="tei:group/tei:text" mode="ul">
    <xsl:apply-templates mode="ul"/>  
  </xsl:template>
  <!-- sectionnement, traverser -->
  <xsl:template match="tei:group | tei:front | tei:body | tei:back | tei:div | tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 " mode="ul">
    <xsl:param name="class">tree</xsl:param>
    <!-- un truc pour pouvoir maintenir ouvert des niveaux de table des matières -->
    <xsl:param name="minus" select="0"/>
    <!-- profondeur limite -->
    <xsl:param name="depth" select="1000"/>
    <xsl:choose>
      <!-- Profondeur dépassée, arrêter -->
      <xsl:when test="$depth &lt; 1"/>
      
      <!-- Pas d'enfants, arrêter -->
      <xsl:when test="count(tei:group | tei:text | tei:div 
        | tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7 ) &lt; 2
        ">
        <xsl:apply-templates select="tei:group | tei:text | tei:div 
        | tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7" mode="ul"/>
      </xsl:when>
      <!-- enfants  -->
      <xsl:otherwise>
        <menu>
          <xsl:if test="$class">
            <xsl:attribute name="class">
              <xsl:value-of select="$class"/>
            </xsl:attribute>
          </xsl:if>
          <xsl:for-each select="tei:back | tei:body | tei:front | tei:group | tei:text | tei:div | tei:div0 | tei:div1 | tei:div2 | tei:div3 | tei:div4 | tei:div5 | tei:div6 | tei:div7">
            <xsl:choose>
              <!-- passer le premier item s'il n'a pas de titre alors que le parent en a un 
              not(tei:head|tei:docTitle|tei:front|tei:titlePage|tei:titlePart) and tei:div[1]/tei:head
      contains(' head docTitle front titlePage titlePart ', concat(' ', local-name(preceding-sibling::tei:*[1]), ' '))
      and not(tei:head|tei:docTitle|tei:front|tei:titlePage|tei:titlePart)

              -->              
              <xsl:when test="self::div and position() = 1 and not(tei:head) and ../tei:head "/>
              <xsl:otherwise>
                <li>
                  <!-- Garder les enfants en mémoire avant d'affecter le bon bouton à l'item -->
                  <xsl:variable name="ul">
                    <xsl:apply-templates select="." mode="ul">
                      <xsl:with-param name="minus" select="number($minus) - 1"/>
                      <xsl:with-param name="depth" select="number($depth) - 1"/>
                      <xsl:with-param name="class"/>
                    </xsl:apply-templates>
                  </xsl:variable>
                  <xsl:choose>
                    <xsl:when test="normalize-space($ul)=''"/>
                    <xsl:when test="number($minus) &gt; 0">
                      <xsl:attribute name="class">minus</xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="class">plus</xsl:attribute>
                    </xsl:otherwise>
                  </xsl:choose>
                  <xsl:apply-templates select="." mode="a"/>
		  <xsl:if test="tei:front/tei:byline/tei:docAuthor">
		    <span style="color:grey;font-size:10pt">
		    <xsl:text> - </xsl:text>
                    <xsl:variable name="nbbyline" select="count(tei:front/tei:byline)"/>
		      <xsl:for-each select="tei:front/tei:byline">
			<xsl:variable name="nbdocauthor" select="count(tei:docAuthor)"/>
			<xsl:for-each select="tei:docAuthor">
		          <xsl:if test="string-length(.) > 0">
			    <xsl:copy-of select="."/>
			    <xsl:if test="position() &lt; $nbdocauthor"><xsl:text>, </xsl:text></xsl:if>
			  </xsl:if>
			</xsl:for-each>
			<xsl:if test="position() &lt; $nbbyline and $nbdocauthor &gt; 0"><xsl:text>, </xsl:text></xsl:if>
		      </xsl:for-each>
		      </span>
		  </xsl:if>
                  <xsl:copy-of select="$ul"/>
                </li>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:for-each>
        </menu>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- Générer une navigation dans les sections -->
  <xsl:template name="nav">
    <xsl:variable name="body-title">
      <xsl:choose>
        <xsl:when test="/*/tei:text/tei:body[tei:head]">
          <xsl:apply-templates select="/*/tei:text/tei:body" mode="title"/>
        </xsl:when>
        <xsl:when test="/*/tei:text/tei:group[tei:head]">
          <xsl:apply-templates select="/*/tei:text/tei:group" mode="title"/>
        </xsl:when>
        <!-- ?
        <xsl:when test="/*/tei:text/tei:front">
          <xsl:apply-templates select="/*/tei:text/tei:front" mode="title"/>
        </xsl:when>
        -->
        <xsl:otherwise>
          <xsl:apply-templates select="/*/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title" mode="title"/>    
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:if test="normalize-space($body-title) != ''">
      <strong>
        <a>
          <xsl:attribute name="href">
            <xsl:for-each select="/">
              <xsl:call-template name="href"/>
            </xsl:for-each>
          </xsl:attribute>
          <xsl:copy-of select="$body-title"/>
        </a>
      </strong>
    </xsl:if>
    <xsl:if test="/*/tei:text/tei:front/tei:div | /*/tei:text/tei:front/tei:div0 | /*/tei:text/tei:front/tei:div1">
      <!-- ??
      <address id="presentation"><a>
        <xsl:attribute name="href">
          <xsl:for-each select="/*/tei:text/tei:front">
            <xsl:call-template name="href"/>
          </xsl:for-each>
        </xsl:attribute>
        <xsl:text>Présentation</xsl:text>
      </a></address>
      -->
      <xsl:apply-templates select="/*/tei:text/tei:front" mode="ul"/>
      <!-- Afficher titre sommaire -->
      <!-- ? <hr/> -->
      <strong>
        <xsl:for-each select="(/*/tei:text/tei:body | /*/tei:text/tei:group)[1]">
          <xsl:choose>
            <!-- Lien sommaire si quelque chose en racine -->
            <xsl:when test="tei:argument|tei:p">
              <a>
                <xsl:attribute name="href">
                  <xsl:call-template name="href"/>
                </xsl:attribute>
                <xsl:call-template name="label">
                  <xsl:with-param name="id">toc</xsl:with-param>
                </xsl:call-template>
              </a>
            </xsl:when>
            <xsl:otherwise>
              <xsl:call-template name="label">
                <xsl:with-param name="id">toc</xsl:with-param>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>        
      </strong>
    </xsl:if>
    <!-- Les items -->
    <xsl:apply-templates select="/*/tei:text/tei:body | /*/tei:text/tei:group " mode="ul"/>
    <xsl:if test="/*/tei:text/tei:back/tei:div | /*/tei:text/tei:front/tei:div0 | /*/tei:text/tei:front/tei:div1">
      <!-- ? <hr/> -->
      <strong>
        <a>
          <xsl:attribute name="href">
            <xsl:for-each select="(/*/tei:text/tei:back)[1]">
              <xsl:call-template name="href"/>
            </xsl:for-each>
          </xsl:attribute>
          <xsl:call-template name="label">
            <xsl:with-param name="id">back</xsl:with-param>
          </xsl:call-template>
        </a>
      </strong>
      <xsl:apply-templates select="/*/tei:text/tei:back" mode="ul"/>
      <!-- ? <hr/> -->
    </xsl:if>
  </xsl:template>
  <!--
<h3>mode="bibl" (ligne bibliographique)</h3>

<p>
Dégager une ligne biliographique d'un élément, avec des enregistrements bibliographique structurés.
Ex : <i>L'édit de Nantes et ses antécédents (1562-1598)</i>, dir. Bernard Barbiche, 2e éd., 2009 (Editions en ligne de l'Ecole des chartes, 5), http://elec.enc.sorbonne.fr/editsdepacification. 
</p>
-->
  <xsl:template match="tei:fileDesc " mode="bibl">
    <!-- titre, requis -->
    <xsl:apply-templates select="tei:titleStmt/tei:title" mode="bibl"/>
    <xsl:if test="tei:titleStmt/tei:principal">
      <!-- direction, requis -->
      <xsl:text>, dir. </xsl:text>
      <xsl:for-each select="tei:titleStmt/tei:principal">
        <xsl:value-of select="."/>
        <xsl:choose>
          <xsl:when test="position() = last()">, </xsl:when>
          <xsl:otherwise>, </xsl:otherwise>
        </xsl:choose>
      </xsl:for-each>
    </xsl:if>
    <!-- édition optionnel -->
    <xsl:if test="tei:editionStmt/@n">
      <xsl:value-of select="tei:editionStmt/@n"/>
      <sup>e</sup>
      <xsl:text> éd., </xsl:text>
    </xsl:if>
    <xsl:variable name="date">
      <!-- date, requis -->
      <xsl:value-of select="tei:publicationStmt/tei:date"/>
      <!-- Collection, optionnel -->
      <xsl:apply-templates select="tei:seriesStmt" mode="bibl"/>
    </xsl:variable>
    <xsl:if test="$date != '' and tei:publicationStmt/tei:idno">
      <xsl:value-of select="$date"/>    
      <xsl:text>, </xsl:text>
    </xsl:if>
    <!-- URI de référence, requis -->
    <xsl:apply-templates select="tei:publicationStmt/tei:idno"/>
    <xsl:text>.</xsl:text>
  </xsl:template>
  <!-- Information de série dans une ligne bibliographique -->
  <xsl:template match="tei:seriesStmt" mode="bibl">
    <span>
      <xsl:call-template name="atts"/>
      <xsl:text> (</xsl:text>
        <xsl:for-each select="*[not(@type='URI')]">
          <xsl:apply-templates select="."/>
          <xsl:choose>
            <xsl:when test="position() = last()"/>
            <xsl:otherwise>, </xsl:otherwise>
          </xsl:choose>
        </xsl:for-each>
      <xsl:text>)</xsl:text>
    </span>
  </xsl:template>
  <!-- titre -->
  <xsl:template match="tei:title" mode="bibl">
    <xsl:text> </xsl:text>
    <em>
      <xsl:call-template name="atts"/>
      <xsl:apply-templates/>
    </em>
  </xsl:template>

  <!--
Historique
==========

* 2010-03 [FG] Remise en ordre et documentation
* 2010-10 [FG] Apparat critique
* 2009-07 [FG] Création à partir des corpus sanctoral et cartulairesIdF

-->
</xsl:transform>
