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] template unique pour 2 utilisations différentes


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre éclairé Avatar de sozie9372
    Inscrit en
    Mai 2005
    Messages
    713
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 713
    Points : 724
    Points
    724
    Par défaut [XSLT] template unique pour 2 utilisations différentes
    Salut !
    Voila mon problème... J'ai un objet défini par la dtd suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <!ELEMENT object (object-id, object-type, source-info, comment) >
    <!ELEMENT object-id (#PCDATA) >
    <!ELEMENT object-type (#PCDATA) >
    <!ELEMENT source-info (#PCDATA) >
    Cet objet intervient dans une importation et dans une exportation
    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
     
    <imports>
                    <source-id>the_import_source_id</source-id>
                    <source-ref>the_source_ref</source-ref>
                    <standards-ref>the_standard_ref</standards-ref>
                    <imported-objects>
                        <object>
                            <object-id>the_object_id</object-id>
                            <object-type>the_object_type</object-type>
                            <source-info>the_source_info</source-info>
                            <comment>the comment....</comment>
                        </object>
                        ...
                    </imported-objects>
    </imports>
     
    <exports>
                    <source-id>the_export_source_id</source-id>
                    <source-ref>the_source_ref</source-ref>
                    <standards-ref>the_standard_ref</standards-ref>
                    <exported-objects>
                        <object>
                            <object-id>the_object_id</object-id>
                            <object-type>the_object_type</object-type>
                            <source-info>the_source_info</source-info>
                            <comment>the comment....</comment>
                        </object>
                        ...
                    </exported-objects>
    </exports>
    Dans ma feuille de style XSL, j'ai fait comme suit :
    Pour l'import :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
        <xsl:template match="imported-objects">
            $ImportedObjects
            <xsl:apply-templates select="object"/>
            $End_ImportedObjects
        </xsl:template>
    Pour l'export :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
        <xsl:template match="test-suite-exports">
            $Begin_TestSuiteExports
            $ExportedObjects
             <xsl:apply-templates select="object"/>
            $End_ExportedObjects
            $End_TestSuiteExports
        </xsl:template>
    Et l'objet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
        <xsl:template match="object">
            $ObjectId <xsl:value-of select="object-id"/>
            $ObjectType <xsl:value-of select="object-type"/>
            $SourceInfo <xsl:value-of select="source-info"/>
            $Comment <xsl:value-of select="comment"/>
        </xsl:template>
    Or, je vourdrais, que lorsque mon objet est importé, il y ait $ImportedObject au début et $End_ImportedObject à la fin de celui-ci. De même avec $ExportedObject et $End_ExportedObject lorsque celui-ci est exporté... Comment puis-je faire ?
    Voici un exemple de résultat :
    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
     
                    $ImportedObjects
                        $ImportedObject
                            $ObjectId i
                            $ObjectType INTEGER
                            $SourceInfo NO_SOURCE
                            $Comment /* COMMENT1 */
                        $End_ImportedObject
                        $ImportedObject
                            $ObjectId k
                            $ObjectType INTEGER
                            $SourceInfo NO_SOURCE
                            $Comment /* COMMENT2 */
                        $End_ImportedObject
                    $End_ImportedObjects
    //
                    $ExportedObjects
                        $ExportedObject
                            $ObjectId i
                            $ObjectType INTEGER
                            $SourceInfo NO_SOURCE
                            $Comment /* COMMENT1 */
                        $End_ExportedObject
                        $ExportedObject
                             $ObjectId k
                             $ObjectType INTEGER
                             $SourceInfo NO_SOURCE
                             $Comment /* COMMENT2 */
                         $End_ExportedObject
                    $End_ExportedObjects
    Merki !
    +++
    Ju
    "Il y a 3 personnes en ce monde sur qui tu peux compter : moi, le pape et le cavalier solitaire ! "
    Penser à svp

  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
    Bonjour,

    en différenciant les deux cas par des templates différents, la sélection de l'un ou l'autre par le processeur XSLT se faisant selon leur parent, ça devrait le faire :
    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
     
        <xsl:template match="exported-objects/object">
          $ExportedObjects
            $ObjectId <xsl:value-of select="object-id"/>
            $ObjectType <xsl:value-of select="object-type"/>
            $SourceInfo <xsl:value-of select="source-info"/>
            $Comment <xsl:value-of select="comment"/>
          $End_ExportedObjects
        </xsl:template>
     
        <xsl:template match="imported-objects/object">
          $ImportedObjects
            $ObjectId <xsl:value-of select="object-id"/>
            $ObjectType <xsl:value-of select="object-type"/>
            $SourceInfo <xsl:value-of select="source-info"/>
            $Comment <xsl:value-of select="comment"/>
          $End_ImportedObjects
        </xsl:template>
    FAQ XML
    ------------
    « Le moyen le plus sûr de cacher aux autres les limites de son savoir est de ne jamais les dépasser »
    Giacomo Leopardi

  3. #3
    Membre éclairé Avatar de sozie9372
    Inscrit en
    Mai 2005
    Messages
    713
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 713
    Points : 724
    Points
    724
    Par défaut
    Citation Envoyé par GrandFather
    ça devrait le faire
    Je test ca tout de suite...
    "Il y a 3 personnes en ce monde sur qui tu peux compter : moi, le pape et le cavalier solitaire ! "
    Penser à svp

  4. #4
    Membre éclairé Avatar de sozie9372
    Inscrit en
    Mai 2005
    Messages
    713
    Détails du profil
    Informations personnelles :
    Âge : 41

    Informations forums :
    Inscription : Mai 2005
    Messages : 713
    Points : 724
    Points
    724
    Par défaut
    Eh ben ca l'a fait !

    Parfaitement même !!!!
    Merki !

    Par contre, j'ai une autre petite question... Est-ce normal que j'ai plein de sauts de lignes (ou lignes vides) dans mon fichier resultant alors que je n'ai rien spécifié ?
    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
     
    $Begin_TestSuiteExports
    $ExportedObjects
     
     
     
    $ExportedObject
    $ObjectId null
    $ObjectType null
    $SourceInfo null
    $Comment null
    $End_ExportedObject
     
     
    $ExportedObject
    $ObjectId object_id
    $ObjectType object_type
    $SourceInfo source_info
    $Comment the comment...
    $End_ExportedObject
     
     
    $ExportedObject
    $ObjectId object_id2
    $ObjectType object_type2
    $SourceInfo source_info2
    $Comment the comment...2
    $End_ExportedObject
     
     
     
    $End_ExportedObjects
    $End_TestSuiteExports
    "Il y a 3 personnes en ce monde sur qui tu peux compter : moi, le pape et le cavalier solitaire ! "
    Penser à svp

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

Discussions similaires

  1. [XSLT][Templates][PHP] Que choisir pour gérer ses templates
    Par ChriGoLioNaDor dans le forum Langage
    Réponses: 8
    Dernier message: 03/09/2008, 20h49
  2. [XSLT] template pour tout sauf
    Par bitbis dans le forum XSL/XSLT/XPATH
    Réponses: 3
    Dernier message: 17/12/2007, 08h57
  3. Réponses: 9
    Dernier message: 12/04/2007, 08h53
  4. utiliser un menu unique pour plusieurs pages...
    Par brouette dans le forum ActionScript 1 & ActionScript 2
    Réponses: 8
    Dernier message: 17/12/2006, 01h29
  5. [XSLT] XSL unique pour structure XML différente.
    Par SONY30 dans le forum XSL/XSLT/XPATH
    Réponses: 5
    Dernier message: 24/10/2006, 10h08

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