Which is the best way to group Elements based on attribute value using XSLT? Would it be better to use XSLT 2.0 or higher?
Many thank in advance for your help
Thomas
Original XML:
<transaction>
<record type="1" >
<field number="1" >
<item >223</item>
</field>
</record>
<record type="14" >
<field number="1" >
<item >777</item>
</field>
</record>
<record type="14" >
<field number="1" >
<item >555</item>
</field>
</record>
</transaction>
Result after grouping:
<transaction>
<records type="1" >
<record type="1" >
<field number="1" >
<item >223</item>
</field>
</record>
</records>
<records type="14" >
<record type="14" >
<field number="1" >
<item >777</item>
</field>
</record>
<record type="14" >
<field number="1" >
<item >555</item>
</field>
</record>
</records>
</transaction>
xsl:for-each-groupconstruct, which makes grouping much easier. So, in this case you would do<xsl:for-each-group select="record" group-by="@type" />