It would help if you supplied the input and output as well-formed XML documents, and used tags that matched those in your stylesheet. You're making your readers do a lot of extra work to save yourself a few keystrokes, and the result is that you don't get an answer.
My first recommendation for grouping problems would be: use XSLT 2.0. If you can't do that, my recommendation would be: use Muenchian grouping.
I can't see anything in this example that makes it different from the standard grouping examples found in every XSLT textbook, but that might be because you haven't explained it well enough.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference