Poème

Soit l'extrait de poème suivant écrit en XML :

1
<poeme titre="The Stone Troll" auteur="JRR Tolkien">
2
<strophe>
3
  <vers>Troll sat alone on his seat of stone,</vers>
4
  <vers>And munched and mumbled a bare old bone;</vers>
5
  <vers>For many a year he had gnawed it near,</vers>
6
  <vers>For meat was hard to come by.</vers>
7
  <vers>Done by! Gum by!</vers>
8
  <vers>In a cave in the hills he dwelt alone,</vers>
9
  <vers>And meat was hard to come by.</vers>
10
</strophe>
11
<strophe>
12
  <vers>Up came Tom with his big boots on.</vers>
13
  <vers>Said he to Troll: 'Pray, what is yon?</vers>
14
  <vers>For it looks like the shin o' my nuncle Tim.</vers>
15
  <vers>As should be a-lyin' in the graveyard.</vers>
16
  <vers>Caveyard! Paveyard!</vers>
17
  <vers>This many a year has Tim been gone,</vers>
18
  <vers>And I thought he were lyin' in the graveyard.</vers>
19
</strophe>
20
</poeme>

Question

Écrire un programme XSL-XSLT permettant de le transformer selon le format HTML suivant :

1
<html>
2
  <head>
3
    <title>The Stone Troll (JRR Tolkien)</title>
4
  </head>
5
  <body>
6
    <p>Troll sat alone on his seat of stone,</p>
7
    <p>And munched and mumbled a bare old bone;</p>
8
    <p>For many a year he had gnawed it near,</p>
9
    <p>For meat was hard to come by.</p>
10
    <p>Done by! Gum by!</p>
11
    <p>In a cave in the hills he dwelt alone,</p>
12
    <p>And meat was hard to come by.</p>
13
    <hr/>
14
    <p>Up came Tom with his big boots on.</p>
15
    <p>Said he to Troll: 'Pray, what is yon?</p>
16
    <p>For it looks like the shin o' my nuncle Tim.</p>
17
    <p>As should be a-lyin' in the graveyard.</p>
18
    <p>Caveyard! Paveyard!</p>
19
    <p>This many a year has Tim been gone,</p>
20
    <p>And I thought he were lyin' in the graveyard.</p>
21
  </body>
22
</html>

Indice

1
<?xml version="1.0" encoding="UTF-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
<xsl:template match="poeme">
4
  <html>
5
    <head>
6
      <title>...</title>
7
    </head>
8
    <body>
9
      <xsl:apply-templates/>
10
    </body>
11
  </html>
12
</xsl:template>
13
<xsl:template match="strophe">
14
  <xsl:apply-templates/>
15
  ...
16
</xsl:template>
17
<xsl:template match="vers">
18
  ...<xsl:value-of select="..."/>...
19
</xsl:template>
20
  ...
21
</xsl:stylesheet>

Indice

Pour gérer l'absence de <hr/> sur la dernière strophe, ajouter une règle qui sélectionne strophe[last()].

Question

Après avoir rappelé que l'ordre des règles n'est pas signifiant en XSLT, expliquer pourquoi, d'après les règles de priorité implicite, strophe[last()] sera toujours prioritaire sur strophe.

Question

En utilisant la fonction XPath position(), proposer une transformation qui affiche une strophe sur deux en italique.

Vous mettrez en place des règles de priorité explicite.