Bonjour,
j'ai un petit souci de transformation d'un fichier xml vers HTML.
Voici un extrait de mon fichier XML :
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 1. <!DOCTYPE BIBLIOTHEQUE SYSTEM "bibliot.dtd"> 2. 3. <BIBLIOTHEQUE SUJET="Littérature"> 4. 5. <LIVRE LANG="Français" GENRE="policier"> 6. <AUTEUR> 7. <NOM>Sjöwall</NOM> 8. <PRENOM>Maj</PRENOM> 9. </AUTEUR> 10. <AUTEUR> 11. <NOM>Wahlöö</NOM> 12. <PRENOM>Per</PRENOM> 13. </AUTEUR> 14. <TRADUCTEUR PREFIXE="Traduit de l'anglais par"> 15. <NOM>Deutsch</NOM> 16. <PRENOM>Michel</PRENOM> 17. </TRADUCTEUR> 18. <TITRE>L'homme au balcon</TITRE> 19. <EDITEUR> 20. <NOM>Rivages/Noir</NOM> 21. </EDITEUR> 22. <DATEPUB>2008</DATEPUB> 23. </LIVRE>
Je dois transformer ce fichier en tableau via XSLT pour obtenir un tableau dans ce format :
http://www.hiboox.fr/go/images/inf [...] 2.jpg.html
Voilà donc mon fichier XSLT permettant d'effectuer cette transformation :
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 1. <?xml version="1.0" encoding="UTF-8"?> 2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 3. <xsl:output method="html" version="html4.01" encoding="UTF-8" indent="yes"/> 4. 5. 6. <xsl:template match="/"> 7. <html> 8. <head> 9. <title>Bibliothèque</title> 10. </head> 11. <body> 12. 13. <h1>Bibliothèque</h1> 14. <h2>Présentée en tableau, classée par auteur</h2> 15. 16. <xsl:apply-templates select="BIBLIOTHEQUE/LIVRE"> 17. <xsl:sort select="AUTEUR/NOM"/> 18. </xsl:apply-templates> 19. 20. </body> 21. </html> 22. </xsl:template> 23. 24. 25. <xsl:template match="LIVRE"> 26. 27. <table bgcolor="#F0FFFF" cellspacing="6" cellpadding="6" width="1200" border="1" 28. align="center"> 29. 30. <tr> 31. <th width="200">Auteur</th> 32. <th width="200">Traducteur</th> 33. <th width="200">Titre</th> 34. <th width="200">Éditeur</th> 35. <th width="200">Genre</th> 36. <th width="200">Année</th> 37. </tr> 38. 39. 40. <tr> 41. <td width="200"> 42. <xsl:value-of select="AUTEUR/NOM"/>, <xsl:value-of select="AUTEUR/PRENOM"/> 43. </td> 44. 45. <td width="200"> 46. <xsl:value-of select="TRADUCTEUR/PRENOM"/>*<xsl:value-of 47. select="TRADUCTEUR/NOM"/> 48. </td> 49. 50. <td width="200"> 51. <em> 52. <xsl:value-of select="TITRE"/> 53. </em> 54. </td> 55. 56. <td width="200"> 57. <xsl:value-of select="EDITEUR/NOM"/><xsl:if test="EDITEUR/LIEU">, <xsl:value-of 58. select="EDITEUR/LIEU"/></xsl:if> 59. </td> 60. 61. <td width="200"> 62. <xsl:value-of select="@GENRE"/> 63. </td> 64. 65. <td width="200"> 66. <xsl:value-of select="DATEPUB"/> 67. </td> 68. 69. </tr> 70. 71. </table> 72. 73. 74. </xsl:template> 75. </xsl:stylesheet>
Mais le souci, c'est que les cellules de titre (<th> ) s'affichent à chaque nouvelle rangée, ce que je ne souhaite pas. J'aimerais que la rangée avec ces balises <th> ne s'affichent qu'une seule fois. Je ne vois vraiment pas d'où vient le souci...
Voilà ce que ça donne :
http://www.hiboox.fr/go/images/inf [...] c.jpg.html
C'est peut-être un détail qui cloche, mais je sèche. Je tiens à préciser que je débute en matière d'XML et XSLT![]()
Merci beaucoup pour votre aide précieuse !
Partager