XSLT test sur xsl:template
Bonjour,
J'ai un fichier XML
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
<?xml version="1.0" encoding="UTF-8"?>
<CategoriesList>
<Category ID="1" >
<Name ID="1395687" Value="Libelle1" langid="1"/>
<Name ID="1395689" Value="" langid="3"/>
</Category>
<Category ID="2" >
<Name ID="1395687" Value="" langid="1"/>
<Name ID="1395689" Value="Libelle2" langid="3"/>
</Category>
</CategoriesList> |
Je voudrait faire une mise à plat du fichier xml et récupérer les infos utiles.
Donc dans category=1 avoir l'attribut name=Libelle1
et Category=2 avoir l'attribut name=Libelle2
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 29 30 31 32
|
<?xml version="1.0" encoding="UTF-8"?>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="CategoriesList">
<xsl:apply-templates select="Category"/>
</xsl:template>
<xsl:template match="Category">
<xsl:element name="Category">
<xsl:attribute name="ID">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:apply-templates select="Name"/>
</xsl:element>
</xsl:template>
<xsl:template match="Name[@langid=3]">
<xsl:attribute name="Name">
<xsl:value-of select="@Value"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="Nom[@langid=1]">
<xsl:attribute name="Name">
<xsl:value-of select="@Value"/>
</xsl:attribute>
</xsl:template> |
Mais ce code, ne me retourne que l'attribut name dont l'attribut langid=3
Or je voudrait lui dire que si langid=3 est vide de prendre langid=1
je tourne autour de cette solution qui ne marche pas et je comprends plus ou moins pourquoi ... mais je suis bloqué
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<xsl:template match="Category">
<xsl:element name="Category">
<xsl:attribute name="ID">
<xsl:value-of select="@ID"/>
</xsl:attribute>
<xsl:if test="Name[@langid=3] != '' ">
<xsl:apply-templates select="Name"/>
</xsl:if>
<xsl:if test="Name[@langid=3] = '' ">
<xsl:apply-templates select="Nom"/>
</xsl:if>
</xsl:element>
</xsl:template> |