+ <template match="html:dt|html:dd" mode="LesML:finalize-list">
+ <param name="used-footnotes" select="/.."/>
+ <variable name="current-level" select="number(&level-pi;)"/>
+ <variable name="notinlist" select="following-sibling::node()[not((self::html:dt or self::html:dd) and &level-pi;=$current-level)][1]"/>
+ <variable name="inlist" select=".|exslset:leading(following-sibling::node(), $notinlist)"/>
+ <variable name="lasts-in-pairing" select="$inlist[self::html:dd and not(exslset:intersection(following-sibling::node()[1]/self::html:dd, $inlist))]|$inlist[last()]"/>
+ <element name="dl" namespace="&xhtml;">
+ <for-each select="$lasts-in-pairing">
+ <variable name="prev-position" select="position()-1"/>
+ <variable name="prev-last" select="$lasts-in-pairing[$prev-position]"/>
+ <element name="div" namespace="&xhtml;">
+ <for-each select="exslset:leading(exslset:trailing($inlist, $prev-last), .)|.">
+ <if test="position()=1 and self::html:dd">
+ <element name="dt" namespace="&xhtml;"/>
+ </if>
+ <copy>
+ <apply-templates select="." mode="LesML:finalize-attributes"/>
+ <apply-templates select="node()" mode="LesML:finalize">
+ <with-param name="used-footnotes" select="$used-footnotes"/>
+ </apply-templates>
+ </copy>
+ <if test="position()=last() and self::html:dt">
+ <element name="dd" namespace="&xhtml;"/>
+ </if>
+ </for-each>
+ </element>
+ </for-each>
+ </element>
+ <if test="$notinlist/self::html:dt or $notinlist/self::html:dd">
+ <apply-templates select="$notinlist" mode="LesML:finalize-list">
+ <with-param name="used-footnotes" select="$used-footnotes"/>
+ </apply-templates>
+ </if>
+ </template>