Partage
  • Partager sur Facebook
  • Partager sur Twitter

Transformation XML - XSL

    4 mars 2015 à 18:03:37

    Bonjour à tous,

    Je travaille sur un projet sur la création d'un carnet d'adresse à l'aide de xml.
    J'ai créé mon fichier "projet.xml", j'aimerai le transformer avec ce fichier "projet.xsl" pour afficher le contenu via le fichier "projet.html".
    Mon problème, j'arrive à afficher certains contenus mais tous. Et les contenus affichés ne correspondent pas à ma liste des "étudiants" car il s'agit bien d'un carnet d'adresse affichant la liste des anciens étudiants. Ci-dessous les codes de mes différents fichiers:

     
    // DTD:
     
    <?xml version="1.0" encoding="UTF-8"?>
     
    <!ELEMENT  carnetDadresse (alumni, formations, entreprises, adresses )>
     
    <!ELEMENT alumni (alumnus)+>
    <!ELEMENT alumnus (nom, prenom, date_naissance, promotion)>
    <!ELEMENT nom (#PCDATA)>
    <!ELEMENT prenom (#PCDATA)>
    <!ELEMENT date_naissance (#PCDATA)>
    <!ELEMENT promotion (#PCDATA)>
    <!ATTLIST alumnus pk_id_alumnus ID #REQUIRED
    		  fk_id_formation IDREF #REQUIRED
    		  fk_id_entreprise IDREF #REQUIRED
    		  fk_id_adresse IDREF #REQUIRED>
     
    <!ELEMENT formations (formation)+>
    <!ELEMENT formation (nom_formation, domaine)>
    <!ELEMENT nom_formation (#PCDATA)>
    <!ELEMENT domaine (#PCDATA)>
    <!ATTLIST formation pk_id_formation ID #REQUIRED>
     
    <!ELEMENT entreprises (entreprise)+>
    <!ELEMENT entreprise (nom_entreprise, fonction, date_entree)>
    <!ELEMENT nom_entreprise (#PCDATA)>
    <!ELEMENT fonction (#PCDATA)>
    <!ELEMENT date_entree (#PCDATA)>
    <!ATTLIST entreprise pk_id_entreprise ID #REQUIRED>
     
    <!ELEMENT adresses (adresse)+>
    <!ELEMENT adresse (numero, rue, code_postal, ville, telephone, email)>
    <!ELEMENT numero (#PCDATA)>
    <!ELEMENT rue (#PCDATA)>
    <!ELEMENT code_postal (#PCDATA)>
    <!ELEMENT ville (#PCDATA)>
    <!ELEMENT telephone (#PCDATA)>
    <!ELEMENT email (#PCDATA)>
    <!ATTLIST adresse pk_id_adresse ID #REQUIRED>
     
    // XML:
     
    <?xml version="1.0" encoding="UTF-8"?>
     
    <!-- New XML document created with EditiX XML Editor (http://www.editix.com) at Tue Feb 24 21:09:17 CET 2015 -->
     
     
    <?xml-stylesheet type="text/xsl" href="projet.xsl" ?>
     
    <!DOCTYPE carnetDadresse SYSTEM "projet.dtd">
     
    <carnetDadresse>
    	<alumni>
    		<alumnus pk_id_alumnus="A1" fk_id_adresse="D1" fk_id_formation="F3" fk_id_entreprise="E2">
    			<nom>Dupont</nom>
    			<prenom>Julien</prenom>
    			<date_naissance>01/02/1990</date_naissance>
    			<promotion>2014-2015</promotion>
    		</alumnus>
     
    		<alumnus pk_id_alumnus="A2" fk_id_adresse="D2" fk_id_formation="F1" fk_id_entreprise="E5">
    			<nom>Dubois</nom>
    			<prenom>Louise</prenom>
    			<date_naissance>04/05/1985</date_naissance>
    			<promotion>2013-2014</promotion>
    		</alumnus>
     
    		<alumnus pk_id_alumnus="A3" fk_id_adresse="D3" fk_id_formation="F2" fk_id_entreprise="E4">
    			<nom>Herbert</nom>
    			<prenom>John</prenom>
    			<date_naissance>07/08/1982</date_naissance>
    			<promotion>2012-2013</promotion>
    		</alumnus>
     
    		<alumnus pk_id_alumnus="A4" fk_id_adresse="D4" fk_id_formation="F1" fk_id_entreprise="E3">
    			<nom>Aloui</nom>
    			<prenom>Henri</prenom>
    			<date_naissance>10/10/1982</date_naissance>
    			<promotion>2011-2012</promotion>
    		</alumnus>
     
    		<alumnus pk_id_alumnus="A5" fk_id_adresse="D5" fk_id_formation="F2" fk_id_entreprise="E1">
    			<nom>Koller</nom>
    			<prenom>Elisa</prenom>
    			<date_naissance>22/10/1988</date_naissance>
    			<promotion>2010-2011</promotion>
    		</alumnus>
     
    	</alumni>
     
    	<formations>
    		<formation pk_id_formation="F1">			
    			<nom_formation>Master IDEMM</nom_formation>
    			<domaine>Information, communication, documentation</domaine>
    		</formation>
     
    		<formation pk_id_formation="F2">			
    			<nom_formation>Master GIDE</nom_formation>
    			<domaine>Information, communication, documentation</domaine>
    		</formation>
     
    		<formation pk_id_formation="F3">			
    			<nom_formation>Master PRISME</nom_formation>
    			<domaine>Information, communication, documentation</domaine>
    		</formation>
     
    	</formations>
     
    	<entreprises>
    		<entreprise pk_id_entreprise="E1">
    			<nom_entreprise>Microsoft</nom_entreprise>
    			<fonction>Chef de projet</fonction>
    			<date_entree>01/01/2010</date_entree>
    		</entreprise>
     
    		<entreprise pk_id_entreprise="E2">
    			<nom_entreprise>Orange</nom_entreprise>
    			<fonction>Community Manager</fonction>
    			<date_entree>01/01/2011</date_entree>
    		</entreprise>
     
    		<entreprise pk_id_entreprise="E3">
    			<nom_entreprise>Google</nom_entreprise>
    			<fonction>Expert SEO</fonction>
    			<date_entree>01/01/2012</date_entree>
    		</entreprise>
     
    		<entreprise pk_id_entreprise="E4">
    			<nom_entreprise>BMW</nom_entreprise>
    			<fonction>Développeur</fonction>
    			<date_entree>01/01/2015</date_entree>
    		</entreprise>
     
    		<entreprise pk_id_entreprise="E5">
    			<nom_entreprise>Microsoft</nom_entreprise>
    			<fonction>CEO</fonction>
    			<date_entree>01/01/2000</date_entree>
    		</entreprise>
     
    	</entreprises>
     
    	<adresses>
    		<adresse pk_id_adresse="D1">
    			<numero>20</numero>
    			<rue>Pont du Petit Paradis</rue>
    			<code_postal>59000</code_postal>
    			<ville>Lille</ville>
    			<telephone>03 20 00 00 00</telephone>
    			<email>jdupont@gmail.com</email>
    		</adresse>
     
    		<adresse pk_id_adresse="D2">
    			<numero>3</numero>
    			<rue>Rue Saint André</rue>
    			<code_postal>59650</code_postal>
    			<ville>Villeneuve d'Ascq</ville>
    			<telephone>01 20 02 00 00</telephone>
    			<email>ldubois@yahoo.fr</email>
    		</adresse>
     
    		<adresse pk_id_adresse="D3">
    			<numero>43</numero>
    			<rue>Rue Saint Sebastien</rue>
    			<code_postal>75000</code_postal>
    			<ville>Paris</ville>
    			<telephone>01 20 02 10 15</telephone>
    			<email>jherbert@orange.fr</email>
    		</adresse>
     
    		<adresse pk_id_adresse="D4">
    			<numero>93</numero>
    			<rue>Rue Royale</rue>
    			<code_postal>59000</code_postal>
    			<ville>Lille</ville>
    			<telephone>03 20 30 30 30</telephone>
    			<email>elisakoller@gmail.com</email>
    		</adresse>
     
    		<adresse pk_id_adresse="D5">
    			<numero>33</numero>
    			<rue>Avenue du Peuple Belge</rue>
    			<code_postal>59000</code_postal>
    			<ville>Lille</ville>
    			<telephone>0120303030</telephone>
    			<email>haloui@yahoo.com</email>
    		</adresse>
    	</adresses>
    </carnetDadresse>
     
    // XSL
     
    <?xml version="1.0" encoding="UTF-8"?>
     
    <!-- New XSLT document created with EditiX XML Editor (http://www.editix.com) at Mon Mar 02 16:16:29 CET 2015 -->
     
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     
    	<xsl:output method="html"/>
     
    	<xsl:template match="/">
    	<html>
    		<head>
    			<meta charset="utf-8"/>
    			<title>Carnet d'adresses</title>
    		</head>
     
    		<body style="background-color:#d0caca; width:100%; margin:auto">
    			<h1>Carnet d'adresses des anciens étudiants</h1>
     
    			<h2 style="background-color:#406e90; color:#fff; width:500px">Liste des étudiants dans le carnet d'adresses:</h2>
     
                <table border="1" cellpadding="10">
                	<thead style="color:#1510a2" >
                		<tr>
                    		<th>PROMOTION</th>
                        	<th>NOM</th>
                        	<th>PRENOM</th>
                        	<th>NAISSANCE</th>
                        	<th>FORMATION</th>
                        	<th>EMAIL</th>
                        	<th>TELEPHONE</th>
                        	<th>ENTREPRISE</th>
                    	</tr>
                	</thead>
                	<xsl:for-each select="carnetDadresse/alumni/alumnus">
                		<tr>
                			<td>
                				<xsl:value-of select="promotion"/>
                			</td>
     
                			<td>
                				<xsl:value-of select="nom"/>
                			</td>
     
                			<td>
                				<xsl:value-of select="prenom"/>
                			</td>
     
                			<td>
                				<xsl:value-of select="date_naissance"/>
                			</td>
     
             			<td>
             			     <xsl:for-each select="carnetDadresse/alumni/alumnus">
             			          <xsl:variable name="alumnus" select="@pk_id_alumnus"/>
                              		  <xsl:for-each select="/carnetDadresse/formations/formation[@fk_id_formation = $alumnus]">
                					<strong>Nom de la formation:</strong><xsl:value-of select="nom_formation"/><br/>
                					<strong>Domaine:</strong><xsl:value-of select="domaine"/>
                				  </xsl:for-each>
                			     </xsl:for-each>
                			</td>
     
                			<td>
                				<xsl:value-of select="/carnetDadresse/adresses/adresse/email"/>
                			</td>
     
                			<td>
                				<xsl:value-of select="/carnetDadresse/adresses/adresse/telephone"/>
                			</td>
     
                			<td>
                				<strong>Nom de l'entreprise:</strong><xsl:value-of select="/carnetDadresse/entreprises/entreprise/nom_entreprise"/><br/>
                				<strong>Fonction:</strong><xsl:value-of select="/carnetDadresse/entreprises/entreprise/fonction"/><br/>
                				<strong>Date d'entrée:</strong><xsl:value-of select="/carnetDadresse/entreprises/entreprise/date_entree"/>
                			</td>
                		</tr>
                	</xsl:for-each>
                </table>
     
    		</body>
    	</html>
    	</xsl:template>
     
    </xsl:stylesheet>

    Quelqu'un pourrait-il m'aider?

    Merci par avance!

    • Partager sur Facebook
    • Partager sur Twitter

    Transformation XML - XSL

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown