+ <template match="*" mode="LesML:partition">
+ <param name="start-sigil"/>
+ <param name="end-sigil"/>
+ <param name="separator"/>
+ <param name="ncname-keys" select="false()"/>
+ <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
+ <variable name="has-start-node" select="$end-node/preceding-sibling::text()[contains(., $start-sigil) and not(following-sibling::* or following-sibling::comment())] or string-length(substring-after($end-node, $start-sigil))>string-length(substring-after($end-node, $end-sigil))"/>
+ <choose>
+ <when test="$end-node and $has-start-node">
+ <variable name="preceding">
+ <copy-of select="$end-node/preceding-sibling::node()"/>
+ <value-of select="substring-before($end-node, $end-sigil)"/>
+ </variable>
+ <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil) and not(following-sibling::*)][last()]"/>
+ <variable name="start-tokens-fragment">
+ <call-template name="LesML:split">
+ <with-param name="source" select="string($start-node)"/>
+ <with-param name="separator" select="$start-sigil"/>
+ </call-template>
+ </variable>
+ <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
+ <variable name="innards">
+ <value-of select="$start-tokens[last()]"/>
+ <for-each select="$start-node/following-sibling::node()">
+ <value-of select="."/>
+ </for-each>
+ </variable>
+ <choose>
+ <when test="contains($innards, $separator)">
+ <variable name="keyval-fragment">
+ <call-template name="LesML:split">
+ <with-param name="source" select="$innards"/>
+ <with-param name="separator" select="$separator"/>
+ </call-template>
+ </variable>
+ <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
+ <variable name="key">
+ <choose>
+ <when test="$ncname-keys">
+ <value-of select="$keyval[1]"/>
+ </when>
+ <otherwise>
+ <for-each select="$keyval[position()!=last()]">
+ <value-of select="."/>
+ <if test="position()!=last()">
+ <value-of select="$separator"/>
+ </if>
+ </for-each>
+ </otherwise>
+ </choose>
+ </variable>
+ <variable name="value">
+ <choose>
+ <when test="$ncname-keys">
+ <for-each select="$keyval[position()!=1]">
+ <value-of select="."/>
+ <if test="position()!=last()">
+ <value-of select="$separator"/>
+ </if>
+ </for-each>
+ </when>
+ <otherwise>
+ <value-of select="$keyval[last()]"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <choose>
+ <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key), ' /([,*', '')=string($key) and exsldyn:evaluate(concat('not(self::html:', $key, ')'))]">
+ <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>
+ </element>
+ <element name="span" namespace="&xhtml;">
+ <value-of select="$key"/>
+ </element>
+ <element name="span" namespace="&xhtml;">
+ <value-of select="$value"/>
+ </element>
+ <element name="span" namespace="&xhtml;">
+ <value-of select="substring-after($end-node, $end-sigil)"/>
+ <copy-of select="$end-node/following-sibling::node()"/>
+ </element>
+ </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()]"/>
+ <value-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>
+ <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()]"/>
+ <value-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:attrify">