+ <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </for-each>
+ </otherwise>
+ </choose>
+ </if>
+ </template>
+ <template match="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6" mode="LesML:finalize-tree">
+ <if test="not(preceding-sibling::node()[position()=1 and self::html:div/processing-instruction()[local-name()='LesML-Continuation']]) or preceding-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][position()=1 and self::html:* and contains(' h1 h2 h3 h4 h5 h6 ', local-name())]">
+ <choose>
+ <when test="following-sibling::node()[position()=1 and self::html:div]/processing-instruction()[local-name()='LesML-Continuation']">
+ <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
+ <element name="hgroup" namespace="&xhtml;">
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ </copy>
+ <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </for-each>
+ </element>
+ </when>
+ <otherwise>
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ </copy>
+ </otherwise>
+ </choose>