[XSLT] Réutiliser une variable définie dans une boucle
Bonjour,
Est ce que quelqu'un peu m'aider parce que je ne m'en sors pas.
Je souhaite modifier un fichier xml c'est à dire que certains éléments d'un noeud selon certaines conditions doivent être déplacés dans un autre noeud.
Mon XML :
Code:
1 2 3 4 5
|
<catalog>
<div style="margin-left:40px"><item id="a"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>text</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><description>blablabla</description></div></div><div style="margin-left:40px"><div style="margin-left:40px"><requires>xxxxx:a_Sound</requires></div></div></item>
<div style="margin-left:40px"><item id="a_Sound"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>audio</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><isRequiredBy>xxxxx:a</isRequiredBy></div></div><div style="margin-left:40px"></item></div><div style="margin-left:40px"><item id="b"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>text</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><description>blablabla</description></div></div><div style="margin-left:40px"><div style="margin-left:40px"><requires>xxxxx:b_Sound</requires></div></div></item>
<div style="margin-left:40px"><item id="b_Sound"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>audio</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><isRequiredBy>xxxxx:b</isRequiredBy></div></div><div style="margin-left:40px"></item></div></catalog> |
En fait ce que je veux obtenir c'est :
Code:
1 2 3 4 5
|
<catalog>
<div style="margin-left:40px"><item id="a"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>text</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><requires>xxxxx:a_Sound</requires></div></div></item>
<div style="margin-left:40px"><item id="a_Sound"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>audio</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><description>blablabla</description></div></div><div style="margin-left:40px"><div style="margin-left:40px"><isRequiredBy>xxxxx:a</isRequiredBy></div></div><div style="margin-left:40px"></item></div><div style="margin-left:40px"><item id="b"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>text</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><requires>xxxxx:b_Sound</requires></div></div></item>
<div style="margin-left:40px"><item id="b_Sound"></div><div style="margin-left:40px"><div style="margin-left:40px"><medium>audio</medium></div></div><div style="margin-left:40px"><div style="margin-left:40px"><description>blablabla</description></div></div><div style="margin-left:40px"><div style="margin-left:40px"><isRequiredBy>xxxxx:b</isRequiredBy></div></div><div style="margin-left:40px"></item></div></catalog> |
<requires>xxxxx:a_Sound</requires> OU
<requires>xxxxx:b_Sound</requires>
<isRequiredBy>xxxxx:a</isRequiredBy> ou <isRequiredBy>xxxxx:b</isRequiredBy>
Pour ces cas là, il faut récupérer ce qui suit après 'xxxxx:'
Soit a_sound (ou b_Sound) ou a (ou b) Ce qui correspond alors à la valeur de l'attribut id de <item>.
Je veux déplacer <description> des item qui ne sont pas des audio dans le noeud <item> qui a comme attribut id la même valeur que la valeur récupérée dans <requires>.
Voilà ce que j'ai commencé à faire pour me permettre de récupérer les idItem Mon XSLT :
Code:
1 2 3 4 5 6 7 8 9 10
|
<xsl:template match="catalog">
<div style="margin-left:40px"><xsl:for-each select="item[contains(medium, 'audio') and (dcterms:isRequiredBy) and not(dc:description)] "></div><div style="margin-left:40px"><div style="margin-left:40px"><xsl:for-each select="dcterms:isRequiredBy"></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><xsl:variable name="idItem" select="substring-after(.,'xxxxx')"/></div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><xsl:call-template name="id"></div></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><xsl:with-param name="idItem"><xsl:value-of select="$idItem"/></xsl:with-param></div></div></div> <div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"></xsl:call-template></div></div></div><div style="margin-left:40px"><div style="margin-left:40px"></xsl:for-each></div></div><div style="margin-left:40px"></xsl:for-each></div><div style="margin-left:40px">
<xsl:for-each select="item[not(contains(medium, 'audio'))]"></div><div style="margin-left:40px"><div style="margin-left:40px"><xsl:variable name="idAnnotation" select="@id"/></div></div><div style="margin-left:40px"><div style="margin-left:40px"><xsl:call-template name="idAnno"></div></div><div style="margin-left:40px"><div style="margin-left:40px"><div style="margin-left:40px"><xsl:with-param name="idAnnotation"><xsl:value-of select="$idAnnotation"/></xsl:with-param></div></div></div><div style="margin-left:40px"><div style="margin-left:40px"></xsl:call-template></div></div><div style="margin-left:40px"></xsl:for-each></div></xsl:template>
<xsl:template name="id">
<div style="margin-left:40px"><xsl:param name="idItem"></xsl:param></div> <div style="margin-left:40px"><div style="margin-left:40px"><xsl:value-of select="$idItem"/></div></div></xsl:template>
<xsl:template name="idAnno">
<div style="margin-left:40px"><xsl:param name="idAnnotation"></xsl:param></div> <div style="margin-left:40px"><xsl:value-of select="$idAnnotation"/></div></xsl:template> |
Je veux récupérer ma variable idItem pour permettre de de faire un
<xsl:if test ="$idItem=$idAnnotation">
<xsl:copy-of select="description>
</xsl:if>
Je ne sais pas si je suis claire mais si quelqu'un comprend est ce qu'il a une idée de la façon par laquelle je peux résoudre ce pb ?
Merci