Note that with my suggested stylesheet and your original input you will get a leading
because of the whitespace before the first child element.
You can avoid that by using
Code:
<xsl:for-each-group select="node()[not(self::text()[not(normalize-space())])]"
group-adjacent="self::em[@style = 'H1'] or self::em[@style = 'H2']">
You might also want <xsl:output indent="yes"/>