XSLT le langage les éléments. Plan introduction exemple template XSLT.
-
Upload
abelle-ferrier -
Category
Documents
-
view
116 -
download
0
Transcript of XSLT le langage les éléments. Plan introduction exemple template XSLT.
![Page 1: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/1.jpg)
XSLTXSLT
le langage
les éléments
![Page 2: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/2.jpg)
PlanPlan
introduction
exemple
template
XSLT
![Page 3: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/3.jpg)
Le langage XSLTLe langage XSLT
Une feuille de style XSLT est composée d'une série de règles modèles.
Chaque règle décrit la manière dont un type d'élément doit être traité.
XSLT est un langage déclaratifOn spécifie la sortie à produire pour un motif d'entrée
l'ordre des règles n'a pas d'importance
![Page 4: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/4.jpg)
TransformationTransformation
date
![Page 5: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/5.jpg)
La feuille de styleLa feuille de style
L'entête
les règles modèles
![Page 6: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/6.jpg)
La feuille de styleLa feuille de style
L'entête
les règles modèles
![Page 7: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/7.jpg)
L'entêteL'entête
L'entête standard : <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
Les espaces de noms constitue une partie essentielle de la recommendation XML.
Ils permettent de mélanger les balises de plusieurs vocabulaires dans une même feuille.
1. Ils sont identifiés par un URI
2. Utilisation en qualité de préfixe de noms d'élément et d'attribut
xmlns:prefix = "namespace-URI"
![Page 8: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/8.jpg)
La feuille de styleLa feuille de style
L'entête
les règles modèles
![Page 9: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/9.jpg)
Les règles Les règles
Pour chaque type d'élément est établie une règle modèle
![Page 10: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/10.jpg)
Les règles Les règles
<poem><xsl:template match="poem">
<html>
<head>
</head>
<body>
</body>
</html>
</xsl:template>
Création du squelette HTML,
![Page 11: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/11.jpg)
Les règles Les règles
<poem><xsl:template match="poem">
<html>
<head>
<title><xsl:value-of select="title"/></title>
</head>
<body>
</body>
</html>
</xsl:template>
![Page 12: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/12.jpg)
Les règles Les règles
<poem><xsl:template match="poem">
<html>
<head>
<title><xsl:value-of select="title"/></title>
</head>
<body>
1. <xsl:apply-templates select="title"/>
2. <xsl:apply-templates select="author"/>
3. <xsl:apply-templates select="stanza"/>
4. <xsl:apply-templates select="date"/>
</body>
</html>
</xsl:template>
définition de l'ordre des éléments
![Page 13: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/13.jpg)
Exemple de règle modèleExemple de règle modèle
<xsl:template match="stanza">
<p>
<xsl:apply-templates select="line"/>
</p>
</xsl:template>
<xsl:template match="line">
<xsl:if test="position() mod 2 = 0"> </xsl:if>
<xsl:value-of select="." />
<br />
</xsl:template>
![Page 14: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/14.jpg)
Exemple de règle modèleExemple de règle modèle
<xsl:template match="stanza">
<p>
<xsl:apply-templates select="line"/>
</p>
</xsl:template>
<xsl:template match="line">
<xsl:if test="position() mod 2 = 0"> </xsl:if>
<xsl:value-of select="." />
<br />
</xsl:template>
Changement du nœud courant
![Page 15: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/15.jpg)
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
![Page 16: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/16.jpg)
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
![Page 17: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/17.jpg)
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<p>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
![Page 18: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/18.jpg)
ComportementComportement
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<p>…
![Page 19: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/19.jpg)
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
![Page 20: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/20.jpg)
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
![Page 21: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/21.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
And suddenly the wind comes soft,
![Page 22: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/22.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
And suddenly the wind comes soft,
<p>And suddenly the wind comes soft,…
![Page 23: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/23.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<br/>
![Page 24: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/24.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<p>
And suddenly the wind comes soft,<br/>…
![Page 25: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/25.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
![Page 26: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/26.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
And Spring is here again;
![Page 27: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/27.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<p>And suddenly the wind comes soft,<br/> And Spring is here again;…
![Page 28: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/28.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<br/>
![Page 29: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/29.jpg)
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
<xsl:template match="line"> <xsl:if test="position() mod 2 = 0"> </xsl:if> <xsl:value-of select="." /> <br /> </xsl:template>
ComportementComportement
<p>And suddenly the wind comes soft,<br/>
And Spring is here again;<br/>…
![Page 30: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/30.jpg)
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
![Page 31: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/31.jpg)
ComportementComportement
<stanza>
<line> And suddenly the wind comes soft, </line>
<line> And Spring is here again; </line>
<line> And the hawthorn quickens with buds of green </line>
<line>And my heart with buds of pain. </line>
</stanza>
</p>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
![Page 32: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/32.jpg)
ComportementComportement
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates
select="line"/></p>
</xsl:template>
<p>And suddenly the wind comes soft,<br/> And Spring is here again;<br/>And the hawthorn quickens with buds of green<br/> And my heart with buds of pain.<br/>
</p>
![Page 33: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/33.jpg)
RésultatRésultat
<html>
<head>
</head>
<body>…
<p>And suddenly the wind comes soft,<br>
And Spring is here again;<br>
And the hawthorn quickens with buds of green<br>
And my heart with buds of pain.<br>
</p>
…</body>
</html>
![Page 34: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/34.jpg)
Retour sur les étapesRetour sur les étapes
![Page 35: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/35.jpg)
poem
author
date
title
Stanza
stanza
stanza
line
line
line
line
line
line
line
line
line
line
line
line
line
line
line
line
![Page 36: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/36.jpg)
poem
authordatetitle Stanza stanza stanza
line line line line line line line line line line line line
Retour sur les étapesRetour sur les étapes
![Page 37: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/37.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><html> <head>
<title><xsl:value-of select="title"/></title></head><body>
<xsl:apply-templates select="title"/><xsl:apply-templates select="author"/><xsl:apply-templates select="stanza"/><xsl:apply-templates select="date"/>
</body></html></xsl:template>
![Page 38: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/38.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><html> <head>
<title><xsl:value-of select="title"/></title></head><body>
<xsl:apply-templates select="title"/><xsl:apply-templates select="author"/><xsl:apply-templates select="stanza"/><xsl:apply-templates select="date"/>
</body></html></xsl:template>
![Page 39: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/39.jpg)
template : titletemplate : title
<xsl:template match="title">
<div align="center">
<h1>
<xsl:value-of select="." />
</h1>
</div>
</xsl:template>
![Page 40: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/40.jpg)
![Page 41: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/41.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><html> <head>
<title><xsl:value-of select="title"/></title></head><body>
<xsl:apply-templates select="title"/><xsl:apply-templates select="author"/><xsl:apply-templates select="stanza"/><xsl:apply-templates select="date"/>
</body></html></xsl:template>
![Page 42: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/42.jpg)
tempalte : authortempalte : author
<xsl:template match="author">
<div align="center">
<h2>By
<xsl:value-of select="." />
</h2>
</div>
</xsl:template>
![Page 43: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/43.jpg)
![Page 44: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/44.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><html> <head>
<title><xsl:value-of select="title"/></title></head><body>
<xsl:apply-templates select="title"/><xsl:apply-templates select="author"/><xsl:apply-templates select="stanza"/><xsl:apply-templates select="date"/>
</body></html></xsl:template>
![Page 45: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/45.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line
<xsl:template match="poem"><xsl:apply-templates select="stanza"/>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates select="line"/></p>
</xsl:template>
![Page 46: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/46.jpg)
![Page 47: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/47.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><html> <head>
<title><xsl:value-of select="title"/></title></head><body>
<xsl:apply-templates select="title"/><xsl:apply-templates select="author"/><xsl:apply-templates select="stanza"/><xsl:apply-templates select="date"/>
</body></html></xsl:template>
![Page 48: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/48.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><xsl:apply-templates select="stanza"/>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates select="line"/></p>
</xsl:template>
![Page 49: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/49.jpg)
![Page 50: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/50.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><html> <head>
<title><xsl:value-of select="title"/></title></head><body>
<xsl:apply-templates select="title"/><xsl:apply-templates select="author"/><xsl:apply-templates select="stanza"/><xsl:apply-templates select="date"/>
</body></html></xsl:template>
![Page 51: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/51.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><xsl:apply-templates select="stanza"/>
</xsl:template>
<xsl:template match="stanza"><p> <xsl:apply-templates select="line"/></p>
</xsl:template>
![Page 52: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/52.jpg)
![Page 53: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/53.jpg)
Retour sur les étapesRetour sur les étapes
poem
author date title Stanza stanza stanza
line line line line line line line line line line line line
<xsl:template match="poem"><html> <head>
<title><xsl:value-of select="title"/></title></head><body>
<xsl:apply-templates select="title"/><xsl:apply-templates select="author"/><xsl:apply-templates select="stanza"/><xsl:apply-templates select="date"/>
</body></html></xsl:template>
![Page 54: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/54.jpg)
![Page 55: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/55.jpg)
PlanPlan
Introduction
Template
![Page 56: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/56.jpg)
xsl:templatexsl:template
<xsl:template> http://www.w3.org/TR/xslt.html#rules
Définit un modèle permettant de produire un résultat. il peut être appelé par la comparaison des nœuds avec un motif ou explicitement par son nom.
Format
<!-- Category: top-level-element --><xsl:template match = pattern name = qname priority = number mode = qname> <!-- Content: (xsl:param*, template) --></xsl:template>
![Page 57: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/57.jpg)
formatformat
<xsl:template match = pattern name = qname priority = number mode = qname > </xsl:template>
match : le motif est utilisé pour définir les nœuds auxquels s'applique cette règle modèle.
en l'absence de cet attribut, il doit y avoir un attribut name.
![Page 58: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/58.jpg)
formatformat
<xsl:template match = pattern name = qname priority = number mode = qname > </xsl:template>
name : le nom du modèle
en l'absence de cet attribut, il doit y avoir un attribut match.
priority : nombre dénotant la priorité de ce modèle
mode : seuls les modèles dont le mode correspond sont considérés
![Page 59: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/59.jpg)
Instanciation d'un modèleInstanciation d'un modèle
Une fois qu'un élément <xsl:template> a été sélectionné pour le traitement :1. en cas d'appel avec <xsl:apply-templates>, le nœud courant et la liste
des nœuds courants sont définis selon les exigences.
2. un nouvel espace est alloué dans la pile afin de contenir une nouvelle instance de chaque variable locale définie dans le modéle.
3. le corps du modèle est instancié, ce qui signifie que les nœuds enfants de l'élément <xsl:template> sont eux aussi instanciés.
4. l'espace alloué est suprimé
![Page 60: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/60.jpg)
xsl:apply-templatexsl:apply-template
<xsl:apply-template>http://www.w3.org/TR/xslt.html#section-Applying-Template-Rules
Définit un ensemble de nœuds à traiter et obtient que le système les traite en sélectionnant une règle modèle appropriée pour chacun de ces nœuds. L'ensemble des nœuds est déterminé par l'attribut select.
Format
<!-- Category: instruction --><xsl:apply-templates select = node-set-expression mode = qname> <!-- Content: (xsl:sort | xsl:with-param)* --></xsl:apply-templates>
![Page 61: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/61.jpg)
xsl:apply-templatexsl:apply-template
<xsl:apply-templates select = node-set-expression mode = qname></xsl:apply-templates>
select : ensemble de nœuds à traiter.
Si aucun n'est spécifié, tous les enfants du nœud courant sont traités.
mode :Mode traitement. Les règles modèles utilisées pour traiter les nœuds
sélectionnés doivent disposer d'un mode de comparaison.
![Page 62: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/62.jpg)
Attribut selectAttribut select
Expression si Select est présent, Expression (XPath) définit les nœuds à traiter.
Il peut s'agir de nœuds associés au nœud courant ou être une sélection depuis le nœud racine (ref. absolue).
Si l'attribut select est omis, les nœuds sont les enfants du nœud courant,
• nœud élément, • texte, • commentaire, • instruction de traitement.• Les nœuds attribut et espace de noms ne sont pas traités.
– omettre select est équivalent à child::node() : selection de tous les enfants du nœud courant.
![Page 63: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/63.jpg)
ExempleExemple
<xsl:apply-template>traite tous les enfants du nœud courant
<xsl:apply-template select="para"/>les éléments <para> enfant du nœud courant sont traités
<xsl:apply-template select="//*" mode="toto">traite chaque élément du document en mode "toto"
![Page 64: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/64.jpg)
tri, with-paramtri, with-param
<xsl:sort> permet de trier avant le traitement des enfants.
<xsl:with-param>définit les paramètres mis à disposition des règles.
![Page 65: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/65.jpg)
ExempleExemple
<xsl:apply-template select="para"><xsl:with-param name="indent" select="$i"/>
</xsl:apply-template>traite tous les <para>, enfant du nœud courant, en définissant dans chaque modèle appelé, la valeur du paramètre indent selon la valeur de la variable $i
<xsl:apply-template select="//book"><xsl:sort select="@isbn"/>
</xsl:apply-template>traite les <book> en les triant par ordre croissant de leur attribut isbn
![Page 66: XSLT le langage les éléments. Plan introduction exemple template XSLT.](https://reader035.fdocument.pub/reader035/viewer/2022070309/551d9d8c497959293b8c0d38/html5/thumbnails/66.jpg)
EOFEOF