Nevermind...i got it i think
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:key name="k1" match="tag/*" use="*/*/matchfield"/>
<xsl:template match="tag">
<xsl:copy>
<xsl:for-each select="*[generate-id() = generate-id(key('k1', */*/matchfield)[1])]">
<group>
<xsl:copy-of select="key('k1', */*/matchfield)"/>
</group>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
|