]> Lady’s Gitweb - LesML/blobdiff - parser.xslt
Improve/adjust note/sectioning elements
[LesML] / parser.xslt
index a938d1fabb0ce552b31304f85dd0ed9aeeda3a8f..a304a462926119f82ce8053d5a5f895a7628bcc9 100644 (file)
@@ -13,7 +13,7 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
 -->
 <!DOCTYPE transform [
        <!ENTITY LesML "urn:fdc:ladys.computer:20240512:LesML">
-       <!ENTITY section-break "">
+       <!ENTITY pilcrow-atts "(local-name()='id' or local-name()='lang') and namespace-uri()='' or local-name()='lang' and namespace-uri()='http://www.w3.org/XML/1998/namespace'">
        <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ' or substring($text, 2, 1)='¶')">
        <!ENTITY unsigiled-text "concat(translate(substring($text, 2, 1), ' ', ''), substring($text, 3, string-length($text)-2))">
        <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
@@ -289,6 +289,56 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                </if>
                <if test="$doclines[normalize-space()!='']">
                        <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
+                       <variable name="paragraphized-fragment">
+                               <call-template name="LesML:paragraphize">
+                                       <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
+                               </call-template>
+                       </variable>
+                       <variable name="paragraphized" select="exsl:node-set($paragraphized-fragment)"/>
+                       <variable name="filtered-ordered-footnotes-fragment">
+                               <for-each select="$paragraphized//html:li[processing-instruction()[local-name()='LesML-Footnote'] and html:p[position()=1 and @id]]">
+                                       <sort select="count(($paragraphized//html:a[@role='doc-noteref' and @href=concat('#', string(current()/html:p[1]/@id))])[1]/preceding::*)" data-type="number"/>
+                                       <if test="$paragraphized//html:a[@role='doc-noteref' and @href=concat('#', string(current()/html:p[1]/@id))]">
+                                               <copy-of select="."/>
+                                       </if>
+                               </for-each>
+                       </variable>
+                       <variable name="used-footnotes-fragment">
+                               <for-each select="exsl:node-set($filtered-ordered-footnotes-fragment)/node()">
+                                       <variable name="links" select="$paragraphized//html:a[@role='doc-noteref' and @href=concat('#', string(current()/html:p[1]/@id))]"/>
+                                       <element name="li" namespace="&xhtml;">
+                                               <variable name="numero" select="position()"/>
+                                               <attribute name="id">
+                                                       <value-of select="html:p[1]/@id"/>
+                                               </attribute>
+                                               <attribute name="value">
+                                                       <value-of select="$numero"/>
+                                               </attribute>
+                                               <copy-of select="@*|node()"/>
+                                               <element name="footer" namespace="&xhtml;">
+                                                       <attribute name="class">
+                                                               <text>backlinks</text>
+                                                       </attribute>
+                                                       <for-each select="$links[@id]">
+                                                               <if test="position()>1">
+                                                                       <text> </text>
+                                                               </if>
+                                                               <element name="a" namespace="&xhtml;">
+                                                                       <attribute name="role">
+                                                                               <text>doc-backlink</text>
+                                                                       </attribute>
+                                                                       <attribute name="href">
+                                                                               <text>#</text>
+                                                                               <value-of select="@id"/>
+                                                                       </attribute>
+                                                                       <value-of select="position()"/>
+                                                               </element>
+                                                       </for-each>
+                                               </element>
+                                       </element>
+                               </for-each>
+                       </variable>
+                       <variable name="used-footnote-nodes" select="exsl:node-set($used-footnotes-fragment)/node()"/>
                        <element name="article" namespace="&xhtml;">
                                <for-each select="$params/html:div/html:dt[string()=' LANG ']">
                                        <attribute name="lang">
@@ -372,10 +422,22 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                        <attribute name="class">
                                                <text>body</text>
                                        </attribute>
-                                       <call-template name="LesML:paragraphize">
-                                               <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
-                                       </call-template>
+                                       <apply-templates select="$paragraphized/node()" mode="LesML:finalize">
+                                               <with-param name="used-footnotes" select="$used-footnote-nodes"/>
+                                       </apply-templates>
                                </element>
+                               <if test="$used-footnote-nodes">
+                                       <element name="section" namespace="&xhtml;">
+                                               <attribute name="role">
+                                                       <text>doc-endnotes</text>
+                                               </attribute>
+                                               <element name="ol" namespace="&xhtml;">
+                                                       <apply-templates select="$used-footnote-nodes" mode="LesML:finalize">
+                                                               <with-param name="used-footnotes" select="$used-footnote-nodes"/>
+                                                       </apply-templates>
+                                               </element>
+                                       </element>
+                               </if>
                        </element>
                </if>
                <if test="$docsep">
@@ -628,13 +690,13 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </element>
                                                        </element>
                                                </when>
-                                               <when test="starts-with($text, '🛈') and &sigiled-text;">
-                                                       <element name="div" namespace="&xhtml;">
+                                               <when test="starts-with($text, '') and &sigiled-text;">
+                                                       <element name="section" namespace="&xhtml;">
                                                                <attribute name="role">
                                                                        <text>note</text>
                                                                </attribute>
                                                                <attribute name="class">
-                                                                       <text>info</text>
+                                                                       <text>note</text>
                                                                </attribute>
                                                                <element name="p" namespace="&xhtml;">
                                                                        <call-template name="LesML:id-and-contents">
@@ -643,13 +705,13 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </element>
                                                        </element>
                                                </when>
-                                               <when test="starts-with($text, '') and &sigiled-text;">
-                                                       <element name="div" namespace="&xhtml;">
+                                               <when test="starts-with($text, '') and &sigiled-text;">
+                                                       <element name="section" namespace="&xhtml;">
                                                                <attribute name="role">
                                                                        <text>note</text>
                                                                </attribute>
                                                                <attribute name="class">
-                                                                       <text>query</text>
+                                                                       <text>caution</text>
                                                                </attribute>
                                                                <element name="p" namespace="&xhtml;">
                                                                        <call-template name="LesML:id-and-contents">
@@ -658,13 +720,13 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </element>
                                                        </element>
                                                </when>
-                                               <when test="starts-with($text, '') and &sigiled-text;">
-                                                       <element name="div" namespace="&xhtml;">
+                                               <when test="starts-with($text, '') and &sigiled-text;">
+                                                       <element name="section" namespace="&xhtml;">
                                                                <attribute name="role">
                                                                        <text>note</text>
                                                                </attribute>
                                                                <attribute name="class">
-                                                                       <text>warn</text>
+                                                                       <text>query</text>
                                                                </attribute>
                                                                <element name="p" namespace="&xhtml;">
                                                                        <call-template name="LesML:id-and-contents">
@@ -673,13 +735,10 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </element>
                                                        </element>
                                                </when>
-                                               <when test="starts-with($text, '') and &sigiled-text;">
-                                                       <element name="div" namespace="&xhtml;">
+                                               <when test="starts-with($text, '@') and &sigiled-text;">
+                                                       <element name="section" namespace="&xhtml;">
                                                                <attribute name="role">
-                                                                       <text>note</text>
-                                                               </attribute>
-                                                               <attribute name="class">
-                                                                       <text>note</text>
+                                                                       <text>doc-abstract</text>
                                                                </attribute>
                                                                <element name="p" namespace="&xhtml;">
                                                                        <call-template name="LesML:id-and-contents">
@@ -688,13 +747,22 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </element>
                                                        </element>
                                                </when>
-                                               <when test="starts-with($text, '') and &sigiled-text;">
-                                                       <element name="div" namespace="&xhtml;">
+                                               <when test="starts-with($text, '🛈') and &sigiled-text;">
+                                                       <element name="section" namespace="&xhtml;">
                                                                <attribute name="role">
-                                                                       <text>note</text>
+                                                                       <text>doc-tip</text>
                                                                </attribute>
-                                                               <attribute name="class">
-                                                                       <text>caution</text>
+                                                               <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="section" namespace="&xhtml;">
+                                                               <attribute name="role">
+                                                                       <text>doc-notice</text>
                                                                </attribute>
                                                                <element name="p" namespace="&xhtml;">
                                                                        <call-template name="LesML:id-and-contents">
@@ -713,6 +781,22 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                </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;"/>
@@ -737,8 +821,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <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="exsl:node-set($blocked-fragment)/node()" mode="LesML:comment"/>
+                       <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>
@@ -758,6 +846,76 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </call-template>
                </element>
        </template>
+       <template match="html:ol[processing-instruction()[local-name()='LesML-Footnote']]|processing-instruction()[local-name()='LesML-Footnote']" mode="LesML:finalize" priority="1"/>
+       <template match="html:a[@role='doc-noteref']" mode="LesML:finalize">
+               <param name="used-footnotes" select="/.."/>
+               <variable name="matching-note" select="$used-footnotes[concat('#', @id)=current()/@href]"/>
+               <copy>
+                       <apply-templates select="@*" mode="LesML:finalize">
+                               <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">
+                                               <with-param name="used-footnotes" select="$used-footnotes"/>
+                                       </apply-templates>
+                               </otherwise>
+                       </choose>
+               </copy>
+       </template>
+       <template match="html:p[position()=1 and ancestor::*]" mode="LesML:finalize">
+               <param name="used-footnotes" select="/.."/>
+               <variable name="content" select="@*[not(&pilcrow-atts;)]|node()"/>
+               <if test="$content">
+                       <copy>
+                               <apply-templates select="$content" mode="LesML:finalize">
+                                       <with-param name="used-footnotes" select="$used-footnotes"/>
+                               </apply-templates>
+                       </copy>
+               </if>
+       </template>
+       <template match="html:section" mode="LesML:finalize">
+               <param name="used-footnotes" select="/.."/>
+               <variable name="notinsection" select="following-sibling::node()[not(html:li/@aria-level>1)][1]"/>
+               <copy>
+                       <apply-templates select="@*|html:p[1]/@*[&pilcrow-atts;]" mode="LesML:finalize"/>
+                       <apply-templates select="node()" mode="LesML:finalize"/>
+                       <for-each select="exslset:leading(following-sibling::node(), $notinsection)">
+                               <copy>
+                                       <apply-templates select="@*|node()" mode="LesML:finalize">
+                                               <with-param name="used-footnotes" select="$used-footnotes"/>
+                                       </apply-templates>
+                               </copy>
+                       </for-each>
+               </copy>
+       </template>
+       <template match="html:*[html:li/@aria-level>1]" mode="LesML:finalize">
+               <param name="used-footnotes" select="/.."/>
+               <if test="not(preceding-sibling::node()[not(html:li/@aria-level>1)][1]/self::html:section)">
+                       <copy>
+                               <apply-templates select="@*|node()" mode="LesML:finalize">
+                                       <with-param name="used-footnotes" select="$used-footnotes"/>
+                               </apply-templates>
+                       </copy>
+               </if>
+       </template>
+       <template match="text()" mode="LesML:finalize">
+               <call-template name="LesML:break-and-unescape">
+                       <with-param name="source" select="string()"/>
+               </call-template>
+       </template>
+       <template match="@*|node()" mode="LesML:finalize" priority="-1">
+               <param name="used-footnotes" select="/.."/>
+               <copy>
+                       <apply-templates select="@*|html:p[1]/@*[&pilcrow-atts;]" mode="LesML:finalize"/>
+                       <apply-templates select="node()" mode="LesML:finalize">
+                               <with-param name="used-footnotes" select="$used-footnotes"/>
+                       </apply-templates>
+               </copy>
+       </template>
        <template match="node()" mode="LesML:finalize-attributes">
                <variable name="notattr" select="following-sibling::node()[not(self::text() and translate(., ' &#x9;', '')='' or self::LesML:attribute)]"/>
                <for-each select="(.|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
@@ -769,19 +927,57 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </if>
                </for-each>
        </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(., ' &#x9;', '')='']" 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>
+                               <copy/>
                        </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())])">
+               <if test="not(processing-instruction()[local-name()='LesML-Continuation']) or not(preceding-sibling::node()[position()=1 and self::html:* and contains(' div h1 h2 h3 h4 h5 h6 li section ', 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())]">
@@ -846,130 +1042,25 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        <apply-templates select="." mode="LesML:finalize-list"/>
                </if>
        </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="@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;">
-                       <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>
+       <template match="html:section" mode="LesML:finalize-tree">
+               <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>
-               </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>
+               </copy>
        </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:comment">
-               <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"/>
-                                                       </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>
-                                               <otherwise>
-                                                       <copy>
-                                                               <copy-of select="@*"/>
-                                                               <apply-templates select="node()" mode="LesML:comment"/>
-                                                       </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"/>
-       </template>
        <template match="node()" mode="LesML:inline">
                <param name="element-name"/>
                <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
@@ -1230,7 +1321,107 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                        </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::*">
@@ -1257,12 +1448,16 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                        <copy-of select="$partitioned[4]/node()"/>
                                                                </copy>
                                                        </variable>
-                                                       <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
+                                                       <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"/>
+                                                               <apply-templates select="node()" mode="LesML:attrify">
+                                                                       <with-param name="footnote-ids" select="$footnote-ids"/>
+                                                               </apply-templates>
                                                        </copy>
                                                </when>
                                                <otherwise>
@@ -1272,7 +1467,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                        <copy-of select="$partitioned/node()"/>
                                                                </copy>
                                                        </variable>
-                                                       <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify"/>
+                                                       <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
+                                                               <with-param name="footnote-ids" select="$footnote-ids"/>
+                                                       </apply-templates>
                                                </otherwise>
                                        </choose>
                                </when>
@@ -1281,9 +1478,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                </otherwise>
                        </choose>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify"/>
+               <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']">
@@ -1323,12 +1523,16 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                        <copy-of select="$partitioned[4]/node()"/>
                                                                </copy>
                                                        </variable>
-                                                       <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
+                                                       <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
+                                                               <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:linkify"/>
+                                                               <apply-templates select="node()" mode="LesML:linkify">
+                                                                       <with-param name="footnote-ids" select="$footnote-ids"/>
+                                                               </apply-templates>
                                                        </copy>
                                                </when>
                                                <otherwise>
@@ -1338,7 +1542,9 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                                                        <copy-of select="$partitioned/node()"/>
                                                                </copy>
                                                        </variable>
-                                                       <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify"/>
+                                                       <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
+                                                               <with-param name="footnote-ids" select="$footnote-ids"/>
+                                                       </apply-templates>
                                                </otherwise>
                                        </choose>
                                </when>
@@ -1347,9 +1553,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                </otherwise>
                        </choose>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:strikethrough">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'s'"/>
@@ -1358,9 +1567,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'⸡'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:underline">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'u'"/>
@@ -1369,9 +1581,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'⸥'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:noted">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'small'"/>
@@ -1381,9 +1596,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="role" select="'note'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:parenthetical">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'small'"/>
@@ -1392,9 +1610,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'⸩'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:code">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'code'"/>
@@ -1403,9 +1624,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'´'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:titled">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'cite'"/>
@@ -1414,9 +1638,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'⟫'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:named">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'u'"/>
@@ -1426,9 +1653,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="class" select="'name'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:offset">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'i'"/>
@@ -1437,9 +1667,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'⟩'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:bolded">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'b'"/>
@@ -1448,9 +1681,12 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'⦄'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:important">
+               <param name="footnote-ids" select="/.."/>
                <variable name="result">
                        <apply-templates select="." mode="LesML:inline">
                                <with-param name="element-name" select="'strong'"/>
@@ -1459,14 +1695,101 @@ If a copy of the M·P·L was not distributed with this file, You can obtain one
                                <with-param name="end-sigil" select="'☜'"/>
                        </apply-templates>
                </variable>
-               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
+               </apply-templates>
        </template>
        <template match="node()" mode="LesML:emphasized">
-               <apply-templates select="." mode="LesML:inline">
-                       <with-param name="element-name" select="'em'"/>
-                       <with-param name="element-namespace" select="'&xhtml;'"/>
-                       <with-param name="start-sigil" select="'⹐'"/>
-                       <with-param name="end-sigil" select="'⹑'"/>
+               <param name="footnote-ids" select="/.."/>
+               <variable name="result">
+                       <apply-templates select="." mode="LesML:inline">
+                               <with-param name="element-name" select="'em'"/>
+                               <with-param name="element-namespace" select="'&xhtml;'"/>
+                               <with-param name="start-sigil" select="'⹐'"/>
+                               <with-param name="end-sigil" select="'⹑'"/>
+                       </apply-templates>
+               </variable>
+               <apply-templates select="exsl:node-set($result)/node()" mode="LesML:footnoted">
+                       <with-param name="footnote-ids" select="$footnote-ids"/>
                </apply-templates>
        </template>
+       <template match="node()" mode="LesML:footnoted">
+               <param name="footnote-ids" select="/.."/>
+               <choose>
+                       <when test="self::*">
+                               <variable name="start-node" select="text()[contains(., '^')][1]"/>
+                               <variable name="after-start" select="substring-after($start-node, '^')"/>
+                               <variable name="footnote-id" select="substring-before($after-start, '.')"/>
+                               <variable name="matched-footnote" select="$footnote-ids[.=$footnote-id]"/>
+                               <choose>
+                                       <when test="$footnote-id!='' and $matched-footnote">
+                                               <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="footnoted-rest-fragment">
+                                                       <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
+                                                               <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, '^')"/>
+                                                       <element name="a" namespace="&xhtml;">
+                                                               <attribute name="id">
+                                                                       <text>LesML.fnref.</text>
+                                                                       <value-of select="generate-id($start-node)"/>
+                                                               </attribute>
+                                                               <attribute name="role">
+                                                                       <text>doc-noteref</text>
+                                                               </attribute>
+                                                               <attribute name="href">
+                                                                       <text>#</text>
+                                                                       <value-of select="$footnote-id"/>
+                                                               </attribute>
+                                                               <attribute name="target">
+                                                                       <text>_self</text>
+                                                               </attribute>
+                                                       </element>
+                                                       <copy-of select="exsl:node-set($footnoted-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="footnoted-rest-fragment">
+                                                       <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
+                                                               <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($footnoted-rest-fragment)/*/node()"/>
+                                               </copy>
+                                       </when>
+                                       <otherwise>
+                                               <copy>
+                                                       <copy-of select="@*"/>
+                                                       <apply-templates select="node()" mode="LesML:footnoted">
+                                                               <with-param name="footnote-ids" select="$footnote-ids"/>
+                                                       </apply-templates>
+                                               </copy>
+                                       </otherwise>
+                               </choose>
+                       </when>
+                       <otherwise>
+                               <copy-of select="."/>
+                       </otherwise>
+               </choose>
+       </template>
 </transform>
This page took 0.057147 seconds and 4 git commands to generate.