IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XSL/XSLT/XPATH XML Discussion :

[XSL] Transformation d'un tableau (fichier xml vers html)


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 3
    Points : 3
    Points
    3
    Par défaut [Résolu] [XSL] Transformation d'un tableau (fichier xml vers html)
    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 !

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    Avez-vous une petite idée ?

  3. #3
    Rédacteur

    Avatar de Erwy
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2003
    Messages
    4 967
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2003
    Messages : 4 967
    Points : 10 927
    Points
    10 927
    Par défaut
    tes déclarations sont simplement situées au mauvais endroit


    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>
     
      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>
     
      16.                 <xsl:apply-templates select="BIBLIOTHEQUE/LIVRE">
      17.                     <xsl:sort select="AUTEUR/NOM"/>
      18.                 </xsl:apply-templates>
      19.   </table>
     
      20.             </body>
      21.         </html>
      22.     </xsl:template>
      23.
      24.
      25.     <xsl:template match="LIVRE">
      26.  
      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.        
      73.
      74.     </xsl:template>
      75. </xsl:stylesheet>

  4. #4
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 3
    Points : 3
    Points
    3
    Par défaut
    Ca ne tenait pas à grand chose
    Merci beaucoup de ton aide !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [DOM] [XSL] Convertir un fichier XML vers un fichier CSS
    Par Invité dans le forum Bibliothèques et frameworks
    Réponses: 7
    Dernier message: 23/03/2007, 10h49
  2. Transformer un très gros fichier XML avec XSL
    Par wozzz dans le forum Format d'échange (XML, JSON...)
    Réponses: 3
    Dernier message: 30/05/2006, 10h57
  3. newbie : fichier xml vers html via command-line
    Par morti dans le forum XML/XSL et SOAP
    Réponses: 1
    Dernier message: 08/11/2005, 07h34
  4. [XSL] Caractère incorrect dans un fichier XML
    Par nicobest dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 05/09/2005, 14h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo