3 SPDX-FileCopyrightText: 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ 💄📝 Les·M·L ∷ parser.xslt
9 © 2024–2025 Lady [@ Ladys Computer]
11 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
12 If a copy of the M·P·L was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0/>.
15 <!ENTITY LesML "urn:fdc:ladys.computer:20240512:LesML">
16 <!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'">
17 <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ' or substring($text, 2, 1)='¶')">
18 <!ENTITY unsigiled-text "concat(translate(substring($text, 2, 1), ' ', ''), substring($text, 3, string-length($text)-2))">
19 <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
22 xmlns="http://www.w3.org/1999/XSL/Transform"
23 xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
24 xmlns:exsl="http://exslt.org/common"
25 xmlns:exsldyn="http://exslt.org/dynamic"
26 xmlns:exslset="http://exslt.org/sets"
27 xmlns:exslstr="http://exslt.org/strings"
28 xmlns:html="http://www.w3.org/1999/xhtml"
29 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
30 exclude-result-prefixes="LesML"
31 extension-element-prefixes="exsl exsldyn exslset exslstr"
34 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
35 <param name="LESML_SECTION_BREAK_CHARS" select="'*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'"/>
36 <template name="LesML:split">
37 <param name="source"/>
38 <param name="separator" select="'
'"/>
40 <when test="contains($source, $separator)">
42 <value-of select="substring-before($source, $separator)"/>
44 <call-template name="LesML:split">
45 <with-param name="source" select="substring-after($source, $separator)"/>
46 <with-param name="separator" select="$separator"/>
51 <value-of select="$source"/>
56 <template name="LesML:break-and-unescape">
57 <param name="source"/>
58 <variable name="broken-fragment">
59 <call-template name="LesML:split">
60 <with-param name="source" select="$source"/>
61 <with-param name="separator" select="'
'"/>
64 <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
65 <for-each select="$broken">
66 <call-template name="LesML:unescape">
67 <with-param name="source" select="string()"/>
69 <if test="position()!=count($broken)">
70 <element name="br" namespace="&xhtml;"/>
74 <template name="LesML:unescape">
75 <param name="source"/>
77 <when test="contains($source, '{U+')">
78 <variable name="after" select="substring-after($source, '{U+')"/>
80 <when test="contains($after, '}')">
81 <variable name="inner" select="substring-before($after, '}')"/>
82 <variable name="components">
83 <call-template name="LesML:split">
84 <with-param name="source" select="$inner"/>
85 <with-param name="separator" select="'.'"/>
88 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
89 <value-of select="substring-before($source, '{U+')"/>
91 <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
93 <value-of select="$inner"/>
95 <call-template name="LesML:unescape">
96 <with-param name="source" select="substring-after($after, '}')"/>
100 <for-each select="$component-nodes">
101 <text disable-output-escaping="yes">&#x</text>
102 <value-of select="."/>
105 <call-template name="LesML:unescape">
106 <with-param name="source" select="substring-after($after, '}')"/>
112 <value-of select="substring-before($source, '{U+')"/>
114 <call-template name="LesML:unescape">
115 <with-param name="source" select="$after"/>
121 <value-of select="$source"/>
125 <template name="LesML:comment-out">
126 <param name="source"/>
127 <variable name="comment-split-fragment">
128 <call-template name="LesML:split">
129 <with-param name="source" select="$source"/>
130 <with-param name="separator" select="'--'"/>
134 <for-each select="exsl:node-set($comment-split-fragment)/*">
135 <if test="string()='' or starts-with(., '‐')">
136 <text>͏</text>
138 <value-of select="."/>
139 <if test="substring(., string-length(.), 1)='‐'">
140 <text>͏</text>
143 <when test="position()!=last()">
144 <text>-͏-</text>
150 <template name="LesML:id-and-contents">
151 <param name="source"/>
152 <variable name="id-and-lang">
153 <if test="starts-with($source, '¶')">
155 <when test="contains($source, ' ')">
156 <value-of select="substring-before(substring-after($source, '¶'), ' ')"/>
159 <value-of select="substring-after($source, '¶')"/>
164 <variable name="restoftext">
166 <when test="starts-with($source, '¶') and contains($source, ' ')">
167 <value-of select="substring-after($source, ' ')"/>
169 <when test="starts-with($source, '¶')"/>
171 <value-of select="$source"/>
175 <variable name="maybe-langtag">
176 <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
177 <variable name="split-tag-fragment">
178 <call-template name="LesML:split">
179 <with-param name="source" select="substring($id-and-lang, 2, string-length($id-and-lang)-2)"/>
180 <with-param name="separator" select="'@'"/>
183 <value-of select="exsl:node-set($split-tag-fragment)/*[last()]"/>
186 <variable name="langtag">
187 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
188 <value-of select="$maybe-langtag"/>
193 <when test="string($langtag)!=''">
194 <value-of select="substring($id-and-lang, 1, string-length($id-and-lang)-(string-length($langtag)+2))"/>
197 <value-of select="$id-and-lang"/>
201 <if test="string($id)!=''">
202 <attribute name="id">
203 <value-of select="$id"/>
206 <if test="string($langtag)!=''">
207 <attribute name="lang">
208 <value-of select="$langtag"/>
210 <attribute name="xml:lang">
211 <value-of select="$langtag"/>
214 <value-of select="$restoftext"/>
216 <template name="LesML:parse">
217 <param name="lines" select="/.."/>
218 <param name="parent-params" select="/.."/>
219 <variable name="first-line" select="$lines[1]"/>
220 <variable name="shebang">
221 <if test="starts-with($first-line, '#!lesml')">
222 <value-of select="$first-line"/>
225 <variable name="params-string">
227 <when test="starts-with($shebang, '#!lesml@')">
228 <value-of select="substring-after($shebang, '$')"/>
231 <value-of select="substring-after($shebang, '#!lesml')"/>
235 <variable name="params-fragment">
237 <when test="$shebang!=''">
239 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
245 <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
249 <for-each select="exslstr:tokenize($params-string)">
251 <when test="contains(., '=')">
254 <value-of select="substring-before(., '=')"/>
257 <value-of select="substring-after(., '=')"/>
264 <value-of select="."/>
273 <when test="$parent-params">
274 <copy-of select="$parent-params"/>
281 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
282 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
283 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
284 <variable name="doclines" select="exslset:leading($noshebang, $docsep)"/>
285 <if test="starts-with($first-line, '##') and $first-line!='##'">
286 <call-template name="LesML:comment-out">
287 <with-param name="source" select="substring-after($first-line, '##')"/>
290 <if test="$doclines[normalize-space()!='']">
291 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
292 <variable name="paragraphized-fragment">
293 <call-template name="LesML:paragraphize">
294 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
297 <variable name="paragraphized" select="exsl:node-set($paragraphized-fragment)"/>
298 <variable name="filtered-ordered-footnotes-fragment">
299 <for-each select="$paragraphized//html:li[processing-instruction()[local-name()='LesML-Footnote'] and html:p[position()=1 and @id]]">
300 <sort select="count(($paragraphized//html:a[@role='doc-noteref' and @href=concat('#', string(current()/html:p[1]/@id))])[1]/preceding::*)" data-type="number"/>
301 <if test="$paragraphized//html:a[@role='doc-noteref' and @href=concat('#', string(current()/html:p[1]/@id))]">
302 <copy-of select="."/>
306 <variable name="used-footnotes-fragment">
307 <for-each select="exsl:node-set($filtered-ordered-footnotes-fragment)/node()">
308 <variable name="links" select="$paragraphized//html:a[@role='doc-noteref' and @href=concat('#', string(current()/html:p[1]/@id))]"/>
309 <element name="li" namespace="&xhtml;">
310 <variable name="numero" select="position()"/>
311 <attribute name="id">
312 <value-of select="html:p[1]/@id"/>
314 <attribute name="value">
315 <value-of select="$numero"/>
317 <copy-of select="@*|node()"/>
318 <element name="footer" namespace="&xhtml;">
319 <attribute name="class">
320 <text>backlinks</text>
322 <for-each select="$links[@id]">
323 <if test="position()>1">
326 <element name="a" namespace="&xhtml;">
327 <attribute name="role">
328 <text>doc-backlink</text>
330 <attribute name="href">
332 <value-of select="@id"/>
334 <value-of select="position()"/>
341 <variable name="used-footnote-nodes" select="exsl:node-set($used-footnotes-fragment)/node()"/>
342 <element name="article" namespace="&xhtml;">
343 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
344 <attribute name="lang">
345 <value-of select="following-sibling::html:dd"/>
347 <attribute name="xml:lang">
348 <value-of select="following-sibling::html:dd"/>
351 <for-each select="$params/html:div/html:dt[string()='profile']">
352 <attribute name="data-lesml-profile">
353 <value-of select="following-sibling::html:dd"/>
356 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
357 <element name="footer" namespace="&xhtml;">
358 <attribute name="class">
361 <for-each select="$record-separators">
362 <variable name="position" select="position()"/>
363 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
364 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)"/>
366 <element name="dl" namespace="&xhtml;">
367 <for-each select="$fields">
369 <when test="starts-with(., ' ') and exslset:leading($fields, .)"/>
371 <variable name="next" select="exslset:intersection(following-sibling::*[not(starts-with(., ' '))][1], $fields)"/>
372 <element name="div" namespace="&xhtml;">
373 <element name="dt" namespace="&xhtml;">
374 <value-of select="normalize-space(substring-before(., ':'))"/>
376 <element name="dd" namespace="&xhtml;">
377 <variable name="firstline">
379 <when test="contains(., ':')">
380 <value-of select="normalize-space(substring-after(., ':'))"/>
383 <value-of select="normalize-space(.)"/>
388 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
389 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
392 <value-of select="$firstline"/>
395 <for-each select="exslset:intersection(following-sibling::*[starts-with(., ' ')], exslset:leading($fields, $next))">
396 <variable name="nextline" select="normalize-space(.)"/>
398 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
399 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
402 <value-of select="$nextline"/>
414 <call-template name="LesML:comment-out">
415 <with-param name="source" select="substring-after(., '%%')"/>
421 <element name="div" namespace="&xhtml;">
422 <attribute name="class">
425 <apply-templates select="$paragraphized/node()" mode="LesML:finalize">
426 <with-param name="used-footnotes" select="$used-footnote-nodes"/>
429 <if test="$used-footnote-nodes">
430 <element name="section" namespace="&xhtml;">
431 <attribute name="role">
432 <text>doc-endnotes</text>
434 <element name="ol" namespace="&xhtml;">
435 <apply-templates select="$used-footnote-nodes" mode="LesML:finalize">
436 <with-param name="used-footnotes" select="$used-footnote-nodes"/>
444 <call-template name="LesML:parse">
445 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
446 <with-param name="parent-params" select="$params"/>
450 <template name="LesML:block">
451 <param name="lines" select="/.."/>
452 <variable name="last-lines" select="$lines[normalize-space()!='' and (normalize-space(following-sibling::*[1])='' or position()=last())]"/>
453 <for-each select="$last-lines">
454 <variable name="position" select="position()"/>
455 <variable name="prev-last" select="$last-lines[($position)-1]"/>
456 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
457 <variable name="prefix" select="substring(translate(., ' 	', ''), 1, 1)"/>
458 <variable name="all-prefixed" select="not($linespans[not(starts-with(translate(., ' 	', ''), $prefix))])"/>
459 <variable name="quoted" select="$all-prefixed and $prefix='»'"/>
460 <variable name="bracketed" select="$all-prefixed and $prefix=']'"/>
462 <when test="count($linespans)=1 and translate(., concat($LESML_SECTION_BREAK_CHARS, ' 	'), '')=''">
463 <element name="hr" namespace="&xhtml;"/>
465 <when test="$quoted or $bracketed">
466 <variable name="innerlines-fragment">
467 <for-each select="$linespans">
468 <variable name="inner">
469 <value-of select="substring-after(., $prefix)"/>
473 <when test="starts-with($inner, ' ') or starts-with($inner, '	')">
474 <value-of select="substring($inner, 1+count(exslstr:tokenize($inner, '')[normalize-space()='' and not(preceding-sibling::*[normalize-space()!=''])]))"/>
477 <value-of select="$inner"/>
483 <variable name="blocked-fragment">
484 <call-template name="LesML:block">
485 <with-param name="lines" select="exsl:node-set($innerlines-fragment)/*"/>
488 <variable name="innerpars" select="exsl:node-set($blocked-fragment)/node()"/>
490 <when test="$quoted and $innerpars[position()=last() and self::html:footer]">
491 <element name="figure" namespace="&xhtml;">
492 <element name="blockquote" namespace="&xhtml;">
493 <copy-of select="$innerpars[position()!=last()]"/>
495 <element name="figcaption" namespace="&xhtml;">
496 <copy-of select="$innerpars[last()]/node()"/>
500 <when test="$quoted">
501 <element name="blockquote" namespace="&xhtml;">
502 <copy-of select="$innerpars"/>
505 <when test="$bracketed">
506 <element name="footer" namespace="&xhtml;">
507 <copy-of select="$innerpars"/>
513 <variable name="preformatted" select="$all-prefixed and $prefix='|'"/>
514 <variable name="text">
515 <for-each select="$linespans">
517 <when test="$preformatted">
518 <value-of select="substring-after(., '|')"/>
521 <value-of select="normalize-space()"/>
524 <if test="position()!=count($linespans)">
526 <when test="$preformatted">
537 <when test="$preformatted">
538 <element name="pre" namespace="&xhtml;">
539 <call-template name="LesML:id-and-contents">
540 <with-param name="source" select="$text"/>
544 <when test="string($text)=''"/>
545 <when test="starts-with($text, '⁌') and &sigiled-text;">
546 <element name="h1" namespace="&xhtml;">
547 <call-template name="LesML:id-and-contents">
548 <with-param name="source" select="&unsigiled-text;"/>
552 <when test="starts-with($text, '§') and &sigiled-text;">
553 <element name="h2" namespace="&xhtml;">
554 <call-template name="LesML:id-and-contents">
555 <with-param name="source" select="&unsigiled-text;"/>
559 <when test="starts-with($text, '❦') and &sigiled-text;">
560 <element name="h3" namespace="&xhtml;">
561 <call-template name="LesML:id-and-contents">
562 <with-param name="source" select="&unsigiled-text;"/>
566 <when test="starts-with($text, '✠') and &sigiled-text;">
567 <element name="h4" namespace="&xhtml;">
568 <call-template name="LesML:id-and-contents">
569 <with-param name="source" select="&unsigiled-text;"/>
573 <when test="starts-with($text, '•') and &sigiled-text;">
574 <element name="li" namespace="&xhtml;">
575 <attribute name="class">
576 <text>unordered</text>
578 <attribute name="aria-level">
581 <element name="p" namespace="&xhtml;">
582 <call-template name="LesML:id-and-contents">
583 <with-param name="source" select="&unsigiled-text;"/>
588 <when test="starts-with($text, '🔢') and &sigiled-text;">
589 <element name="li" namespace="&xhtml;">
590 <attribute name="class">
593 <attribute name="aria-level">
596 <element name="p" namespace="&xhtml;">
597 <call-template name="LesML:id-and-contents">
598 <with-param name="source" select="&unsigiled-text;"/>
603 <when test="starts-with($text, '◦') and &sigiled-text;">
604 <element name="li" namespace="&xhtml;">
605 <attribute name="class">
606 <text>unordered</text>
608 <attribute name="aria-level">
611 <element name="p" namespace="&xhtml;">
612 <call-template name="LesML:id-and-contents">
613 <with-param name="source" select="&unsigiled-text;"/>
618 <when test="starts-with($text, '🔠') and &sigiled-text;">
619 <element name="li" namespace="&xhtml;">
620 <attribute name="class">
623 <attribute name="aria-level">
626 <element name="p" namespace="&xhtml;">
627 <call-template name="LesML:id-and-contents">
628 <with-param name="source" select="&unsigiled-text;"/>
633 <when test="starts-with($text, '▪') and &sigiled-text;">
634 <element name="li" namespace="&xhtml;">
635 <attribute name="class">
636 <text>unordered</text>
638 <attribute name="aria-level">
641 <element name="p" namespace="&xhtml;">
642 <call-template name="LesML:id-and-contents">
643 <with-param name="source" select="&unsigiled-text;"/>
648 <when test="starts-with($text, '🔡') and &sigiled-text;">
649 <element name="li" namespace="&xhtml;">
650 <attribute name="class">
653 <attribute name="aria-level">
656 <element name="p" namespace="&xhtml;">
657 <call-template name="LesML:id-and-contents">
658 <with-param name="source" select="&unsigiled-text;"/>
663 <when test="starts-with($text, '⁃') and &sigiled-text;">
664 <element name="li" namespace="&xhtml;">
665 <attribute name="class">
666 <text>unordered</text>
668 <attribute name="aria-level">
671 <element name="p" namespace="&xhtml;">
672 <call-template name="LesML:id-and-contents">
673 <with-param name="source" select="&unsigiled-text;"/>
678 <when test="starts-with($text, '🔣') and &sigiled-text;">
679 <element name="li" namespace="&xhtml;">
680 <attribute name="class">
683 <attribute name="aria-level">
686 <element name="p" namespace="&xhtml;">
687 <call-template name="LesML:id-and-contents">
688 <with-param name="source" select="&unsigiled-text;"/>
693 <when test="starts-with($text, '※') and &sigiled-text;">
694 <element name="section" namespace="&xhtml;">
695 <attribute name="role">
698 <attribute name="class">
701 <element name="p" namespace="&xhtml;">
702 <call-template name="LesML:id-and-contents">
703 <with-param name="source" select="&unsigiled-text;"/>
708 <when test="starts-with($text, '☡') and &sigiled-text;">
709 <element name="section" namespace="&xhtml;">
710 <attribute name="role">
713 <attribute name="class">
716 <element name="p" namespace="&xhtml;">
717 <call-template name="LesML:id-and-contents">
718 <with-param name="source" select="&unsigiled-text;"/>
723 <when test="starts-with($text, '⯑') and &sigiled-text;">
724 <element name="section" namespace="&xhtml;">
725 <attribute name="role">
728 <attribute name="class">
731 <element name="p" namespace="&xhtml;">
732 <call-template name="LesML:id-and-contents">
733 <with-param name="source" select="&unsigiled-text;"/>
738 <when test="starts-with($text, '@') and &sigiled-text;">
739 <element name="section" namespace="&xhtml;">
740 <attribute name="role">
741 <text>doc-abstract</text>
743 <element name="p" namespace="&xhtml;">
744 <call-template name="LesML:id-and-contents">
745 <with-param name="source" select="&unsigiled-text;"/>
750 <when test="starts-with($text, '🛈') and &sigiled-text;">
751 <element name="section" namespace="&xhtml;">
752 <attribute name="role">
755 <element name="p" namespace="&xhtml;">
756 <call-template name="LesML:id-and-contents">
757 <with-param name="source" select="&unsigiled-text;"/>
762 <when test="starts-with($text, '⚠') and &sigiled-text;">
763 <element name="section" namespace="&xhtml;">
764 <attribute name="role">
765 <text>doc-notice</text>
767 <element name="p" namespace="&xhtml;">
768 <call-template name="LesML:id-and-contents">
769 <with-param name="source" select="&unsigiled-text;"/>
774 <when test="starts-with($text, '⋯') and &sigiled-text;">
775 <element name="div" namespace="&xhtml;">
776 <processing-instruction name="LesML-Continuation"/>
777 <element name="p" namespace="&xhtml;">
778 <call-template name="LesML:id-and-contents">
779 <with-param name="source" select="&unsigiled-text;"/>
784 <when test="starts-with($text, '^') and &sigiled-text;">
785 <element name="li" namespace="&xhtml;">
786 <attribute name="class">
787 <text>ordered footnote</text>
789 <attribute name="aria-level">
792 <processing-instruction name="LesML-Footnote"/>
793 <element name="p" namespace="&xhtml;">
794 <call-template name="LesML:id-and-contents">
795 <with-param name="source" select="&unsigiled-text;"/>
800 <when test="starts-with($text, '#') and &sigiled-text;">
801 <call-template name="LesML:comment-out">
802 <with-param name="source" select="&unsigiled-text;"/>
806 <element name="p" namespace="&xhtml;">
807 <call-template name="LesML:id-and-contents">
808 <with-param name="source" select="$text"/>
817 <template name="LesML:paragraphize">
818 <param name="lines" select="/.."/>
819 <variable name="blocked-fragment">
820 <call-template name="LesML:block">
821 <with-param name="lines" select="$lines"/>
824 <variable name="blocked" select="exsl:node-set($blocked-fragment)"/>
825 <variable name="footnote-ids" select="$blocked//html:li[processing-instruction()[local-name()='LesML-Footnote']]/html:p[1]/@id"/>
826 <variable name="inlined-fragment">
827 <apply-templates select="$blocked/node()" mode="LesML:comment">
828 <with-param name="footnote-ids" select="$footnote-ids"/>
831 <apply-templates select="exsl:node-set($inlined-fragment)/node()" mode="LesML:finalize-tree"/>
833 <template match="html:script[@type='text/lesml']">
834 <variable name="lines-fragment">
835 <call-template name="LesML:split">
836 <with-param name="source">
837 <for-each select=".//text()">
838 <value-of select="."/>
843 <element name="div" namespace="&xhtml;">
844 <call-template name="LesML:parse">
845 <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
849 <template match="html:ol[processing-instruction()[local-name()='LesML-Footnote']]|processing-instruction()[local-name()='LesML-Footnote']" mode="LesML:finalize" priority="1"/>
850 <template match="html:a[@role='doc-noteref']" mode="LesML:finalize">
851 <param name="used-footnotes" select="/.."/>
852 <variable name="matching-note" select="$used-footnotes[concat('#', @id)=current()/@href]"/>
854 <apply-templates select="@*" mode="LesML:finalize">
855 <with-param name="used-footnotes" select="$used-footnotes"/>
858 <when test="$matching-note">
859 <value-of select="$matching-note/@value"/>
862 <apply-templates select="node()" mode="LesML:finalize">
863 <with-param name="used-footnotes" select="$used-footnotes"/>
869 <template match="html:p[position()=1 and ancestor::*]" mode="LesML:finalize">
870 <param name="used-footnotes" select="/.."/>
871 <variable name="content" select="@*[not(&pilcrow-atts;)]|node()"/>
874 <apply-templates select="$content" mode="LesML:finalize">
875 <with-param name="used-footnotes" select="$used-footnotes"/>
880 <template match="html:section" mode="LesML:finalize">
881 <param name="used-footnotes" select="/.."/>
882 <variable name="notinsection" select="following-sibling::node()[not(html:li/@aria-level>1)][1]"/>
884 <apply-templates select="@*|html:p[1]/@*[&pilcrow-atts;]" mode="LesML:finalize"/>
885 <apply-templates select="node()" mode="LesML:finalize"/>
886 <for-each select="exslset:leading(following-sibling::node(), $notinsection)">
888 <apply-templates select="@*|node()" mode="LesML:finalize">
889 <with-param name="used-footnotes" select="$used-footnotes"/>
895 <template match="html:*[html:li/@aria-level>1]" mode="LesML:finalize">
896 <param name="used-footnotes" select="/.."/>
897 <if test="not(preceding-sibling::node()[not(html:li/@aria-level>1)][1]/self::html:section)">
899 <apply-templates select="@*|node()" mode="LesML:finalize">
900 <with-param name="used-footnotes" select="$used-footnotes"/>
905 <template match="text()" mode="LesML:finalize">
906 <call-template name="LesML:break-and-unescape">
907 <with-param name="source" select="string()"/>
910 <template match="@*|node()" mode="LesML:finalize" priority="-1">
911 <param name="used-footnotes" select="/.."/>
913 <apply-templates select="@*|html:p[1]/@*[&pilcrow-atts;]" mode="LesML:finalize"/>
914 <apply-templates select="node()" mode="LesML:finalize">
915 <with-param name="used-footnotes" select="$used-footnotes"/>
919 <template match="node()" mode="LesML:finalize-attributes">
920 <variable name="notattr" select="following-sibling::node()[not(self::text() and translate(., ' 	', '')='' or self::LesML:attribute)]"/>
921 <for-each select="(.|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
922 <copy-of select="."/>
923 <if test="local-name()='lang' and namespace-uri()=''">
924 <attribute name="xml:lang">
925 <value-of select="."/>
930 <template match="html:li" mode="LesML:finalize-list">
931 <param name="parent-level" select="0"/>
932 <variable name="current-class" select="string(@class)"/>
933 <variable name="current-level" select="number(@aria-level)"/>
934 <variable name="wrapper">
936 <when test="contains(concat(' ', @class, ' '), ' ordered ')">
944 <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]"/>
945 <element name="{$wrapper}" namespace="&xhtml;">
946 <if test="contains(concat(' ', @class, ' '), ' footnote ')">
947 <processing-instruction name="LesML-Footnote"/>
949 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)[self::html:li and @aria-level=$current-level]">
950 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
952 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
953 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
954 <apply-templates select="node()" mode="LesML:finalize-tree"/>
956 <if test="$notcontinuation/self::html:li[@aria-level>$current-level]">
957 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
958 <with-param name="parent-level" select="$current-level"/>
964 <if test="$notinlist/self::html:li[@aria-level>$parent-level]">
965 <apply-templates select="$notinlist" mode="LesML:finalize-list">
966 <with-param name="parent-level" select="$parent-level"/>
970 <template match="LesML:attribute[preceding-sibling::node()[position()=1 and (self::text() or self::*)]]|text()[preceding-sibling::node()[position()=1 and self::*] and following-sibling::node()[position()=1 and self::LesML:attribute] and translate(., ' 	', '')='']" mode="LesML:finalize-tree" priority="2"/>
971 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize-tree" priority="1">
972 <element name="span" namespace="&xhtml;">
973 <apply-templates select="." mode="LesML:finalize-attributes"/>
974 <if test="self::text()">
979 <template match="html:div" mode="LesML:finalize-tree">
980 <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())])">
981 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
983 <when test="processing-instruction()[local-name()='LesML-Continuation'] and $notcontinuation[self::html:* and contains(' h1 h2 h3 h4 h5 h6 ', local-name())]">
984 <variable name="notcontinuation2" select="$notcontinuation/following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
985 <element name="hgroup" namespace="&xhtml;">
986 <apply-templates select="node()" mode="LesML:finalize-tree"/>
987 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation2)">
989 <when test="self::html:div">
990 <apply-templates select="node()" mode="LesML:finalize-tree"/>
994 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
1001 <when test="not(processing-instruction()[local-name()='LesML-Continuation'])">
1003 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
1004 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
1005 <apply-templates select="node()" mode="LesML:finalize-tree"/>
1010 <apply-templates select="node()" mode="LesML:finalize-tree"/>
1011 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
1012 <apply-templates select="node()" mode="LesML:finalize-tree"/>
1018 <template match="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6" mode="LesML:finalize-tree">
1019 <if test="not(preceding-sibling::node()[position()=1 and self::html:div/processing-instruction()[local-name()='LesML-Continuation']]) or preceding-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][position()=1 and self::html:* and contains(' h1 h2 h3 h4 h5 h6 ', local-name())]">
1021 <when test="following-sibling::node()[position()=1 and self::html:div]/processing-instruction()[local-name()='LesML-Continuation']">
1022 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
1023 <element name="hgroup" namespace="&xhtml;">
1025 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
1027 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
1028 <apply-templates select="node()" mode="LesML:finalize-tree"/>
1034 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
1040 <template match="html:li" mode="LesML:finalize-tree">
1041 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[not(preceding-sibling::* and self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][position()=1 and not(self::html:li)]">
1042 <apply-templates select="." mode="LesML:finalize-list"/>
1045 <template match="html:section" mode="LesML:finalize-tree">
1046 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div/processing-instruction()[local-name()='LesML-Continuation'])][1]"/>
1048 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
1049 <for-each select="exslset:leading(following-sibling::node(), $notcontinuation)">
1050 <apply-templates select="node()" mode="LesML:finalize-tree"/>
1054 <template match="processing-instruction()[local-name()='LesML-Continuation']" mode="LesML:finalize-tree"/>
1055 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finalize-tree">
1056 <value-of select="."/>
1058 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
1060 <apply-templates select="." mode="LesML:finalize-attributes"/>
1061 <apply-templates select="node()" mode="LesML:finalize-tree"/>
1064 <template match="node()" mode="LesML:inline">
1065 <param name="element-name"/>
1066 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
1067 <param name="start-sigil"/>
1068 <param name="end-sigil"/>
1069 <param name="class"/>
1070 <param name="role"/>
1072 <when test="self::*">
1073 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1074 <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))"/>
1076 <when test="$end-node and $has-start-node">
1077 <variable name="preceding">
1078 <copy-of select="$end-node/preceding-sibling::node()"/>
1079 <value-of select="substring-before($end-node, $end-sigil)"/>
1081 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
1082 <variable name="start-tokens-fragment">
1083 <call-template name="LesML:split">
1084 <with-param name="source" select="string($start-node)"/>
1085 <with-param name="separator" select="$start-sigil"/>
1088 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
1089 <variable name="wrapped">
1091 <copy-of select="@*"/>
1092 <copy-of select="$start-node/preceding-sibling::node()"/>
1093 <for-each select="$start-tokens[position()!=last()]">
1094 <value-of select="."/>
1095 <if test="position()!=last()">
1096 <value-of select="$start-sigil"/>
1099 <element name="{$element-name}" namespace="{$element-namespace}">
1100 <if test="string($role)!=''">
1101 <attribute name="role">
1102 <value-of select="$role"/>
1105 <if test="string($class)!=''">
1106 <attribute name="class">
1107 <value-of select="$class"/>
1110 <value-of select="$start-tokens[last()]"/>
1111 <copy-of select="$start-node/following-sibling::node()"/>
1113 <value-of select="substring-after($end-node, $end-sigil)"/>
1114 <copy-of select="$end-node/following-sibling::node()"/>
1117 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
1118 <with-param name="element-name" select="$element-name"/>
1119 <with-param name="element-namespace" select="$element-namespace"/>
1120 <with-param name="start-sigil" select="$start-sigil"/>
1121 <with-param name="end-sigil" select="$end-sigil"/>
1122 <with-param name="role" select="$role"/>
1127 <copy-of select="@*"/>
1128 <apply-templates select="node()" mode="LesML:inline">
1129 <with-param name="element-name" select="$element-name"/>
1130 <with-param name="element-namespace" select="$element-namespace"/>
1131 <with-param name="start-sigil" select="$start-sigil"/>
1132 <with-param name="end-sigil" select="$end-sigil"/>
1133 <with-param name="role" select="$role"/>
1140 <copy-of select="."/>
1144 <template match="*" mode="LesML:partition">
1145 <param name="start-sigil"/>
1146 <param name="end-sigil"/>
1147 <param name="separator"/>
1148 <param name="ncname-keys" select="false()"/>
1149 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1150 <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))"/>
1152 <when test="$end-node and $has-start-node">
1153 <variable name="preceding-fragment">
1154 <copy-of select="$end-node/preceding-sibling::node()"/>
1155 <value-of select="substring-before($end-node, $end-sigil)"/>
1157 <variable name="preceding" select="exsl:node-set($preceding-fragment)/node()"/>
1158 <variable name="start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()][not($ncname-keys) or not(following-sibling::* or following-sibling::comment())]"/>
1159 <variable name="start-tokens-fragment">
1160 <if test="$start-node">
1161 <call-template name="LesML:split">
1162 <with-param name="source" select="string($start-node)"/>
1163 <with-param name="separator" select="$start-sigil"/>
1167 <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
1168 <variable name="innards-fragment">
1169 <value-of select="$start-tokens[last()]"/>
1170 <copy-of select="$start-node/following-sibling::node()"/>
1172 <variable name="innards" select="exsl:node-set($innards-fragment)/node()"/>
1173 <variable name="separator-node" select="($innards[self::text() and contains(., $separator)])[not($ncname-keys)*(last()-1)+1]"/>
1175 <when test="not($start-node) or $separator-node[following-sibling::* or following-sibling::comment()]">
1176 <variable name="bad-start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()]"/>
1177 <variable name="bad-start-tokens-fragment">
1178 <call-template name="LesML:split">
1179 <with-param name="source" select="string($bad-start-node)"/>
1180 <with-param name="separator" select="$start-sigil"/>
1183 <element name="span" namespace="&xhtml;">
1184 <copy-of select="$bad-start-node/preceding-sibling::node()"/>
1185 <for-each select="exsl:node-set($bad-start-tokens-fragment)/*">
1186 <value-of select="."/>
1187 <if test="position()!=last()">
1188 <processing-instruction name="LesML-Token-Escape">
1189 <value-of select="$start-sigil"/>
1190 </processing-instruction>
1193 <copy-of select="$bad-start-node/following-sibling::node()"/>
1194 <value-of select="$end-sigil"/>
1195 <value-of select="substring-after($end-node, $end-sigil)"/>
1196 <copy-of select="$end-node/following-sibling::node()"/>
1199 <when test="$separator-node">
1200 <variable name="keyval-fragment">
1201 <call-template name="LesML:split">
1202 <with-param name="source" select="$separator-node"/>
1203 <with-param name="separator" select="$separator"/>
1206 <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
1207 <variable name="key-fragment">
1209 <when test="$ncname-keys">
1210 <for-each select="$separator-node/preceding-sibling::node()">
1211 <value-of select="."/>
1213 <value-of select="$keyval[1]"/>
1216 <copy-of select="$separator-node/preceding-sibling::node()"/>
1217 <for-each select="$keyval[position()!=last()]">
1218 <value-of select="."/>
1219 <if test="position()!=last()">
1220 <value-of select="$separator"/>
1226 <variable name="value">
1228 <when test="$ncname-keys">
1229 <for-each select="$keyval[position()!=1]">
1230 <value-of select="."/>
1231 <if test="position()!=last()">
1232 <value-of select="$separator"/>
1237 <value-of select="$keyval[last()]"/>
1240 <for-each select="$separator-node/following-sibling::node()">
1241 <value-of select="."/>
1245 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key-fragment), ' /([,*', '')=$key-fragment and exsldyn:evaluate(concat('not(self::html:', $key-fragment, ')'))]">
1246 <element name="span" namespace="&xhtml;">
1247 <copy-of select="$start-node/preceding-sibling::node()"/>
1248 <for-each select="$start-tokens[position()!=last()]">
1249 <value-of select="."/>
1250 <if test="position()!=last()">
1251 <value-of select="$start-sigil"/>
1255 <element name="span" namespace="&xhtml;">
1256 <copy-of select="$key-fragment"/>
1258 <element name="span" namespace="&xhtml;">
1259 <value-of select="$value"/>
1261 <element name="span" namespace="&xhtml;">
1262 <value-of select="substring-after($end-node, $end-sigil)"/>
1263 <copy-of select="$end-node/following-sibling::node()"/>
1267 <element name="span" namespace="&xhtml;">
1268 <copy-of select="$start-node/preceding-sibling::node()"/>
1269 <for-each select="$start-tokens[position()!=last()]">
1270 <value-of select="."/>
1271 <if test="position()!=last()">
1272 <value-of select="$start-sigil"/>
1275 <processing-instruction name="LesML-Token-Escape">
1276 <value-of select="$start-sigil"/>
1277 </processing-instruction>
1278 <value-of select="$start-tokens[last()]"/>
1279 <value-of select="$start-node/following-sibling::node()"/>
1280 <value-of select="$end-sigil"/>
1281 <value-of select="substring-after($end-node, $end-sigil)"/>
1282 <copy-of select="$end-node/following-sibling::node()"/>
1288 <element name="span" namespace="&xhtml;">
1289 <copy-of select="$start-node/preceding-sibling::node()"/>
1290 <for-each select="$start-tokens[position()!=last()]">
1291 <value-of select="."/>
1292 <if test="position()!=last()">
1293 <value-of select="$start-sigil"/>
1296 <processing-instruction name="LesML-Token-Escape">
1297 <value-of select="$start-sigil"/>
1298 </processing-instruction>
1299 <value-of select="$start-tokens[last()]"/>
1300 <copy-of select="$start-node/following-sibling::node()"/>
1301 <value-of select="$end-sigil"/>
1302 <value-of select="substring-after($end-node, $end-sigil)"/>
1303 <copy-of select="$end-node/following-sibling::node()"/>
1308 <when test="$end-node">
1309 <element name="span" namespace="&xhtml;">
1310 <copy-of select="$end-node/preceding-sibling::node()"/>
1311 <value-of select="substring-before($end-node, $end-sigil)"/>
1312 <processing-instruction name="LesML-Token-Escape">
1313 <value-of select="$end-sigil"/>
1314 </processing-instruction>
1315 <value-of select="substring-after($end-node, $end-sigil)"/>
1316 <copy-of select="$end-node/following-sibling::node()"/>
1320 <processing-instruction name="LesML-All-Done"/>
1324 <template match="node()" mode="LesML:comment">
1325 <param name="footnote-ids" select="/.."/>
1326 <variable name="result">
1328 <when test="self::*">
1329 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
1330 <variable name="after-start">
1331 <if test="$start-node">
1332 <value-of select="substring-after($start-node, '⌦')"/>
1335 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
1337 <when test="$start-node and $has-end-node">
1338 <variable name="following">
1339 <value-of select="$after-start"/>
1340 <copy-of select="$start-node/following-sibling::node()"/>
1342 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
1343 <variable name="comment">
1344 <for-each select="$end-node/preceding-sibling::node()">
1345 <value-of select="."/>
1347 <value-of select="substring-before($end-node, '⌫')"/>
1349 <variable name="rest-fragment">
1350 <element name="span" namespace="&xhtml;">
1351 <value-of select="substring-after($end-node, '⌫')"/>
1352 <copy-of select="$end-node/following-sibling::node()"/>
1355 <variable name="commented-rest-fragment">
1356 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
1357 <with-param name="footnote-ids" select="$footnote-ids"/>
1361 <copy-of select="@*"/>
1362 <copy-of select="$start-node/preceding-sibling::node()"/>
1363 <copy-of select="substring-before($start-node, '⌦')"/>
1364 <call-template name="LesML:comment-out">
1365 <with-param name="source" select="string($comment)"/>
1367 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
1370 <when test="$start-node">
1371 <variable name="rest-fragment">
1372 <element name="div" namespace="&xhtml;">
1373 <value-of select="substring-after($after-start, '⌦')"/>
1374 <copy-of select="$start-node/following-sibling::node()"/>
1377 <variable name="commented-rest-fragment">
1378 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
1379 <with-param name="footnote-ids" select="$footnote-ids"/>
1383 <copy-of select="@*"/>
1384 <copy-of select="$start-node/preceding-sibling::node()"/>
1385 <copy-of select="substring-before($start-node, '⌦')"/>
1387 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
1392 <copy-of select="@*"/>
1393 <apply-templates select="node()" mode="LesML:comment">
1394 <with-param name="footnote-ids" select="$footnote-ids"/>
1400 <when test="self::text()[contains(., '⌧')]">
1401 <variable name="split-fragment">
1402 <call-template name="LesML:split">
1403 <with-param name="source" select="string()"/>
1404 <with-param name="separator" select="'⌧'"/>
1407 <for-each select="exsl:node-set($split-fragment)/node()">
1408 <value-of select="."/>
1409 <if test="position()!=last()">
1410 <call-template name="LesML:comment-out"/>
1415 <copy-of select="."/>
1419 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:attrify">
1420 <with-param name="footnote-ids" select="$footnote-ids"/>
1423 <template match="node()" mode="LesML:attrify">
1424 <param name="footnote-ids" select="/.."/>
1425 <variable name="result">
1427 <when test="self::*">
1428 <variable name="partitioned-fragment">
1429 <apply-templates mode="LesML:partition" select=".">
1430 <with-param name="start-sigil" select="'{@'"/>
1431 <with-param name="end-sigil" select="'"}'"/>
1432 <with-param name="separator" select="'="'"/>
1433 <with-param name="ncname-keys" select="true()"/>
1436 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1438 <when test="count($partitioned)>1">
1439 <variable name="processed">
1441 <copy-of select="@*"/>
1442 <copy-of select="$partitioned[1]/node()"/>
1443 <element name="LesML:attribute" namespace="&LesML;">
1444 <attribute name="{$partitioned[2]}">
1445 <value-of select="$partitioned[3]"/>
1448 <copy-of select="$partitioned[4]/node()"/>
1451 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1452 <with-param name="footnote-ids" select="$footnote-ids"/>
1455 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1457 <copy-of select="@*"/>
1458 <apply-templates select="node()" mode="LesML:attrify">
1459 <with-param name="footnote-ids" select="$footnote-ids"/>
1464 <variable name="processed">
1466 <copy-of select="@*"/>
1467 <copy-of select="$partitioned/node()"/>
1470 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1471 <with-param name="footnote-ids" select="$footnote-ids"/>
1477 <copy-of select="."/>
1481 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:linkify">
1482 <with-param name="footnote-ids" select="$footnote-ids"/>
1485 <template match="node()" mode="LesML:linkify">
1486 <param name="footnote-ids" select="/.."/>
1487 <variable name="result">
1489 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1491 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1494 <when test="self::*">
1495 <variable name="partitioned-fragment">
1496 <apply-templates mode="LesML:partition" select=".">
1497 <with-param name="start-sigil" select="'{🔗'"/>
1498 <with-param name="end-sigil" select="'>}'"/>
1499 <with-param name="separator" select="'<'"/>
1502 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1504 <when test="count($partitioned)>1">
1505 <variable name="processed">
1507 <copy-of select="@*"/>
1508 <copy-of select="$partitioned[1]/node()"/>
1509 <element name="a" namespace="&xhtml;">
1510 <attribute name="href">
1511 <value-of select="$partitioned[3]"/>
1513 <processing-instruction name="LesML-All-Done"/>
1515 <when test="not($partitioned[2]/node())">
1516 <value-of select="$partitioned[3]"/>
1519 <copy-of select="$partitioned[2]/node()"/>
1523 <copy-of select="$partitioned[4]/node()"/>
1526 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1527 <with-param name="footnote-ids" select="$footnote-ids"/>
1530 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1532 <copy-of select="@*"/>
1533 <apply-templates select="node()" mode="LesML:linkify">
1534 <with-param name="footnote-ids" select="$footnote-ids"/>
1539 <variable name="processed">
1541 <copy-of select="@*"/>
1542 <copy-of select="$partitioned/node()"/>
1545 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1546 <with-param name="footnote-ids" select="$footnote-ids"/>
1552 <copy-of select="."/>
1556 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough">
1557 <with-param name="footnote-ids" select="$footnote-ids"/>
1560 <template match="node()" mode="LesML:strikethrough">
1561 <param name="footnote-ids" select="/.."/>
1562 <variable name="result">
1563 <apply-templates select="." mode="LesML:inline">
1564 <with-param name="element-name" select="'s'"/>
1565 <with-param name="element-namespace" select="'&xhtml;'"/>
1566 <with-param name="start-sigil" select="'⸠'"/>
1567 <with-param name="end-sigil" select="'⸡'"/>
1570 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline">
1571 <with-param name="footnote-ids" select="$footnote-ids"/>
1574 <template match="node()" mode="LesML:underline">
1575 <param name="footnote-ids" select="/.."/>
1576 <variable name="result">
1577 <apply-templates select="." mode="LesML:inline">
1578 <with-param name="element-name" select="'u'"/>
1579 <with-param name="element-namespace" select="'&xhtml;'"/>
1580 <with-param name="start-sigil" select="'⸤'"/>
1581 <with-param name="end-sigil" select="'⸥'"/>
1584 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted">
1585 <with-param name="footnote-ids" select="$footnote-ids"/>
1588 <template match="node()" mode="LesML:noted">
1589 <param name="footnote-ids" select="/.."/>
1590 <variable name="result">
1591 <apply-templates select="." mode="LesML:inline">
1592 <with-param name="element-name" select="'small'"/>
1593 <with-param name="element-namespace" select="'&xhtml;'"/>
1594 <with-param name="start-sigil" select="'⟦'"/>
1595 <with-param name="end-sigil" select="'⟧'"/>
1596 <with-param name="role" select="'note'"/>
1599 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical">
1600 <with-param name="footnote-ids" select="$footnote-ids"/>
1603 <template match="node()" mode="LesML:parenthetical">
1604 <param name="footnote-ids" select="/.."/>
1605 <variable name="result">
1606 <apply-templates select="." mode="LesML:inline">
1607 <with-param name="element-name" select="'small'"/>
1608 <with-param name="element-namespace" select="'&xhtml;'"/>
1609 <with-param name="start-sigil" select="'⸨'"/>
1610 <with-param name="end-sigil" select="'⸩'"/>
1613 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code">
1614 <with-param name="footnote-ids" select="$footnote-ids"/>
1617 <template match="node()" mode="LesML:code">
1618 <param name="footnote-ids" select="/.."/>
1619 <variable name="result">
1620 <apply-templates select="." mode="LesML:inline">
1621 <with-param name="element-name" select="'code'"/>
1622 <with-param name="element-namespace" select="'&xhtml;'"/>
1623 <with-param name="start-sigil" select="'`'"/>
1624 <with-param name="end-sigil" select="'´'"/>
1627 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled">
1628 <with-param name="footnote-ids" select="$footnote-ids"/>
1631 <template match="node()" mode="LesML:titled">
1632 <param name="footnote-ids" select="/.."/>
1633 <variable name="result">
1634 <apply-templates select="." mode="LesML:inline">
1635 <with-param name="element-name" select="'cite'"/>
1636 <with-param name="element-namespace" select="'&xhtml;'"/>
1637 <with-param name="start-sigil" select="'⟪'"/>
1638 <with-param name="end-sigil" select="'⟫'"/>
1641 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:named">
1642 <with-param name="footnote-ids" select="$footnote-ids"/>
1645 <template match="node()" mode="LesML:named">
1646 <param name="footnote-ids" select="/.."/>
1647 <variable name="result">
1648 <apply-templates select="." mode="LesML:inline">
1649 <with-param name="element-name" select="'u'"/>
1650 <with-param name="element-namespace" select="'&xhtml;'"/>
1651 <with-param name="start-sigil" select="'⸶'"/>
1652 <with-param name="end-sigil" select="'⸷'"/>
1653 <with-param name="class" select="'name'"/>
1656 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset">
1657 <with-param name="footnote-ids" select="$footnote-ids"/>
1660 <template match="node()" mode="LesML:offset">
1661 <param name="footnote-ids" select="/.."/>
1662 <variable name="result">
1663 <apply-templates select="." mode="LesML:inline">
1664 <with-param name="element-name" select="'i'"/>
1665 <with-param name="element-namespace" select="'&xhtml;'"/>
1666 <with-param name="start-sigil" select="'⟨'"/>
1667 <with-param name="end-sigil" select="'⟩'"/>
1670 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded">
1671 <with-param name="footnote-ids" select="$footnote-ids"/>
1674 <template match="node()" mode="LesML:bolded">
1675 <param name="footnote-ids" select="/.."/>
1676 <variable name="result">
1677 <apply-templates select="." mode="LesML:inline">
1678 <with-param name="element-name" select="'b'"/>
1679 <with-param name="element-namespace" select="'&xhtml;'"/>
1680 <with-param name="start-sigil" select="'⦃'"/>
1681 <with-param name="end-sigil" select="'⦄'"/>
1684 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important">
1685 <with-param name="footnote-ids" select="$footnote-ids"/>
1688 <template match="node()" mode="LesML:important">
1689 <param name="footnote-ids" select="/.."/>
1690 <variable name="result">
1691 <apply-templates select="." mode="LesML:inline">
1692 <with-param name="element-name" select="'strong'"/>
1693 <with-param name="element-namespace" select="'&xhtml;'"/>
1694 <with-param name="start-sigil" select="'☞'"/>
1695 <with-param name="end-sigil" select="'☜'"/>
1698 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized">
1699 <with-param name="footnote-ids" select="$footnote-ids"/>
1702 <template match="node()" mode="LesML:emphasized">
1703 <param name="footnote-ids" select="/.."/>
1704 <variable name="result">
1705 <apply-templates select="." mode="LesML:inline">
1706 <with-param name="element-name" select="'em'"/>
1707 <with-param name="element-namespace" select="'&xhtml;'"/>
1708 <with-param name="start-sigil" select="'⹐'"/>
1709 <with-param name="end-sigil" select="'⹑'"/>
1712 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:footnoted">
1713 <with-param name="footnote-ids" select="$footnote-ids"/>
1716 <template match="node()" mode="LesML:footnoted">
1717 <param name="footnote-ids" select="/.."/>
1719 <when test="self::*">
1720 <variable name="start-node" select="text()[contains(., '^')][1]"/>
1721 <variable name="after-start" select="substring-after($start-node, '^')"/>
1722 <variable name="footnote-id" select="substring-before($after-start, '.')"/>
1723 <variable name="matched-footnote" select="$footnote-ids[.=$footnote-id]"/>
1725 <when test="$footnote-id!='' and $matched-footnote">
1726 <variable name="rest-fragment">
1727 <element name="div" namespace="&xhtml;">
1728 <value-of select="substring-after($after-start, '.')"/>
1729 <copy-of select="$start-node/following-sibling::node()"/>
1732 <variable name="footnoted-rest-fragment">
1733 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1734 <with-param name="footnote-ids" select="$footnote-ids"/>
1738 <copy-of select="@*"/>
1739 <copy-of select="$start-node/preceding-sibling::node()"/>
1740 <copy-of select="substring-before($start-node, '^')"/>
1741 <element name="a" namespace="&xhtml;">
1742 <attribute name="id">
1743 <text>LesML.fnref.</text>
1744 <value-of select="generate-id($start-node)"/>
1746 <attribute name="role">
1747 <text>doc-noteref</text>
1749 <attribute name="href">
1751 <value-of select="$footnote-id"/>
1753 <attribute name="target">
1757 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1760 <when test="$start-node">
1761 <variable name="rest-fragment">
1762 <element name="div" namespace="&xhtml;">
1763 <value-of select="substring-after($after-start, '^')"/>
1764 <copy-of select="$start-node/following-sibling::node()"/>
1767 <variable name="footnoted-rest-fragment">
1768 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1769 <with-param name="footnote-ids" select="$footnote-ids"/>
1773 <copy-of select="@*"/>
1774 <copy-of select="$start-node/preceding-sibling::node()"/>
1775 <copy-of select="substring-before($start-node, '^')"/>
1777 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1782 <copy-of select="@*"/>
1783 <apply-templates select="node()" mode="LesML:footnoted">
1784 <with-param name="footnote-ids" select="$footnote-ids"/>
1791 <copy-of select="."/>