I went through XSLT Grouping Examples and Using for-each-group for high performance XSLT . I have a problem with for-each-group.
My XML
Each of your grouping steps is taking the original set of elements as input, whereas you need each step to work on the groups produced by the previous grouping step. And there are lots of other errors too, for example h1-title is not an attribute name.
It needs to be something like this:
... similar logic for the next level ...
You can nest that as deeply as you want depending how many levels you want to handle; or if you want to handle an indefinite number, you can put the code in a named template and make a recursive call to handle the next level. At the innermost level, leave out the xsl:choose and just do xsl:copy-of select="current-group().
(I just noticed the trailing spaces in the "name" attribute. If these really exist, you will need to include them in the comparison test, or do normalize-space() to get rid of them.)