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 :

[XSLT][xalan] transformation et renommage d'éléments


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 7
    Points : 5
    Points
    5
    Par défaut [XSLT][xalan] transformation et renommage d'éléments
    Voici le fichier de départ : SAPinput2.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
    <?xml version="1.0" encoding="UTF-16"?> 
    <SAP xsi:noNamespaceSchemaLocation="SAP.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <ficheInformation> 
    <fiche> 
    <document> 
    <NE/> 
    </document> 
    </fiche> 
    <fiche> 
    <document> 
    <NE/> 
    </document> 
    </fiche> 
    <fiche> 
    <document> 
    <IM/> 
    </document> 
    </fiche> 
    <fiche> 
    <document> 
    <DS/> 
    </document> 
    </fiche> 
    </ficheInformation> 
    </SAP>
    Je veux le transformer en utilisant XSLT pour obtenir en sortie le fichier suivant : SAPoutputModel2.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
    <?xml version="1.0" encoding="ISO-8859-1"?> 
    <Information> 
    <ficheInfo> 
    <doc>Interne</doc> 
    </ficheInfo> 
    <ficheInfo> 
    <doc>Interne</doc> 
    </ficheInfo> 
    <ficheInfo> 
    <doc>Externe</doc> 
    </ficheInfo> 
    <ficheInfo> 
    <doc>Interne</doc> 
    </ficheInfo> 
    </Information>
    Voici le fichier de transformation : SAP02.xsl
    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="ISO-8859-1"?> 
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <!--modification de encoding--> 
    <xsl:output method="xml" encoding="ISO-8859-1" indent="yes"/> 
    <xsl:template match="/SAP"> 
    <xsl:for-each select="ficheInformation"> 
    <Information> 
    <xsl:for-each select="fiche"> 
    <ficheInfo> 
    <doc> 
    <xsl:apply-templates select="document"/> 
    </doc> 
    </ficheInfo> 
    </xsl:for-each> 
    </Information> 
    </xsl:for-each> 
    </xsl:template> 
    <xsl:template match="document"> 
    <xsl:for-each select="descendant::*"> 
    <xsl:copy-of select="local-name()"/> 
    <!--c'est là que je devrais opérer la sélection: 
    si enfants de <document> = NE ou DS alors renvoyer Interne en sortie 
    si enfants de <document> = IM alors renvoyer Externe en sortie--> 
    </xsl:for-each> 
    </xsl:template> 
    </xsl:stylesheet>
    Voici ce que SAP02.xsl me retourne en output : SAPoutput02.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
    <?xml version="1.0" encoding="ISO-8859-1"?> 
    <Information> 
    <ficheInfo> 
    <doc>NE</doc> 
    </ficheInfo> 
    <ficheInfo> 
    <doc>NE</doc> 
    </ficheInfo> 
    <ficheInfo> 
    <doc>IM</doc> 
    </ficheInfo> 
    <ficheInfo> 
    <doc>DS</doc> 
    </ficheInfo> 
    </Information>
    Je n'arrive pas à faire le changement de valeur en sortie selon la condition commentée dans le fichier SAP02.xsl
    Merci de venir à mon aide.

  2. #2
    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
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    <xsl:copy-of select="local-name()"/> 
    <!--c'est là que je devrais opérer la sélection: 
    si enfants de <document> = NE ou DS alors renvoyer Interne en sortie 
    si enfants de <document> = IM alors renvoyer Externe en sortie-->
    plutot

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    	<xsl:choose>
    		<xsl:when test="name()='IM'">Externe</xsl:when>
    		<xsl:when test="name()='NE' or name()='DS'">Interne</xsl:when>
     
    		<xsl:otherwise><xsl:value-of select="name()"></xsl:value-of></xsl:otherwise>
    	</xsl:choose>

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 7
    Points : 5
    Points
    5
    Par défaut
    Merci bien pour cette réponse. Ca fonctionne
    Bernols

Discussions similaires

  1. [XSLT] Transformer du texte en élément
    Par Hefbee dans le forum XSL/XSLT/XPATH
    Réponses: 9
    Dernier message: 17/10/2007, 21h51
  2. [XML - CSS - XSLT] Non-transformation ET non-mise en forme !?
    Par ghohm dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 18/05/2006, 17h44
  3. [xslt][xalan] convertir caracteres en ascii
    Par bernols dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 04/05/2006, 11h24
  4. [XSLT][xalan] créer un identifiant
    Par bernols dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 10/04/2006, 18h46
  5. [XSLT][.NET] Transformer du XML dans un string
    Par Floyd dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 31/10/2005, 15h41

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