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 :

Factoriser d'un code - hiérarchie [XSLT 1.0]


Sujet :

XSL/XSLT/XPATH XML

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut Factoriser d'un code - hiérarchie
    Bonjour,

    J'aimerais de l'aide pour factoriser ce code afin de le rendre plus élégant si c'est possible :

    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
    			<!-- Lien interne (Niveau 1) : Il est important d'identifier l'id de la section vers lequel pointe le lien -->
    			<xsl:when test="(starts-with(@href, '#L') or starts-with(@href, $URLHTTP)) and $IdSection!='' and /document/summary/section[@id=$IdSection]/@id">
    				<fo:basic-link internal-destination="{generate-id(/document/summary/section[@id=$IdSection]/@id)}" color="#003366" font-weight="bold">
    					<xsl:choose>
    						<xsl:when test="text()"><xsl:value-of select="text()"/></xsl:when>
    						<xsl:otherwise><xsl:value-of select="@href"/></xsl:otherwise>
    					</xsl:choose>
    				</fo:basic-link>
    			</xsl:when>
    			<!-- Lien interne (Niveau 2) : Il est important d'identifier l'id de la section vers lequel pointe le lien -->
    			<xsl:when test="(starts-with(@href, '#L') or starts-with(@href, $URLHTTP)) and $IdSection!='' and /document/summary/section/section[@id=$IdSection]/@id">
    				<fo:basic-link internal-destination="{generate-id(/document/summary/section/section[@id=$IdSection]/@id)}" color="#003366" font-weight="bold">
    					<xsl:choose>
    						<xsl:when test="text()"><xsl:value-of select="text()"/></xsl:when>
    						<xsl:otherwise><xsl:value-of select="@href"/></xsl:otherwise>
    					</xsl:choose>
    				</fo:basic-link>
    			</xsl:when>
    			<!-- Lien interne (Niveau 3) : Il est important d'identifier l'id de la section vers lequel pointe le lien -->
    			<xsl:when test="(starts-with(@href, '#L') or starts-with(@href, $URLHTTP)) and $IdSection!='' and /document/summary/section/section/section[@id=$IdSection]/@id">
    				<xsl:message><xsl:value-of select="$IdSection"/></xsl:message>
    				<fo:basic-link internal-destination="{generate-id(/document/summary/section/section/section[@id=$IdSection]/@id)}" color="#003366" font-weight="bold">
    					<xsl:choose>
    						<xsl:when test="text()"><xsl:value-of select="text()"/></xsl:when>
    						<xsl:otherwise><xsl:value-of select="@href"/></xsl:otherwise>
    					</xsl:choose>
    				</fo:basic-link>
    			</xsl:when>
    J'ai plusieurs when en fcontion du niveau de section. Je ne sais pas si je peux améliorer ce code. Comme vous pouvez le constatez, ce qui change est ceci : /document/summary/section[@id=$IdSection]/@idCar en fonction de l'arborescence, je suis au niveau 1, 2, 3... (section section/section...) car je peux avoir 2 niveaux comme je peux en avoir 10.
    Donc mettre 10 when, ça fait un peu tâche.

    Merci !

  2. #2
    Membre Expert
    Avatar de Loceka
    Profil pro
    Inscrit en
    Mars 2004
    Messages
    2 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2004
    Messages : 2 276
    Par défaut
    Et comme ça ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <xsl:when test="(starts-with(@href, '#L') or starts-with(@href, $URLHTTP)) and $IdSection!='' and /document/summary/descendant::section[@id=$IdSection]/@id">
    	<fo:basic-link internal-destination="{generate-id(/document/summary/descendant::section[@id=$IdSection]/@id)}" color="#003366" font-weight="bold">
    		<xsl:choose>
    			<xsl:when test="text()"><xsl:value-of select="text()"/></xsl:when>
    			<xsl:otherwise><xsl:value-of select="@href"/></xsl:otherwise>
    		</xsl:choose>
    	</fo:basic-link>
    </xsl:when>

  3. #3
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    Je teste et te dis ça.


  4. #4
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    C'est parfait !


  5. #5
    Membre Expert Avatar de tsuji
    Inscrit en
    Octobre 2011
    Messages
    1 558
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 558
    Par défaut
    Juste une parenthèse: le candidat principal est certainement l'axe descesdant comme on y arrive déjà, mais, ce n'est pas l'histoire complète pour racourcir une structure comme ça, dit:
    Code text : Sélectionner tout - Visualiser dans une fenêtre à part
    /document/summary/section/section/...(all sections).../section[@id=$IdSection]
    Le rendrement
    Code text : Sélectionner tout - Visualiser dans une fenêtre à part
    /document/summary/descendant::section[@id=$IdSection]
    permit une identification d'un noeud du type:
    Code text : Sélectionner tout - Visualiser dans une fenêtre à part
    /document/summary/interleaf/section/interleaf/section/section[@id=$IdSection]
    ce qui n'est pas le cas dans la question originelle.

    Je dirais il devrait ajouter un prédicat de plus pour en rendre equivalent.
    Code text : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    /document/summary/descendant::section[@id=$IdSection]
        [count(ancestor::section) = count(ancestor::*) - 2]
    Déduction de deux (2) parce que document et summary.

    Volià!

  6. #6
    Responsable Perl et Outils

    Avatar de djibril
    Homme Profil pro
    Inscrit en
    Avril 2004
    Messages
    19 822
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 19 822
    Par défaut
    Ta remarque est pertinente même si je n'en ai pas besoin car rien ne peut s'intercaler entre les sections.

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 08/02/2007, 09h11
  2. [C++] Factorisation de code
    Par xterminhate dans le forum C++
    Réponses: 6
    Dernier message: 07/11/2006, 16h21
  3. factoriser du code
    Par grabriel dans le forum Langage
    Réponses: 3
    Dernier message: 26/10/2006, 15h00
  4. Réponses: 7
    Dernier message: 01/08/2006, 11h58
  5. Réponses: 4
    Dernier message: 06/11/2003, 10h37

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