+ </element>
+ </element>
+ </when>
+ <when test="starts-with($text, '⚠') and &sigiled-text;">
+ <element name="div" namespace="&xhtml;">
+ <attribute name="role">
+ <text>note</text>
+ </attribute>
+ <attribute name="class">
+ <text>warn</text>
+ </attribute>
+ <element name="p" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </element>
+ </when>
+ <when test="starts-with($text, '※') and &sigiled-text;">
+ <element name="div" namespace="&xhtml;">
+ <attribute name="role">
+ <text>note</text>
+ </attribute>
+ <attribute name="class">
+ <text>note</text>
+ </attribute>
+ <element name="p" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </element>
+ </when>
+ <when test="starts-with($text, '☡') and &sigiled-text;">
+ <element name="div" namespace="&xhtml;">
+ <attribute name="role">
+ <text>note</text>
+ </attribute>
+ <attribute name="class">
+ <text>caution</text>
+ </attribute>
+ <element name="p" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </element>
+ </when>
+ <when test="starts-with($text, '⋯') and &sigiled-text;">
+ <element name="div" namespace="&xhtml;">
+ <processing-instruction name="LesML-Continuation"/>
+ <element name="p" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </element>
+ </when>
+ <when test="starts-with($text, '^') and &sigiled-text;">
+ <element name="li" namespace="&xhtml;">
+ <attribute name="class">
+ <text>ordered footnote</text>
+ </attribute>
+ <attribute name="aria-level">
+ <text>1</text>
+ </attribute>
+ <processing-instruction name="LesML-Footnote"/>
+ <element name="p" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </element>
+ </element>
+ </when>
+ <when test="starts-with($text, '#') and &sigiled-text;">
+ <call-template name="LesML:comment-out">
+ <with-param name="source" select="&unsigiled-text;"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <element name="p" namespace="&xhtml;">
+ <call-template name="LesML:id-and-contents">
+ <with-param name="source" select="$text"/>
+ </call-template>
+ </element>
+ </otherwise>
+ </choose>
+ </otherwise>
+ </choose>
+ </for-each>
+ </template>
+ <template name="LesML:paragraphize">
+ <param name="lines" select="/.."/>
+ <variable name="blocked-fragment">
+ <call-template name="LesML:block">
+ <with-param name="lines" select="$lines"/>
+ </call-template>
+ </variable>
+ <variable name="blocked" select="exsl:node-set($blocked-fragment)"/>
+ <variable name="footnote-ids" select="$blocked//html:li[processing-instruction()[local-name()='LesML-Footnote']]/html:p[1]/@id"/>
+ <variable name="inlined-fragment">
+ <apply-templates select="$blocked/node()" mode="LesML:comment">
+ <with-param name="footnote-ids" select="$footnote-ids"/>
+ </apply-templates>
+ </variable>
+ <apply-templates select="exsl:node-set($inlined-fragment)/node()" mode="LesML:finalize-tree"/>
+ </template>
+ <template match="html:script[@type='text/lesml']">
+ <variable name="lines-fragment">
+ <call-template name="LesML:split">
+ <with-param name="source">
+ <for-each select=".//text()">
+ <value-of select="."/>
+ </for-each>
+ </with-param>
+ </call-template>
+ </variable>
+ <element name="div" namespace="&xhtml;">
+ <call-template name="LesML:parse">
+ <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
+ </call-template>
+ </element>
+ </template>
+ <template match="node()" mode="LesML:finalize-attributes">
+ <variable name="notattr" select="following-sibling::node()[not(self::text() and translate(., ' 	', '')='' or self::LesML:attribute)]"/>
+ <for-each select="(.|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
+ <copy-of select="."/>
+ <if test="local-name()='lang' and namespace-uri()=''">
+ <attribute name="xml:lang">
+ <value-of select="."/>
+ </attribute>
+ </if>
+ </for-each>
+ </template>
+ <template match="html:a[@role='doc-noteref']" mode="LesML:finalize-footnotes">
+ <param name="used-footnotes" select="/.."/>
+ <variable name="matching-note" select="$used-footnotes[concat('#', @id)=current()/@href]"/>
+ <copy>
+ <apply-templates select="@*" mode="LesML:finalize-footnotes">
+ <with-param name="used-footnotes" select="$used-footnotes"/>
+ </apply-templates>
+ <choose>
+ <when test="$matching-note">
+ <value-of select="$matching-note/@value"/>
+ </when>
+ <otherwise>
+ <apply-templates select="node()" mode="LesML:finalize-footnotes">
+ <with-param name="used-footnotes" select="$used-footnotes"/>
+ </apply-templates>
+ </otherwise>
+ </choose>
+ </copy>
+ </template>
+ <template match="html:p[preceding-sibling::*[1]=processing-instruction()[local-name()='LesML-Footnote']]" mode="LesML:finalize-footnotes">
+ <variable name="content" select="@*[not(local-name()='@id' and namespace-uri()='')]|node()"/>
+ <if test="$content">
+ <copy>
+ <apply-templates select="$content" mode="LesML:finalize-footnotes"/>
+ </copy>
+ </if>
+ </template>
+ <template match="html:ol[processing-instruction()[local-name()='LesML-Footnote']]|processing-instruction()[local-name()='LesML-Footnote']" mode="LesML:finalize-footnotes"/>
+ <template match="@*|node()" mode="LesML:finalize-footnotes" priority="-1">
+ <param name="used-footnotes" select="/.."/>
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-footnotes">
+ <with-param name="used-footnotes" select="$used-footnotes"/>
+ </apply-templates>
+ </copy>
+ </template>
+ <template match="html:li" mode="LesML:finalize-list">
+ <param name="parent-level" select="0"/>
+ <variable name="current-class" select="string(@class)"/>
+ <variable name="current-level" select="number(@aria-level)"/>
+ <variable name="wrapper">
+ <choose>
+ <when test="contains(concat(' ', @class, ' '), ' ordered ')">
+ <text>ol</text>
+ </when>
+ <otherwise>
+ <text>ul</text>
+ </otherwise>
+ </choose>
+ </variable>
+ <variable name="notinlist" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'] or self::html:li and (@aria-level>$current-level or @aria-level=$current-level and @class=$current-class))][1]"/>
+ <element name="{$wrapper}" namespace="&xhtml;">
+ <if test="contains(concat(' ', @class, ' '), ' footnote ')">
+ <processing-instruction name="LesML-Footnote"/>
+ </if>
+ <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @aria-level=$current-level]">
+ <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </for-each>
+ <if test="$notcontinuation/self::html:li[@aria-level>$current-level]">
+ <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
+ <with-param name="parent-level" select="$current-level"/>
+ </apply-templates>
+ </if>
+ </copy>
+ </for-each>
+ </element>
+ <if test="$notinlist/self::html:li[@aria-level>$parent-level]">
+ <apply-templates select="$notinlist" mode="LesML:finalize-list">
+ <with-param name="parent-level" select="$parent-level"/>
+ </apply-templates>
+ </if>
+ </template>
+ <template match="LesML:attribute[preceding-sibling::node()[position()=1 and (self::text() or self::*)]]|text()[preceding-sibling::node()[position()=1 and self::*] and following-sibling::node()[position()=1 and self::LesML:attribute] and translate(., ' 	', '')='']" mode="LesML:finalize-tree" priority="2"/>
+ <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize-tree" priority="1">
+ <element name="span" namespace="&xhtml;">
+ <apply-templates select="." mode="LesML:finalize-attributes"/>
+ <if test="self::text()">
+ <call-template name="LesML:break-and-unescape">
+ <with-param name="source" select="string(.)"/>
+ </call-template>
+ </if>
+ </element>
+ </template>
+ <template match="html:div" mode="LesML:finalize-tree">
+ <if test="not(processing-instruction()[local-name()='LesML-Continuation']) or not(preceding-sibling::node()[position()=1 and self::html:* and contains(' div li h1 h2 h3 h4 h5 h6 ', local-name())])">
+ <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
+ <choose>
+ <when test="processing-instruction()[local-name()='LesML-Continuation'] and $notcontinuation[self::html:* and contains(' h1 h2 h3 h4 h5 h6 ', local-name())]">
+ <variable name="notcontinuation2" select="$notcontinuation/following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
+ <element name="hgroup" namespace="&xhtml;">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ <for-each select="exslset:leading(following-sibling::node(), $notcontinuation2)">
+ <choose>
+ <when test="self::html:div">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </when>
+ <otherwise>
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ </copy>
+ </otherwise>
+ </choose>
+ </for-each>
+ </element>
+ </when>
+ <when test="not(processing-instruction()[local-name()='LesML-Continuation'])">
+ <copy>
+ <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
+ <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </for-each>
+ </copy>
+ </when>
+ <otherwise>
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ <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>
+ </if>
+ </template>
+ <template match="html:li" mode="LesML:finalize-tree">
+ <if test="not(preceding-sibling::node()) or preceding-sibling::node()[not(preceding-sibling::* and self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][position()=1 and not(self::html:li)]">
+ <apply-templates select="." mode="LesML:finalize-list"/>
+ </if>
+ </template>
+ <template match="processing-instruction()[local-name()='LesML-Continuation']" mode="LesML:finalize-tree"/>
+ <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finalize-tree">
+ <value-of select="."/>
+ </template>
+ <template match="text()" mode="LesML:finalize-tree">
+ <call-template name="LesML:break-and-unescape">
+ <with-param name="source" select="string(.)"/>
+ </call-template>
+ </template>
+ <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
+ <copy>
+ <apply-templates select="." mode="LesML:finalize-attributes"/>
+ <apply-templates select="node()" mode="LesML:finalize-tree"/>
+ </copy>
+ </template>
+ <template match="node()" mode="LesML:inline">
+ <param name="element-name"/>
+ <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
+ <param name="start-sigil"/>
+ <param name="end-sigil"/>
+ <param name="class"/>
+ <param name="role"/>
+ <choose>
+ <when test="self::*">
+ <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
+ <variable name="has-start-node" select="$end-node/preceding-sibling::text()[contains(., $start-sigil)] 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)][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="wrapped">
+ <copy>
+ <copy-of select="@*"/>
+ <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 name="{$element-name}" namespace="{$element-namespace}">
+ <if test="string($role)!=''">
+ <attribute name="role">
+ <value-of select="$role"/>
+ </attribute>
+ </if>
+ <if test="string($class)!=''">
+ <attribute name="class">
+ <value-of select="$class"/>
+ </attribute>
+ </if>
+ <value-of select="$start-tokens[last()]"/>
+ <copy-of select="$start-node/following-sibling::node()"/>
+ </element>
+ <value-of select="substring-after($end-node, $end-sigil)"/>
+ <copy-of select="$end-node/following-sibling::node()"/>
+ </copy>
+ </variable>
+ <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
+ <with-param name="element-name" select="$element-name"/>
+ <with-param name="element-namespace" select="$element-namespace"/>
+ <with-param name="start-sigil" select="$start-sigil"/>
+ <with-param name="end-sigil" select="$end-sigil"/>
+ <with-param name="role" select="$role"/>
+ </apply-templates>
+ </when>
+ <otherwise>
+ <copy>
+ <copy-of select="@*"/>
+ <apply-templates select="node()" mode="LesML:inline">
+ <with-param name="element-name" select="$element-name"/>
+ <with-param name="element-namespace" select="$element-namespace"/>
+ <with-param name="start-sigil" select="$start-sigil"/>
+ <with-param name="end-sigil" select="$end-sigil"/>
+ <with-param name="role" select="$role"/>
+ </apply-templates>
+ </copy>
+ </otherwise>
+ </choose>
+ </when>
+ <otherwise>
+ <copy-of select="."/>
+ </otherwise>
+ </choose>
+ </template>
+ <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)] 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-fragment">
+ <copy-of select="$end-node/preceding-sibling::node()"/>
+ <value-of select="substring-before($end-node, $end-sigil)"/>
+ </variable>
+ <variable name="preceding" select="exsl:node-set($preceding-fragment)/node()"/>
+ <variable name="start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()][not($ncname-keys) or not(following-sibling::* or following-sibling::comment())]"/>
+ <variable name="start-tokens-fragment">
+ <if test="$start-node">
+ <call-template name="LesML:split">
+ <with-param name="source" select="string($start-node)"/>
+ <with-param name="separator" select="$start-sigil"/>
+ </call-template>
+ </if>
+ </variable>
+ <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
+ <variable name="innards-fragment">
+ <value-of select="$start-tokens[last()]"/>
+ <copy-of select="$start-node/following-sibling::node()"/>
+ </variable>
+ <variable name="innards" select="exsl:node-set($innards-fragment)/node()"/>
+ <variable name="separator-node" select="($innards[self::text() and contains(., $separator)])[not($ncname-keys)*(last()-1)+1]"/>
+ <choose>
+ <when test="not($start-node) or $separator-node[following-sibling::* or following-sibling::comment()]">
+ <variable name="bad-start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()]"/>
+ <variable name="bad-start-tokens-fragment">
+ <call-template name="LesML:split">
+ <with-param name="source" select="string($bad-start-node)"/>
+ <with-param name="separator" select="$start-sigil"/>
+ </call-template>
+ </variable>
+ <element name="span" namespace="&xhtml;">
+ <copy-of select="$bad-start-node/preceding-sibling::node()"/>
+ <for-each select="exsl:node-set($bad-start-tokens-fragment)/*">
+ <value-of select="."/>
+ <if test="position()!=last()">
+ <processing-instruction name="LesML-Token-Escape">
+ <value-of select="$start-sigil"/>
+ </processing-instruction>
+ </if>
+ </for-each>
+ <copy-of select="$bad-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>
+ </when>
+ <when test="$separator-node">
+ <variable name="keyval-fragment">
+ <call-template name="LesML:split">
+ <with-param name="source" select="$separator-node"/>
+ <with-param name="separator" select="$separator"/>
+ </call-template>
+ </variable>
+ <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
+ <variable name="key-fragment">
+ <choose>
+ <when test="$ncname-keys">
+ <for-each select="$separator-node/preceding-sibling::node()">
+ <value-of select="."/>
+ </for-each>
+ <value-of select="$keyval[1]"/>
+ </when>
+ <otherwise>
+ <copy-of select="$separator-node/preceding-sibling::node()"/>
+ <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>
+ <for-each select="$separator-node/following-sibling::node()">
+ <value-of select="."/>
+ </for-each>
+ </variable>
+ <choose>
+ <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key-fragment), ' /([,*', '')=$key-fragment and exsldyn:evaluate(concat('not(self::html:', $key-fragment, ')'))]">
+ <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;">
+ <copy-of select="$key-fragment"/>
+ </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>