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"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:key name="regrouper" match="foo" use="@name"/>
<xsl:template match="root">
<root>
<xsl:apply-templates select="foo[generate-id(.)=generate-id(key('regrouper',@name)[1])]"/>
</root>
</xsl:template>
<xsl:template match="foo">
<foo name="{@name}">
<xsl:apply-templates select="//bar[../@name=current()/@name]"/>
</foo>
</xsl:template>
<xsl:template match="bar">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet> |