Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1025 connectés 

  FORUM HardWare.fr
  Programmation
  XML/XSL

  Transformation d'un tableau (fichier xml vers html)

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Transformation d'un tableau (fichier xml vers html)

n°1983004
bananou
Posté le 11-04-2010 à 20:12:05  profilanswer
 

Bonjour,
 
j'ai un petit souci de transformation d'un fichier xml vers HTML.
Voici un extrait de mon fichier XML :  
 

Code :
  1. <!DOCTYPE BIBLIOTHEQUE SYSTEM "bibliot.dtd">
  2. <BIBLIOTHEQUE SUJET="Littérature">
  3. <LIVRE LANG="Français" GENRE="policier">
  4.         <AUTEUR>
  5.             <NOM>Sjöwall</NOM>
  6.             <PRENOM>Maj</PRENOM>
  7.         </AUTEUR>
  8.         <AUTEUR>
  9.             <NOM>Wahlöö</NOM>
  10.             <PRENOM>Per</PRENOM>
  11.         </AUTEUR>
  12.         <TRADUCTEUR PREFIXE="Traduit de l'anglais par">
  13.             <NOM>Deutsch</NOM>
  14.             <PRENOM>Michel</PRENOM>
  15.         </TRADUCTEUR>
  16.         <TITRE>L'homme au balcon</TITRE>
  17.         <EDITEUR>
  18.             <NOM>Rivages/Noir</NOM>
  19.         </EDITEUR>
  20.         <DATEPUB>2008</DATEPUB>
  21.     </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 :
  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.     <xsl:template match="/">
  5.         <html>
  6.             <head>
  7.                 <title>Bibliothèque</title>
  8.             </head>
  9.             <body>
  10.                 <h1>Bibliothèque</h1>
  11.                 <h2>Présentée en tableau, classée par auteur</h2>
  12.                 <xsl:apply-templates select="BIBLIOTHEQUE/LIVRE">
  13.                     <xsl:sort select="AUTEUR/NOM"/>
  14.                 </xsl:apply-templates>
  15.             </body>
  16.         </html>
  17.     </xsl:template>
  18.     <xsl:template match="LIVRE">
  19.         <table bgcolor="#F0FFFF" cellspacing="6" cellpadding="6" width="1200" border="1"
  20.             align="center">
  21.             <tr>
  22.                 <th width="200">Auteur</th>
  23.                 <th width="200">Traducteur</th>
  24.                 <th width="200">Titre</th>
  25.                 <th width="200">Éditeur</th>
  26.                 <th width="200">Genre</th>
  27.                 <th width="200">Année</th>
  28.             </tr>
  29.             <tr>
  30.                 <td width="200">
  31.                     <xsl:value-of select="AUTEUR/NOM"/>, <xsl:value-of select="AUTEUR/PRENOM"/>
  32.                 </td>
  33.                 <td width="200">
  34.                     <xsl:value-of select="TRADUCTEUR/PRENOM"/>&#160;<xsl:value-of
  35.                         select="TRADUCTEUR/NOM"/>
  36.                 </td>
  37.                 <td width="200">
  38.                     <em>
  39.                         <xsl:value-of select="TITRE"/>
  40.                     </em>
  41.                 </td>
  42.                 <td width="200">
  43.                     <xsl:value-of select="EDITEUR/NOM"/><xsl:if test="EDITEUR/LIEU">, <xsl:value-of
  44.                         select="EDITEUR/LIEU"/></xsl:if>
  45.                 </td>
  46.                 <td width="200">
  47.                     <xsl:value-of select="@GENRE"/>
  48.                 </td>
  49.                 <td width="200">
  50.                     <xsl:value-of select="DATEPUB"/>
  51.                 </td>
  52.             </tr>
  53.         </table>
  54.     </xsl:template>
  55. </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 !


Message édité par bananou le 11-04-2010 à 20:14:31
mood
Publicité
Posté le 11-04-2010 à 20:12:05  profilanswer
 

n°1987733
bananou
Posté le 26-04-2010 à 18:04:31  profilanswer
 

une petite idée  :) ?


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  XML/XSL

  Transformation d'un tableau (fichier xml vers html)

 

Sujets relatifs
[VBA] remplir une colonne excel avec une variable tableauRemplir un tableau associatif vide au départ (et puis l'afficher)
Récupérer les valeurs des textarea d'un tableau (table)Pb pour rentrer une chaine de caractere dans un tableau !
Outil tranche sous photoshop + HTMLaction auto lors d'ajour de fichier dans le serveur
[Resolu] Détail d'un fichier sous DOSMacro pour formater un fichier texte ou excel [Résolu]
Tri d'un Tableau par moiCasse-tête... Class Library C++/CLI vers C#?
Plus de sujets relatifs à : Transformation d'un tableau (fichier xml vers html)


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR