Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

08 Exercice XSL - Rep

Télécharger au format doc, pdf ou txt
Télécharger au format doc, pdf ou txt
Vous êtes sur la page 1sur 3

EXERCICES XML

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

On désire créer un fichier XML pour stocker l’emploi de temps de la classe :


Sc1. où on enregistre pour chaque jour les cours étudiés dans les quatre séances
de la journée : 8-10, 10-12, 14-16, 16-18.
1- donner un fichier XML représentant la structure de l’emploi
2- donner un fichier XSL pour afficher l’emploi sous forme de tableau html

Réponses
Exercice N°1
Fichier XML

<?xml version="1.0" encoding="iso-8859-1"?>


<?xml-stylesheet href="contact1.xsl" type="text/xsl"?>
<contact>
<personne>
<nom>Benbouna</nom>
<prenom>Abderrahim</prenom>
</personne>
<personne>
<nom>Khadraoui</nom>
<prenom>Nadia</prenom>
</personne>
<personne>
<nom>Barodi</nom>
<prenom>Amina</prenom>
</personne>
</contact>

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>

Vous aimerez peut-être aussi