<xsl:for-each-group select="*" group-starting-with="h1"> <div> <xsl:apply-templates select="current-group()"/> </div> </xsl:for-each-group>