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 :

XML Transformation grace a un XSLT


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    111
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 111
    Points : 59
    Points
    59
    Par défaut XML Transformation grace a un XSLT
    Bonjours j'ai un fichier XML que je souhaite transformer a l'aide d'un fichier XSLT.
    J'ai donc fais ce XSLT :
    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
     
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     
    		<xsl:template match="/root">
     
    		<xsl:result-document href="auNorme.xml">
     
    			<!--<?xml version="1.0" encoding="UTF-8"?>-->
    			<root>
     
    				<xsl:for-each select="eleve">
     
    					<!-- Cree variable-->
    					<xsl:variable name="vide" select="''"/>		
    					<xsl:variable name="numero" select="num"/>
     
    					<xsl:variable name="nbre" select="position()"/>
     
    					<xsl:if test="$vide!=$numero">	
     
    							<!--Affiche que pour un deuxième passage-->
    							<xsl:if test="$nbre!=1">
    									</eleve>
    							</xsl:if>
     
    							<eleve>
    							<num><xsl:value-of select="$numero"/></num>
    							<nom><xsl:value-of select="nom"/></nom>
    							<prenom><xsl:value-of select="prenom"/></prenom>
     
    							<notes>
    					</xsl:if>
     
    					<xsl:if test="$vide=$numero">
    							<notes>
    					</xsl:if>
     
    						<matiere><xsl:value-of select="matiere"/></matiere>
    						<note><xsl:value-of select="note"/></note>
     
    						</notes>
     
    				</xsl:for-each>
     
    				</eleve>
    			</root>
    		</xsl:result-document>
    		</xsl:template>
    	</xsl:stylesheet>
    Le problème c'est que j'ai des erreur car certaine de mes balise ne se ferme pas dans la boucle ou elle a été ouverte.

    Comment arranger cela ?
    Es-t'-il possible de faire des balises sans les fermer dans leur boucle mais plus bas....???

    MERCI
    SILVIA

  2. #2
    Expert éminent
    Avatar de GrandFather
    Inscrit en
    Mai 2004
    Messages
    4 587
    Détails du profil
    Informations personnelles :
    Âge : 54

    Informations forums :
    Inscription : Mai 2004
    Messages : 4 587
    Points : 7 103
    Points
    7 103
    Par défaut Re: XML Transformation grace a un XSLT
    Bonjour,

    Citation Envoyé par Silvia12
    Es-t'-il possible de faire des balises sans les fermer dans leur boucle mais plus bas....???
    Non, pour la bonne et simple raison que XSLT s'écrit lui-même en XML, et qu'à ce titre il doit être lui-même bien formé.

    Il faut donc que tu réorganises ta feuille de style XSLT.

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    111
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 111
    Points : 59
    Points
    59
    Par défaut
    Et Zut...
    Comment puis-je transformer un XML comme ceci :
    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
     
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <root>
    	<eleve>
    		<num>1</num>
    		<nom>Dupond</nom>
    		<prenom>Jerome</prenom>
    		<matiere>Math</matiere>
    		<note>10</note>
    	</eleve>
    	<eleve>
    		<num/>
    		<nom/>
    		<prenom/>
    		<matiere>Espagnol</matiere>
    		<note>12</note>
    	</eleve>
    	<eleve>
    		<num>2</num>
    		<nom>Durand</nom>
    		<prenom>Corine</prenom>
    		<matiere>Anglais</matiere>
    		<note>11</note>
    	</eleve>
    </root>
    En ceci

    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    	<eleve>
    		<num>1</num>
    		<nom>Dupond</nom>
    		<prenom>Jerome</prenom>
    		<notes>
    			<matiere>Math</matiere>
    			<note>10</note>
    		</notes>
    		<notes>
    			<matiere>Espagnol</matiere>
    			<note>12</note>
    		</notes>
    	</eleve>
    	<eleve>
    		<num>2</num>
    		<nom>Durand</nom>
    		<prenom>Corrine</prenom>
    		<notes>
    			<matiere>Anglais</matiere>
    			<note>11</note>
    		</notes>
    	</eleve>
    </root>
    Donner moi une idée svp
    MERCI

  4. #4
    Membre éclairé Avatar de luta
    Inscrit en
    Novembre 2003
    Messages
    1 038
    Détails du profil
    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 038
    Points : 786
    Points
    786
    Par défaut
    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
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="/root">
          <xsl:result-document href="auNorme.xml">
             <root>
                <xsl:for-each select="eleve[num!='']">
    				<xsl:copy-of select="num"/>
    				<xsl:copy-of select="nom"/>
    				<xsl:copy-of select="prenom"/>
    				<xsl:element name="notes">
    					<xsl:copy-of select="matiere"/>
    					<xsl:copy-of select="note"/>
    				</xsl:element>
    				<xsl:variable name="currentId" select="generate-id()"/>
    				<xsl:for-each select="following-sibling::eleve[num!='' and generate-id(preceding-sibling::eleve[1]) = $currentId ] "
    			</xsl:for-each>
    			</root>
          </xsl:template>
       </xsl:stylesheet>
    non testé

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    111
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2004
    Messages : 111
    Points : 59
    Points
    59
    Par défaut
    Citation Envoyé par tiscars
    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
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:template match="/root">
          <xsl:result-document href="auNorme.xml">
             <root>
                <xsl:for-each select="eleve[num!='']">
    				<xsl:copy-of select="num"/>
    				<xsl:copy-of select="nom"/>
    				<xsl:copy-of select="prenom"/>
    				<xsl:element name="notes">
    					<xsl:copy-of select="matiere"/>
    					<xsl:copy-of select="note"/>
    				</xsl:element>
    				<xsl:variable name="currentId" select="generate-id()"/>
    				<xsl:for-each select="following-sibling::eleve[num!='' and generate-id(preceding-sibling::eleve[1]) = $currentId ] "
    			</xsl:for-each>
    			</root>
          </xsl:template>
       </xsl:stylesheet>
    non testé

    Non, ca fais pas tout a fait ce que je veux, je vais essayé de m'aider de ton code....

    Merci quand meme

  6. #6
    Membre éclairé Avatar de luta
    Inscrit en
    Novembre 2003
    Messages
    1 038
    Détails du profil
    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 038
    Points : 786
    Points
    786
    Par défaut
    j aurais pu factoriser un peu plus peut etre mais ca a l air de marcher comme ça
    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
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    	<xsl:output method="xml"/>
    	<xsl:template match="/root">
    		<root>
    			<xsl:for-each select="eleve[num!='']">
    				<xsl:copy-of select="num"/>
    				<xsl:copy-of select="nom"/>
    				<xsl:copy-of select="prenom"/>
    				<xsl:element name="notes">
    					<xsl:copy-of select="matiere"/>
    					<xsl:copy-of select="note"/>
    				</xsl:element>
    				<xsl:variable name="currentId" select="generate-id()"/>
    				<xsl:choose>
    					<xsl:when test="following-sibling::eleve[num!='']">
    						<xsl:for-each select="following-sibling::eleve[num!='' and generate-id(preceding-sibling::eleve[num!=''][1]) = $currentId ] ">
    							<xsl:element name="notes">
    								<xsl:copy-of select="matiere"/>
    								<xsl:copy-of select="note"/>
    							</xsl:element>
    						</xsl:for-each>
    					</xsl:when>
    					<xsl:otherwise>
    						<xsl:for-each select="following-sibling::eleve">
    							<xsl:element name="notes">
    								<xsl:copy-of select="matiere"/>
    								<xsl:copy-of select="note"/>
    							</xsl:element>
    						</xsl:for-each>
    					</xsl:otherwise>
    				</xsl:choose>
    			</xsl:for-each>
    		</root>
    	</xsl:template>
    </xsl:stylesheet>

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

Discussions similaires

  1. Transformer XML de 500 Mo via XSLT
    Par Pignoufy dans le forum Format d'échange (XML, JSON...)
    Réponses: 2
    Dernier message: 08/11/2005, 20h58
  2. [XML][XSLT] transformer le xml en binaire via une xslt
    Par chama dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 25/07/2005, 11h42
  3. xhtml-->xml transformation xslt
    Par yos dans le forum XSL/XSLT/XPATH
    Réponses: 10
    Dernier message: 15/06/2005, 15h23
  4. [XSLT][XSD>XML]transformer xsd en xml avec xslt
    Par émile-henri dans le forum XSL/XSLT/XPATH
    Réponses: 7
    Dernier message: 14/06/2005, 15h06
  5. xhtml->xml transformation xslt
    Par yos dans le forum XSL/XSLT/XPATH
    Réponses: 6
    Dernier message: 14/06/2005, 11h17

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