3 @(#)💄📝 Les·M·L xslt/lesml.xslt 2026-03-31T01:28:11Z
4 SPDX-FileCopyrightText: 2024, 2025, 2026 Lady <https://www.ladys.computer/about/#lady>
5 SPDX-License-Identifier: MPL-2.0
9 ⁌ The 💄📝 Les·M·L transform
11 ∎ Copyright © 2024–2026 Lady [@ Ladys Computer]
13 ⋮ This Source Code Form is subject to the terms of the Mozilla Public
15 If a copy of the M·P·L was not distributed with this file, You can
16 obtain one at {🔗<https://mozilla.org/MPL/2.0/>}.
18 This file implements a transformation, via X·S·L·T, from an H·T·M·L
19 `<script>´ element with `@type="text/lesml"´ into the corresponding
20 H·T·M·L representation of the text it contains.
21 This forms the “canonical” definition of the Les·M·L syntax;
22 no features will be added to the language which are not feasible to
27 <!ENTITY LesML "urn:fdc:ladys.computer:20240512:LesML">
28 <!ENTITY block-types "self::html:blockquote or self::html:footer or self::html:li or self::html:dt or self::html:dd or self::html:section or ¶graph-types;">
29 <!ENTITY paragraph-types "self::html:p or self::html:pre or self::html:h1 or self::html:h2 or self::html:h3 or self::html:h4">
30 <!ENTITY level-pi "processing-instruction()[local-name()='LesML-Level']">
31 <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
34 xmlns="http://www.w3.org/1999/XSL/Transform"
36 xmlns:exsl="http://exslt.org/common"
37 xmlns:exsldyn="http://exslt.org/dynamic"
38 xmlns:exslfunc="http://exslt.org/functions"
39 xmlns:exslset="http://exslt.org/sets"
40 xmlns:exslstr="http://exslt.org/strings"
42 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
43 exclude-result-prefixes="LesML"
44 extension-element-prefixes="exsl exsldyn exslfunc exslset exslstr"
47 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
48 <param name="LESML_SECTION_BREAK_CHARS" select="'*-.=_~ ·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'"/>
49 <exslfunc:function name="LesML:split">
50 <param name="source" select="string()"/>
51 <param name="separator" select="'
'"/>
52 <variable name="result-fragment">
53 <call-template name="LesML:do-split">
54 <with-param name="source" select="$source"/>
55 <with-param name="separator" select="$separator"/>
58 <exslfunc:result select="exsl:node-set($result-fragment)/node()"/>
60 <template name="LesML:do-split">
61 <param name="source"/>
62 <param name="separator" select="'
'"/>
64 <when test="contains($source, $separator)">
66 <value-of select="substring-before($source, $separator)"/>
68 <call-template name="LesML:do-split">
69 <with-param name="source" select="substring-after($source, $separator)"/>
70 <with-param name="separator" select="$separator"/>
75 <value-of select="$source"/>
80 <template name="LesML:comment-out">
81 <param name="source"/>
83 <for-each select="LesML:split($source, '--')">
84 <if test="string()='' or starts-with(., '‐')">
87 <value-of select="."/>
88 <if test="substring(., string-length(.), 1)='‐'">
92 <when test="position()!=last()">
93 <text>-͏-</text>
99 <template name="LesML:unescape">
100 <param name="source"/>
102 <when test="contains($source, '{U+')">
103 <variable name="after" select="substring-after($source, '{U+')"/>
105 <when test="contains($after, '}')">
106 <variable name="inner" select="substring-before($after, '}')"/>
107 <variable name="components" select="LesML:split($inner, '.')"/>
108 <value-of select="substring-before($source, '{U+')"/>
110 <when test="$components[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
112 <value-of select="$inner"/>
114 <call-template name="LesML:unescape">
115 <with-param name="source" select="substring-after($after, '}')"/>
119 <for-each select="$components">
120 <text disable-output-escaping="yes">&#x</text>
121 <value-of select="."/>
124 <call-template name="LesML:unescape">
125 <with-param name="source" select="substring-after($after, '}')"/>
131 <value-of select="substring-before($source, '{U+')"/>
133 <call-template name="LesML:unescape">
134 <with-param name="source" select="$after"/>
140 <value-of select="$source"/>
144 <template name="LesML:expand-sigils">
145 <param name="sigils" select="/.."/>
146 <param name="level" select="0"/>
147 <param name="partype"/>
148 <param name="syntax"/>
149 <param name="lines" select="/.."/>
151 <when test="$sigils">
152 <variable name="wrapper-frag">
154 <when test="$sigils[1]='•'">
155 <element name="li" namespace="&xhtml;">
156 <attribute name="class">
157 <text>unordered</text>
161 <when test="$sigils[1]='№'">
162 <element name="li" namespace="&xhtml;">
163 <attribute name="class">
168 <when test="$sigils[1]='※'">
169 <element name="section" namespace="&xhtml;">
170 <attribute name="role">
173 <attribute name="class">
178 <when test="$sigils[1]='⯑'">
179 <element name="section" namespace="&xhtml;">
180 <attribute name="role">
183 <attribute name="class">
188 <when test="$sigils[1]='∫'">
189 <element name="section" namespace="&xhtml;">
190 <attribute name="role">
191 <text>doc-abstract</text>
193 <attribute name="class">
194 <text>abstract</text>
198 <when test="$sigils[1]='☡'">
199 <element name="section" namespace="&xhtml;">
200 <attribute name="role">
201 <text>doc-notice</text>
203 <attribute name="class">
208 <when test="$sigils[1]='⚠'">
209 <element name="section" namespace="&xhtml;">
210 <attribute name="role">
211 <text>doc-notice</text>
213 <attribute name="class">
218 <when test="$sigils[1]='🛈'">
219 <element name="section" namespace="&xhtml;">
220 <attribute name="role">
223 <attribute name="class">
228 <when test="$sigils[1]='💡'">
229 <element name="section" namespace="&xhtml;">
230 <attribute name="role">
233 <attribute name="class">
238 <when test="$sigils[1]='»'">
239 <element name="blockquote" namespace="&xhtml;"/>
241 <when test="$sigils[1]='∎'">
242 <element name="footer" namespace="&xhtml;"/>
245 <message terminate="yes">
246 <text>Unrecognized sigil: </text>
247 <value-of select="$sigils[1]"/>
253 <for-each select="exsl:node-set($wrapper-frag)/*">
255 <copy-of select="@*|node()"/>
256 <processing-instruction name="LesML-Level">
257 <value-of select="$level"/>
258 </processing-instruction>
259 <call-template name="LesML:expand-sigils">
260 <with-param name="sigils" select="$sigils[position()>1]"/>
261 <with-param name="level" select="$level+1"/>
262 <with-param name="partype" select="$partype"/>
263 <with-param name="syntax" select="$syntax"/>
264 <with-param name="lines" select="$lines"/>
269 <when test="$partype='comment'">
270 <element name="div" namespace="&xhtml;">
271 <processing-instruction name="LesML-Level">
272 <value-of select="$level"/>
273 </processing-instruction>
274 <call-template name="LesML:comment-out">
275 <with-param name="source">
276 <for-each select="$lines">
277 <value-of select="."/>
278 <if test="position()!=count($lines)">
287 <variable name="firstchar" select="substring(translate($lines[1], ' 	', ''), 1, 1)"/>
288 <variable name="firstline">
290 <when test="$firstchar!=''">
291 <value-of select="concat($firstchar, substring-after($lines[1], $firstchar))"/>
295 <variable name="firsttokens" select="exslstr:tokenize($firstline, ' 	')"/>
296 <variable name="id-and-lang">
297 <if test="$firstchar='¶'">
298 <value-of select="$firsttokens[1]"/>
301 <variable name="restofline">
303 <when test="$id-and-lang!=''">
304 <variable name="nosp" select="substring($firsttokens[1+number($id-and-lang!='')], 1, 1)"/>
305 <if test="$nosp!=''">
306 <value-of select="concat($nosp, substring-after(substring-after($firstline, $id-and-lang), $nosp))"/>
310 <value-of select="$lines[1]"/>
314 <variable name="maybe-langtag">
315 <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
316 <value-of select="LesML:split(substring($id-and-lang, 2, string-length($id-and-lang)-2), '@')[last()]"/>
319 <variable name="langtag">
320 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
321 <value-of select="$maybe-langtag"/>
326 <when test="string($langtag)!=''">
327 <value-of select="substring($id-and-lang, 2, string-length($id-and-lang)-(string-length($langtag)+3))"/>
330 <value-of select="substring($id-and-lang, 2)"/>
334 <variable name="newline">
336 <when test="$partype='pre' or $partype='pre code'">
337 <element name="br" namespace="&xhtml;"/>
344 <variable name="text">
345 <if test="$id-and-lang='' or $restofline!=''">
346 <value-of select="$restofline"/>
347 <if test="count($lines)>1">
348 <copy-of select="$newline"/>
351 <for-each select="$lines[position()>1]">
352 <value-of select="."/>
353 <if test="position()!=count($lines[position()>1])">
354 <copy-of select="$newline"/>
358 <variable name="parwrapper">
360 <when test="$partype='pre code'">
363 <when test="$partype='footnote'">
366 <when test="$partype!=''">
367 <value-of select="$partype"/>
374 <element name="div" namespace="&xhtml;">
376 <attribute name="id">
377 <value-of select="$id"/>
380 <if test="$langtag!=''">
381 <attribute name="lang">
382 <value-of select="$langtag"/>
384 <attribute name="xml:lang">
385 <value-of select="$langtag"/>
388 <if test="$partype='footnote'">
389 <processing-instruction name="LesML-Footnote">
390 <value-of select="$id"/>
391 </processing-instruction>
393 <processing-instruction name="LesML-Level">
394 <value-of select="$level"/>
395 </processing-instruction>
396 <element name="{$parwrapper}" namespace="&xhtml;">
397 <if test="$parwrapper='pre'">
398 <attribute name="role">
399 <text>paragraph</text>
402 <if test="$partype='pre code'">
403 <attribute name="class">
407 <if test="$syntax!=''">
408 <attribute name="data-syntax">
409 <value-of select="$syntax"/>
413 <when test="$parwrapper='hr'">
414 <attribute name="data-source-text">
415 <value-of select="$text"/>
419 <copy-of select="$text"/>
427 <template name="LesML:chunk">
428 <param name="lines" select="/.."/>
429 <variable name="last-lines" select="$lines[normalize-space()!='' and (normalize-space(following-sibling::*[1])='' or position()=last())]"/>
430 <for-each select="$last-lines">
431 <variable name="position" select="position()"/>
432 <variable name="prev-last" select="$last-lines[($position)-1]"/>
433 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
434 <variable name="nospace" select="translate($linespans[1], ' 	', '')"/>
435 <variable name="firstnolevel" select="substring(translate($nospace, '⋮', ''), 1, 1)"/>
436 <variable name="levelling">
438 <when test="$firstnolevel!=''">
439 <value-of select="substring-before($linespans[1], $firstnolevel)"/>
442 <value-of select="$linespans[1]"/>
446 <variable name="nested-bullet">
448 <when test="contains('◦▪⁃', $firstnolevel)">
449 <value-of select="$firstnolevel"/>
454 <variable name="level-modifier">
456 <when test="$nested-bullet='◦'">
459 <when test="$nested-bullet='▪'">
462 <when test="$nested-bullet='⁃'">
470 <variable name="nobullet">
472 <when test="$nested-bullet!=''">
473 <value-of select="substring-after($nospace, $nested-bullet)"/>
476 <value-of select="concat($firstnolevel, substring-after($nospace, $firstnolevel))"/>
480 <variable name="firstnosigil" select="substring(translate($nobullet, '•№※⯑∫☡⚠🛈💡»∎', ''), 1, 1)"/>
481 <variable name="sigilling">
483 <when test="$firstnosigil!=''">
484 <value-of select="substring-before(substring-after($linespans[1], concat($levelling, $nested-bullet)), $firstnosigil)"/>
487 <value-of select="substring-after($linespans[1], concat($levelling, $nested-bullet))"/>
491 <variable name="nosigil">
492 <value-of select="concat($firstnosigil, substring-after($nobullet, $firstnosigil))"/>
494 <variable name="ruled" select="count($linespans)=1 and $nosigil!='' and translate($nosigil, $LESML_SECTION_BREAK_CHARS, '')=''"/>
495 <variable name="prefix">
497 <when test="not($ruled) and $firstnosigil='|'">
498 <variable name="postpipe" select="substring-after($linespans[1], '|')"/>
500 <when test="substring(translate($postpipe, '0123456789abcdefghijklmnopqrstuvwxyz/.-', ''), 1, 1)='$'">
501 <value-of select="concat(substring-before($linespans[1], '$'), '$')"/>
504 <value-of select="concat(substring-before($linespans[1], '|'), '|')"/>
508 <when test="not($ruled) and contains('⁌§❦✠#^', $firstnosigil)">
509 <value-of select="concat(substring-before($linespans[1], $firstnosigil), $firstnosigil)"/>
511 <when test="$firstnosigil!=''">
512 <value-of select="substring-before($linespans[1], $firstnosigil)"/>
515 <value-of select="$linespans[1]"/>
519 <variable name="preformatted" select="$firstnosigil='|' and not($linespans[not(starts-with(., $prefix))])"/>
520 <variable name="inner-lines-fragment">
521 <for-each select="$linespans">
523 <when test="$preformatted or position()=1">
525 <value-of select="substring-after(., $prefix)"/>
529 <copy-of select="."/>
534 <variable name="inner-lines" select="exsl:node-set($inner-lines-fragment)/node()"/>
535 <call-template name="LesML:expand-sigils">
536 <with-param name="sigils" select="exslstr:tokenize(translate(concat($nested-bullet, $sigilling), '◦▪⁃ 	', '•••'), '')"/>
537 <with-param name="level" select="string-length(translate($levelling, ' 	', ''))+$level-modifier"/>
538 <with-param name="partype">
540 <when test="$preformatted">
542 <if test="contains($prefix, '$')">
549 <when test="$firstnosigil='#'">
552 <when test="$firstnosigil='^'">
553 <text>footnote</text>
555 <when test="$firstnosigil='⁌'">
558 <when test="$firstnosigil='§'">
561 <when test="$firstnosigil='❦'">
564 <when test="$firstnosigil='✠'">
570 <with-param name="syntax" select="substring-before(substring-after($prefix, '|'), '$')"/>
571 <with-param name="lines" select="$inner-lines"/>
575 <template name="LesML:paragraphize">
576 <param name="lines" select="/.."/>
577 <variable name="chunked-fragment">
578 <call-template name="LesML:chunk">
579 <with-param name="lines" select="$lines"/>
582 <apply-templates select="exsl:node-set($chunked-fragment)" mode="LesML:blockify"/>
584 <template name="LesML:parse">
585 <param name="lines" select="/.."/>
586 <param name="parent-params" select="/.."/>
587 <variable name="first-line" select="$lines[1]"/>
588 <variable name="shero">
589 <if test="starts-with($first-line, '#?lesml')">
590 <value-of select="$first-line"/>
593 <variable name="params-string">
595 <when test="starts-with($shero, '#?lesml@')">
596 <value-of select="substring-after($shero, '$')"/>
599 <value-of select="substring-after($shero, '#?lesml')"/>
603 <variable name="params-fragment">
605 <when test="$shero!=''">
607 <if test="starts-with($shero, '#?lesml@') and contains($shero, '$')">
613 <value-of select="substring-before(substring-after($shero, '#?lesml@'), '$')"/>
617 <for-each select="exslstr:tokenize($params-string)">
619 <when test="contains(., '=')">
622 <value-of select="substring-before(., '=')"/>
625 <value-of select="substring-after(., '=')"/>
632 <value-of select="."/>
641 <when test="$parent-params">
642 <copy-of select="$parent-params"/>
649 <variable name="params" select="exsl:node-set($params-fragment)/node()"/>
650 <variable name="noshero" select="$lines[position()>1 or not(starts-with(., '#?lesml') or starts-with(., '##'))]"/>
651 <variable name="docsep" select="$noshero[starts-with(., '#?lesml') or starts-with(., '##')][1]"/>
652 <variable name="doclines" select="exslset:leading($noshero, $docsep)"/>
653 <if test="starts-with($first-line, '##') and $first-line!='##'">
654 <call-template name="LesML:comment-out">
655 <with-param name="source" select="substring-after($first-line, '##')"/>
658 <if test="$doclines[normalize-space()!='']">
659 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
660 <variable name="paragraphized-fragment">
661 <call-template name="LesML:paragraphize">
662 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
665 <variable name="paragraphized-document" select="exsl:node-set($paragraphized-fragment)"/>
666 <variable name="filtered-ordered-footnotes-fragment">
667 <for-each select="$paragraphized-document//processing-instruction()[local-name()='LesML-Footnote']">
668 <sort select="count(($paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string(current()))])[1]/preceding::*)" data-type="number"/>
669 <if test="$paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string(current()))]">
670 <copy-of select=".."/>
674 <variable name="used-footnotes-fragment">
675 <for-each select="exsl:node-set($filtered-ordered-footnotes-fragment)/node()">
676 <variable name="footnote-id" select="processing-instruction()[local-name()='LesML-Footnote']"/>
677 <variable name="links" select="$paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string($footnote-id))]"/>
678 <element name="li" namespace="&xhtml;">
679 <variable name="numero" select="position()"/>
680 <attribute name="id">
681 <value-of select="$footnote-id"/>
683 <attribute name="value">
684 <value-of select="$numero"/>
686 <copy-of select="node()[not(self::processing-instruction() and local-name()='LesML-Footnote')]"/>
687 <element name="footer" namespace="&xhtml;">
688 <attribute name="class">
689 <text>backlinks</text>
691 <for-each select="$links[@id]">
692 <if test="position()>1">
695 <element name="a" namespace="&xhtml;">
696 <attribute name="role">
697 <text>doc-backlink</text>
699 <attribute name="href">
701 <value-of select="@id"/>
703 <value-of select="position()"/>
710 <variable name="used-footnotes" select="exsl:node-set($used-footnotes-fragment)/node()"/>
711 <element name="article" namespace="&xhtml;">
712 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
713 <attribute name="lang">
714 <value-of select="following-sibling::html:dd"/>
716 <attribute name="xml:lang">
717 <value-of select="following-sibling::html:dd"/>
720 <for-each select="$params/html:div/html:dt[string()='profile']">
721 <attribute name="data-lesml-profile">
722 <value-of select="following-sibling::html:dd"/>
725 <if test="$record-separators and exslset:difference(exslset:leading($doclines, $record-separators[last()]), $record-separators)[normalize-space()!='']">
726 <element name="footer" namespace="&xhtml;">
727 <attribute name="class">
730 <for-each select="$record-separators">
731 <variable name="position" select="position()"/>
732 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
733 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)[normalize-space()!='']"/>
735 <element name="dl" namespace="&xhtml;">
736 <for-each select="$fields">
737 <variable name="following" select="exslset:intersection($fields, following-sibling::*)"/>
739 <when test="contains(' 	', substring(., 1, 1)) and exslset:has-same-node($fields, preceding-sibling::*[1])"/>
741 <variable name="next" select="$following[not(contains(' 	', substring(., 1, 1)))][1]"/>
742 <element name="div" namespace="&xhtml;">
743 <element name="dt" namespace="&xhtml;">
744 <value-of select="normalize-space(substring-before(., ':'))"/>
746 <element name="dd" namespace="&xhtml;">
747 <variable name="firstline">
749 <when test="contains(., ':')">
750 <value-of select="normalize-space(substring-after(., ':'))"/>
753 <value-of select="normalize-space(.)"/>
758 <when test="substring($firstline, string-length($firstline))='\' and $following[position()=1 and contains(' 	', substring(., 1, 1))]">
759 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
762 <value-of select="$firstline"/>
765 <for-each select="exslset:leading($following, $next)[contains(' 	', substring(., 1, 1))]">
766 <variable name="nextline" select="normalize-space(.)"/>
768 <when test="substring($nextline, string-length($nextline))='\' and exslset:intersection($fields, following-sibling::*)[position()=1 and contains(' 	', substring(., 1, 1))]">
769 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
772 <value-of select="$nextline"/>
783 <if test="substring-after(., '%%')!=''">
784 <call-template name="LesML:comment-out">
785 <with-param name="source" select="substring-after(., '%%')"/>
791 <element name="div" namespace="&xhtml;">
792 <attribute name="class">
795 <apply-templates select="$paragraphized-document/node()" mode="LesML:finalize">
796 <with-param name="used-footnotes" select="$used-footnotes"/>
799 <if test="$used-footnotes">
800 <element name="section" namespace="&xhtml;">
801 <attribute name="role">
802 <text>doc-endnotes</text>
804 <element name="ol" namespace="&xhtml;">
805 <apply-templates select="$used-footnotes" mode="LesML:finalize">
806 <with-param name="used-footnotes" select="$used-footnotes"/>
814 <call-template name="LesML:parse">
815 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
816 <with-param name="parent-params" select="$params"/>
820 <template match="html:script[@type='text/lesml']">
821 <variable name="source">
822 <for-each select=".//text()">
823 <value-of select="."/>
826 <element name="div" namespace="&xhtml;">
827 <call-template name="LesML:parse">
828 <with-param name="lines" select="LesML:split($source)"/>
832 <template match="/" mode="LesML:blockify">
833 <variable name="nested-fragment">
834 <apply-templates mode="LesML:nesting-blocks"/>
836 <variable name="nested-document" select="exsl:node-set($nested-fragment)"/>
837 <apply-templates select="exsl:node-set($nested-fragment)/node()" mode="LesML:inlinify">
838 <with-param name="footnote-ids" select="$nested-document/*/processing-instruction()[local-name()='LesML-Footnote']"/>
841 <template match="*[&level-pi;]" mode="LesML:nesting-blocks">
842 <variable name="current-level" select="number(&level-pi;)"/>
843 <if test="not(preceding-sibling::*[&level-pi; and $current-level>&level-pi;])">
844 <variable name="notatlevel" select="following-sibling::*[$current-level>=&level-pi;][1]"/>
845 <variable name="contents-fragment">
846 <copy-of select="node()"/>
847 <copy-of select="exslset:leading(following-sibling::*, $notatlevel)"/>
850 <copy-of select="@*"/>
851 <apply-templates select="exsl:node-set($contents-fragment)/node()" mode="LesML:nesting-blocks"/>
855 <template match="node()" mode="LesML:nesting-blocks" priority="-1">
857 <copy-of select="@*"/>
858 <apply-templates select="node()" mode="LesML:nesting-blocks"/>
861 <template match="*[&level-pi;]" mode="LesML:inlinify">
862 <param name="footnote-ids" select="/.."/>
864 <copy-of select="@*"/>
865 <apply-templates mode="LesML:inlinify">
866 <with-param name="footnote-ids" select="$footnote-ids|*/processing-instruction()[local-name()='LesML-Footnote']"/>
870 <template match="node()" mode="LesML:inlinify" priority="-1">
871 <param name="footnote-ids" select="/.."/>
872 <apply-templates select="." mode="LesML:comment">
873 <with-param name="footnote-ids" select="$footnote-ids"/>
876 <template match="node()" mode="LesML:comment">
877 <param name="footnote-ids" select="/.."/>
878 <variable name="result-fragment">
880 <when test="self::*">
881 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
882 <variable name="after-start">
883 <if test="$start-node">
884 <value-of select="substring-after($start-node, '⌦')"/>
887 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
889 <when test="$start-node and $has-end-node">
890 <variable name="following">
891 <value-of select="$after-start"/>
892 <copy-of select="$start-node/following-sibling::node()"/>
894 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
895 <variable name="comment">
896 <for-each select="$end-node/preceding-sibling::node()">
897 <value-of select="."/>
899 <value-of select="substring-before($end-node, '⌫')"/>
901 <variable name="rest-fragment">
902 <element name="span" namespace="&xhtml;">
903 <value-of select="substring-after($end-node, '⌫')"/>
904 <copy-of select="$end-node/following-sibling::node()"/>
907 <variable name="commented-rest-fragment">
908 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
909 <with-param name="footnote-ids" select="$footnote-ids"/>
913 <copy-of select="@*"/>
914 <copy-of select="$start-node/preceding-sibling::node()"/>
915 <copy-of select="substring-before($start-node, '⌦')"/>
916 <call-template name="LesML:comment-out">
917 <with-param name="source" select="string($comment)"/>
919 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
922 <when test="$start-node">
923 <variable name="rest-fragment">
924 <element name="div" namespace="&xhtml;">
925 <value-of select="substring-after($after-start, '⌦')"/>
926 <copy-of select="$start-node/following-sibling::node()"/>
929 <variable name="commented-rest-fragment">
930 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
931 <with-param name="footnote-ids" select="$footnote-ids"/>
935 <copy-of select="@*"/>
936 <copy-of select="$start-node/preceding-sibling::node()"/>
937 <copy-of select="substring-before($start-node, '⌦')"/>
939 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
944 <copy-of select="@*"/>
945 <apply-templates select="node()" mode="LesML:comment">
946 <with-param name="footnote-ids" select="$footnote-ids"/>
952 <when test="self::text()[contains(., '⌧')]">
953 <for-each select="LesML:split(., '⌧')">
954 <value-of select="."/>
955 <if test="position()!=last()">
956 <call-template name="LesML:comment-out"/>
961 <copy-of select="."/>
965 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:attrify">
966 <with-param name="footnote-ids" select="$footnote-ids"/>
969 <template match="*" mode="LesML:partition">
970 <param name="start-sigil"/>
971 <param name="end-sigil"/>
972 <param name="separator"/>
973 <param name="ncname-keys" select="false()"/>
974 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
975 <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))"/>
977 <when test="$end-node and $has-start-node">
978 <variable name="preceding-fragment">
979 <copy-of select="$end-node/preceding-sibling::node()"/>
980 <value-of select="substring-before($end-node, $end-sigil)"/>
982 <variable name="preceding" select="exsl:node-set($preceding-fragment)/node()"/>
983 <variable name="start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()][not($ncname-keys) or not(following-sibling::*[not(self::html:br)] or following-sibling::comment())]"/>
984 <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
985 <variable name="innards-fragment">
986 <value-of select="$start-tokens[last()]"/>
987 <for-each select="$start-node/following-sibling::node()">
989 <when test="$ncname-keys and self::html:br">
993 <copy-of select="."/>
998 <variable name="innards" select="exsl:node-set($innards-fragment)/node()"/>
999 <variable name="separator-node" select="($innards[self::text() and contains(., $separator)])[not($ncname-keys)*(last()-1)+1]"/>
1001 <when test="not($start-node) or $separator-node[following-sibling::* or following-sibling::comment()]">
1002 <variable name="bad-start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()]"/>
1003 <element name="span" namespace="&xhtml;">
1004 <copy-of select="$bad-start-node/preceding-sibling::node()"/>
1005 <for-each select="LesML:split($bad-start-node, $start-sigil)">
1006 <value-of select="."/>
1007 <if test="position()!=last()">
1008 <processing-instruction name="LesML-Token-Escape">
1009 <value-of select="$start-sigil"/>
1010 </processing-instruction>
1013 <copy-of select="$bad-start-node/following-sibling::node()"/>
1014 <value-of select="$end-sigil"/>
1015 <value-of select="substring-after($end-node, $end-sigil)"/>
1016 <copy-of select="$end-node/following-sibling::node()"/>
1019 <when test="$separator-node">
1020 <variable name="keyval" select="LesML:split($separator-node, $separator)"/>
1021 <variable name="key-fragment">
1023 <when test="$ncname-keys">
1024 <for-each select="$separator-node/preceding-sibling::node()">
1025 <value-of select="."/>
1027 <value-of select="$keyval[1]"/>
1030 <copy-of select="$separator-node/preceding-sibling::node()"/>
1031 <for-each select="$keyval[position()!=last()]">
1032 <value-of select="."/>
1033 <if test="position()!=last()">
1034 <value-of select="$separator"/>
1040 <variable name="value">
1042 <when test="$ncname-keys">
1043 <for-each select="$keyval[position()!=1]">
1044 <value-of select="."/>
1045 <if test="position()!=last()">
1046 <value-of select="$separator"/>
1051 <value-of select="$keyval[last()]"/>
1054 <for-each select="$separator-node/following-sibling::node()">
1055 <value-of select="."/>
1059 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key-fragment), ' /([,*', '')=$key-fragment and exsldyn:evaluate(concat('not(self::html:', $key-fragment, ')'))]">
1060 <element name="span" namespace="&xhtml;">
1061 <copy-of select="$start-node/preceding-sibling::node()"/>
1062 <for-each select="$start-tokens[position()!=last()]">
1063 <value-of select="."/>
1064 <if test="position()!=last()">
1065 <value-of select="$start-sigil"/>
1069 <element name="span" namespace="&xhtml;">
1070 <copy-of select="$key-fragment"/>
1072 <element name="span" namespace="&xhtml;">
1073 <value-of select="$value"/>
1075 <element name="span" namespace="&xhtml;">
1076 <value-of select="substring-after($end-node, $end-sigil)"/>
1077 <copy-of select="$end-node/following-sibling::node()"/>
1081 <element name="span" namespace="&xhtml;">
1082 <copy-of select="$start-node/preceding-sibling::node()"/>
1083 <for-each select="$start-tokens[position()!=last()]">
1084 <value-of select="."/>
1085 <if test="position()!=last()">
1086 <value-of select="$start-sigil"/>
1089 <processing-instruction name="LesML-Token-Escape">
1090 <value-of select="$start-sigil"/>
1091 </processing-instruction>
1092 <value-of select="$start-tokens[last()]"/>
1093 <value-of select="$start-node/following-sibling::node()"/>
1094 <value-of select="$end-sigil"/>
1095 <value-of select="substring-after($end-node, $end-sigil)"/>
1096 <copy-of select="$end-node/following-sibling::node()"/>
1102 <element name="span" namespace="&xhtml;">
1103 <copy-of select="$start-node/preceding-sibling::node()"/>
1104 <for-each select="$start-tokens[position()!=last()]">
1105 <value-of select="."/>
1106 <if test="position()!=last()">
1107 <value-of select="$start-sigil"/>
1110 <processing-instruction name="LesML-Token-Escape">
1111 <value-of select="$start-sigil"/>
1112 </processing-instruction>
1113 <value-of select="$start-tokens[last()]"/>
1114 <copy-of select="$start-node/following-sibling::node()"/>
1115 <value-of select="$end-sigil"/>
1116 <value-of select="substring-after($end-node, $end-sigil)"/>
1117 <copy-of select="$end-node/following-sibling::node()"/>
1122 <when test="$end-node">
1123 <element name="span" namespace="&xhtml;">
1124 <copy-of select="$end-node/preceding-sibling::node()"/>
1125 <value-of select="substring-before($end-node, $end-sigil)"/>
1126 <processing-instruction name="LesML-Token-Escape">
1127 <value-of select="$end-sigil"/>
1128 </processing-instruction>
1129 <value-of select="substring-after($end-node, $end-sigil)"/>
1130 <copy-of select="$end-node/following-sibling::node()"/>
1134 <processing-instruction name="LesML-All-Done"/>
1138 <template match="node()" mode="LesML:attrify">
1139 <param name="footnote-ids" select="/.."/>
1140 <variable name="result-fragment">
1142 <when test="self::*">
1143 <variable name="partitioned-fragment">
1144 <apply-templates mode="LesML:partition" select=".">
1145 <with-param name="start-sigil" select="'{@'"/>
1146 <with-param name="end-sigil" select="'"}'"/>
1147 <with-param name="separator" select="'="'"/>
1148 <with-param name="ncname-keys" select="true()"/>
1151 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1153 <when test="count($partitioned)>1">
1154 <variable name="processed">
1156 <copy-of select="@*"/>
1157 <copy-of select="$partitioned[1]/node()"/>
1158 <element name="LesML:attribute" namespace="&LesML;">
1159 <attribute name="{$partitioned[2]}">
1160 <value-of select="$partitioned[3]"/>
1163 <copy-of select="$partitioned[4]/node()"/>
1166 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1167 <with-param name="footnote-ids" select="$footnote-ids"/>
1170 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1172 <copy-of select="@*"/>
1173 <apply-templates select="node()" mode="LesML:attrify">
1174 <with-param name="footnote-ids" select="$footnote-ids"/>
1179 <variable name="processed">
1181 <copy-of select="@*"/>
1182 <copy-of select="$partitioned/node()"/>
1185 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1186 <with-param name="footnote-ids" select="$footnote-ids"/>
1192 <copy-of select="."/>
1196 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:linkify">
1197 <with-param name="footnote-ids" select="$footnote-ids"/>
1200 <template match="node()" mode="LesML:linkify">
1201 <param name="footnote-ids" select="/.."/>
1202 <variable name="result-fragment">
1204 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1206 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1209 <when test="self::*">
1210 <variable name="partitioned-fragment">
1211 <apply-templates mode="LesML:partition" select=".">
1212 <with-param name="start-sigil" select="'{🔗'"/>
1213 <with-param name="end-sigil" select="'>}'"/>
1214 <with-param name="separator" select="'<'"/>
1217 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1219 <when test="count($partitioned)>1">
1220 <variable name="processed">
1222 <copy-of select="@*"/>
1223 <copy-of select="$partitioned[1]/node()"/>
1224 <element name="a" namespace="&xhtml;">
1225 <attribute name="href">
1226 <value-of select="$partitioned[3]"/>
1228 <processing-instruction name="LesML-All-Done"/>
1230 <when test="not($partitioned[2]/node())">
1231 <value-of select="$partitioned[3]"/>
1234 <copy-of select="$partitioned[2]/node()"/>
1238 <copy-of select="$partitioned[4]/node()"/>
1241 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1242 <with-param name="footnote-ids" select="$footnote-ids"/>
1245 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1247 <copy-of select="@*"/>
1248 <apply-templates select="node()" mode="LesML:linkify">
1249 <with-param name="footnote-ids" select="$footnote-ids"/>
1254 <variable name="processed">
1256 <copy-of select="@*"/>
1257 <copy-of select="$partitioned/node()"/>
1260 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1261 <with-param name="footnote-ids" select="$footnote-ids"/>
1267 <copy-of select="."/>
1271 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:strikethrough">
1272 <with-param name="footnote-ids" select="$footnote-ids"/>
1275 <template match="node()" mode="LesML:inline">
1276 <param name="element-name"/>
1277 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
1278 <param name="start-sigil"/>
1279 <param name="end-sigil"/>
1280 <param name="class"/>
1281 <param name="role"/>
1283 <when test="self::*">
1284 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1285 <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))"/>
1287 <when test="$end-node and $has-start-node">
1288 <variable name="preceding">
1289 <copy-of select="$end-node/preceding-sibling::node()"/>
1290 <value-of select="substring-before($end-node, $end-sigil)"/>
1292 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
1293 <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
1294 <variable name="wrapped">
1296 <copy-of select="@*"/>
1297 <copy-of select="$start-node/preceding-sibling::node()"/>
1298 <for-each select="$start-tokens[position()!=last()]">
1299 <value-of select="."/>
1300 <if test="position()!=last()">
1301 <value-of select="$start-sigil"/>
1304 <element name="{$element-name}" namespace="{$element-namespace}">
1305 <if test="string($role)!=''">
1306 <attribute name="role">
1307 <value-of select="$role"/>
1310 <if test="string($class)!=''">
1311 <attribute name="class">
1312 <value-of select="$class"/>
1315 <value-of select="$start-tokens[last()]"/>
1316 <copy-of select="$start-node/following-sibling::node()"/>
1318 <value-of select="substring-after($end-node, $end-sigil)"/>
1319 <copy-of select="$end-node/following-sibling::node()"/>
1322 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
1323 <with-param name="element-name" select="$element-name"/>
1324 <with-param name="element-namespace" select="$element-namespace"/>
1325 <with-param name="start-sigil" select="$start-sigil"/>
1326 <with-param name="end-sigil" select="$end-sigil"/>
1327 <with-param name="role" select="$role"/>
1332 <copy-of select="@*"/>
1333 <apply-templates select="node()" mode="LesML:inline">
1334 <with-param name="element-name" select="$element-name"/>
1335 <with-param name="element-namespace" select="$element-namespace"/>
1336 <with-param name="start-sigil" select="$start-sigil"/>
1337 <with-param name="end-sigil" select="$end-sigil"/>
1338 <with-param name="role" select="$role"/>
1345 <copy-of select="."/>
1349 <template match="node()" mode="LesML:strikethrough">
1350 <param name="footnote-ids" select="/.."/>
1351 <variable name="result-fragment">
1352 <apply-templates select="." mode="LesML:inline">
1353 <with-param name="element-name" select="'s'"/>
1354 <with-param name="element-namespace" select="'&xhtml;'"/>
1355 <with-param name="start-sigil" select="'⸠'"/>
1356 <with-param name="end-sigil" select="'⸡'"/>
1359 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:underline">
1360 <with-param name="footnote-ids" select="$footnote-ids"/>
1363 <template match="node()" mode="LesML:underline">
1364 <param name="footnote-ids" select="/.."/>
1365 <variable name="result-fragment">
1366 <apply-templates select="." mode="LesML:inline">
1367 <with-param name="element-name" select="'u'"/>
1368 <with-param name="element-namespace" select="'&xhtml;'"/>
1369 <with-param name="start-sigil" select="'⸤'"/>
1370 <with-param name="end-sigil" select="'⸥'"/>
1373 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:noted">
1374 <with-param name="footnote-ids" select="$footnote-ids"/>
1377 <template match="node()" mode="LesML:noted">
1378 <param name="footnote-ids" select="/.."/>
1379 <variable name="result-fragment">
1380 <apply-templates select="." mode="LesML:inline">
1381 <with-param name="element-name" select="'small'"/>
1382 <with-param name="element-namespace" select="'&xhtml;'"/>
1383 <with-param name="start-sigil" select="'⟦'"/>
1384 <with-param name="end-sigil" select="'⟧'"/>
1385 <with-param name="role" select="'note'"/>
1388 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:parenthetical">
1389 <with-param name="footnote-ids" select="$footnote-ids"/>
1392 <template match="node()" mode="LesML:parenthetical">
1393 <param name="footnote-ids" select="/.."/>
1394 <variable name="result-fragment">
1395 <apply-templates select="." mode="LesML:inline">
1396 <with-param name="element-name" select="'small'"/>
1397 <with-param name="element-namespace" select="'&xhtml;'"/>
1398 <with-param name="start-sigil" select="'⸨'"/>
1399 <with-param name="end-sigil" select="'⸩'"/>
1402 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:code">
1403 <with-param name="footnote-ids" select="$footnote-ids"/>
1406 <template match="node()" mode="LesML:code">
1407 <param name="footnote-ids" select="/.."/>
1408 <variable name="result-fragment">
1409 <apply-templates select="." mode="LesML:inline">
1410 <with-param name="element-name" select="'code'"/>
1411 <with-param name="element-namespace" select="'&xhtml;'"/>
1412 <with-param name="start-sigil" select="'`'"/>
1413 <with-param name="end-sigil" select="'´'"/>
1416 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:titled">
1417 <with-param name="footnote-ids" select="$footnote-ids"/>
1420 <template match="node()" mode="LesML:titled">
1421 <param name="footnote-ids" select="/.."/>
1422 <variable name="result-fragment">
1423 <apply-templates select="." mode="LesML:inline">
1424 <with-param name="element-name" select="'cite'"/>
1425 <with-param name="element-namespace" select="'&xhtml;'"/>
1426 <with-param name="start-sigil" select="'⟪'"/>
1427 <with-param name="end-sigil" select="'⟫'"/>
1430 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:named">
1431 <with-param name="footnote-ids" select="$footnote-ids"/>
1434 <template match="node()" mode="LesML:named">
1435 <param name="footnote-ids" select="/.."/>
1436 <variable name="result-fragment">
1437 <apply-templates select="." mode="LesML:inline">
1438 <with-param name="element-name" select="'u'"/>
1439 <with-param name="element-namespace" select="'&xhtml;'"/>
1440 <with-param name="start-sigil" select="'⸶'"/>
1441 <with-param name="end-sigil" select="'⸷'"/>
1442 <with-param name="class" select="'name'"/>
1445 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:offset">
1446 <with-param name="footnote-ids" select="$footnote-ids"/>
1449 <template match="node()" mode="LesML:offset">
1450 <param name="footnote-ids" select="/.."/>
1451 <variable name="result-fragment">
1452 <apply-templates select="." mode="LesML:inline">
1453 <with-param name="element-name" select="'i'"/>
1454 <with-param name="element-namespace" select="'&xhtml;'"/>
1455 <with-param name="start-sigil" select="'⟨'"/>
1456 <with-param name="end-sigil" select="'⟩'"/>
1459 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:bolded">
1460 <with-param name="footnote-ids" select="$footnote-ids"/>
1463 <template match="node()" mode="LesML:bolded">
1464 <param name="footnote-ids" select="/.."/>
1465 <variable name="result-fragment">
1466 <apply-templates select="." mode="LesML:inline">
1467 <with-param name="element-name" select="'b'"/>
1468 <with-param name="element-namespace" select="'&xhtml;'"/>
1469 <with-param name="start-sigil" select="'⦃'"/>
1470 <with-param name="end-sigil" select="'⦄'"/>
1473 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:important">
1474 <with-param name="footnote-ids" select="$footnote-ids"/>
1477 <template match="node()" mode="LesML:important">
1478 <param name="footnote-ids" select="/.."/>
1479 <variable name="result-fragment">
1480 <apply-templates select="." mode="LesML:inline">
1481 <with-param name="element-name" select="'strong'"/>
1482 <with-param name="element-namespace" select="'&xhtml;'"/>
1483 <with-param name="start-sigil" select="'☞'"/>
1484 <with-param name="end-sigil" select="'☜'"/>
1487 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:emphasized">
1488 <with-param name="footnote-ids" select="$footnote-ids"/>
1491 <template match="node()" mode="LesML:emphasized">
1492 <param name="footnote-ids" select="/.."/>
1493 <variable name="result-fragment">
1494 <apply-templates select="." mode="LesML:inline">
1495 <with-param name="element-name" select="'em'"/>
1496 <with-param name="element-namespace" select="'&xhtml;'"/>
1497 <with-param name="start-sigil" select="'⹐'"/>
1498 <with-param name="end-sigil" select="'⹑'"/>
1501 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:footnoted">
1502 <with-param name="footnote-ids" select="$footnote-ids"/>
1505 <template match="node()" mode="LesML:footnoted">
1506 <param name="footnote-ids" select="/.."/>
1507 <variable name="result-fragment">
1509 <when test="self::*">
1510 <variable name="start-node" select="text()[contains(., '[^')][1]"/>
1511 <variable name="after-start" select="substring-after($start-node, '[^')"/>
1512 <variable name="footnote-id" select="substring-before($after-start, ']')"/>
1513 <variable name="matched-footnote" select="$footnote-ids[.=$footnote-id]"/>
1515 <when test="$footnote-id!='' and $matched-footnote">
1516 <variable name="rest-fragment">
1517 <element name="div" namespace="&xhtml;">
1518 <value-of select="substring-after($after-start, ']')"/>
1519 <copy-of select="$start-node/following-sibling::node()"/>
1522 <variable name="footnoted-rest-fragment">
1523 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1524 <with-param name="footnote-ids" select="$footnote-ids"/>
1528 <copy-of select="@*"/>
1529 <copy-of select="$start-node/preceding-sibling::node()"/>
1530 <copy-of select="substring-before($start-node, '[^')"/>
1531 <element name="a" namespace="&xhtml;">
1532 <attribute name="id">
1533 <text>LesML.fnref.</text>
1534 <value-of select="generate-id($start-node)"/>
1536 <attribute name="role">
1537 <text>doc-noteref</text>
1539 <attribute name="href">
1541 <value-of select="$footnote-id"/>
1543 <attribute name="target">
1547 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1550 <when test="$start-node">
1551 <variable name="rest-fragment">
1552 <element name="div" namespace="&xhtml;">
1553 <value-of select="substring-after($start-node, '[^')"/>
1554 <copy-of select="$start-node/following-sibling::node()"/>
1557 <variable name="footnoted-rest-fragment">
1558 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1559 <with-param name="footnote-ids" select="$footnote-ids"/>
1563 <copy-of select="@*"/>
1564 <copy-of select="$start-node/preceding-sibling::node()"/>
1565 <copy-of select="substring-before($start-node, '[^')"/>
1567 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1572 <copy-of select="@*"/>
1573 <apply-templates select="node()" mode="LesML:footnoted">
1574 <with-param name="footnote-ids" select="$footnote-ids"/>
1581 <copy-of select="."/>
1585 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:finish"/>
1587 <template match="processing-instruction()[local-name()='LesML-All-Done']" mode="LesML:finish"/>
1588 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finish">
1589 <value-of select="."/>
1591 <template match="@*|node()" mode="LesML:finish" priority="-1">
1593 <apply-templates select="@*|node()" mode="LesML:finish"/>
1598 ❦ Templates in the `LesML:finalize´ and related modes
1600 These templates finalize the resulting tree.
1603 <template match="node()" mode="LesML:finalize-attributes">
1604 <param name="exclude-level" select="false()"/>
1605 <variable name="notattr" select="following-sibling::node()[not(self::LesML:attribute)]"/>
1606 <variable name="div" select="self::html:div|self::*[&block-types;]/node()[not(self::processing-instruction())][position()=1 and self::html:div]"/>
1607 <variable name="para" select="self::html:p|$div/node()[not(self::processing-instruction())][position()=1 and self::html:p]"/>
1608 <variable name="emptypara" select="$para[not(@*|node()[not(self::processing-instruction())])]"/>
1609 <for-each select="(.|$emptypara/..|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
1610 <copy-of select="."/>
1611 <if test="local-name()='lang' and namespace-uri()=''">
1612 <attribute name="xml:lang">
1613 <value-of select="."/>
1617 <if test="not($exclude-level) and &level-pi;!=0">
1618 <attribute name="data-level">
1619 <value-of select="&level-pi;"/>
1623 <template match="html:li" mode="LesML:finalize-list">
1624 <param name="used-footnotes" select="/.."/>
1625 <variable name="current-class" select="string(@class)"/>
1626 <variable name="current-level" select="number(&level-pi;)"/>
1627 <variable name="wrapper">
1629 <when test="contains(concat(' ', @class, ' '), ' ordered ')">
1637 <variable name="notinlist" select="following-sibling::node()[not(self::html:li and &level-pi;=$current-level and @class=$current-class)][1]"/>
1638 <element name="{$wrapper}" namespace="&xhtml;">
1639 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)">
1641 <apply-templates select="." mode="LesML:finalize-attributes"/>
1642 <apply-templates select="node()" mode="LesML:finalize">
1643 <with-param name="used-footnotes" select="$used-footnotes"/>
1648 <if test="$notinlist/self::html:li">
1649 <apply-templates select="$notinlist" mode="LesML:finalize-list">
1650 <with-param name="used-footnotes" select="$used-footnotes"/>
1654 <template match="*[processing-instruction()[local-name()='LesML-Footnote']]|html:div/node()[not(self::processing-instruction())][position()=1 and self::html:p and not(@*|node())]|LesML:attribute[preceding-sibling::node()[position()=1 and (self::text() or self::*)]]|processing-instruction()" mode="LesML:finalize" priority="2"/>
1655 <template match="html:div[not((node()[not(self::processing-instruction())])/following-sibling::node()[not(self::processing-instruction())])]" mode="LesML:finalize" priority="1">
1656 <param name="used-footnotes" select="/.."/>
1657 <variable name="context" select="."/>
1658 <variable name="result-fragment">
1659 <apply-templates select="node()" mode="LesML:finalize">
1660 <with-param name="used-footnotes" select="$used-footnotes"/>
1663 <variable name="result" select="exsl:node-set($result-fragment)/node()"/>
1665 <when test="not(../&level-pi;) and &level-pi;!=0 or ../&level-pi; and &level-pi;-1!=../&level-pi;">
1667 <apply-templates select="$context" mode="LesML:finalize-attributes"/>
1668 <copy-of select="$result"/>
1671 <when test="$result">
1672 <for-each select="$result">
1674 <apply-templates select="$context" mode="LesML:finalize-attributes">
1675 <with-param name="exclude-level" select="true()"/>
1677 <copy-of select="@*|node()"/>
1681 <when test="* and (preceding-sibling::node()[not(self::processing-instruction())] or not(ancestor::*))">
1682 <for-each select="*">
1684 <apply-templates select="$context" mode="LesML:finalize-attributes">
1685 <with-param name="exclude-level" select="true()"/>
1687 <copy-of select="@*|node()"/>
1694 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize" priority="1">
1695 <element name="span" namespace="&xhtml;">
1696 <apply-templates select="." mode="LesML:finalize-attributes"/>
1697 <if test="self::text()">
1702 <template match="html:blockquote[node()[position()=last() and self::html:footer]]" mode="LesML:finalize">
1703 <param name="used-footnotes" select="/.."/>
1704 <element name="figure" namespace="&xhtml;">
1706 <apply-templates select="." mode="LesML:finalize-attributes"/>
1707 <apply-templates select="node()[position()!=last()]" mode="LesML:finalize">
1708 <with-param name="used-footnotes" select="$used-footnotes"/>
1711 <for-each select="node()[last()]">
1712 <element name="figcaption" namespace="&xhtml;">
1713 <apply-templates select="." mode="LesML:finalize-attributes">
1714 <with-param name="exclude-level" select="true()"/>
1716 <apply-templates select="node()" mode="LesML:finalize">
1717 <with-param name="used-footnotes" select="$used-footnotes"/>
1723 <template match="html:div[(self::*|html:div)[html:h1 or html:h2 or html:h3 or html:h4 or html:h5 or html:h6]]" mode="LesML:finalize">
1724 <param name="used-footnotes" select="/.."/>
1725 <element name="hgroup" namespace="&xhtml;">
1726 <apply-templates select="." mode="LesML:finalize-attributes"/>
1727 <apply-templates select="node()" mode="LesML:finalize">
1728 <with-param name="used-footnotes" select="$used-footnotes"/>
1732 <template match="html:li" mode="LesML:finalize">
1733 <param name="used-footnotes" select="/.."/>
1734 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:li)]">
1735 <apply-templates select="." mode="LesML:finalize-list">
1736 <with-param name="used-footnotes" select="$used-footnotes"/>
1740 <template match="html:pre" mode="LesML:finalize">
1741 <param name="used-footnotes" select="/.."/>
1743 <apply-templates select="." mode="LesML:finalize-attributes"/>
1745 <when test="@class='code'">
1746 <element name="code" namespace="&xhtml;">
1747 <apply-templates select="node()" mode="LesML:finalize">
1748 <with-param name="used-footnotes" select="$used-footnotes"/>
1753 <apply-templates select="node()" mode="LesML:finalize">
1754 <with-param name="used-footnotes" select="$used-footnotes"/>
1760 <template match="html:a[@role='doc-noteref']" mode="LesML:finalize">
1761 <param name="used-footnotes" select="/.."/>
1762 <variable name="matching-note" select="$used-footnotes[concat('#', @id)=current()/@href]"/>
1764 <apply-templates select="." mode="LesML:finalize-attributes"/>
1766 <when test="$matching-note">
1767 <value-of select="$matching-note/@value"/>
1770 <apply-templates select="node()" mode="LesML:finalize">
1771 <with-param name="used-footnotes" select="$used-footnotes"/>
1777 <template match="text()" mode="LesML:finalize">
1778 <call-template name="LesML:unescape">
1779 <with-param name="source" select="string()"/>
1782 <template match="node()" mode="LesML:finalize" priority="-1">
1783 <param name="used-footnotes" select="/.."/>
1785 <apply-templates select="." mode="LesML:finalize-attributes"/>
1786 <apply-templates select="node()" mode="LesML:finalize">
1787 <with-param name="used-footnotes" select="$used-footnotes"/>