Bonjour tout le monde,
le code suivant est le fichier xml:
Sachant que les éléments XML sont déjà tiés (dans le fichier XML) selon le département, je veux faire un fichier XSLT (contenant une seule boucle xsl:for-each) permettant d'afficher la liste des profs par département.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 <?xml version="1.0"?> <?xml-stylesheet version="1.0" type="text/xsl" href="Enseignant.xsl"?> <institut> <contact> <dept nom="Informatique" fax="73 222 222"/> <dept nom="Telecoms" fax="73 111 111"/> </contact> <enseignant nom="Ben Saleh" prenom="Ali"> <email affiche="oui">ali.bensaleh@yahoo.fr</email> <matiere vol="6"> Théorie des graphes </matiere> <matiere vol="3"> Programmation XML </matiere> <departement>Informatique</departement> </enseignant> <enseignant nom="Ben Ali" prenom="Mehdi"> <email affiche="oui">mehdi.benali@yahoo.fr</email> <matiere vol="4"> Bases de données </matiere> <matiere vol="2"> UML </matiere> <departement>Informatique</departement> </enseignant> <enseignant nom="Tarek" prenom="Nour"> <email affiche="non">nour.tarek@yahoo.fr</email> <matiere vol="16"> Protocoles Internet </matiere> <matiere vol="4"> Réseaux Telecoms </matiere> <departement>Telecoms</departement> </enseignant> <enseignant nom="Youssef" prenom="sami"> <email affiche="non">sami.youssef@yahoo.fr</email> <matiere vol="5"> Files d'attente</matiere> <departement>Telecoms</departement> </enseignant> </institut>
L'affichage se fera comme suit (Dans le cas où il y a plusieurs spécialités, seule la première est affichée).
- Nom du département : fax -
Nom Prénom
Spécialité (volume horaire)
Nom Prénom
Spécialité (volume horaire)
...
- Nom du département : fax -
...
j'ai parvenu à le faire avec deux boucles xsl:for-each
et merci d'avance.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/institut"> <html> <body> <xsl:for-each select="./contact/dept"> <xsl:variable name="nomd" select="@nom" /> <center>- <a name="{@nom}" /> <xsl:value-of select="@nom" /> : <xsl:value-of select="@fax" /> -</center> <br /> <xsl:for-each select="/institut/enseignant[departement=$nomd]"> <xsl:value-of select="@nom" /> ~ <xsl:value-of select="@prenom" /> <br /> <xsl:value-of select="./matiere" /> ( <xsl:value-of select="./matiere/@vol" /> ). <br /> </xsl:for-each> <br /> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>
Partager