VIII - Découpage d'une application XSLT
        Instruction xsl:include
                Syntaxe
                Sémantique
                        Processus mis en œuvre
                        Erreurs possibles
                        Position des instructions xsl:include
                        Intérêt de l'instruction xsl:include
                Exemple
        Instruction xsl:import
                Syntaxe
                Sémantique
                        Processus mis en œuvre
                        Intérêt de l'instruction xsl:import
                Exemple
        Instruction xsl:apply-imports
                Syntaxe
                Règle XSLT typique
                Sémantique
                Exemple
                Evolution


Chapitre VIII - Découpage d'une application XSLT

Instruction xsl:include

Syntaxe

xsl:include
<xsl:include
    href="..."
/>

Sémantique

Processus mis en œuvre

Erreurs possibles

Position des instructions xsl:include

Intérêt de l'instruction xsl:include

Exemple

Planning
        Semaine 47 :  "Le Poème Harmonique" 
        Semaine 3 :  "A deux violes esgales" 
        Semaine 8 :  "Ensemble Baroque de Nice" 
annonces.xml
<?xml version="1.0" encoding="UTF-16" standalone="yes"?>

<Annonces>
    <Entête> "Les Concerts d'Anacréon" </Entête>
    <Annonce>
        <Date>
            <Jour id="mar"/>
            <Quantième>20</Quantième>
            <Mois id="nov"/>
            <Année>2001</Année>
            <Heure>20H30</Heure>
        </Date>
        <Lieu>Chapelle des Ursules</Lieu>
        <Ensemble> "Le Poème Harmonique" </Ensemble>
    </Annonce>
    <Annonce>
        <Date>
            <Jour id="jeu"/>
            <Quantième>17</Quantième>
            <Mois id="jnv"/>
            <Année>2002</Année>
            <Heure>20H30</Heure>
        </Date>
        <Lieu>Chapelle des Ursules</Lieu>
        <Ensemble> "A deux violes esgales" </Ensemble>
    </Annonce>
    <Annonce>
        <Date>
            <Jour id="dim"/>
            <Quantième>24</Quantième>
            <Mois id="mar"/>
            <Année>2002</Année>
            <Heure>17H</Heure>
        </Date>
        <Lieu>Chapelle des Ursules</Lieu>
        <Ensemble> "Ensemble Baroque de Nice" </Ensemble>
    </Annonce>
    
    <!-- etc. -->
    
</Annonces>
planning.xsl
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:dt="http://xsltsl.org/date-time"
    version="1.0">

    <xsl:output  method='text' encoding='ISO-8859-1' />
    
    <xsl:include href="../../xsltsl-1.0/date-time.xsl"/>
    
    <xsl:variable name="Dictionnaire" 
                  select="document('dictionnaire.xml')/Dictionnaire"/>
    
    <xsl:template match="Annonce">
        
        <xsl:variable 
            name="quantième" 
            select="./Date/Quantième" />
        
        <xsl:variable 
            name="NoMois" 
            select="$Dictionnaire/mot[@id=current()/Date/Mois/@id]/@num" />
        
        <xsl:variable 
            name="année" 
            select="./Date/Année" />
            
        <xsl:variable name="NoSemaine">
            <xsl:call-template name="dt:calculate-week-number">
                <xsl:with-param name="year" select="$année"/>
                <xsl:with-param name="month" select="$NoMois"/>
                <xsl:with-param name="day" select="$quantième"/>
            </xsl:call-template>
        </xsl:variable>
         
        <xsl:text>
        Semaine </xsl:text>
        <xsl:value-of select="$NoSemaine"/> : <xsl:value-of 
                                              select="./Ensemble"/>
         
    </xsl:template>
    
    <xsl:template match="text()" />
    
</xsl:stylesheet>

Dictionnaire.xml
<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<Dictionnaire>
    
    <mot id="jnv" num="1">
        <traduction lang="fr">janvier</traduction>
        <traduction lang="en">january</traduction>
    </mot>
    
    <mot id="mrs" num="3">
        <traduction lang="fr">mars</traduction>
        <traduction lang="en">march</traduction>
    </mot>
    
    <mot id="nov" num="11">
        <traduction lang="fr">novembre</traduction>
        <traduction lang="en">november</traduction>
    </mot>
    
</Dictionnaire>
date-time.xsl (extrait)
<?xml version="1.0" encoding="UTF-16" standalone="yes"?>
<xsl:stylesheet
  version="1.0"
  extension-element-prefixes="doc"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="http://xsltsl.org/xsl/documentation/1.0"
  xmlns:dt="http://xsltsl.org/date-time"
>
...
<xsl:template name="dt:calculate-julian-day">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>

    <xsl:variable name="a" select="floor((14 - $month) div 12)"/>
    <xsl:variable name="y" select="$year + 4800 - $a"/>
    <xsl:variable name="m" select="$month + 12 * $a - 3"/>

    <xsl:value-of select="$day + floor((153 * $m + 2) div 5) + 
                          $y * 365 + floor($y div 4) - floor($y div 100) + 
                          floor($y div 400) - 32045"/>
</xsl:template>
  
<xsl:template name="dt:calculate-week-number">
    <xsl:param name="year"/>
    <xsl:param name="month"/>
    <xsl:param name="day"/>

    <xsl:variable name="J">
        <xsl:call-template name="dt:calculate-julian-day">
        <xsl:with-param name="year" select="$year"/>
        <xsl:with-param name="month" select="$month"/>
        <xsl:with-param name="day" select="$day"/>
        </xsl:call-template>
    </xsl:variable>
    
    <xsl:variable name="d4" select="($J + 31741 - ($J mod 7)) mod 146097 
                                     mod 36524 mod 1461"/>
    <xsl:variable name="L" select="floor($d4 div 1460)"/>
    <xsl:variable name="d1" select="(($d4 - $L) mod 365) + $L"/>
    
    <xsl:value-of select="floor($d1 div 7) + 1"/>
</xsl:template>
...
</xsl:stylesheet>

Instruction xsl:import

Syntaxe

xsl:import
<xsl:import
    href="..."
/>

Sémantique

Processus mis en œuvre

Intérêt de l'instruction xsl:import

Exemple

<?xml version="1.0" encoding="UTF-16" ?>
<!DOCTYPE article SYSTEM "customdocbook.dtd">
<article lang="fr"> 
     <articleinfo> 
          <author> 
                <firstname>Philippe</firstname> 
                <surname>Drix</surname> 
                <affiliation> 
                     <jobtitle>Consultant Architectures Objet</jobtitle> 
                     <orgname>Objectiva</orgname> 
                </affiliation> 
          </author> 
          <title>SPECIFICATION XML DU REFERENTIEL METIER DE L'APPLICATION
                CANOFETE</title> 
          <revhistory> 
                <revision> 
                     <revnumber>1.0</revnumber> 
                     <date>7-XI-2001</date> 
                     <authorinitials>PhD</authorinitials> 
                     <revremark>Création du document.</revremark> 
                </revision> 
          </revhistory> 
     </articleinfo> 
     <abstract> 
          <para>Ce document présente les composants XML de l'application 
          Canofête, coté référentiel métier, et non coté présentation. 
          Ces composants XML sont tous liés au générateur de code Java, 
          et décrivent les transactions et les services fonctionnels.</para> 
     </abstract>
     <sect1> 
          <title>Introduction - Structure générale</title> 
          <sect2> 
                <title>Fichier <emphasis>CyclaModel.xml</emphasis></title> 
                <para>
                Le générateur part du fichier 
                XML <filename>CyclaModel.xml</filename>, qui 
                décrit la correspondance entre les objets métiers et les 
                différentes tables de la base de données LASSO.
                </para>  
                
     <!-- etc. -->
              
</article>
docbook.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
                exclude-result-prefixes="doc"
                version='1.0'>

<xsl:output method="html"
            encoding="ISO-8859-1"
            indent="no"/>

<!-- ********************************************************************
     $Id: docbook.xsl,v 1.6 2001/07/04 16:17:43 uid48421 Exp $
     ********************************************************************

     This file is part of the XSL DocBook Stylesheet distribution.
     See ../README or http://nwalsh.com/docbook/xsl/ for copyright
     and other information.

     ******************************************************************** -->

<!-- ==================================================================== -->

<xsl:include href="../VERSION"/>
<xsl:include href="param.xsl"/>
<xsl:include href="../lib/lib.xsl"/>
<xsl:include href="../common/l10n.xsl"/>
<xsl:include href="../common/common.xsl"/>
<xsl:include href="../common/labels.xsl"/>
<xsl:include href="../common/titles.xsl"/>
<xsl:include href="../common/subtitles.xsl"/>
<xsl:include href="../common/gentext.xsl"/>
<xsl:include href="autotoc.xsl"/>
<xsl:include href="lists.xsl"/>
<xsl:include href="callout.xsl"/>
<xsl:include href="verbatim.xsl"/>
<xsl:include href="graphics.xsl"/>
<xsl:include href="xref.xsl"/>
<xsl:include href="formal.xsl"/>
<xsl:include href="table.xsl"/>
<xsl:include href="sections.xsl"/>
<xsl:include href="inline.xsl"/>
<!-- etc. -->
inline.xsl
<xsl:template name="inline.monoseq">
  <xsl:param name="content">
    <xsl:call-template name="anchor"/>
    <xsl:apply-templates/>
  </xsl:param>
  <tt><xsl:copy-of select="$content"/></tt>
</xsl:template>

<xsl:template match="filename">
  <xsl:call-template name="inline.monoseq"/>
</xsl:template>
<tt class="filename">CyclaModel.xml</tt>
monDocBook.xsl
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version='1.0'
                xmlns="http://www.w3.org/TR/xhtml1/transitional"
                exclude-result-prefixes="#default"> 
                
    
    <xsl:import
    href="file:///c:\DocBook\docbook-xsl-1.45\html\docbook.xsl"/>
    
    <xsl:template name="inline.monoseq">
      <xsl:param name="cssClassName"/>
      <xsl:param name="content">
        <xsl:call-template name="anchor"/>
        <xsl:apply-templates/>
      </xsl:param>
      <tt class="{$cssClassName}"><xsl:copy-of select="$content"/></tt>
    </xsl:template>
    
    <xsl:template match="filename">
          <xsl:call-template name="inline.monoseq">
             <xsl:with-param name="cssClassName" select="'filename'"/>
          </xsl:call-template>
    </xsl:template>
    
</xsl:stylesheet>

Instruction xsl:apply-imports

Syntaxe

xsl:apply-imports
<xsl:apply-imports/>

Règle XSLT typique

<xsl:template match="... motif (pattern) ...">
    ...
    <xsl:apply-imports/>
    ...
</xsl:template> 

Sémantique

Exemple

<xsl:template match="para">
  <p>
    <xsl:if test="position() = 1 and parent::listitem">
      <xsl:call-template name="anchor">
        <xsl:with-param name="node" select="parent::listitem"/>
      </xsl:call-template>
    </xsl:if>

    <xsl:call-template name="anchor"/>
    <xsl:apply-templates/>
  </p>
</xsl:template>
 
        <para revisionflag="added" >
        Le générateur part du fichier 
        XML <filename>CyclaModel.xml</filename>, qui 
        décrit la correspondance entre les objets métiers et les 
        différentes tables de la base de données LASSO.
        </para>  
changebars.xsl
<?xml version="1.0"?>
<xsl:stylesheet 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
    
    <xsl:import href="docbook.xsl"/>
    
    <xsl:param name="show.revisionflag" select="'1'"/>
    
    <xsl:template name="user.head.content">
        <style type="text/css">
            <xsl:text>
            div.added    { background-color: yellow; }
            div.deleted  { text-decoration: line-through;
                           background-color: #FF7F7F; }
            div.changed  { background-color: lime; }
            div.off      {  }
            
            span.added   { background-color: yellow; }
            span.deleted { text-decoration: line-through;
                           background-color: #FF7F7F; }
            span.changed { background-color: lime; }
            span.off     {  }
            </xsl:text>
        </style>
    </xsl:template>
    
    <xsl:template match="*[@revisionflag]">
      <xsl:choose>
        <xsl:when 
            test=" local-name(.) = 'para'
                or local-name(.) = 'section'
                or local-name(.) = 'sect1'
                or local-name(.) = 'sect2'
                or local-name(.) = 'sect3'
                or local-name(.) = 'sect4'
                or local-name(.) = 'sect5'
                or local-name(.) = 'chapter'
                or local-name(.) = 'preface'
                or local-name(.) = 'itemizedlist'
                or local-name(.) = 'varlistentry'
                or local-name(.) = 'glossary'
                or local-name(.) = 'bibliography'
                or local-name(.) = 'index'
                or local-name(.) = 'appendix'">
                
            <div class='{@revisionflag}'>
                <xsl:apply-imports/>
            </div>
            
        </xsl:when>
        <!-- ... -->
      </xsl:choose>
    </xsl:template>

</xsl:stylesheet>

Evolution

preceding-sibling::*[1] Table following-sibling::*[1]