I have an xml datasource which looks like this:
The following stylesheet shows a general approach to grouping at multiple levels:
It produces the following output on your input:
HR SD MM HR SD SD MM