Laissons le support xpath ou xslt complet ou incomplet à part, on parle le xpath et le xslt en soi.
Le xpath qui identifier le groupe de item avec @cat consécutif (A B C) peut s'écrire comme ça :
"item[@cat='A' and following-sibling::item[1]/@cat='B' and following-sibling::item[2]/@cat='C']"
Le xpath qui identifier le groupe de item avec @cat consécutif (B C) qui n'est pas du groupe (A B C) peut s'écrire comme ça :
"item[@cat='B' and preceding-sibling::item[1]/@cat!='A' and following-sibling::item[1]/@cat='C']"
Parlant xslt, on construie ces trois templates au titre d'exemple :
1 2 3 4 5 6 7 8 9 10 11 12
| <xsl:template match="item[@cat='A' and following-sibling::item[1]/@cat='B' and following-sibling::item[2]/@cat='C']">
<value><xsl:value-of select="." /></value>
<value><xsl:value-of select="following-sibling::item[1]" /></value>
<value><xsl:value-of select="following-sibling::item[2]" /></value>
</xsl:template>
<xsl:template match="item[@cat='B' and preceding-sibling::item[1]/@cat!='A' and following-sibling::item[1]/@cat='C']">
<value><xsl:value-of select="." /></value>
<value><xsl:value-of select="following-sibling::item[1]" /></value>
</xsl:template>
<xsl:template match="item" /> |
Les sorties seraient :
1 2 3 4 5
| <value>2</value>
<value>3</value>
<value>4</value>
<value>6</value>
<value>7</value> |
Voilà tout. Mais voyez-vous ? ce type d'écriture n'est pas de xml
Si on ne connaît pas assez encore les dossiers xml, on ne serait pas prêt à faire ce genre de problèmes en xpath et xslt.
Partager