5 hours before your post someone else asked about grouping: check the answer to that post.
If you are producing multiple output documents you will want to use XSLT 2.0 with its xsl:result-document instruction.
<xsl:for-each-group select="row" group-by="id">
<xsl:result-document href="{current-grouping-key()}.xml">
<xsl:copy-of select="current-group()"/>
</xsl:result-document>
</xsl:for-each-group>
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference