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:
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 !