In XSLT 1.0, using Muenchian grouping.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="division" match="User" use="@Division" />
<xsl:template match="Users">
<AllUsers>
<xsl:apply-templates select="User[generate-id(.)=generate-id(key('division',@Division)[1])]"/>
</AllUsers>
</xsl:template>
<xsl:template match="User">
<Division value="{@Division}">
<xsl:for-each select="key('division', @Division)">
<User>
<id><xsl:value-of select="@id" /></id>
<name><xsl:value-of select="@name" /></name>
</User>
</xsl:for-each>
</Division>
</xsl:template>
</xsl:stylesheet>
In XSLT 2.0, use xsl:foreach-group
<xsl:output method="xml" indent="yes" />
<xsl:template match="Users">
<AllUsers>
<xsl:for-each-group select="User" group-by="@Division">
<Division value="{@Division}">
<xsl:for-each select="current-group()">
<User>
<id><xsl:value-of select="@id" /></id>
<name><xsl:value-of select="@name" /></name>
</User>
</xsl:for-each>
</Division>
</xsl:for-each-group>
</AllUsers>
</xsl:template>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…