+ </when>
+ <otherwise>
+ <element name="span" namespace="&xhtml;">
+ <copy-of select="$start-node/preceding-sibling::node()"/>
+ <for-each select="$start-tokens[position()!=last()]">
+ <value-of select="."/>
+ <if test="position()!=last()">
+ <value-of select="$start-sigil"/>
+ </if>
+ </for-each>
+ <processing-instruction name="LesML-Token-Escape">
+ <value-of select="$start-sigil"/>
+ </processing-instruction>
+ <value-of select="$start-tokens[last()]"/>
+ <copy-of select="$start-node/following-sibling::node()"/>
+ <value-of select="$end-sigil"/>
+ <value-of select="substring-after($end-node, $end-sigil)"/>
+ <copy-of select="$end-node/following-sibling::node()"/>
+ </element>
+ </otherwise>
+ </choose>
+ </when>
+ <when test="$end-node">
+ <element name="span" namespace="&xhtml;">
+ <copy-of select="$end-node/preceding-sibling::node()"/>
+ <value-of select="substring-before($end-node, $end-sigil)"/>
+ <processing-instruction name="LesML-Token-Escape">
+ <value-of select="$end-sigil"/>
+ </processing-instruction>
+ <value-of select="substring-after($end-node, $end-sigil)"/>
+ <copy-of select="$end-node/following-sibling::node()"/>
+ </element>
+ </when>
+ <otherwise>
+ <processing-instruction name="LesML-All-Done"/>
+ </otherwise>
+ </choose>
+ </template>
+ <template match="node()" mode="LesML:comment">
+ <param name="footnote-ids" select="/.."/>
+ <variable name="result">
+ <choose>
+ <when test="self::*">
+ <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
+ <variable name="after-start">
+ <if test="$start-node">
+ <value-of select="substring-after($start-node, '⌦')"/>
+ </if>
+ </variable>
+ <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
+ <choose>
+ <when test="$start-node and $has-end-node">
+ <variable name="following">
+ <value-of select="$after-start"/>
+ <copy-of select="$start-node/following-sibling::node()"/>
+ </variable>
+ <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
+ <variable name="comment">
+ <for-each select="$end-node/preceding-sibling::node()">
+ <value-of select="."/>
+ </for-each>
+ <value-of select="substring-before($end-node, '⌫')"/>
+ </variable>
+ <variable name="rest-fragment">
+ <element name="span" namespace="&xhtml;">
+ <value-of select="substring-after($end-node, '⌫')"/>
+ <copy-of select="$end-node/following-sibling::node()"/>
+ </element>
+ </variable>
+ <variable name="commented-rest-fragment">
+ <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </variable>
+ <copy>
+ <copy-of select="@*"/>
+ <copy-of select="$start-node/preceding-sibling::node()"/>
+ <copy-of select="substring-before($start-node, '⌦')"/>
+ <call-template name="LesML:comment-out">
+ <with-param name="source" select="string($comment)"/>
+ </call-template>
+ <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
+ </copy>
+ </when>
+ <when test="$start-node">
+ <variable name="rest-fragment">
+ <element name="div" namespace="&xhtml;">
+ <value-of select="substring-after($after-start, '⌦')"/>
+ <copy-of select="$start-node/following-sibling::node()"/>
+ </element>
+ </variable>
+ <variable name="commented-rest-fragment">
+ <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </variable>
+ <copy>
+ <copy-of select="@*"/>
+ <copy-of select="$start-node/preceding-sibling::node()"/>
+ <copy-of select="substring-before($start-node, '⌦')"/>
+ <text>^</text>
+ <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
+ </copy>
+ </when>
+ <otherwise>
+ <copy>
+ <copy-of select="@*"/>
+ <apply-templates select="node()" mode="LesML:comment">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </copy>
+ </otherwise>
+ </choose>
+ </when>
+ <when test="self::text()[contains(., '⌧')]">
+ <variable name="split-fragment">
+ <call-template name="LesML:split">
+ <with-param name="source" select="string()"/>
+ <with-param name="separator" select="'⌧'"/>
+ </call-template>
+ </variable>
+ <for-each select="exsl:node-set($split-fragment)/node()">
+ <value-of select="."/>
+ <if test="position()!=last()">
+ <call-template name="LesML:comment-out"/>
+ </if>
+ </for-each>
+ </when>
+ <otherwise>
+ <copy-of select="."/>
+ </otherwise>
+ </choose>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:attrify">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </template>
+ <template match="node()" mode="LesML:attrify">
+ <param name="footnote-ids" select="/.."/>
+ <variable name="result">
+ <choose>
+ <when test="self::*">
+ <variable name="partitioned-fragment">
+ <apply-templates mode="LesML:partition" select=".">
+ <with-param name="start-sigil" select="'{@'"/>
+ <with-param name="end-sigil" select="'"}'"/>
+ <with-param name="separator" select="'="'"/>
+ <with-param name="ncname-keys" select="true()"/>
+ </apply-templates>
+ </variable>
+ <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
+ <choose>
+ <when test="count($partitioned)>1">
+ <variable name="processed">
+ <copy>
+ <copy-of select="@*"/>
+ <copy-of select="$partitioned[1]/node()"/>
+ <element name="LesML:attribute" namespace="&LesML;">
+ <attribute name="{$partitioned[2]}">
+ <value-of select="$partitioned[3]"/>
+ </attribute>
+ </element>
+ <copy-of select="$partitioned[4]/node()"/>
+ </copy>
+ </variable>
+ <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </when>
+ <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
+ <copy>
+ <copy-of select="@*"/>
+ <apply-templates select="node()" mode="LesML:attrify">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </copy>
+ </when>
+ <otherwise>
+ <variable name="processed">
+ <copy>
+ <copy-of select="@*"/>
+ <copy-of select="$partitioned/node()"/>
+ </copy>
+ </variable>
+ <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </otherwise>
+ </choose>
+ </when>
+ <otherwise>
+ <copy-of select="."/>
+ </otherwise>
+ </choose>
+ </variable>
+ <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </template>
+ <template match="node()" mode="LesML:linkify">
+ <param name="footnote-ids" select="/.."/>
+ <variable name="result">
+ <choose>
+ <when test="processing-instruction()[local-name()='LesML-All-Done']">
+ <copy>
+ <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>