<poeme titre="The Stone Troll" auteur="JRR Tolkien">
<strophe>
<vers>Troll sat alone on his seat of stone,</vers>
<vers>And munched and mumbled a bare old bone;</vers>
<vers>For many a year he had gnawed it near,</vers>
<vers>For meat was hard to come by.</vers>
<vers>Done by! Gum by!</vers>
<vers>In a cave in the hills he dwelt alone,</vers>
<vers>And meat was hard to come by.</vers>
</strophe>
<strophe>
<vers>Up came Tom with his big boots on.</vers>
<vers>Said he to Troll: 'Pray, what is yon?</vers>
<vers>For it looks like the shin o' my nuncle Tim.</vers>
<vers>As should be a-lyin' in the graveyard.</vers>
<vers>Caveyard! Paveyard!</vers>
<vers>This many a year has Tim been gone,</vers>
<vers>And I thought he were lyin' in the graveyard.</vers>
</strophe>
</poeme>
Écrire un programme XSL-XSLT permettant de le transformer selon le format HTML suivant :
<html>
<head>
<title>The Stone Troll (JRR Tolkien)</title>
</head>
<body>
<p>Troll sat alone on his seat of stone,</p>
<p>And munched and mumbled a bare old bone;</p>
<p>For many a year he had gnawed it near,</p>
<p>For meat was hard to come by.</p>
<p>Done by! Gum by!</p>
<p>In a cave in the hills he dwelt alone,</p>
<p>And meat was hard to come by.</p>
<hr/>
<p>Up came Tom with his big boots on.</p>
<p>Said he to Troll: 'Pray, what is yon?</p>
<p>For it looks like the shin o' my nuncle Tim.</p>
<p>As should be a-lyin' in the graveyard.</p>
<p>Caveyard! Paveyard!</p>
<p>This many a year has Tim been gone,</p>
<p>And I thought he were lyin' in the graveyard.</p>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="poeme">
<html>
<head>
<title>...</title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="strophe">
<xsl:apply-templates/>
...
</xsl:template>
<xsl:template match="vers">
...<xsl:value-of select="..."/>...
</xsl:template>
...
</xsl:stylesheet>
Pour gérer l'absence de <hr/>
sur la dernière strophe, ajouter une règle qui sélectionne strophe[last()]
.