Regrouper par elements identiques
Bonjour,
A partir de ce XML :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?xml version="1.0" encoding="UTF-8"?>
<doc>
<spe>
<id>1</id>
<ci>a</ci>
<ci>b</ci>
</spe>
<spe>
<id>2</id>
<ci>a</ci>
<ci>b</ci>
<ci>c</ci>
</spe>
<spe>
<id>3</id>
<ci>a</ci>
<ci>b</ci>
<ci>d</ci>
</spe>
</doc> |
j'aimerai obtenir le résultat suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?xml version="1.0" encoding="UTF-8"?>
<doc>
<commun>
<id>1</id>
<id>2</id>
<id>3</id>
<ci>a</ci>
<ci>b</ci>
</commun>
<commun>
<id>2</id>
<ci>c</ci>
</commun>
<commun>
<id>3</id>
<ci>d</ci>
</commun>
</doc> |
voici un essai d'xsl qui ne donne pas le résultat souhaité :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<doc>
<xsl:for-each-group select="//ci" group-by="text()">
<commun>
<xsl:for-each select="current-group()">
<id>
<xsl:value-of select="preceding-sibling::id"/>
</id>
</xsl:for-each>
<ci>
<xsl:value-of select="current-grouping-key()"/>
</ci>
</commun>
</xsl:for-each-group>
</doc>
</xsl:template>
</xsl:stylesheet> |
Merci pour votre aide.