htmlFile : /var/www/elec/diple/transform/diple.html

Templates (diple.xsl

© 2010–2011, École nationale des chartes, licence CeCILL-C/LGPL ) Différentes fonctions XSLT utiles, agnostique sur l'espace de noms. Doit pouvoir servir à tous types de transformations. Noter l'usage d'un fichier d'initulé (tei.rdfs).
<xsl:param…
Fichier de messages pour étiquettes générées.
$messages="tei.rdfs"
Langue des messages (pour l'instant seul fr est implémenté)cf. [tlabel]
$lang="fr"
Date de génération, modifiable à l'appel.cf. [thtml]
$date
2011
$xslBase
$corpusId=/*/@xml:id
Paramètre de titre de livre, utilisé en préfixe d'identifiant
$bookId
$dipleHref
../ http://subversion.cru.fr/diple/trunk/
$theme=
Surchargeable si lien css différent de corpus.csscf. [thtml]
$css
theme/neutre/diple.css
<xsl:variable…
charger le fichier de messages, document('') permet de résoudre les chemin relativement à ce fichiercf. [tlabel]
$rdf:Property=document($messages, document(''))/*/rdf:Property
Une barre d'espaces insécables, utilisable pour de l'indentation automatique
$nbsp="                                                                                         "
pour conversion
$ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$abc="abcdefghijklmnopqrstuvwxyz"
$apos="'"
$quote="""
document()$messages

mode="label" (titre court)

Le mode label génère un intitulé court obtenu par une liste de valeurs localisés (./tei.rdfs).

source
<xsl:template name="label">
<xsl:param name="id" select="local-name()"/>
<xsl:choose>
<xsl:when test="
$rdf:Property[@xml:id = $id]/rdfs:label[@xml:lang = $lang]
">
<xsl:copy-of select="
$rdf:Property[@xml:id = $id]/rdfs:label[@xml:lang = $lang]/node()
"/>
</xsl:when>
<xsl:when test="$rdf:Property[@xml:id = $id]/rdfs:label">
<xsl:copy-of select="$rdf:Property[@xml:id = $id]/rdfs:label[1]/node()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
(l. 104) [label]
$rdf:Property[@xml:id = $id]/rdfs:label[@xml:lang = $lang]/node(), $rdf:Property[@xml:id = $id]/rdfs:label[1]/node(), $id
  • $id :
Message, intitulé court d'un élément TEI lorsque disponible
source
<xsl:template match="/" xml:space="preserve" name="html">
    
<--
    <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">]]>
</xsl:text>
-->
<html> <head> <meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> <meta name="modified" content="{$date}"/> <xsl:choose xml:space="default"> <xsl:when test="$theme != ''"> <link rel="stylesheet" type="text/css" href="{$theme}html.css"/> <link rel="stylesheet" type="text/css" href="{$theme}diple_html.css"/> <link rel="stylesheet" type="text/css" href="{$theme}{$corpusId}.css"/> </xsl:when> <xsl:when test="normalize-space($css) != ''"> <link rel="stylesheet" type="text/css" media="screen" href="{$css}"/> </xsl:when> </xsl:choose> <script type="text/javascript" src="{$dipleHref}js/Tree.js">//</script> <xsl:call-template name="head"/> </head> <body class="{$corpusId} fixed"> <div id="nav" class="nav"> <xsl:call-template name="nav"/> </div> <div id="article" class="article"> <xsl:apply-templates/> </div> </body> <xsl:call-template name="bottom_script"/> </html>
</xsl:template>
(l. 120) [html] /
<body>, <div>, <head>, <html>, <link>, <meta>, <script>, "//"
Racine, créer un document HTML par défaut.
source
<xsl:template name="head"/>
(l. 156) [head]
Template à surcharger permettant d'ajouter du contenu dans l'entête
source
<xsl:template name="nav"/>
(l. 157) [nav]
source
<xsl:template name="bottom_script"/>
(l. 159) [bottom_script]
Template à surcharger permettant d'ajouter du contenu après la fermeture du body
source
<xsl:template name="xslBase">
<xsl:param name="path" select="
/processing-instruction('xml-stylesheet')[contains(., 'xsl')]
"/>
<xsl:choose>
<xsl:when test="">
<xsl:call-template name="xslBase">
<xsl:with-param name="path" select=""/>
</xsl:call-template>
</xsl:when>
<!-- au cas où le type est après le href -->
<xsl:when test="">
<xsl:call-template name="xslBase">
<xsl:with-param name="path" select=""/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($path, '/')">
<xsl:value-of select="substring-before($path, '/')"/>
<xsl:call-template name="xslBase">
<xsl:with-param name="path" select="substring-after($path, '/')"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:template>
(l. 162) [xslBase]
"/", substring-before($path, '/')
  • $path :
pour obtenir un chemin relatif à l'XSLT appliquée
source
<xsl:template match="*">
<div>
<xsl:call-template name="tag"/>
<b style="color:red">
<xsl:value-of select="name()"/>
</b>
</div>
</xsl:template>
(l. 187) *
<b>, <div>, "</", ">", name()
<*>, modèle par défaut d'interception des éléments non pris en charge
source
<xsl:template name="tag">
<b style="color:red">
<xsl:value-of select="name()"/>
<xsl:for-each select="@*">
<xsl:value-of select="name()"/>
<xsl:value-of select="."/>
</xsl:for-each>
</b>
</xsl:template>
(l. 200) [tag]
<b>, "<", "="", """, ">", name(), name(), .
Utile au déboguage, affichage de l'élément en cours
source
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
(l. 218) [string-replace-all]
substring-before($text,$replace), $by, $text
  • $text :
  • $replace :
  • $by :
AGA, xslt 1 donc pas de fonction replace, un template pour y remedier.
source
<xsl:template name="nb_mois">
<xsl:param name="le-mois" select="''"/>
<xsl:choose>
<xsl:when test="$le-mois='01'">janvier</xsl:when>
<xsl:when test="$le-mois='02'">février</xsl:when>
<xsl:when test="$le-mois='03'">mars</xsl:when>
<xsl:when test="$le-mois='04'">avril</xsl:when>
<xsl:when test="$le-mois='05'">mai</xsl:when>
<xsl:when test="$le-mois='06'">juin</xsl:when>
<xsl:when test="$le-mois='07'">juillet</xsl:when>
<xsl:when test="$le-mois='08'">août</xsl:when>
<xsl:when test="$le-mois='09'">septembre</xsl:when>
<xsl:when test="$le-mois='10'">octobre</xsl:when>
<xsl:when test="$le-mois='11'">novembre</xsl:when>
<xsl:when test="$le-mois='12'">décembre</xsl:when>
</xsl:choose>
</xsl:template>
(l. 239) [nb_mois]
"janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"
  • $le-mois :
équivalent d'une fonction xslt, gardée ici pour mémoire
source
<xsl:template name="date">
<!-- arondir dates inventées -->
<xsl:choose>
<!-- déjà des attributs -->
<xsl:when test="@notBefore and @notAfter and @notAfter=@notBefore">
<xsl:attribute name="when">
<xsl:value-of select="@notAfter"/>
</xsl:attribute>
</xsl:when>
<!-- notBefore="1200-09-01" notAfter="1200-09-30" -->
<xsl:when test="
substring(@notBefore, 8, 3) = '-01' and contains('-30-31-28', substring(@notAfter, 8, 3))
">
<xsl:attribute name="when">
<xsl:value-of select="substring(@notBefore, 1, 7)"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="@notBefore|@notAfter|@when">
<xsl:copy-of select="@*"/>
</xsl:when>
<!-- deux dates, problème -->
<xsl:when test="contains(., ')(')">
<!-- xsl:message>Acte <xsl:value-of select="ancestor::text[1]/@n"/>, 2 dates <xsl:value-of select="."/></xsl:message -->
</xsl:when>
<!-- que des chiffres, année ? -->
<xsl:when test="translate(., '()1234567890.', '') = ''">
<xsl:attribute name="when">
<xsl:value-of select="translate(., '(). ', '')"/>
</xsl:attribute>
</xsl:when>
<!-- date simple -->
<xsl:when test="starts-with(., '(Vers')">
<xsl:attribute name="when">
<xsl:value-of select="translate(., '(Vers) ', '')"/>
</xsl:attribute>
</xsl:when>
<!-- date simple -->
<xsl:when test="starts-with(., '(Avant')">
<xsl:attribute name="notAfter">
<xsl:value-of select="translate(., '(Avant) ', '')"/>
</xsl:attribute>
</xsl:when>
<!-- date simple -->
<xsl:when test="starts-with(., '(Après')">
<xsl:attribute name="notBefore">
<xsl:value-of select="translate(., '(Après) ', '')"/>
</xsl:attribute>
</xsl:when>
<!-- période -->
<xsl:when test="starts-with(., '(Entre')">
<xsl:attribute name="notBefore">
<xsl:value-of select="
substring-before(substring-after(., 'Entre '), ' ')
"/>
</xsl:attribute>
<xsl:attribute name="notAfter">
<xsl:value-of select="
translate( substring-before(substring-after(., 'et '), ')') , '(). ', '')
"/>
</xsl:attribute>
</xsl:when>
<!-- cas non pris en compte, à remplir ensuite -->
<xsl:otherwise>
<!-- xsl:message>Acte <xsl:value-of select="ancestor::text[1]/@n"/>, date non prise en charge <xsl:value-of select="."/></xsl:message -->
</xsl:otherwise>
</xsl:choose>
</xsl:template>
(l. 259) [date]
@when, @*, @notAfter, substring(@notBefore, 1, 7), translate(., '(). ', ''), translate(., '(Vers) ', ''), translate(., '(Avant) ', ''), translate(., '(Après) ', ''), substring-before(substring-after(., 'Entre '), ' '), translate( substring-before(substring-after(., 'et '), ')') , '(). ', '')

attribut de dates en fonctions de la valeur courant, dégrossi le travail, mais du reste à faire

source
<xsl:template name="idpath">
<xsl:for-each select="ancestor-or-self::*">
<xsl:value-of select="name()"/>
</xsl:for-each>
</xsl:template>
(l. 322) [idpath]
"/", "[", "]", name()
Pour débogage afficher un path
source
<xsl:template name="rom2int">
<xsl:param name="rom"/>
<xsl:param name="int" select="0"/>
<xsl:choose>
<xsl:when test="normalize-space($rom) = ''">
<xsl:value-of select="$int"/>
</xsl:when>
<xsl:when test="starts-with($rom,'XC')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 90"/>
<xsl:with-param name="rom" select="substring($rom,3)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'IC')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 99"/>
<xsl:with-param name="rom" select="substring($rom,3)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'XL')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 40"/>
<xsl:with-param name="rom" select="substring($rom,3)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'L')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 50"/>
<xsl:with-param name="rom" select="substring($rom,2)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'C')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 100"/>
<xsl:with-param name="rom" select="substring($rom, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'D')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 500"/>
<xsl:with-param name="rom" select="substring($rom, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'M')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 1000"/>
<xsl:with-param name="rom" select="substring($rom, 2)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'IV')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 4"/>
<xsl:with-param name="rom" select="substring($rom, 3)"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'IX')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 9"/>
<xsl:with-param name="rom" select="substring($rom, 3 )"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'IIX')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 8"/>
<xsl:with-param name="rom" select="substring($rom, 4 )"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'I')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 1"/>
<xsl:with-param name="rom" select="substring($rom, 2 )"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'V')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 5"/>
<xsl:with-param name="rom" select="substring($rom, 2 )"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="starts-with($rom,'X')">
<xsl:call-template name="rom2int">
<xsl:with-param name="int" select="$int + 10"/>
<xsl:with-param name="rom" select="substring($rom, 2 )"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$int"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
(l. 333) [rom2int]
$int, $int
  • $rom :
  • $int :
nombre romain en décimal
source
<xsl:template name="dot">
<xsl:param name="current" select="."/>
<xsl:variable name="lastChar" select="substring($current, string-length($current))"/>
<xsl:if test="translate($lastChar, '.?!,;:', '') != ''">. </xsl:if>
</xsl:template>
(l. 424) [dot]
". "
  • $current :
Mettre un point à la fin d'un contenu