Bonjour,

je débute toujours en XSL et ma question est, je pense, très simple.

En fait j'ai un fichier XML qui ressemble à ceci:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
<APPARTEMENT>
<SURFACE>80</SURFACE>
<NB_ETAGES>1</NB_ETAGES>
<NB_PIECES>4</NB_PIECES>
<NB_CHAMBRES>3</NB_CHAMBRES>
</APPARTEMENT>
Dans mon XSL je fais:
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
 
<xsl:if test="cml:APPARTEMENT">  << cml étant mon espace de nom que j'ai donné
<xsl:choose>
            <xsl:when test="not ((cml:APPARTEMENT/cml:SURFACE = '') and (cml:APPARTEMENT/cml:SURFACE = 0))">
              Terrain: <xsl:value-of select="cml:APPARTEMENT/cml:SURFACE_TERRAIN"/>
            </xsl:when>
            <xsl:otherwise>
              Terrain: -
            </xsl:otherwise>
            </xsl:choose>
 
            <xsl:choose>
            <xsl:when test="not ((cml:APPARTEMENT/cml:NB_CHAMBRES = '') and (cml:APPARTEMENT/cml:NB_CHAMBRES = 0))">
              Nb chambre: <xsl:value-of select="cml:APPARTEMENT/cml:NB_CHAMBRES"/>
            </xsl:when>
            <xsl:otherwise>
              Nb chambre:-
            </xsl:otherwise>
            </xsl:choose>
On voit que le noeud qui est renvoyé est "APPARTEMENT". Mais je peux recevoir le même fichier XML avec à la place du noeud APPARTEMENT, le noeud MAISON. JE n'ai pas envie de repartir avec un <xsl:if test="cml:MAISON">........

J'aimerais me rapprocher de ceci (ATTENTION la syntaxe est inventée, c'est justement l'objet de ma question):
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
J récupère dans une variable le noeud (MAISON ou APPARTEMENT ou autre...)

$TypeLogement = <xsl:value-of select="cml:APPARTEMENT"/>

Ensuite je retire le IF que j'ai fait au début et j'écris:

<xsl:choose>
            <xsl:when test="not (($TypeLogement/cml:SURFACE = '') and ($TypeLogement/cml:SURFACE = 0))">
              Terrain: <xsl:value-of select="$TypeLogement/cml:SURFACE_TERRAIN"/>
            </xsl:when>
            <xsl:otherwise>
              Terrain: -
            </xsl:otherwise>
            </xsl:choose>
...
Est il possible de faire ce ci, et si oui, comment?

Par avance, merci.

Alex