I have an xml snippet like this:
<root>
<order>
<item>
<item_type>A</item_type>
<item_type>A</item_type>
<item_type>B</item_type>
<item_type>C</item_type>
</item>
</order>
<order>
<item>
<item_type>A</item_type>
<item_type>B</item_type>
<item_type>C</item_type>
<item_type>C</item_type>
</item>
</order>
<order>
<item>
<item_type>C</item_type>
<item_type>C</item_type>
<item_type>B</item_type>
</item>
</order>
</root>
and I need to group it by item_type element, but on "order" element scope, so my desired output would be:
<root>
<order>
<item>A</item>
<item>B</item>
<item>C</item>
</order>
<order>
<item>A</item>
<item>B</item>
<item>C</item>
</order>
<order>
<item>B</item>
<item>C</item>
</order>
</root>
I'm using this xslt version 1.0, but I can't figure it out.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:key name="groups" match="order/item" use="item_type">
</xsl:key>
<xsl:template match="/">
<xsl:for-each select="//root/order">
<order>
<xsl:for-each select="item[generate-id() = generate-id(key('groups', item_type))]">
<item>
<xsl:value-of select="key('groups', item_type)"/>
</item>
</xsl:for-each>
</order>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Solution have to be in xslt 1.0.