08 Exercice XSL - Rep
08 Exercice XSL - Rep
08 Exercice XSL - Rep
XSL
Exercice N°1
On désire créer une liste des contacts formée de personnes où pour chacun on
garde le nom et le prénom.
1- Proposer un fichier XML pour cette liste
2- Proposer aussi un fichier XSL pour les afficher sous forme de tableau
html.
Exercice N°2
Réponses
Exercice N°1
Fichier XML
Fichier XSL
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD
XHTML 1.0 Transitional//EN" doctype-
system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html>
<head>
<title>Liste des contacts</title>
</head>
<body>
Liste des contacts
<table border="1">
<tr>
<th>Prénom</th><th>Nom</th>
</tr>
<xsl:for-each select="contact/personne">
<tr>
<td><xsl:value-of select="prenom"/></td>
<td><xsl:value-of select="nom"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Exercice N°2
Fichier XML
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="emploi.xsl" type="text/xsl"?>
<emploi>
<classe>Sc 1</classe>
<jour>
<nom>Lundi</nom>
<s1>Math</s1>
<s2>Français</s2>
<s3>Anglais</s3>
<s4>Arabe</s4>
</jour>
<jour>
<nom>Mardi</nom>
<s1>Informatique</s1>
<s2></s2>
<s3>Français</s3>
<s4>Français</s4>
</jour>
</emploi>
Fichier XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD
XHTML 1.0 Transitional//EN" doctype-
system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
<xsl:template match="/">
<html>
<head>
<title>Emploi</title>
</head>
<body>
Emploi du temps: <xsl:value-of select="emploi/classe"/>
<table border="1">
<tr>
<th>Jour</th><th>8 - 10</th><th>10 - 12</th><th>14 - 16</th><th>16 -
18</th>
</tr>
<xsl:for-each select="emploi/jour">
<tr>
<td><xsl:value-of select="nom"/></td>
<td><xsl:value-of select="s1"/></td>
<td><xsl:value-of select="s2"/></td>
<td><xsl:value-of select="s3"/></td>
<td><xsl:value-of select="s4"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>