]> Lady’s Gitweb - LesML/blob - xslt/lesml.xslt
Support definition lists (finally!)
[LesML] / xslt / lesml.xslt
1 <?xml version="1.0"?>
2 <!--
3 @(#)💄📝 Les·M·L xslt/lesml.xslt 2026-03-31T01:31:16Z
4 SPDX-FileCopyrightText: 2024, 2025, 2026 Lady <https://www.ladys.computer/about/#lady>
5 SPDX-License-Identifier: MPL-2.0
6 -->
7
8 <!-->
9 ⁌ The 💄📝 Les·M·L transform
10
11 ∎ Copyright © 2024–2026 Lady [@ Ladys Computer]
12
13 ⋮ This Source Code Form is subject to the terms of the Mozilla Public
14 License, v 2.0.
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/>}.
17
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
23 be implemented here.
24
25 § Implementation
26
27 ❦ On `LesML-´ processing instructions
28
29 Processing instructions which begin with `LesML-´ are used internally
30 for bookkeeping as, unlike attributes, the Les·M·L format provides
31 no means by which authors could generate them.
32 All of these instructions should be removed by the end of the
33 transformation, but understanding them is important to understanding
34 how this code operates.
35 The processing instructions are as follows :⁠—
36
37 • `<?LesML-Footnote?>´ identifies list items which are also footnotes.
38
39 • `<?LesML-Level?>´ gives the level of the containing block or
40 paragraph.
41
42 ❦ Doctype, entity, and namespace definitions
43
44 The `&block-types;´ and `&paragraph-types;´ entities provide X·Path
45 tests for determining if the current node is a block or paragraph
46 element.
47 The `&level-pi;´ entity provides an X·Path selector for
48 `<?LesML-Level?>´ processing instructions.
49 </!-->
50
51 <!DOCTYPE transform [
52 <!ENTITY LesML "urn:fdc:ladys.computer:20240512:LesML">
53 <!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 &paragraph-types;">
54 <!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">
55 <!ENTITY level-pi "processing-instruction()[local-name()='LesML-Level']">
56 <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
57 ]>
58 <transform
59 xmlns="http://www.w3.org/1999/XSL/Transform"
60 xmlns:LesML="&LesML;"
61 xmlns:exsl="http://exslt.org/common"
62 xmlns:exsldyn="http://exslt.org/dynamic"
63 xmlns:exslfunc="http://exslt.org/functions"
64 xmlns:exslset="http://exslt.org/sets"
65 xmlns:exslstr="http://exslt.org/strings"
66 xmlns:html="&xhtml;"
67 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
68 exclude-result-prefixes="LesML"
69 extension-element-prefixes="exsl exsldyn exslfunc exslset exslstr"
70 version="1.0"
71 >
72 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
73
74 <!-->
75 ❦ Template parameters
76
77 The `LESML_SECTION_BREAK_CHARS´ parameter is provided to allow users to
78 configure which characters are treated as section break characters.
79 Changing this value isn¦t recommended, but the option is provided for
80 now.
81 </!-->
82
83 <param name="LESML_SECTION_BREAK_CHARS" select="'*-.=_~ ·․‥…⁂⁠⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'"/>
84
85 <!-->
86 ❦ Functions
87
88 The `LesML:split´ function returns a nodeset of H·T·M·L `<span>´
89 elements, with each one giving the next item whivh results from
90 splitting the provided source text on the provided separator.
91 This is just a convenience wrapper for the `LesML:do-split´ named
92 template.
93 </!-->
94
95 <exslfunc:function name="LesML:split">
96 <param name="source" select="string()"/>
97 <param name="separator" select="'&#xA;'"/>
98 <variable name="result-fragment">
99 <call-template name="LesML:do-split">
100 <with-param name="source" select="$source"/>
101 <with-param name="separator" select="$separator"/>
102 </call-template>
103 </variable>
104 <exslfunc:result select="exsl:node-set($result-fragment)/node()"/>
105 </exslfunc:function>
106
107 <!-->
108 ❦ Named templates
109
110 In contrast to matching templates, named templates generally operate on
111 a single string or a flat list of lines, which are provided as
112 parameters.
113 Some of these are small utility templates, whereas others provide the
114 bulk of the block‐level processing.
115
116 ✠ `LesML:do-split´
117
118 The `LesML:do-split´ template provides the internal implementation for
119 the `LesML:split´ function.
120 </!-->
121
122 <template name="LesML:do-split">
123 <param name="source"/>
124 <param name="separator" select="'&#xA;'"/>
125 <choose>
126 <when test="contains($source, $separator)">
127 <html:span>
128 <value-of select="substring-before($source, $separator)"/>
129 </html:span>
130 <call-template name="LesML:do-split">
131 <with-param name="source" select="substring-after($source, $separator)"/>
132 <with-param name="separator" select="$separator"/>
133 </call-template>
134 </when>
135 <otherwise>
136 <html:span>
137 <value-of select="$source"/>
138 </html:span>
139 </otherwise>
140 </choose>
141 </template>
142
143 <!-->
144 ✠ `LesML:comment-out´
145
146 The `LesML:comment-out´ template simply produces an X·M·L comment
147 containing the provided text.
148 This is only nontrivial because it has to escape any `{U+2D}{U+2D}´
149 sequences, which are not permitted in X·M·L.
150
151 The escaping simply inserts `U+034F COMBINING GRAPHEME JOINER´, which
152 is (per Unicode) intended to be used when disambiguating digraphs
153 from two independent characters in sequence.
154 </!-->
155
156 <template name="LesML:comment-out">
157 <param name="source"/>
158 <comment>
159 <for-each select="LesML:split($source, '--')">
160 <if test="string()='' or starts-with(., '‐')">
161 <text>&#x034F;</text>
162 </if>
163 <value-of select="."/>
164 <if test="substring(., string-length(.), 1)='‐'">
165 <text>&#x034F;</text>
166 </if>
167 <choose>
168 <when test="position()!=last()">
169 <text>-&#x034F;-</text>
170 </when>
171 </choose>
172 </for-each>
173 </comment>
174 </template>
175
176 <!-->
177 ✠ `LesML:unescape´
178
179 The `LesML:unescape´ template takes the provided source text and
180 processes the Unicode character escapes within it.
181 The result of this template is raw, unescaped X·M·L, because the only
182 way to implement Unicode character escapes is to convert them to
183 X·M·L entities, which do not have a representation in the X·S·L·T
184 data model.
185 Consequently, this template must be among the last ones called and its
186 output cannot be fed back into X·S·L·T safely.
187 </!-->
188
189 <template name="LesML:unescape">
190 <param name="source"/>
191 <choose>
192 <when test="contains($source, '{U+')">
193 <variable name="after" select="substring-after($source, '{U+')"/>
194 <choose>
195 <when test="contains($after, '}')">
196 <variable name="inner" select="substring-before($after, '}')"/>
197 <variable name="components" select="LesML:split($inner, '.')"/>
198 <value-of select="substring-before($source, '{U+')"/>
199 <choose>
200 <when test="$components[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
201 <text>{U+</text>
202 <value-of select="$inner"/>
203 <text>}</text>
204 <call-template name="LesML:unescape">
205 <with-param name="source" select="substring-after($after, '}')"/>
206 </call-template>
207 </when>
208 <otherwise>
209 <for-each select="$components">
210 <text disable-output-escaping="yes">&amp;#x</text>
211 <value-of select="."/>
212 <text>;</text>
213 </for-each>
214 <call-template name="LesML:unescape">
215 <with-param name="source" select="substring-after($after, '}')"/>
216 </call-template>
217 </otherwise>
218 </choose>
219 </when>
220 <otherwise>
221 <value-of select="substring-before($source, '{U+')"/>
222 <text>{U+</text>
223 <call-template name="LesML:unescape">
224 <with-param name="source" select="$after"/>
225 </call-template>
226 </otherwise>
227 </choose>
228 </when>
229 <otherwise>
230 <value-of select="$source"/>
231 </otherwise>
232 </choose>
233 </template>
234
235 <!-->
236 ✠ `LesML:expand-sigils´
237
238 The `LesML:expand-sigils´ template converts a list of block sigils into
239 the resulting H·T·M·L structure.
240 It requires a number of parameters :⁠—
241
242 • The sigils themselves, as a flat list of nodes.
243
244 • The level of the resulting (outermost) block.
245
246 • The type of paragraph to be created within the (innermost) block.
247
248 • For preformatted code paragraphs, the associated syntax name.
249
250 • The lines of content within the paragraph, as a flat list of nodes.
251
252 For as long as the sigils are nonempty, the template is simply called
253 again with the level incremented and the outer sigil removed, with
254 the result wrapped appropriately.
255 When no sigils remain, an appropriate paragraph element is created,
256 processing as necessary a leading `¶´ only if it appears on the first
257 line.
258
259 Paragraphs and comments are “wrapped” in a `<div>´ to enable them to
260 participate in level nesting, and this `<div>´ is assigned their
261 `@id´ and `@lang´.
262 They will later be “unwrapped”, and reclaim these attributes, if they
263 are not footnotes or comments and do not have any block children.
264 If a block is nested within the wrapping `<div>´ of a paragraph, the
265 wrapping `<div>´ is preserved as the wrapper for both the paragraph
266 and its nested contents.
267 </!-->
268
269 <template name="LesML:expand-sigils">
270 <param name="sigils" select="/.."/>
271 <param name="level" select="0"/>
272 <param name="partype"/>
273 <param name="syntax"/>
274 <param name="lines" select="/.."/>
275 <choose>
276 <when test="$sigils">
277 <variable name="wrapper-frag">
278 <choose>
279 <when test="$sigils[1]='•'">
280 <element name="li" namespace="&xhtml;">
281 <attribute name="class">
282 <text>unordered</text>
283 </attribute>
284 </element>
285 </when>
286 <when test="$sigils[1]='№'">
287 <element name="li" namespace="&xhtml;">
288 <attribute name="class">
289 <text>ordered</text>
290 </attribute>
291 </element>
292 </when>
293 <when test="$sigils[1]='℣'">
294 <element name="dt" namespace="&xhtml;"/>
295 </when>
296 <when test="$sigils[1]='℟'">
297 <element name="dd" namespace="&xhtml;"/>
298 </when>
299 <when test="$sigils[1]='※'">
300 <element name="section" namespace="&xhtml;">
301 <attribute name="role">
302 <text>note</text>
303 </attribute>
304 <attribute name="class">
305 <text>note</text>
306 </attribute>
307 </element>
308 </when>
309 <when test="$sigils[1]='⯑'">
310 <element name="section" namespace="&xhtml;">
311 <attribute name="role">
312 <text>note</text>
313 </attribute>
314 <attribute name="class">
315 <text>query</text>
316 </attribute>
317 </element>
318 </when>
319 <when test="$sigils[1]='∫'">
320 <element name="section" namespace="&xhtml;">
321 <attribute name="role">
322 <text>doc-abstract</text>
323 </attribute>
324 <attribute name="class">
325 <text>abstract</text>
326 </attribute>
327 </element>
328 </when>
329 <when test="$sigils[1]='☡'">
330 <element name="section" namespace="&xhtml;">
331 <attribute name="role">
332 <text>doc-notice</text>
333 </attribute>
334 <attribute name="class">
335 <text>caution</text>
336 </attribute>
337 </element>
338 </when>
339 <when test="$sigils[1]='⚠'">
340 <element name="section" namespace="&xhtml;">
341 <attribute name="role">
342 <text>doc-notice</text>
343 </attribute>
344 <attribute name="class">
345 <text>warning</text>
346 </attribute>
347 </element>
348 </when>
349 <when test="$sigils[1]='🛈'">
350 <element name="section" namespace="&xhtml;">
351 <attribute name="role">
352 <text>doc-tip</text>
353 </attribute>
354 <attribute name="class">
355 <text>info</text>
356 </attribute>
357 </element>
358 </when>
359 <when test="$sigils[1]='💡'">
360 <element name="section" namespace="&xhtml;">
361 <attribute name="role">
362 <text>doc-tip</text>
363 </attribute>
364 <attribute name="class">
365 <text>tip</text>
366 </attribute>
367 </element>
368 </when>
369 <when test="$sigils[1]='»'">
370 <element name="blockquote" namespace="&xhtml;"/>
371 </when>
372 <when test="$sigils[1]='∎'">
373 <element name="footer" namespace="&xhtml;"/>
374 </when>
375 <otherwise>
376 <message terminate="yes">
377 <text>Unrecognized sigil: </text>
378 <value-of select="$sigils[1]"/>
379 <text>.</text>
380 </message>
381 </otherwise>
382 </choose>
383 </variable>
384 <for-each select="exsl:node-set($wrapper-frag)/*">
385 <copy>
386 <copy-of select="@*|node()"/>
387 <processing-instruction name="LesML-Level">
388 <value-of select="$level"/>
389 </processing-instruction>
390 <call-template name="LesML:expand-sigils">
391 <with-param name="sigils" select="$sigils[position()>1]"/>
392 <with-param name="level" select="$level+1"/>
393 <with-param name="partype" select="$partype"/>
394 <with-param name="syntax" select="$syntax"/>
395 <with-param name="lines" select="$lines"/>
396 </call-template>
397 </copy>
398 </for-each>
399 </when>
400 <when test="$partype='comment'">
401 <element name="div" namespace="&xhtml;">
402 <processing-instruction name="LesML-Level">
403 <value-of select="$level"/>
404 </processing-instruction>
405 <call-template name="LesML:comment-out">
406 <with-param name="source">
407 <for-each select="$lines">
408 <value-of select="."/>
409 <if test="position()!=count($lines)">
410 <text>&#xA;</text>
411 </if>
412 </for-each>
413 </with-param>
414 </call-template>
415 </element>
416 </when>
417 <otherwise>
418 <variable name="firstchar" select="substring(translate($lines[1], ' &#x9;', ''), 1, 1)"/>
419 <variable name="firstline">
420 <choose>
421 <when test="$firstchar!=''">
422 <value-of select="concat($firstchar, substring-after($lines[1], $firstchar))"/>
423 </when>
424 </choose>
425 </variable>
426 <variable name="firsttokens" select="exslstr:tokenize($firstline, ' &#x9;')"/>
427 <variable name="id-and-lang">
428 <if test="$firstchar='¶'">
429 <value-of select="$firsttokens[1]"/>
430 </if>
431 </variable>
432 <variable name="restofline">
433 <choose>
434 <when test="$id-and-lang!=''">
435 <variable name="nosp" select="substring($firsttokens[1+number($id-and-lang!='')], 1, 1)"/>
436 <if test="$nosp!=''">
437 <value-of select="concat($nosp, substring-after(substring-after($firstline, $id-and-lang), $nosp))"/>
438 </if>
439 </when>
440 <otherwise>
441 <value-of select="$lines[1]"/>
442 </otherwise>
443 </choose>
444 </variable>
445 <variable name="maybe-langtag">
446 <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
447 <value-of select="LesML:split(substring($id-and-lang, 2, string-length($id-and-lang)-2), '@')[last()]"/>
448 </if>
449 </variable>
450 <variable name="langtag">
451 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
452 <value-of select="$maybe-langtag"/>
453 </if>
454 </variable>
455 <variable name="id">
456 <choose>
457 <when test="string($langtag)!=''">
458 <value-of select="substring($id-and-lang, 2, string-length($id-and-lang)-(string-length($langtag)+3))"/>
459 </when>
460 <otherwise>
461 <value-of select="substring($id-and-lang, 2)"/>
462 </otherwise>
463 </choose>
464 </variable>
465 <variable name="newline">
466 <choose>
467 <when test="$partype='pre' or $partype='pre code'">
468 <element name="br" namespace="&xhtml;"/>
469 </when>
470 <otherwise>
471 <text>&#xA;</text>
472 </otherwise>
473 </choose>
474 </variable>
475 <variable name="text">
476 <if test="$id-and-lang='' or $restofline!=''">
477 <value-of select="$restofline"/>
478 <if test="count($lines)>1">
479 <copy-of select="$newline"/>
480 </if>
481 </if>
482 <for-each select="$lines[position()>1]">
483 <value-of select="."/>
484 <if test="position()!=count($lines[position()>1])">
485 <copy-of select="$newline"/>
486 </if>
487 </for-each>
488 </variable>
489 <variable name="parwrapper">
490 <choose>
491 <when test="$partype='pre code'">
492 <text>pre</text>
493 </when>
494 <when test="$partype='footnote'">
495 <text>p</text>
496 </when>
497 <when test="$partype!=''">
498 <value-of select="$partype"/>
499 </when>
500 <otherwise>
501 <text>p</text>
502 </otherwise>
503 </choose>
504 </variable>
505 <element name="div" namespace="&xhtml;">
506 <if test="$id!=''">
507 <attribute name="id">
508 <value-of select="$id"/>
509 </attribute>
510 </if>
511 <if test="$langtag!=''">
512 <attribute name="lang">
513 <value-of select="$langtag"/>
514 </attribute>
515 <attribute name="xml:lang">
516 <value-of select="$langtag"/>
517 </attribute>
518 </if>
519 <if test="$partype='footnote'">
520 <processing-instruction name="LesML-Footnote">
521 <value-of select="$id"/>
522 </processing-instruction>
523 </if>
524 <processing-instruction name="LesML-Level">
525 <value-of select="$level"/>
526 </processing-instruction>
527 <element name="{$parwrapper}" namespace="&xhtml;">
528 <if test="$parwrapper='pre'">
529 <attribute name="role">
530 <text>paragraph</text>
531 </attribute>
532 </if>
533 <if test="$partype='pre code'">
534 <attribute name="class">
535 <text>code</text>
536 </attribute>
537 </if>
538 <if test="$syntax!=''">
539 <attribute name="data-syntax">
540 <value-of select="$syntax"/>
541 </attribute>
542 </if>
543 <choose>
544 <when test="$parwrapper='hr'">
545 <attribute name="data-source-text">
546 <value-of select="$text"/>
547 </attribute>
548 </when>
549 <otherwise>
550 <copy-of select="$text"/>
551 </otherwise>
552 </choose>
553 </element>
554 </element>
555 </otherwise>
556 </choose>
557 </template>
558
559 <!-->
560 ✠ `LesML:chunk´
561
562 The `LesML:chunk´ template converts the provided list of lines into the
563 list of block elements that they represent.
564 This comprises the following steps :⁠—
565
566 • Discovering the “last” lines of each block, which are nonempty lines
567 that are not followed by a nonempty line.
568
569 • Collecting all of the lines in the block; i·e all lines since the
570 previous “last” line that are not empty.
571
572 • Determining the level of the block and its sigils.
573
574 • Passing the lines of the block, with any leading sigils removed, to
575 `LesML:expand-sigils´ to generate the actual block element.
576 This also requires processing any paragraph‐type indicators and
577 stripping them if necessary to get the type of the underlying
578 paragraph.
579 </!-->
580
581 <template name="LesML:chunk">
582 <param name="lines" select="/.."/>
583 <variable name="last-lines" select="$lines[normalize-space()!='' and (normalize-space(following-sibling::*[1])='' or position()=last())]"/>
584 <for-each select="$last-lines">
585 <variable name="position" select="position()"/>
586 <variable name="prev-last" select="$last-lines[($position)-1]"/>
587 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
588 <variable name="nospace" select="translate($linespans[1], ' &#x9;', '')"/>
589 <variable name="firstnolevel" select="substring(translate($nospace, '⋮', ''), 1, 1)"/>
590 <variable name="levelling">
591 <choose>
592 <when test="$firstnolevel!=''">
593 <value-of select="substring-before($linespans[1], $firstnolevel)"/>
594 </when>
595 <otherwise>
596 <value-of select="$linespans[1]"/>
597 </otherwise>
598 </choose>
599 </variable>
600 <variable name="nested-bullet">
601 <choose>
602 <when test="contains('◦▪⁃', $firstnolevel)">
603 <value-of select="$firstnolevel"/>
604 </when>
605 <otherwise/>
606 </choose>
607 </variable>
608 <variable name="level-modifier">
609 <choose>
610 <when test="$nested-bullet='◦'">
611 <text>1</text>
612 </when>
613 <when test="$nested-bullet='▪'">
614 <text>2</text>
615 </when>
616 <when test="$nested-bullet='⁃'">
617 <text>3</text>
618 </when>
619 <otherwise>
620 <text>0</text>
621 </otherwise>
622 </choose>
623 </variable>
624 <variable name="nobullet">
625 <choose>
626 <when test="$nested-bullet!=''">
627 <value-of select="substring-after($nospace, $nested-bullet)"/>
628 </when>
629 <otherwise>
630 <value-of select="concat($firstnolevel, substring-after($nospace, $firstnolevel))"/>
631 </otherwise>
632 </choose>
633 </variable>
634 <variable name="firstnosigil" select="substring(translate($nobullet, '•№※⯑∫☡⚠🛈💡»∎℣℟', ''), 1, 1)"/>
635 <variable name="sigilling">
636 <choose>
637 <when test="$firstnosigil!=''">
638 <value-of select="substring-before(substring-after($linespans[1], concat($levelling, $nested-bullet)), $firstnosigil)"/>
639 </when>
640 <otherwise>
641 <value-of select="substring-after($linespans[1], concat($levelling, $nested-bullet))"/>
642 </otherwise>
643 </choose>
644 </variable>
645 <variable name="nosigil">
646 <value-of select="concat($firstnosigil, substring-after($nobullet, $firstnosigil))"/>
647 </variable>
648 <variable name="ruled" select="count($linespans)=1 and $nosigil!='' and translate($nosigil, $LESML_SECTION_BREAK_CHARS, '')=''"/>
649 <variable name="prefix">
650 <choose>
651 <when test="not($ruled) and $firstnosigil='|'">
652 <variable name="postpipe" select="substring-after($linespans[1], '|')"/>
653 <choose>
654 <when test="substring(translate($postpipe, '0123456789abcdefghijklmnopqrstuvwxyz/.-', ''), 1, 1)='$'">
655 <value-of select="concat(substring-before($linespans[1], '$'), '$')"/>
656 </when>
657 <otherwise>
658 <value-of select="concat(substring-before($linespans[1], '|'), '|')"/>
659 </otherwise>
660 </choose>
661 </when>
662 <when test="not($ruled) and contains('⁌§❦✠#^', $firstnosigil)">
663 <value-of select="concat(substring-before($linespans[1], $firstnosigil), $firstnosigil)"/>
664 </when>
665 <when test="$firstnosigil!=''">
666 <value-of select="substring-before($linespans[1], $firstnosigil)"/>
667 </when>
668 <otherwise>
669 <value-of select="$linespans[1]"/>
670 </otherwise>
671 </choose>
672 </variable>
673 <variable name="preformatted" select="$firstnosigil='|' and not($linespans[not(starts-with(., $prefix))])"/>
674 <variable name="inner-lines-fragment">
675 <for-each select="$linespans">
676 <choose>
677 <when test="$preformatted or position()=1">
678 <html:span>
679 <value-of select="substring-after(., $prefix)"/>
680 </html:span>
681 </when>
682 <otherwise>
683 <copy-of select="."/>
684 </otherwise>
685 </choose>
686 </for-each>
687 </variable>
688 <variable name="inner-lines" select="exsl:node-set($inner-lines-fragment)/node()"/>
689 <call-template name="LesML:expand-sigils">
690 <with-param name="sigils" select="exslstr:tokenize(translate(concat($nested-bullet, $sigilling), '◦▪⁃ &#x9;', '•••'), '')"/>
691 <with-param name="level" select="string-length(translate($levelling, ' &#x9;', ''))+$level-modifier"/>
692 <with-param name="partype">
693 <choose>
694 <when test="$preformatted">
695 <text>pre</text>
696 <if test="contains($prefix, '$')">
697 <text> code</text>
698 </if>
699 </when>
700 <when test="$ruled">
701 <text>hr</text>
702 </when>
703 <when test="$firstnosigil='#'">
704 <text>comment</text>
705 </when>
706 <when test="$firstnosigil='^'">
707 <text>footnote</text>
708 </when>
709 <when test="$firstnosigil='⁌'">
710 <text>h1</text>
711 </when>
712 <when test="$firstnosigil='§'">
713 <text>h2</text>
714 </when>
715 <when test="$firstnosigil='❦'">
716 <text>h3</text>
717 </when>
718 <when test="$firstnosigil='✠'">
719 <text>h4</text>
720 </when>
721 <otherwise/>
722 </choose>
723 </with-param>
724 <with-param name="syntax" select="substring-before(substring-after($prefix, '|'), '$')"/>
725 <with-param name="lines" select="$inner-lines"/>
726 </call-template>
727 </for-each>
728 </template>
729
730 <!-->
731 ✠ `LesML:paragraphize´
732
733 The `LesML:paragraphize´ template first turns the provided lines into
734 blocks via `LesML:chunk´, arranges those blocks by applying templates
735 in the `LesML:blockify´ mode, then processes the inline contents of
736 those blocks by applying templates in the `LesML:inlinify´ mode.
737 This does much of the processing for the body of a Les·M·L document,
738 altho some things, like footnote handling, can¦t be fully finalized
739 until later.
740 </!-->
741
742 <template name="LesML:paragraphize">
743 <param name="lines" select="/.."/>
744 <variable name="chunked-fragment">
745 <call-template name="LesML:chunk">
746 <with-param name="lines" select="$lines"/>
747 </call-template>
748 </variable>
749 <apply-templates select="exsl:node-set($chunked-fragment)" mode="LesML:blockify"/>
750 </template>
751
752 <!-->
753 ✠ `LesML:parse´
754
755 The `LesML:parse´ template is the main entrypoint for Les·M·L handling,
756 taking a list of input lines and returning a series of resulting
757 Les·M·L documents.
758 This template operates by outputting the result of the first document
759 in the provided lines, and then calling itself recursively with any
760 remaining documents until the lines are exhausted.
761 </!-->
762
763 <template name="LesML:parse">
764 <param name="lines" select="/.."/>
765 <param name="parent-params" select="/.."/>
766 <variable name="first-line" select="$lines[1]"/>
767 <variable name="shero">
768 <if test="starts-with($first-line, '#?lesml')">
769 <value-of select="$first-line"/>
770 </if>
771 </variable>
772 <variable name="params-string">
773 <choose>
774 <when test="starts-with($shero, '#?lesml@')">
775 <value-of select="substring-after($shero, '$')"/>
776 </when>
777 <otherwise>
778 <value-of select="substring-after($shero, '#?lesml')"/>
779 </otherwise>
780 </choose>
781 </variable>
782 <variable name="params-fragment">
783 <choose>
784 <when test="$shero!=''">
785 <html:dl>
786 <if test="starts-with($shero, '#?lesml@') and contains($shero, '$')">
787 <html:div>
788 <html:dt>
789 <text> LANG </text>
790 </html:dt>
791 <html:dd>
792 <value-of select="substring-before(substring-after($shero, '#?lesml@'), '$')"/>
793 </html:dd>
794 </html:div>
795 </if>
796 <for-each select="exslstr:tokenize($params-string)">
797 <choose>
798 <when test="contains(., '=')">
799 <html:div>
800 <html:dt>
801 <value-of select="substring-before(., '=')"/>
802 </html:dt>
803 <html:dd>
804 <value-of select="substring-after(., '=')"/>
805 </html:dd>
806 </html:div>
807 </when>
808 <otherwise>
809 <html:div>
810 <html:dt>
811 <value-of select="."/>
812 </html:dt>
813 <html:dd/>
814 </html:div>
815 </otherwise>
816 </choose>
817 </for-each>
818 </html:dl>
819 </when>
820 <when test="$parent-params">
821 <copy-of select="$parent-params"/>
822 </when>
823 <otherwise>
824 <html:dl/>
825 </otherwise>
826 </choose>
827 </variable>
828 <variable name="params" select="exsl:node-set($params-fragment)/node()"/>
829 <variable name="noshero" select="$lines[position()>1 or not(starts-with(., '#?lesml') or starts-with(., '##'))]"/>
830 <variable name="docsep" select="$noshero[starts-with(., '#?lesml') or starts-with(., '##')][1]"/>
831 <variable name="doclines" select="exslset:leading($noshero, $docsep)"/>
832 <if test="starts-with($first-line, '##') and $first-line!='##'">
833 <call-template name="LesML:comment-out">
834 <with-param name="source" select="substring-after($first-line, '##')"/>
835 </call-template>
836 </if>
837 <if test="$doclines[normalize-space()!='']">
838 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
839 <variable name="paragraphized-fragment">
840 <call-template name="LesML:paragraphize">
841 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
842 </call-template>
843 </variable>
844 <variable name="paragraphized-document" select="exsl:node-set($paragraphized-fragment)"/>
845 <variable name="filtered-ordered-footnotes-fragment">
846 <for-each select="$paragraphized-document//processing-instruction()[local-name()='LesML-Footnote']">
847 <sort select="count(($paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string(current()))])[1]/preceding::*)" data-type="number"/>
848 <if test="$paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string(current()))]">
849 <copy-of select=".."/>
850 </if>
851 </for-each>
852 </variable>
853 <variable name="used-footnotes-fragment">
854 <for-each select="exsl:node-set($filtered-ordered-footnotes-fragment)/node()">
855 <variable name="footnote-id" select="processing-instruction()[local-name()='LesML-Footnote']"/>
856 <variable name="links" select="$paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string($footnote-id))]"/>
857 <element name="li" namespace="&xhtml;">
858 <variable name="numero" select="position()"/>
859 <attribute name="id">
860 <value-of select="$footnote-id"/>
861 </attribute>
862 <attribute name="value">
863 <value-of select="$numero"/>
864 </attribute>
865 <copy-of select="node()[not(self::processing-instruction() and local-name()='LesML-Footnote')]"/>
866 <element name="footer" namespace="&xhtml;">
867 <attribute name="class">
868 <text>backlinks</text>
869 </attribute>
870 <for-each select="$links[@id]">
871 <if test="position()>1">
872 <text> </text>
873 </if>
874 <element name="a" namespace="&xhtml;">
875 <attribute name="role">
876 <text>doc-backlink</text>
877 </attribute>
878 <attribute name="href">
879 <text>#</text>
880 <value-of select="@id"/>
881 </attribute>
882 <value-of select="position()"/>
883 </element>
884 </for-each>
885 </element>
886 </element>
887 </for-each>
888 </variable>
889 <variable name="used-footnotes" select="exsl:node-set($used-footnotes-fragment)/node()"/>
890 <element name="article" namespace="&xhtml;">
891 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
892 <attribute name="lang">
893 <value-of select="following-sibling::html:dd"/>
894 </attribute>
895 <attribute name="xml:lang">
896 <value-of select="following-sibling::html:dd"/>
897 </attribute>
898 </for-each>
899 <for-each select="$params/html:div/html:dt[string()='profile']">
900 <attribute name="data-lesml-profile">
901 <value-of select="following-sibling::html:dd"/>
902 </attribute>
903 </for-each>
904 <if test="$record-separators and exslset:difference(exslset:leading($doclines, $record-separators[last()]), $record-separators)[normalize-space()!='']">
905 <element name="footer" namespace="&xhtml;">
906 <attribute name="class">
907 <text>head</text>
908 </attribute>
909 <for-each select="$record-separators">
910 <variable name="position" select="position()"/>
911 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
912 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)[normalize-space()!='']"/>
913 <if test="$fields">
914 <element name="dl" namespace="&xhtml;">
915 <for-each select="$fields">
916 <variable name="following" select="exslset:intersection($fields, following-sibling::*)"/>
917 <choose>
918 <when test="contains(' &#x9;', substring(., 1, 1)) and exslset:has-same-node($fields, preceding-sibling::*[1])"/>
919 <otherwise>
920 <variable name="next" select="$following[not(contains(' &#x9;', substring(., 1, 1)))][1]"/>
921 <element name="div" namespace="&xhtml;">
922 <element name="dt" namespace="&xhtml;">
923 <value-of select="normalize-space(substring-before(., ':'))"/>
924 </element>
925 <element name="dd" namespace="&xhtml;">
926 <variable name="firstline">
927 <choose>
928 <when test="contains(., ':')">
929 <value-of select="normalize-space(substring-after(., ':'))"/>
930 </when>
931 <otherwise>
932 <value-of select="normalize-space(.)"/>
933 </otherwise>
934 </choose>
935 </variable>
936 <choose>
937 <when test="substring($firstline, string-length($firstline))='\' and $following[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
938 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
939 </when>
940 <otherwise>
941 <value-of select="$firstline"/>
942 </otherwise>
943 </choose>
944 <for-each select="exslset:leading($following, $next)[contains(' &#x9;', substring(., 1, 1))]">
945 <variable name="nextline" select="normalize-space(.)"/>
946 <choose>
947 <when test="substring($nextline, string-length($nextline))='\' and exslset:intersection($fields, following-sibling::*)[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
948 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
949 </when>
950 <otherwise>
951 <value-of select="$nextline"/>
952 </otherwise>
953 </choose>
954 </for-each>
955 </element>
956 </element>
957 </otherwise>
958 </choose>
959 </for-each>
960 </element>
961 </if>
962 <if test="substring-after(., '%%')!=''">
963 <call-template name="LesML:comment-out">
964 <with-param name="source" select="substring-after(., '%%')"/>
965 </call-template>
966 </if>
967 </for-each>
968 </element>
969 </if>
970 <element name="div" namespace="&xhtml;">
971 <attribute name="class">
972 <text>body</text>
973 </attribute>
974 <apply-templates select="$paragraphized-document/node()" mode="LesML:finalize">
975 <with-param name="used-footnotes" select="$used-footnotes"/>
976 </apply-templates>
977 </element>
978 <if test="$used-footnotes">
979 <element name="section" namespace="&xhtml;">
980 <attribute name="role">
981 <text>doc-endnotes</text>
982 </attribute>
983 <element name="ol" namespace="&xhtml;">
984 <apply-templates select="$used-footnotes" mode="LesML:finalize">
985 <with-param name="used-footnotes" select="$used-footnotes"/>
986 </apply-templates>
987 </element>
988 </element>
989 </if>
990 </element>
991 </if>
992 <if test="$docsep">
993 <call-template name="LesML:parse">
994 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
995 <with-param name="parent-params" select="$params"/>
996 </call-template>
997 </if>
998 </template>
999
1000 <!-->
1001 ❦ Templates in the default mode
1002
1003 This file provides a single template in the default mode: one which
1004 matches H·T·M·L `<script>´ elements with a `@type="text/lesml"´ and
1005 passes the contents thru to `LesML:parse´.
1006 </!-->
1007
1008 <template match="html:script[@type='text/lesml']">
1009 <variable name="source">
1010 <for-each select=".//text()">
1011 <value-of select="."/>
1012 </for-each>
1013 </variable>
1014 <element name="div" namespace="&xhtml;">
1015 <call-template name="LesML:parse">
1016 <with-param name="lines" select="LesML:split($source)"/>
1017 </call-template>
1018 </element>
1019 </template>
1020
1021 <!-->
1022 ❦ Templates in the `LesML:blockify´ mode
1023
1024 There is only one template in the `LesML:blockify´ mode and it can only
1025 process an entire document at a time.
1026 It successively applies templates in the `LesML:nesting-blocks´ and
1027 `LesML:inlinify´ modes to convert the relatively flat structure
1028 produced by chunking into approximately the final tree.
1029 </!-->
1030
1031 <template match="/" mode="LesML:blockify">
1032 <variable name="nested-fragment">
1033 <apply-templates mode="LesML:nesting-blocks"/>
1034 </variable>
1035 <variable name="nested-document" select="exsl:node-set($nested-fragment)"/>
1036 <apply-templates select="exsl:node-set($nested-fragment)/node()" mode="LesML:inlinify">
1037 <with-param name="footnote-ids" select="$nested-document/*/processing-instruction()[local-name()='LesML-Footnote']"/>
1038 </apply-templates>
1039 </template>
1040
1041 <!-->
1042 ❦ Templates in the `LesML:nesting-blocks´ mode
1043
1044 For any given block element, this template moves any following elements
1045 with a higher level inside and then reprocesses the resulting
1046 children.
1047 Elements which are preceded by elements of a lower level are assumed to
1048 be nested and are not rendered.
1049 (At the time that these templates run, block elements can only have
1050 block siblings.)
1051 </!-->
1052
1053 <template match="*[&level-pi;]" mode="LesML:nesting-blocks">
1054 <variable name="current-level" select="number(&level-pi;)"/>
1055 <if test="not(preceding-sibling::*[&level-pi; and $current-level>&level-pi;])">
1056 <variable name="notatlevel" select="following-sibling::*[$current-level>=&level-pi;][1]"/>
1057 <variable name="contents-fragment">
1058 <copy-of select="node()"/>
1059 <copy-of select="exslset:leading(following-sibling::*, $notatlevel)"/>
1060 </variable>
1061 <copy>
1062 <copy-of select="@*"/>
1063 <apply-templates select="exsl:node-set($contents-fragment)/node()" mode="LesML:nesting-blocks"/>
1064 </copy>
1065 </if>
1066 </template>
1067 <template match="node()" mode="LesML:nesting-blocks" priority="-1">
1068 <copy>
1069 <copy-of select="@*"/>
1070 <apply-templates select="node()" mode="LesML:nesting-blocks"/>
1071 </copy>
1072 </template>
1073
1074 <!-->
1075 ❦ Templates in the `LesML:inlinify´ and related modes
1076
1077 These modes break up the lines of a paragraph into constituent inline
1078 nodes.
1079 </!-->
1080
1081 <template match="*[&level-pi;]" mode="LesML:inlinify">
1082 <param name="footnote-ids" select="/.."/>
1083 <copy>
1084 <copy-of select="@*"/>
1085 <apply-templates mode="LesML:inlinify">
1086 <with-param name="footnote-ids" select="$footnote-ids|*/processing-instruction()[local-name()='LesML-Footnote']"/>
1087 </apply-templates>
1088 </copy>
1089 </template>
1090 <template match="node()" mode="LesML:inlinify" priority="-1">
1091 <param name="footnote-ids" select="/.."/>
1092 <apply-templates select="." mode="LesML:comment">
1093 <with-param name="footnote-ids" select="$footnote-ids"/>
1094 </apply-templates>
1095 </template>
1096 <template match="node()" mode="LesML:comment">
1097 <param name="footnote-ids" select="/.."/>
1098 <variable name="result-fragment">
1099 <choose>
1100 <when test="self::*">
1101 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
1102 <variable name="after-start">
1103 <if test="$start-node">
1104 <value-of select="substring-after($start-node, '⌦')"/>
1105 </if>
1106 </variable>
1107 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
1108 <choose>
1109 <when test="$start-node and $has-end-node">
1110 <variable name="following">
1111 <value-of select="$after-start"/>
1112 <copy-of select="$start-node/following-sibling::node()"/>
1113 </variable>
1114 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
1115 <variable name="comment">
1116 <for-each select="$end-node/preceding-sibling::node()">
1117 <value-of select="."/>
1118 </for-each>
1119 <value-of select="substring-before($end-node, '⌫')"/>
1120 </variable>
1121 <variable name="rest-fragment">
1122 <element name="span" namespace="&xhtml;">
1123 <value-of select="substring-after($end-node, '⌫')"/>
1124 <copy-of select="$end-node/following-sibling::node()"/>
1125 </element>
1126 </variable>
1127 <variable name="commented-rest-fragment">
1128 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
1129 <with-param name="footnote-ids" select="$footnote-ids"/>
1130 </apply-templates>
1131 </variable>
1132 <copy>
1133 <copy-of select="@*"/>
1134 <copy-of select="$start-node/preceding-sibling::node()"/>
1135 <copy-of select="substring-before($start-node, '⌦')"/>
1136 <call-template name="LesML:comment-out">
1137 <with-param name="source" select="string($comment)"/>
1138 </call-template>
1139 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
1140 </copy>
1141 </when>
1142 <when test="$start-node">
1143 <variable name="rest-fragment">
1144 <element name="div" namespace="&xhtml;">
1145 <value-of select="substring-after($after-start, '⌦')"/>
1146 <copy-of select="$start-node/following-sibling::node()"/>
1147 </element>
1148 </variable>
1149 <variable name="commented-rest-fragment">
1150 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
1151 <with-param name="footnote-ids" select="$footnote-ids"/>
1152 </apply-templates>
1153 </variable>
1154 <copy>
1155 <copy-of select="@*"/>
1156 <copy-of select="$start-node/preceding-sibling::node()"/>
1157 <copy-of select="substring-before($start-node, '⌦')"/>
1158 <text>^</text>
1159 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
1160 </copy>
1161 </when>
1162 <otherwise>
1163 <copy>
1164 <copy-of select="@*"/>
1165 <apply-templates select="node()" mode="LesML:comment">
1166 <with-param name="footnote-ids" select="$footnote-ids"/>
1167 </apply-templates>
1168 </copy>
1169 </otherwise>
1170 </choose>
1171 </when>
1172 <when test="self::text()[contains(., '⌧')]">
1173 <for-each select="LesML:split(., '⌧')">
1174 <value-of select="."/>
1175 <if test="position()!=last()">
1176 <call-template name="LesML:comment-out"/>
1177 </if>
1178 </for-each>
1179 </when>
1180 <otherwise>
1181 <copy-of select="."/>
1182 </otherwise>
1183 </choose>
1184 </variable>
1185 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:attrify">
1186 <with-param name="footnote-ids" select="$footnote-ids"/>
1187 </apply-templates>
1188 </template>
1189 <template match="*" mode="LesML:partition">
1190 <param name="start-sigil"/>
1191 <param name="end-sigil"/>
1192 <param name="separator"/>
1193 <param name="ncname-keys" select="false()"/>
1194 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1195 <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))"/>
1196 <choose>
1197 <when test="$end-node and $has-start-node">
1198 <variable name="preceding-fragment">
1199 <copy-of select="$end-node/preceding-sibling::node()"/>
1200 <value-of select="substring-before($end-node, $end-sigil)"/>
1201 </variable>
1202 <variable name="preceding" select="exsl:node-set($preceding-fragment)/node()"/>
1203 <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())]"/>
1204 <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
1205 <variable name="innards-fragment">
1206 <value-of select="$start-tokens[last()]"/>
1207 <for-each select="$start-node/following-sibling::node()">
1208 <choose>
1209 <when test="$ncname-keys and self::html:br">
1210 <text>&#xA;</text>
1211 </when>
1212 <otherwise>
1213 <copy-of select="."/>
1214 </otherwise>
1215 </choose>
1216 </for-each>
1217 </variable>
1218 <variable name="innards" select="exsl:node-set($innards-fragment)/node()"/>
1219 <variable name="separator-node" select="($innards[self::text() and contains(., $separator)])[not($ncname-keys)*(last()-1)+1]"/>
1220 <choose>
1221 <when test="not($start-node) or $separator-node[following-sibling::* or following-sibling::comment()]">
1222 <variable name="bad-start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()]"/>
1223 <element name="span" namespace="&xhtml;">
1224 <copy-of select="$bad-start-node/preceding-sibling::node()"/>
1225 <for-each select="LesML:split($bad-start-node, $start-sigil)">
1226 <value-of select="."/>
1227 <if test="position()!=last()">
1228 <processing-instruction name="LesML-Token-Escape">
1229 <value-of select="$start-sigil"/>
1230 </processing-instruction>
1231 </if>
1232 </for-each>
1233 <copy-of select="$bad-start-node/following-sibling::node()"/>
1234 <value-of select="$end-sigil"/>
1235 <value-of select="substring-after($end-node, $end-sigil)"/>
1236 <copy-of select="$end-node/following-sibling::node()"/>
1237 </element>
1238 </when>
1239 <when test="$separator-node">
1240 <variable name="keyval" select="LesML:split($separator-node, $separator)"/>
1241 <variable name="key-fragment">
1242 <choose>
1243 <when test="$ncname-keys">
1244 <for-each select="$separator-node/preceding-sibling::node()">
1245 <value-of select="."/>
1246 </for-each>
1247 <value-of select="$keyval[1]"/>
1248 </when>
1249 <otherwise>
1250 <copy-of select="$separator-node/preceding-sibling::node()"/>
1251 <for-each select="$keyval[position()!=last()]">
1252 <value-of select="."/>
1253 <if test="position()!=last()">
1254 <value-of select="$separator"/>
1255 </if>
1256 </for-each>
1257 </otherwise>
1258 </choose>
1259 </variable>
1260 <variable name="value">
1261 <choose>
1262 <when test="$ncname-keys">
1263 <for-each select="$keyval[position()!=1]">
1264 <value-of select="."/>
1265 <if test="position()!=last()">
1266 <value-of select="$separator"/>
1267 </if>
1268 </for-each>
1269 </when>
1270 <otherwise>
1271 <value-of select="$keyval[last()]"/>
1272 </otherwise>
1273 </choose>
1274 <for-each select="$separator-node/following-sibling::node()">
1275 <value-of select="."/>
1276 </for-each>
1277 </variable>
1278 <choose>
1279 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key-fragment), ' /([,*', '')=$key-fragment and exsldyn:evaluate(concat('not(self::html:', $key-fragment, ')'))]">
1280 <element name="span" namespace="&xhtml;">
1281 <copy-of select="$start-node/preceding-sibling::node()"/>
1282 <for-each select="$start-tokens[position()!=last()]">
1283 <value-of select="."/>
1284 <if test="position()!=last()">
1285 <value-of select="$start-sigil"/>
1286 </if>
1287 </for-each>
1288 </element>
1289 <element name="span" namespace="&xhtml;">
1290 <copy-of select="$key-fragment"/>
1291 </element>
1292 <element name="span" namespace="&xhtml;">
1293 <value-of select="$value"/>
1294 </element>
1295 <element name="span" namespace="&xhtml;">
1296 <value-of select="substring-after($end-node, $end-sigil)"/>
1297 <copy-of select="$end-node/following-sibling::node()"/>
1298 </element>
1299 </when>
1300 <otherwise>
1301 <element name="span" namespace="&xhtml;">
1302 <copy-of select="$start-node/preceding-sibling::node()"/>
1303 <for-each select="$start-tokens[position()!=last()]">
1304 <value-of select="."/>
1305 <if test="position()!=last()">
1306 <value-of select="$start-sigil"/>
1307 </if>
1308 </for-each>
1309 <processing-instruction name="LesML-Token-Escape">
1310 <value-of select="$start-sigil"/>
1311 </processing-instruction>
1312 <value-of select="$start-tokens[last()]"/>
1313 <value-of select="$start-node/following-sibling::node()"/>
1314 <value-of select="$end-sigil"/>
1315 <value-of select="substring-after($end-node, $end-sigil)"/>
1316 <copy-of select="$end-node/following-sibling::node()"/>
1317 </element>
1318 </otherwise>
1319 </choose>
1320 </when>
1321 <otherwise>
1322 <element name="span" namespace="&xhtml;">
1323 <copy-of select="$start-node/preceding-sibling::node()"/>
1324 <for-each select="$start-tokens[position()!=last()]">
1325 <value-of select="."/>
1326 <if test="position()!=last()">
1327 <value-of select="$start-sigil"/>
1328 </if>
1329 </for-each>
1330 <processing-instruction name="LesML-Token-Escape">
1331 <value-of select="$start-sigil"/>
1332 </processing-instruction>
1333 <value-of select="$start-tokens[last()]"/>
1334 <copy-of select="$start-node/following-sibling::node()"/>
1335 <value-of select="$end-sigil"/>
1336 <value-of select="substring-after($end-node, $end-sigil)"/>
1337 <copy-of select="$end-node/following-sibling::node()"/>
1338 </element>
1339 </otherwise>
1340 </choose>
1341 </when>
1342 <when test="$end-node">
1343 <element name="span" namespace="&xhtml;">
1344 <copy-of select="$end-node/preceding-sibling::node()"/>
1345 <value-of select="substring-before($end-node, $end-sigil)"/>
1346 <processing-instruction name="LesML-Token-Escape">
1347 <value-of select="$end-sigil"/>
1348 </processing-instruction>
1349 <value-of select="substring-after($end-node, $end-sigil)"/>
1350 <copy-of select="$end-node/following-sibling::node()"/>
1351 </element>
1352 </when>
1353 <otherwise>
1354 <processing-instruction name="LesML-All-Done"/>
1355 </otherwise>
1356 </choose>
1357 </template>
1358 <template match="node()" mode="LesML:attrify">
1359 <param name="footnote-ids" select="/.."/>
1360 <variable name="result-fragment">
1361 <choose>
1362 <when test="self::*">
1363 <variable name="partitioned-fragment">
1364 <apply-templates mode="LesML:partition" select=".">
1365 <with-param name="start-sigil" select="'{@'"/>
1366 <with-param name="end-sigil" select="'&quot;}'"/>
1367 <with-param name="separator" select="'=&quot;'"/>
1368 <with-param name="ncname-keys" select="true()"/>
1369 </apply-templates>
1370 </variable>
1371 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1372 <choose>
1373 <when test="count($partitioned)>1">
1374 <variable name="processed">
1375 <copy>
1376 <copy-of select="@*"/>
1377 <copy-of select="$partitioned[1]/node()"/>
1378 <element name="LesML:attribute" namespace="&LesML;">
1379 <attribute name="{$partitioned[2]}">
1380 <value-of select="$partitioned[3]"/>
1381 </attribute>
1382 </element>
1383 <copy-of select="$partitioned[4]/node()"/>
1384 </copy>
1385 </variable>
1386 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1387 <with-param name="footnote-ids" select="$footnote-ids"/>
1388 </apply-templates>
1389 </when>
1390 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1391 <copy>
1392 <copy-of select="@*"/>
1393 <apply-templates select="node()" mode="LesML:attrify">
1394 <with-param name="footnote-ids" select="$footnote-ids"/>
1395 </apply-templates>
1396 </copy>
1397 </when>
1398 <otherwise>
1399 <variable name="processed">
1400 <copy>
1401 <copy-of select="@*"/>
1402 <copy-of select="$partitioned/node()"/>
1403 </copy>
1404 </variable>
1405 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1406 <with-param name="footnote-ids" select="$footnote-ids"/>
1407 </apply-templates>
1408 </otherwise>
1409 </choose>
1410 </when>
1411 <otherwise>
1412 <copy-of select="."/>
1413 </otherwise>
1414 </choose>
1415 </variable>
1416 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:linkify">
1417 <with-param name="footnote-ids" select="$footnote-ids"/>
1418 </apply-templates>
1419 </template>
1420 <template match="node()" mode="LesML:linkify">
1421 <param name="footnote-ids" select="/.."/>
1422 <variable name="result-fragment">
1423 <choose>
1424 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1425 <copy>
1426 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1427 </copy>
1428 </when>
1429 <when test="self::*">
1430 <variable name="partitioned-fragment">
1431 <apply-templates mode="LesML:partition" select=".">
1432 <with-param name="start-sigil" select="'{🔗'"/>
1433 <with-param name="end-sigil" select="'>}'"/>
1434 <with-param name="separator" select="'&lt;'"/>
1435 </apply-templates>
1436 </variable>
1437 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1438 <choose>
1439 <when test="count($partitioned)>1">
1440 <variable name="processed">
1441 <copy>
1442 <copy-of select="@*"/>
1443 <copy-of select="$partitioned[1]/node()"/>
1444 <element name="a" namespace="&xhtml;">
1445 <attribute name="href">
1446 <value-of select="$partitioned[3]"/>
1447 </attribute>
1448 <processing-instruction name="LesML-All-Done"/>
1449 <choose>
1450 <when test="not($partitioned[2]/node())">
1451 <value-of select="$partitioned[3]"/>
1452 </when>
1453 <otherwise>
1454 <copy-of select="$partitioned[2]/node()"/>
1455 </otherwise>
1456 </choose>
1457 </element>
1458 <copy-of select="$partitioned[4]/node()"/>
1459 </copy>
1460 </variable>
1461 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1462 <with-param name="footnote-ids" select="$footnote-ids"/>
1463 </apply-templates>
1464 </when>
1465 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1466 <copy>
1467 <copy-of select="@*"/>
1468 <apply-templates select="node()" mode="LesML:linkify">
1469 <with-param name="footnote-ids" select="$footnote-ids"/>
1470 </apply-templates>
1471 </copy>
1472 </when>
1473 <otherwise>
1474 <variable name="processed">
1475 <copy>
1476 <copy-of select="@*"/>
1477 <copy-of select="$partitioned/node()"/>
1478 </copy>
1479 </variable>
1480 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1481 <with-param name="footnote-ids" select="$footnote-ids"/>
1482 </apply-templates>
1483 </otherwise>
1484 </choose>
1485 </when>
1486 <otherwise>
1487 <copy-of select="."/>
1488 </otherwise>
1489 </choose>
1490 </variable>
1491 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:strikethrough">
1492 <with-param name="footnote-ids" select="$footnote-ids"/>
1493 </apply-templates>
1494 </template>
1495 <template match="node()" mode="LesML:inline">
1496 <param name="element-name"/>
1497 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
1498 <param name="start-sigil"/>
1499 <param name="end-sigil"/>
1500 <param name="class"/>
1501 <param name="role"/>
1502 <choose>
1503 <when test="self::*">
1504 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1505 <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))"/>
1506 <choose>
1507 <when test="$end-node and $has-start-node">
1508 <variable name="preceding">
1509 <copy-of select="$end-node/preceding-sibling::node()"/>
1510 <value-of select="substring-before($end-node, $end-sigil)"/>
1511 </variable>
1512 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
1513 <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
1514 <variable name="wrapped">
1515 <copy>
1516 <copy-of select="@*"/>
1517 <copy-of select="$start-node/preceding-sibling::node()"/>
1518 <for-each select="$start-tokens[position()!=last()]">
1519 <value-of select="."/>
1520 <if test="position()!=last()">
1521 <value-of select="$start-sigil"/>
1522 </if>
1523 </for-each>
1524 <element name="{$element-name}" namespace="{$element-namespace}">
1525 <if test="string($role)!=''">
1526 <attribute name="role">
1527 <value-of select="$role"/>
1528 </attribute>
1529 </if>
1530 <if test="string($class)!=''">
1531 <attribute name="class">
1532 <value-of select="$class"/>
1533 </attribute>
1534 </if>
1535 <value-of select="$start-tokens[last()]"/>
1536 <copy-of select="$start-node/following-sibling::node()"/>
1537 </element>
1538 <value-of select="substring-after($end-node, $end-sigil)"/>
1539 <copy-of select="$end-node/following-sibling::node()"/>
1540 </copy>
1541 </variable>
1542 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
1543 <with-param name="element-name" select="$element-name"/>
1544 <with-param name="element-namespace" select="$element-namespace"/>
1545 <with-param name="start-sigil" select="$start-sigil"/>
1546 <with-param name="end-sigil" select="$end-sigil"/>
1547 <with-param name="role" select="$role"/>
1548 </apply-templates>
1549 </when>
1550 <otherwise>
1551 <copy>
1552 <copy-of select="@*"/>
1553 <apply-templates select="node()" mode="LesML:inline">
1554 <with-param name="element-name" select="$element-name"/>
1555 <with-param name="element-namespace" select="$element-namespace"/>
1556 <with-param name="start-sigil" select="$start-sigil"/>
1557 <with-param name="end-sigil" select="$end-sigil"/>
1558 <with-param name="role" select="$role"/>
1559 </apply-templates>
1560 </copy>
1561 </otherwise>
1562 </choose>
1563 </when>
1564 <otherwise>
1565 <copy-of select="."/>
1566 </otherwise>
1567 </choose>
1568 </template>
1569 <template match="node()" mode="LesML:strikethrough">
1570 <param name="footnote-ids" select="/.."/>
1571 <variable name="result-fragment">
1572 <apply-templates select="." mode="LesML:inline">
1573 <with-param name="element-name" select="'s'"/>
1574 <with-param name="element-namespace" select="'&xhtml;'"/>
1575 <with-param name="start-sigil" select="'⸠'"/>
1576 <with-param name="end-sigil" select="'⸡'"/>
1577 </apply-templates>
1578 </variable>
1579 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:underline">
1580 <with-param name="footnote-ids" select="$footnote-ids"/>
1581 </apply-templates>
1582 </template>
1583 <template match="node()" mode="LesML:underline">
1584 <param name="footnote-ids" select="/.."/>
1585 <variable name="result-fragment">
1586 <apply-templates select="." mode="LesML:inline">
1587 <with-param name="element-name" select="'u'"/>
1588 <with-param name="element-namespace" select="'&xhtml;'"/>
1589 <with-param name="start-sigil" select="'⸤'"/>
1590 <with-param name="end-sigil" select="'⸥'"/>
1591 </apply-templates>
1592 </variable>
1593 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:noted">
1594 <with-param name="footnote-ids" select="$footnote-ids"/>
1595 </apply-templates>
1596 </template>
1597 <template match="node()" mode="LesML:noted">
1598 <param name="footnote-ids" select="/.."/>
1599 <variable name="result-fragment">
1600 <apply-templates select="." mode="LesML:inline">
1601 <with-param name="element-name" select="'small'"/>
1602 <with-param name="element-namespace" select="'&xhtml;'"/>
1603 <with-param name="start-sigil" select="'⟦'"/>
1604 <with-param name="end-sigil" select="'⟧'"/>
1605 <with-param name="role" select="'note'"/>
1606 </apply-templates>
1607 </variable>
1608 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:parenthetical">
1609 <with-param name="footnote-ids" select="$footnote-ids"/>
1610 </apply-templates>
1611 </template>
1612 <template match="node()" mode="LesML:parenthetical">
1613 <param name="footnote-ids" select="/.."/>
1614 <variable name="result-fragment">
1615 <apply-templates select="." mode="LesML:inline">
1616 <with-param name="element-name" select="'small'"/>
1617 <with-param name="element-namespace" select="'&xhtml;'"/>
1618 <with-param name="start-sigil" select="'⸨'"/>
1619 <with-param name="end-sigil" select="'⸩'"/>
1620 </apply-templates>
1621 </variable>
1622 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:code">
1623 <with-param name="footnote-ids" select="$footnote-ids"/>
1624 </apply-templates>
1625 </template>
1626 <template match="node()" mode="LesML:code">
1627 <param name="footnote-ids" select="/.."/>
1628 <variable name="result-fragment">
1629 <apply-templates select="." mode="LesML:inline">
1630 <with-param name="element-name" select="'code'"/>
1631 <with-param name="element-namespace" select="'&xhtml;'"/>
1632 <with-param name="start-sigil" select="'`'"/>
1633 <with-param name="end-sigil" select="'´'"/>
1634 </apply-templates>
1635 </variable>
1636 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:titled">
1637 <with-param name="footnote-ids" select="$footnote-ids"/>
1638 </apply-templates>
1639 </template>
1640 <template match="node()" mode="LesML:titled">
1641 <param name="footnote-ids" select="/.."/>
1642 <variable name="result-fragment">
1643 <apply-templates select="." mode="LesML:inline">
1644 <with-param name="element-name" select="'cite'"/>
1645 <with-param name="element-namespace" select="'&xhtml;'"/>
1646 <with-param name="start-sigil" select="'⟪'"/>
1647 <with-param name="end-sigil" select="'⟫'"/>
1648 </apply-templates>
1649 </variable>
1650 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:named">
1651 <with-param name="footnote-ids" select="$footnote-ids"/>
1652 </apply-templates>
1653 </template>
1654 <template match="node()" mode="LesML:named">
1655 <param name="footnote-ids" select="/.."/>
1656 <variable name="result-fragment">
1657 <apply-templates select="." mode="LesML:inline">
1658 <with-param name="element-name" select="'u'"/>
1659 <with-param name="element-namespace" select="'&xhtml;'"/>
1660 <with-param name="start-sigil" select="'⸶'"/>
1661 <with-param name="end-sigil" select="'⸷'"/>
1662 <with-param name="class" select="'name'"/>
1663 </apply-templates>
1664 </variable>
1665 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:offset">
1666 <with-param name="footnote-ids" select="$footnote-ids"/>
1667 </apply-templates>
1668 </template>
1669 <template match="node()" mode="LesML:offset">
1670 <param name="footnote-ids" select="/.."/>
1671 <variable name="result-fragment">
1672 <apply-templates select="." mode="LesML:inline">
1673 <with-param name="element-name" select="'i'"/>
1674 <with-param name="element-namespace" select="'&xhtml;'"/>
1675 <with-param name="start-sigil" select="'⟨'"/>
1676 <with-param name="end-sigil" select="'⟩'"/>
1677 </apply-templates>
1678 </variable>
1679 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:bolded">
1680 <with-param name="footnote-ids" select="$footnote-ids"/>
1681 </apply-templates>
1682 </template>
1683 <template match="node()" mode="LesML:bolded">
1684 <param name="footnote-ids" select="/.."/>
1685 <variable name="result-fragment">
1686 <apply-templates select="." mode="LesML:inline">
1687 <with-param name="element-name" select="'b'"/>
1688 <with-param name="element-namespace" select="'&xhtml;'"/>
1689 <with-param name="start-sigil" select="'⦃'"/>
1690 <with-param name="end-sigil" select="'⦄'"/>
1691 </apply-templates>
1692 </variable>
1693 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:important">
1694 <with-param name="footnote-ids" select="$footnote-ids"/>
1695 </apply-templates>
1696 </template>
1697 <template match="node()" mode="LesML:important">
1698 <param name="footnote-ids" select="/.."/>
1699 <variable name="result-fragment">
1700 <apply-templates select="." mode="LesML:inline">
1701 <with-param name="element-name" select="'strong'"/>
1702 <with-param name="element-namespace" select="'&xhtml;'"/>
1703 <with-param name="start-sigil" select="'☞'"/>
1704 <with-param name="end-sigil" select="'☜'"/>
1705 </apply-templates>
1706 </variable>
1707 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:emphasized">
1708 <with-param name="footnote-ids" select="$footnote-ids"/>
1709 </apply-templates>
1710 </template>
1711 <template match="node()" mode="LesML:emphasized">
1712 <param name="footnote-ids" select="/.."/>
1713 <variable name="result-fragment">
1714 <apply-templates select="." mode="LesML:inline">
1715 <with-param name="element-name" select="'em'"/>
1716 <with-param name="element-namespace" select="'&xhtml;'"/>
1717 <with-param name="start-sigil" select="'⹐'"/>
1718 <with-param name="end-sigil" select="'⹑'"/>
1719 </apply-templates>
1720 </variable>
1721 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:footnoted">
1722 <with-param name="footnote-ids" select="$footnote-ids"/>
1723 </apply-templates>
1724 </template>
1725 <template match="node()" mode="LesML:footnoted">
1726 <param name="footnote-ids" select="/.."/>
1727 <variable name="result-fragment">
1728 <choose>
1729 <when test="self::*">
1730 <variable name="start-node" select="text()[contains(., '[^')][1]"/>
1731 <variable name="after-start" select="substring-after($start-node, '[^')"/>
1732 <variable name="footnote-id" select="substring-before($after-start, ']')"/>
1733 <variable name="matched-footnote" select="$footnote-ids[.=$footnote-id]"/>
1734 <choose>
1735 <when test="$footnote-id!='' and $matched-footnote">
1736 <variable name="rest-fragment">
1737 <element name="div" namespace="&xhtml;">
1738 <value-of select="substring-after($after-start, ']')"/>
1739 <copy-of select="$start-node/following-sibling::node()"/>
1740 </element>
1741 </variable>
1742 <variable name="footnoted-rest-fragment">
1743 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1744 <with-param name="footnote-ids" select="$footnote-ids"/>
1745 </apply-templates>
1746 </variable>
1747 <copy>
1748 <copy-of select="@*"/>
1749 <copy-of select="$start-node/preceding-sibling::node()"/>
1750 <copy-of select="substring-before($start-node, '[^')"/>
1751 <element name="a" namespace="&xhtml;">
1752 <attribute name="id">
1753 <text>LesML.fnref.</text>
1754 <value-of select="generate-id($start-node)"/>
1755 </attribute>
1756 <attribute name="role">
1757 <text>doc-noteref</text>
1758 </attribute>
1759 <attribute name="href">
1760 <text>#</text>
1761 <value-of select="$footnote-id"/>
1762 </attribute>
1763 <attribute name="target">
1764 <text>_self</text>
1765 </attribute>
1766 </element>
1767 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1768 </copy>
1769 </when>
1770 <when test="$start-node">
1771 <variable name="rest-fragment">
1772 <element name="div" namespace="&xhtml;">
1773 <value-of select="substring-after($start-node, '[^')"/>
1774 <copy-of select="$start-node/following-sibling::node()"/>
1775 </element>
1776 </variable>
1777 <variable name="footnoted-rest-fragment">
1778 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1779 <with-param name="footnote-ids" select="$footnote-ids"/>
1780 </apply-templates>
1781 </variable>
1782 <copy>
1783 <copy-of select="@*"/>
1784 <copy-of select="$start-node/preceding-sibling::node()"/>
1785 <copy-of select="substring-before($start-node, '[^')"/>
1786 <text>[^</text>
1787 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1788 </copy>
1789 </when>
1790 <otherwise>
1791 <copy>
1792 <copy-of select="@*"/>
1793 <apply-templates select="node()" mode="LesML:footnoted">
1794 <with-param name="footnote-ids" select="$footnote-ids"/>
1795 </apply-templates>
1796 </copy>
1797 </otherwise>
1798 </choose>
1799 </when>
1800 <otherwise>
1801 <copy-of select="."/>
1802 </otherwise>
1803 </choose>
1804 </variable>
1805 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:finish"/>
1806 </template>
1807 <template match="processing-instruction()[local-name()='LesML-All-Done']" mode="LesML:finish"/>
1808 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finish">
1809 <value-of select="."/>
1810 </template>
1811 <template match="@*|node()" mode="LesML:finish" priority="-1">
1812 <copy>
1813 <apply-templates select="@*|node()" mode="LesML:finish"/>
1814 </copy>
1815 </template>
1816
1817 <!-->
1818 ❦ Templates in the `LesML:finalize´ and related modes
1819
1820 These templates finalize the resulting tree.
1821 </!-->
1822
1823 <template match="node()" mode="LesML:finalize-attributes">
1824 <param name="exclude-level" select="false()"/>
1825 <variable name="notattr" select="following-sibling::node()[not(self::LesML:attribute)]"/>
1826 <variable name="div" select="self::html:div|self::*[&block-types;]/node()[not(self::processing-instruction())][position()=1 and self::html:div]"/>
1827 <variable name="para" select="self::html:p|$div/node()[not(self::processing-instruction())][position()=1 and self::html:p]"/>
1828 <variable name="emptypara" select="$para[not(@*|node()[not(self::processing-instruction())])]"/>
1829 <for-each select="(.|$emptypara/..|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
1830 <copy-of select="."/>
1831 <if test="local-name()='lang' and namespace-uri()=''">
1832 <attribute name="xml:lang">
1833 <value-of select="."/>
1834 </attribute>
1835 </if>
1836 </for-each>
1837 <if test="not($exclude-level) and &level-pi;!=0">
1838 <attribute name="data-level">
1839 <value-of select="&level-pi;"/>
1840 </attribute>
1841 </if>
1842 </template>
1843 <template match="html:dt|html:dd" mode="LesML:finalize-list">
1844 <param name="used-footnotes" select="/.."/>
1845 <variable name="current-level" select="number(&level-pi;)"/>
1846 <variable name="notinlist" select="following-sibling::node()[not((self::html:dt or self::html:dd) and &level-pi;=$current-level)][1]"/>
1847 <variable name="inlist" select=".|exslset:leading(following-sibling::node(), $notinlist)"/>
1848 <variable name="lasts-in-pairing" select="$inlist[self::html:dd and not(exslset:intersection(following-sibling::node()[1]/self::html:dd, $inlist))]|$inlist[last()]"/>
1849 <element name="dl" namespace="&xhtml;">
1850 <for-each select="$lasts-in-pairing">
1851 <variable name="prev-position" select="position()-1"/>
1852 <variable name="prev-last" select="$lasts-in-pairing[$prev-position]"/>
1853 <element name="div" namespace="&xhtml;">
1854 <for-each select="exslset:leading(exslset:trailing($inlist, $prev-last), .)|.">
1855 <if test="position()=1 and self::html:dd">
1856 <element name="dt" namespace="&xhtml;"/>
1857 </if>
1858 <copy>
1859 <apply-templates select="." mode="LesML:finalize-attributes"/>
1860 <apply-templates select="node()" mode="LesML:finalize">
1861 <with-param name="used-footnotes" select="$used-footnotes"/>
1862 </apply-templates>
1863 </copy>
1864 <if test="position()=last() and self::html:dt">
1865 <element name="dd" namespace="&xhtml;"/>
1866 </if>
1867 </for-each>
1868 </element>
1869 </for-each>
1870 </element>
1871 <if test="$notinlist/self::html:dt or $notinlist/self::html:dd">
1872 <apply-templates select="$notinlist" mode="LesML:finalize-list">
1873 <with-param name="used-footnotes" select="$used-footnotes"/>
1874 </apply-templates>
1875 </if>
1876 </template>
1877 <template match="html:li" mode="LesML:finalize-list">
1878 <param name="used-footnotes" select="/.."/>
1879 <variable name="current-class" select="string(@class)"/>
1880 <variable name="current-level" select="number(&level-pi;)"/>
1881 <variable name="wrapper">
1882 <choose>
1883 <when test="contains(concat(' ', @class, ' '), ' ordered ')">
1884 <text>ol</text>
1885 </when>
1886 <otherwise>
1887 <text>ul</text>
1888 </otherwise>
1889 </choose>
1890 </variable>
1891 <variable name="notinlist" select="following-sibling::node()[not(self::html:li and &level-pi;=$current-level and @class=$current-class)][1]"/>
1892 <element name="{$wrapper}" namespace="&xhtml;">
1893 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)">
1894 <copy>
1895 <apply-templates select="." mode="LesML:finalize-attributes"/>
1896 <apply-templates select="node()" mode="LesML:finalize">
1897 <with-param name="used-footnotes" select="$used-footnotes"/>
1898 </apply-templates>
1899 </copy>
1900 </for-each>
1901 </element>
1902 <if test="$notinlist/self::html:li">
1903 <apply-templates select="$notinlist" mode="LesML:finalize-list">
1904 <with-param name="used-footnotes" select="$used-footnotes"/>
1905 </apply-templates>
1906 </if>
1907 </template>
1908 <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"/>
1909 <template match="html:div[not((node()[not(self::processing-instruction())])/following-sibling::node()[not(self::processing-instruction())])]" mode="LesML:finalize" priority="1">
1910 <param name="used-footnotes" select="/.."/>
1911 <variable name="context" select="."/>
1912 <variable name="result-fragment">
1913 <apply-templates select="node()" mode="LesML:finalize">
1914 <with-param name="used-footnotes" select="$used-footnotes"/>
1915 </apply-templates>
1916 </variable>
1917 <variable name="result" select="exsl:node-set($result-fragment)/node()"/>
1918 <choose>
1919 <when test="not(../&level-pi;) and &level-pi;!=0 or ../&level-pi; and &level-pi;-1!=../&level-pi;">
1920 <copy>
1921 <apply-templates select="$context" mode="LesML:finalize-attributes"/>
1922 <copy-of select="$result"/>
1923 </copy>
1924 </when>
1925 <when test="$result">
1926 <for-each select="$result">
1927 <copy>
1928 <apply-templates select="$context" mode="LesML:finalize-attributes">
1929 <with-param name="exclude-level" select="true()"/>
1930 </apply-templates>
1931 <copy-of select="@*|node()"/>
1932 </copy>
1933 </for-each>
1934 </when>
1935 <when test="* and (preceding-sibling::node()[not(self::processing-instruction())] or not(ancestor::*))">
1936 <for-each select="*">
1937 <copy>
1938 <apply-templates select="$context" mode="LesML:finalize-attributes">
1939 <with-param name="exclude-level" select="true()"/>
1940 </apply-templates>
1941 <copy-of select="@*|node()"/>
1942 </copy>
1943 </for-each>
1944 </when>
1945 <otherwise/>
1946 </choose>
1947 </template>
1948 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize" priority="1">
1949 <element name="span" namespace="&xhtml;">
1950 <apply-templates select="." mode="LesML:finalize-attributes"/>
1951 <if test="self::text()">
1952 <copy/>
1953 </if>
1954 </element>
1955 </template>
1956 <template match="html:blockquote[node()[position()=last() and self::html:footer]]" mode="LesML:finalize">
1957 <param name="used-footnotes" select="/.."/>
1958 <element name="figure" namespace="&xhtml;">
1959 <copy>
1960 <apply-templates select="." mode="LesML:finalize-attributes"/>
1961 <apply-templates select="node()[position()!=last()]" mode="LesML:finalize">
1962 <with-param name="used-footnotes" select="$used-footnotes"/>
1963 </apply-templates>
1964 </copy>
1965 <for-each select="node()[last()]">
1966 <element name="figcaption" namespace="&xhtml;">
1967 <apply-templates select="." mode="LesML:finalize-attributes">
1968 <with-param name="exclude-level" select="true()"/>
1969 </apply-templates>
1970 <apply-templates select="node()" mode="LesML:finalize">
1971 <with-param name="used-footnotes" select="$used-footnotes"/>
1972 </apply-templates>
1973 </element>
1974 </for-each>
1975 </element>
1976 </template>
1977 <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">
1978 <param name="used-footnotes" select="/.."/>
1979 <element name="hgroup" namespace="&xhtml;">
1980 <apply-templates select="." mode="LesML:finalize-attributes"/>
1981 <apply-templates select="node()" mode="LesML:finalize">
1982 <with-param name="used-footnotes" select="$used-footnotes"/>
1983 </apply-templates>
1984 </element>
1985 </template>
1986 <template match="html:dt|html:dd" mode="LesML:finalize">
1987 <param name="used-footnotes" select="/.."/>
1988 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:dt or self::html:dd)]">
1989 <apply-templates select="." mode="LesML:finalize-list">
1990 <with-param name="used-footnotes" select="$used-footnotes"/>
1991 </apply-templates>
1992 </if>
1993 </template>
1994 <template match="html:li" mode="LesML:finalize">
1995 <param name="used-footnotes" select="/.."/>
1996 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:li)]">
1997 <apply-templates select="." mode="LesML:finalize-list">
1998 <with-param name="used-footnotes" select="$used-footnotes"/>
1999 </apply-templates>
2000 </if>
2001 </template>
2002 <template match="html:pre" mode="LesML:finalize">
2003 <param name="used-footnotes" select="/.."/>
2004 <copy>
2005 <apply-templates select="." mode="LesML:finalize-attributes"/>
2006 <choose>
2007 <when test="@class='code'">
2008 <element name="code" namespace="&xhtml;">
2009 <apply-templates select="node()" mode="LesML:finalize">
2010 <with-param name="used-footnotes" select="$used-footnotes"/>
2011 </apply-templates>
2012 </element>
2013 </when>
2014 <otherwise>
2015 <apply-templates select="node()" mode="LesML:finalize">
2016 <with-param name="used-footnotes" select="$used-footnotes"/>
2017 </apply-templates>
2018 </otherwise>
2019 </choose>
2020 </copy>
2021 </template>
2022 <template match="html:a[@role='doc-noteref']" mode="LesML:finalize">
2023 <param name="used-footnotes" select="/.."/>
2024 <variable name="matching-note" select="$used-footnotes[concat('#', @id)=current()/@href]"/>
2025 <copy>
2026 <apply-templates select="." mode="LesML:finalize-attributes"/>
2027 <choose>
2028 <when test="$matching-note">
2029 <value-of select="$matching-note/@value"/>
2030 </when>
2031 <otherwise>
2032 <apply-templates select="node()" mode="LesML:finalize">
2033 <with-param name="used-footnotes" select="$used-footnotes"/>
2034 </apply-templates>
2035 </otherwise>
2036 </choose>
2037 </copy>
2038 </template>
2039 <template match="text()" mode="LesML:finalize">
2040 <call-template name="LesML:unescape">
2041 <with-param name="source" select="string()"/>
2042 </call-template>
2043 </template>
2044 <template match="node()" mode="LesML:finalize" priority="-1">
2045 <param name="used-footnotes" select="/.."/>
2046 <copy>
2047 <apply-templates select="." mode="LesML:finalize-attributes"/>
2048 <apply-templates select="node()" mode="LesML:finalize">
2049 <with-param name="used-footnotes" select="$used-footnotes"/>
2050 </apply-templates>
2051 </copy>
2052 </template>
2053 </transform>
This page took 1.037629 seconds and 5 git commands to generate.