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 :

Utilisation d'un template


Sujet :

XSL/XSLT/XPATH XML

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    553
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 553
    Points : 566
    Points
    566
    Par défaut Utilisation d'un template
    Bonjour,
    J'ai un xml comem ci-dessous

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    <?xml version="1.0" encoding="utf-8"?>
    <RestrictionAll xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <RestrictionData>
        <ClientID>XXXXXXX</ClientID>
        <UniqueID>0</UniqueID>
        <CodeService>YYYYY</CodeService>
        <LienDeco>1</LienDeco>
        <Action>ACTIVE</Action>
        <KitID>1</KitID>
        <TypeData>TTTT</TypeData>
      </RestrictionData>
    </RestrictionAll>
    Je veux lui appliquer le template

    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
     
    <xsl:template name="RestrictionData" match="RestrictionData">Restriction Data:<xsl:value-of select="$newline"/>
        <xsl:if test="ClientID">Identifiant client: <xsl:value-of select="ClientID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="KitID">Identifiant Kit: <xsl:value-of select="KitID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="UniqueID">Identifiant service: <xsl:value-of select="UniqueID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="CodeService">Code service restriction: <xsl:value-of select="CodeService"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="LienDeco">Lien de déconnexion: <xsl:value-of select="LienDeco"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>  
        Type de Restriction :<xsl:choose>
         <xsl:when test="TypeData = 'TROISG'">DataRoaming 3G</xsl:when>
         <xsl:when test="TypeData = 'MVNO'">DataRoaming MVNO</xsl:when>
         <xsl:when test="TypeData = 'WIFI'">WIFI OFF LOAD</xsl:when>     
         <xsl:otherwise>
           <xsl:value-of select="TypeData"></xsl:value-of>
         </xsl:otherwise>
         </xsl:choose>
        <xsl:if test="Action">Action restriction: <xsl:choose>
            <xsl:when test="Action = 'ACTIVE'">Activer la restriction</xsl:when>
            <xsl:when test="Action = 'DESACTIVE'">Désactiver la restriction</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="Action"></xsl:value-of>
            </xsl:otherwise>
          </xsl:choose><xsl:value-of select="$newline"/>
        </xsl:if>
      </xsl:template>
    Je rentre bien dans le templaet mais tous les test <xsl:if test=" et le <xsl:choose> ne fonctionne pas et je ne comprend pas pourquoi

    J'ai un doute sur l'utilisation du match

    Merci d'avance pour votre aide

  2. #2
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 567
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 567
    Points : 21 635
    Points
    21 635
    Par défaut
    Chez moi ça marche. Tu aurais pas des xmlns un peu partout et que tu ne nous aurais pas montrés, dans tes balises ?

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    553
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 553
    Points : 566
    Points
    566
    Par défaut
    J'ai résolu mon problème en faisant ceci mais je ne trouve pas çà très propre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     <xsl:template name="RestrictionData">Restriction Data:<xsl:value-of select="$newline"/>   
        <xsl:if test="RestrictionData/ClientID">Identifiant client: <xsl:value-of select="RestrictionData/ClientID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>

  4. #4
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 567
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 567
    Points : 21 635
    Points
    21 635
    Par défaut
    Citation Envoyé par helios77 Voir le message
    J'ai résolu mon problème en faisant ceci mais je ne trouve pas çà très propre

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
     <xsl:template name="RestrictionData">Restriction Data:<xsl:value-of select="$newline"/>   
        <xsl:if test="RestrictionData/ClientID">Identifiant client: <xsl:value-of select="RestrictionData/ClientID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
    Ah, d'accord.

    Vire-moi ce name="RestrictionData"
    Remets le match="RestrictionData"

    Enlève le truc qui faisait <xsl:call-template>. Il a rien à faire là.

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    553
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 553
    Points : 566
    Points
    566
    Par défaut
    Si je retire le <xsl:call-template>, comment il saura quel template utiliser ?

    j'en ai plusieurs dans mon xslt

  6. #6
    Modérateur

    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    12 567
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 12 567
    Points : 21 635
    Points
    21 635
    Par défaut
    Citation Envoyé par helios77 Voir le message
    Si je retire le <xsl:call-template>, comment il saura quel template utiliser ?
    Parce que l'élément s'appelle <RestrictionData>, exactement ce que dit le match.

    Si c'est bien fait, il y a des <xsl:apply-templates/> un peu partout, ou alors il n'y en a pas besoin. Tout dépend de ton cas précis.

  7. #7
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    553
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 553
    Points : 566
    Points
    566
    Par défaut
    Voici ma XSLT complète

    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
    78
    79
    80
    81
    82
    83
    84
    85
    86
     
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ms="urn:schemas-microsoft-com:xslt">
        <xsl:output encoding="UTF-8" method="text"></xsl:output>
     
    <xsl:variable name="newline">
    <xsl:text>
    </xsl:text>
    </xsl:variable>
     
    <xsl:template match="/">Detail Restriction:<xsl:value-of select="$newline"/><xsl:apply-templates></xsl:apply-templates>
    </xsl:template>
     
    <xsl:template match="RestrictionAll">        
        <xsl:if test="ListeRestrictionTel/RestrictionTel"><xsl:for-each select="ListeRestrictionTel/RestrictionTel">
            <xsl:call-template name="ListeRestrictionTel"></xsl:call-template>
        </xsl:for-each>
        </xsl:if>
        <xsl:if test="RestrictionVOD">
            <xsl:call-template name="RestrictionVOD"></xsl:call-template>    
        </xsl:if>
        <xsl:if test="RestrictionData">
          <xsl:call-template name="RestrictionData"></xsl:call-template>
        </xsl:if>
    </xsl:template>
     
    <xsl:template name="ListeRestrictionTel" match="ListeRestrictionTel/RestrictionTel">Restriction Téléphonique:<xsl:value-of select="$newline"/>
        <xsl:if test="ClientID">Identifiant client: <xsl:value-of select="ClientID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>   
        <xsl:if test="KitID">Identifiant Kit: <xsl:value-of select="KitID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if> 
        <xsl:if test="CodeServiceRestriction">Code service restriction: <xsl:value-of select="CodeServiceRestriction"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if> 
        <xsl:if test="UniqueID">Identifiant service: <xsl:value-of select="UniqueID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if> 
        <xsl:if test="LienDeco">Lien de déconnexion: <xsl:value-of select="LienDeco"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if> 
        <xsl:if test="Action">Action restriction: <xsl:choose>
            <xsl:when test="Action = 'ACTIVE'">Activer la restriction (ajouter le service de restriction)</xsl:when>
            <xsl:when test="Action = 'DESACTIVE'">Désactiver la restriction (annuler le service de restriction)</xsl:when>
            <xsl:when test="Action = 'ACTIVE_INTERNATIONAL_SPECIAUX'">Activer la restriction International et numéros spéciaux</xsl:when>
            <xsl:when test="Action = 'ACTIVE_MAGHREB'">Activer la restriction Maghreb</xsl:when>
          <xsl:otherwise><xsl:value-of select="Action"></xsl:value-of></xsl:otherwise>
        </xsl:choose><xsl:value-of select="$newline"/>
        </xsl:if>
    </xsl:template>
    <xsl:template name="RestrictionVOD">Restriction VOD:<xsl:value-of select="$newline"/>
        <xsl:if test="RestrictionVOD/ClientID">Identifiant client: <xsl:value-of select="RestrictionVOD/ClientID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>   
        <xsl:if test="RestrictionVOD/CodeRaisonRestriction">Code raison restriction VOD: <xsl:value-of select="RestrictionVOD/CodeRaisonRestriction"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="RestrictionVOD/Action">Action restriction: <xsl:choose>
            <xsl:when test="RestrictionVOD/Action = 'ACTIVE'">Activer la restriction VOD</xsl:when>
            <xsl:when test="RestrictionVOD/Action = 'DESACTIVE'">Désactiver la restriction VOD</xsl:when>
            <xsl:otherwise><xsl:value-of select="Action"></xsl:value-of></xsl:otherwise>
        </xsl:choose><xsl:value-of select="$newline"/>
        </xsl:if>
    </xsl:template>
     <xsl:template name="RestrictionData">Restriction Data:<xsl:value-of select="$newline"/>   
        <xsl:if test="RestrictionData/ClientID">Identifiant client: <xsl:value-of select="RestrictionData/ClientID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="RestrictionData/KitID">Identifiant Kit: <xsl:value-of select="RestrictionData/KitID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="RestrictionData/UniqueID != 0">Identifiant service: <xsl:value-of select="RestrictionData/UniqueID"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="RestrictionData/CodeService">Code service restriction: <xsl:value-of select="RestrictionData/CodeService"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>
        <xsl:if test="RestrictionData/LienDeco">Lien de déconnexion: <xsl:value-of select="RestrictionData/LienDeco"></xsl:value-of><xsl:value-of select="$newline"/>
        </xsl:if>Type de Restriction :<xsl:choose>
         <xsl:when test="RestrictionData/TypeData = 'TROISG'">DataRoaming 3G</xsl:when>
         <xsl:when test="RestrictionData/TypeData = 'MVNO'">DataRoaming MVNO</xsl:when>
         <xsl:when test="RestrictionData/TypeData = 'WIFI'">WIFI OFF LOAD</xsl:when>     
         <xsl:otherwise>
           <xsl:value-of select="RestrictionData/TypeData"></xsl:value-of>
         </xsl:otherwise>
         </xsl:choose><xsl:value-of select="$newline"/>
        <xsl:if test="RestrictionData/Action">Action restriction: <xsl:choose>
            <xsl:when test="RestrictionData/Action = 'ACTIVE'">Activer la restriction</xsl:when>
            <xsl:when test="RestrictionData/Action = 'DESACTIVE'">Désactiver la restriction</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="RestrictionData/Action"></xsl:value-of>
            </xsl:otherwise>
          </xsl:choose><xsl:value-of select="$newline"/>
        </xsl:if>
      </xsl:template>
     
    </xsl:stylesheet>

Discussions similaires

  1. [MySQL] Récupérer valeur d'un select en utilisant systeme de template
    Par Blade dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 28/11/2008, 10h43
  2. Utilisation avancée des templates
    Par olivier2019 dans le forum Eclipse Java
    Réponses: 4
    Dernier message: 03/04/2008, 14h26
  3. utilisation d'une template css comme Master page
    Par phpieur dans le forum ASP.NET
    Réponses: 1
    Dernier message: 30/04/2007, 10h42
  4. [XSLT] utilisation d'un template ?
    Par ghohm dans le forum XSL/XSLT/XPATH
    Réponses: 11
    Dernier message: 11/09/2006, 17h37
  5. Utilisation d'un template avec une map
    Par bonano dans le forum Langage
    Réponses: 6
    Dernier message: 09/08/2006, 21h26

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