]> Lady’s Gitweb - LesML/blob - xslt/lesml.xslt
9a603834c4bbef7c765730fdbce743b28a721df24c006aea7d1ef3110a405e68
[LesML] / xslt / lesml.xslt
1 <?xml version="1.0"?>
2 <!--
3 @(#)💄📝 Les·M·L xslt/lesml.xslt 2026-03-31T01:28:11Z
4 SPDX-FileCopyrightText: 2024, 2025, 2026 Lady <https://www.ladys.computer/about/#lady>
5 SPDX-License-Identifier: MPL-2.0
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
26 <!DOCTYPE transform [
27 <!ENTITY LesML "urn:fdc:ladys.computer:20240512:LesML">
28 <!ENTITY block-types "self::html:blockquote or self::html:footer or self::html:li or self::html:dt or self::html:dd or self::html:section or &paragraph-types;">
29 <!ENTITY paragraph-types "self::html:p or self::html:pre or self::html:h1 or self::html:h2 or self::html:h3 or self::html:h4">
30 <!ENTITY level-pi "processing-instruction()[local-name()='LesML-Level']">
31 <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
32 ]>
33 <transform
34 xmlns="http://www.w3.org/1999/XSL/Transform"
35 xmlns:LesML="&LesML;"
36 xmlns:exsl="http://exslt.org/common"
37 xmlns:exsldyn="http://exslt.org/dynamic"
38 xmlns:exslfunc="http://exslt.org/functions"
39 xmlns:exslset="http://exslt.org/sets"
40 xmlns:exslstr="http://exslt.org/strings"
41 xmlns:html="&xhtml;"
42 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
43 exclude-result-prefixes="LesML"
44 extension-element-prefixes="exsl exsldyn exslfunc exslset exslstr"
45 version="1.0"
46 >
47 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
48 <param name="LESML_SECTION_BREAK_CHARS" select="'*-.=_~ ·․‥…⁂⁠⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'"/>
49 <exslfunc:function name="LesML:split">
50 <param name="source" select="string()"/>
51 <param name="separator" select="'&#xA;'"/>
52 <variable name="result-fragment">
53 <call-template name="LesML:do-split">
54 <with-param name="source" select="$source"/>
55 <with-param name="separator" select="$separator"/>
56 </call-template>
57 </variable>
58 <exslfunc:result select="exsl:node-set($result-fragment)/node()"/>
59 </exslfunc:function>
60 <template name="LesML:do-split">
61 <param name="source"/>
62 <param name="separator" select="'&#xA;'"/>
63 <choose>
64 <when test="contains($source, $separator)">
65 <html:span>
66 <value-of select="substring-before($source, $separator)"/>
67 </html:span>
68 <call-template name="LesML:do-split">
69 <with-param name="source" select="substring-after($source, $separator)"/>
70 <with-param name="separator" select="$separator"/>
71 </call-template>
72 </when>
73 <otherwise>
74 <html:span>
75 <value-of select="$source"/>
76 </html:span>
77 </otherwise>
78 </choose>
79 </template>
80 <template name="LesML:comment-out">
81 <param name="source"/>
82 <comment>
83 <for-each select="LesML:split($source, '--')">
84 <if test="string()='' or starts-with(., '‐')">
85 <text>&#x034F;</text>
86 </if>
87 <value-of select="."/>
88 <if test="substring(., string-length(.), 1)='‐'">
89 <text>&#x034F;</text>
90 </if>
91 <choose>
92 <when test="position()!=last()">
93 <text>-&#x034F;-</text>
94 </when>
95 </choose>
96 </for-each>
97 </comment>
98 </template>
99 <template name="LesML:unescape">
100 <param name="source"/>
101 <choose>
102 <when test="contains($source, '{U+')">
103 <variable name="after" select="substring-after($source, '{U+')"/>
104 <choose>
105 <when test="contains($after, '}')">
106 <variable name="inner" select="substring-before($after, '}')"/>
107 <variable name="components" select="LesML:split($inner, '.')"/>
108 <value-of select="substring-before($source, '{U+')"/>
109 <choose>
110 <when test="$components[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
111 <text>{U+</text>
112 <value-of select="$inner"/>
113 <text>}</text>
114 <call-template name="LesML:unescape">
115 <with-param name="source" select="substring-after($after, '}')"/>
116 </call-template>
117 </when>
118 <otherwise>
119 <for-each select="$components">
120 <text disable-output-escaping="yes">&amp;#x</text>
121 <value-of select="."/>
122 <text>;</text>
123 </for-each>
124 <call-template name="LesML:unescape">
125 <with-param name="source" select="substring-after($after, '}')"/>
126 </call-template>
127 </otherwise>
128 </choose>
129 </when>
130 <otherwise>
131 <value-of select="substring-before($source, '{U+')"/>
132 <text>{U+</text>
133 <call-template name="LesML:unescape">
134 <with-param name="source" select="$after"/>
135 </call-template>
136 </otherwise>
137 </choose>
138 </when>
139 <otherwise>
140 <value-of select="$source"/>
141 </otherwise>
142 </choose>
143 </template>
144 <template name="LesML:expand-sigils">
145 <param name="sigils" select="/.."/>
146 <param name="level" select="0"/>
147 <param name="partype"/>
148 <param name="syntax"/>
149 <param name="lines" select="/.."/>
150 <choose>
151 <when test="$sigils">
152 <variable name="wrapper-frag">
153 <choose>
154 <when test="$sigils[1]='•'">
155 <element name="li" namespace="&xhtml;">
156 <attribute name="class">
157 <text>unordered</text>
158 </attribute>
159 </element>
160 </when>
161 <when test="$sigils[1]='№'">
162 <element name="li" namespace="&xhtml;">
163 <attribute name="class">
164 <text>ordered</text>
165 </attribute>
166 </element>
167 </when>
168 <when test="$sigils[1]='※'">
169 <element name="section" namespace="&xhtml;">
170 <attribute name="role">
171 <text>note</text>
172 </attribute>
173 <attribute name="class">
174 <text>note</text>
175 </attribute>
176 </element>
177 </when>
178 <when test="$sigils[1]='⯑'">
179 <element name="section" namespace="&xhtml;">
180 <attribute name="role">
181 <text>note</text>
182 </attribute>
183 <attribute name="class">
184 <text>query</text>
185 </attribute>
186 </element>
187 </when>
188 <when test="$sigils[1]='∫'">
189 <element name="section" namespace="&xhtml;">
190 <attribute name="role">
191 <text>doc-abstract</text>
192 </attribute>
193 <attribute name="class">
194 <text>abstract</text>
195 </attribute>
196 </element>
197 </when>
198 <when test="$sigils[1]='☡'">
199 <element name="section" namespace="&xhtml;">
200 <attribute name="role">
201 <text>doc-notice</text>
202 </attribute>
203 <attribute name="class">
204 <text>caution</text>
205 </attribute>
206 </element>
207 </when>
208 <when test="$sigils[1]='⚠'">
209 <element name="section" namespace="&xhtml;">
210 <attribute name="role">
211 <text>doc-notice</text>
212 </attribute>
213 <attribute name="class">
214 <text>warning</text>
215 </attribute>
216 </element>
217 </when>
218 <when test="$sigils[1]='🛈'">
219 <element name="section" namespace="&xhtml;">
220 <attribute name="role">
221 <text>doc-tip</text>
222 </attribute>
223 <attribute name="class">
224 <text>info</text>
225 </attribute>
226 </element>
227 </when>
228 <when test="$sigils[1]='💡'">
229 <element name="section" namespace="&xhtml;">
230 <attribute name="role">
231 <text>doc-tip</text>
232 </attribute>
233 <attribute name="class">
234 <text>tip</text>
235 </attribute>
236 </element>
237 </when>
238 <when test="$sigils[1]='»'">
239 <element name="blockquote" namespace="&xhtml;"/>
240 </when>
241 <when test="$sigils[1]='∎'">
242 <element name="footer" namespace="&xhtml;"/>
243 </when>
244 <otherwise>
245 <message terminate="yes">
246 <text>Unrecognized sigil: </text>
247 <value-of select="$sigils[1]"/>
248 <text>.</text>
249 </message>
250 </otherwise>
251 </choose>
252 </variable>
253 <for-each select="exsl:node-set($wrapper-frag)/*">
254 <copy>
255 <copy-of select="@*|node()"/>
256 <processing-instruction name="LesML-Level">
257 <value-of select="$level"/>
258 </processing-instruction>
259 <call-template name="LesML:expand-sigils">
260 <with-param name="sigils" select="$sigils[position()>1]"/>
261 <with-param name="level" select="$level+1"/>
262 <with-param name="partype" select="$partype"/>
263 <with-param name="syntax" select="$syntax"/>
264 <with-param name="lines" select="$lines"/>
265 </call-template>
266 </copy>
267 </for-each>
268 </when>
269 <when test="$partype='comment'">
270 <element name="div" namespace="&xhtml;">
271 <processing-instruction name="LesML-Level">
272 <value-of select="$level"/>
273 </processing-instruction>
274 <call-template name="LesML:comment-out">
275 <with-param name="source">
276 <for-each select="$lines">
277 <value-of select="."/>
278 <if test="position()!=count($lines)">
279 <text>&#xA;</text>
280 </if>
281 </for-each>
282 </with-param>
283 </call-template>
284 </element>
285 </when>
286 <otherwise>
287 <variable name="firstchar" select="substring(translate($lines[1], ' &#x9;', ''), 1, 1)"/>
288 <variable name="firstline">
289 <choose>
290 <when test="$firstchar!=''">
291 <value-of select="concat($firstchar, substring-after($lines[1], $firstchar))"/>
292 </when>
293 </choose>
294 </variable>
295 <variable name="firsttokens" select="exslstr:tokenize($firstline, ' &#x9;')"/>
296 <variable name="id-and-lang">
297 <if test="$firstchar='¶'">
298 <value-of select="$firsttokens[1]"/>
299 </if>
300 </variable>
301 <variable name="restofline">
302 <choose>
303 <when test="$id-and-lang!=''">
304 <variable name="nosp" select="substring($firsttokens[1+number($id-and-lang!='')], 1, 1)"/>
305 <if test="$nosp!=''">
306 <value-of select="concat($nosp, substring-after(substring-after($firstline, $id-and-lang), $nosp))"/>
307 </if>
308 </when>
309 <otherwise>
310 <value-of select="$lines[1]"/>
311 </otherwise>
312 </choose>
313 </variable>
314 <variable name="maybe-langtag">
315 <if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
316 <value-of select="LesML:split(substring($id-and-lang, 2, string-length($id-and-lang)-2), '@')[last()]"/>
317 </if>
318 </variable>
319 <variable name="langtag">
320 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
321 <value-of select="$maybe-langtag"/>
322 </if>
323 </variable>
324 <variable name="id">
325 <choose>
326 <when test="string($langtag)!=''">
327 <value-of select="substring($id-and-lang, 2, string-length($id-and-lang)-(string-length($langtag)+3))"/>
328 </when>
329 <otherwise>
330 <value-of select="substring($id-and-lang, 2)"/>
331 </otherwise>
332 </choose>
333 </variable>
334 <variable name="newline">
335 <choose>
336 <when test="$partype='pre' or $partype='pre code'">
337 <element name="br" namespace="&xhtml;"/>
338 </when>
339 <otherwise>
340 <text>&#xA;</text>
341 </otherwise>
342 </choose>
343 </variable>
344 <variable name="text">
345 <if test="$id-and-lang='' or $restofline!=''">
346 <value-of select="$restofline"/>
347 <if test="count($lines)>1">
348 <copy-of select="$newline"/>
349 </if>
350 </if>
351 <for-each select="$lines[position()>1]">
352 <value-of select="."/>
353 <if test="position()!=count($lines[position()>1])">
354 <copy-of select="$newline"/>
355 </if>
356 </for-each>
357 </variable>
358 <variable name="parwrapper">
359 <choose>
360 <when test="$partype='pre code'">
361 <text>pre</text>
362 </when>
363 <when test="$partype='footnote'">
364 <text>p</text>
365 </when>
366 <when test="$partype!=''">
367 <value-of select="$partype"/>
368 </when>
369 <otherwise>
370 <text>p</text>
371 </otherwise>
372 </choose>
373 </variable>
374 <element name="div" namespace="&xhtml;">
375 <if test="$id!=''">
376 <attribute name="id">
377 <value-of select="$id"/>
378 </attribute>
379 </if>
380 <if test="$langtag!=''">
381 <attribute name="lang">
382 <value-of select="$langtag"/>
383 </attribute>
384 <attribute name="xml:lang">
385 <value-of select="$langtag"/>
386 </attribute>
387 </if>
388 <if test="$partype='footnote'">
389 <processing-instruction name="LesML-Footnote">
390 <value-of select="$id"/>
391 </processing-instruction>
392 </if>
393 <processing-instruction name="LesML-Level">
394 <value-of select="$level"/>
395 </processing-instruction>
396 <element name="{$parwrapper}" namespace="&xhtml;">
397 <if test="$parwrapper='pre'">
398 <attribute name="role">
399 <text>paragraph</text>
400 </attribute>
401 </if>
402 <if test="$partype='pre code'">
403 <attribute name="class">
404 <text>code</text>
405 </attribute>
406 </if>
407 <if test="$syntax!=''">
408 <attribute name="data-syntax">
409 <value-of select="$syntax"/>
410 </attribute>
411 </if>
412 <choose>
413 <when test="$parwrapper='hr'">
414 <attribute name="data-source-text">
415 <value-of select="$text"/>
416 </attribute>
417 </when>
418 <otherwise>
419 <copy-of select="$text"/>
420 </otherwise>
421 </choose>
422 </element>
423 </element>
424 </otherwise>
425 </choose>
426 </template>
427 <template name="LesML:chunk">
428 <param name="lines" select="/.."/>
429 <variable name="last-lines" select="$lines[normalize-space()!='' and (normalize-space(following-sibling::*[1])='' or position()=last())]"/>
430 <for-each select="$last-lines">
431 <variable name="position" select="position()"/>
432 <variable name="prev-last" select="$last-lines[($position)-1]"/>
433 <variable name="linespans" select="(exslset:intersection(exslset:trailing($lines, $prev-last), exslset:leading($lines, .))|.)[normalize-space()!='']"/>
434 <variable name="nospace" select="translate($linespans[1], ' &#x9;', '')"/>
435 <variable name="firstnolevel" select="substring(translate($nospace, '⋮', ''), 1, 1)"/>
436 <variable name="levelling">
437 <choose>
438 <when test="$firstnolevel!=''">
439 <value-of select="substring-before($linespans[1], $firstnolevel)"/>
440 </when>
441 <otherwise>
442 <value-of select="$linespans[1]"/>
443 </otherwise>
444 </choose>
445 </variable>
446 <variable name="nested-bullet">
447 <choose>
448 <when test="contains('◦▪⁃', $firstnolevel)">
449 <value-of select="$firstnolevel"/>
450 </when>
451 <otherwise/>
452 </choose>
453 </variable>
454 <variable name="level-modifier">
455 <choose>
456 <when test="$nested-bullet='◦'">
457 <text>1</text>
458 </when>
459 <when test="$nested-bullet='▪'">
460 <text>2</text>
461 </when>
462 <when test="$nested-bullet='⁃'">
463 <text>3</text>
464 </when>
465 <otherwise>
466 <text>0</text>
467 </otherwise>
468 </choose>
469 </variable>
470 <variable name="nobullet">
471 <choose>
472 <when test="$nested-bullet!=''">
473 <value-of select="substring-after($nospace, $nested-bullet)"/>
474 </when>
475 <otherwise>
476 <value-of select="concat($firstnolevel, substring-after($nospace, $firstnolevel))"/>
477 </otherwise>
478 </choose>
479 </variable>
480 <variable name="firstnosigil" select="substring(translate($nobullet, '•№※⯑∫☡⚠🛈💡»∎', ''), 1, 1)"/>
481 <variable name="sigilling">
482 <choose>
483 <when test="$firstnosigil!=''">
484 <value-of select="substring-before(substring-after($linespans[1], concat($levelling, $nested-bullet)), $firstnosigil)"/>
485 </when>
486 <otherwise>
487 <value-of select="substring-after($linespans[1], concat($levelling, $nested-bullet))"/>
488 </otherwise>
489 </choose>
490 </variable>
491 <variable name="nosigil">
492 <value-of select="concat($firstnosigil, substring-after($nobullet, $firstnosigil))"/>
493 </variable>
494 <variable name="ruled" select="count($linespans)=1 and $nosigil!='' and translate($nosigil, $LESML_SECTION_BREAK_CHARS, '')=''"/>
495 <variable name="prefix">
496 <choose>
497 <when test="not($ruled) and $firstnosigil='|'">
498 <variable name="postpipe" select="substring-after($linespans[1], '|')"/>
499 <choose>
500 <when test="substring(translate($postpipe, '0123456789abcdefghijklmnopqrstuvwxyz/.-', ''), 1, 1)='$'">
501 <value-of select="concat(substring-before($linespans[1], '$'), '$')"/>
502 </when>
503 <otherwise>
504 <value-of select="concat(substring-before($linespans[1], '|'), '|')"/>
505 </otherwise>
506 </choose>
507 </when>
508 <when test="not($ruled) and contains('⁌§❦✠#^', $firstnosigil)">
509 <value-of select="concat(substring-before($linespans[1], $firstnosigil), $firstnosigil)"/>
510 </when>
511 <when test="$firstnosigil!=''">
512 <value-of select="substring-before($linespans[1], $firstnosigil)"/>
513 </when>
514 <otherwise>
515 <value-of select="$linespans[1]"/>
516 </otherwise>
517 </choose>
518 </variable>
519 <variable name="preformatted" select="$firstnosigil='|' and not($linespans[not(starts-with(., $prefix))])"/>
520 <variable name="inner-lines-fragment">
521 <for-each select="$linespans">
522 <choose>
523 <when test="$preformatted or position()=1">
524 <html:span>
525 <value-of select="substring-after(., $prefix)"/>
526 </html:span>
527 </when>
528 <otherwise>
529 <copy-of select="."/>
530 </otherwise>
531 </choose>
532 </for-each>
533 </variable>
534 <variable name="inner-lines" select="exsl:node-set($inner-lines-fragment)/node()"/>
535 <call-template name="LesML:expand-sigils">
536 <with-param name="sigils" select="exslstr:tokenize(translate(concat($nested-bullet, $sigilling), '◦▪⁃ &#x9;', '•••'), '')"/>
537 <with-param name="level" select="string-length(translate($levelling, ' &#x9;', ''))+$level-modifier"/>
538 <with-param name="partype">
539 <choose>
540 <when test="$preformatted">
541 <text>pre</text>
542 <if test="contains($prefix, '$')">
543 <text> code</text>
544 </if>
545 </when>
546 <when test="$ruled">
547 <text>hr</text>
548 </when>
549 <when test="$firstnosigil='#'">
550 <text>comment</text>
551 </when>
552 <when test="$firstnosigil='^'">
553 <text>footnote</text>
554 </when>
555 <when test="$firstnosigil='⁌'">
556 <text>h1</text>
557 </when>
558 <when test="$firstnosigil='§'">
559 <text>h2</text>
560 </when>
561 <when test="$firstnosigil='❦'">
562 <text>h3</text>
563 </when>
564 <when test="$firstnosigil='✠'">
565 <text>h4</text>
566 </when>
567 <otherwise/>
568 </choose>
569 </with-param>
570 <with-param name="syntax" select="substring-before(substring-after($prefix, '|'), '$')"/>
571 <with-param name="lines" select="$inner-lines"/>
572 </call-template>
573 </for-each>
574 </template>
575 <template name="LesML:paragraphize">
576 <param name="lines" select="/.."/>
577 <variable name="chunked-fragment">
578 <call-template name="LesML:chunk">
579 <with-param name="lines" select="$lines"/>
580 </call-template>
581 </variable>
582 <apply-templates select="exsl:node-set($chunked-fragment)" mode="LesML:blockify"/>
583 </template>
584 <template name="LesML:parse">
585 <param name="lines" select="/.."/>
586 <param name="parent-params" select="/.."/>
587 <variable name="first-line" select="$lines[1]"/>
588 <variable name="shero">
589 <if test="starts-with($first-line, '#?lesml')">
590 <value-of select="$first-line"/>
591 </if>
592 </variable>
593 <variable name="params-string">
594 <choose>
595 <when test="starts-with($shero, '#?lesml@')">
596 <value-of select="substring-after($shero, '$')"/>
597 </when>
598 <otherwise>
599 <value-of select="substring-after($shero, '#?lesml')"/>
600 </otherwise>
601 </choose>
602 </variable>
603 <variable name="params-fragment">
604 <choose>
605 <when test="$shero!=''">
606 <html:dl>
607 <if test="starts-with($shero, '#?lesml@') and contains($shero, '$')">
608 <html:div>
609 <html:dt>
610 <text> LANG </text>
611 </html:dt>
612 <html:dd>
613 <value-of select="substring-before(substring-after($shero, '#?lesml@'), '$')"/>
614 </html:dd>
615 </html:div>
616 </if>
617 <for-each select="exslstr:tokenize($params-string)">
618 <choose>
619 <when test="contains(., '=')">
620 <html:div>
621 <html:dt>
622 <value-of select="substring-before(., '=')"/>
623 </html:dt>
624 <html:dd>
625 <value-of select="substring-after(., '=')"/>
626 </html:dd>
627 </html:div>
628 </when>
629 <otherwise>
630 <html:div>
631 <html:dt>
632 <value-of select="."/>
633 </html:dt>
634 <html:dd/>
635 </html:div>
636 </otherwise>
637 </choose>
638 </for-each>
639 </html:dl>
640 </when>
641 <when test="$parent-params">
642 <copy-of select="$parent-params"/>
643 </when>
644 <otherwise>
645 <html:dl/>
646 </otherwise>
647 </choose>
648 </variable>
649 <variable name="params" select="exsl:node-set($params-fragment)/node()"/>
650 <variable name="noshero" select="$lines[position()>1 or not(starts-with(., '#?lesml') or starts-with(., '##'))]"/>
651 <variable name="docsep" select="$noshero[starts-with(., '#?lesml') or starts-with(., '##')][1]"/>
652 <variable name="doclines" select="exslset:leading($noshero, $docsep)"/>
653 <if test="starts-with($first-line, '##') and $first-line!='##'">
654 <call-template name="LesML:comment-out">
655 <with-param name="source" select="substring-after($first-line, '##')"/>
656 </call-template>
657 </if>
658 <if test="$doclines[normalize-space()!='']">
659 <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
660 <variable name="paragraphized-fragment">
661 <call-template name="LesML:paragraphize">
662 <with-param name="lines" select="exslset:trailing($doclines, $record-separators[last()])"/>
663 </call-template>
664 </variable>
665 <variable name="paragraphized-document" select="exsl:node-set($paragraphized-fragment)"/>
666 <variable name="filtered-ordered-footnotes-fragment">
667 <for-each select="$paragraphized-document//processing-instruction()[local-name()='LesML-Footnote']">
668 <sort select="count(($paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string(current()))])[1]/preceding::*)" data-type="number"/>
669 <if test="$paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string(current()))]">
670 <copy-of select=".."/>
671 </if>
672 </for-each>
673 </variable>
674 <variable name="used-footnotes-fragment">
675 <for-each select="exsl:node-set($filtered-ordered-footnotes-fragment)/node()">
676 <variable name="footnote-id" select="processing-instruction()[local-name()='LesML-Footnote']"/>
677 <variable name="links" select="$paragraphized-document//html:a[@role='doc-noteref' and @href=concat('#', string($footnote-id))]"/>
678 <element name="li" namespace="&xhtml;">
679 <variable name="numero" select="position()"/>
680 <attribute name="id">
681 <value-of select="$footnote-id"/>
682 </attribute>
683 <attribute name="value">
684 <value-of select="$numero"/>
685 </attribute>
686 <copy-of select="node()[not(self::processing-instruction() and local-name()='LesML-Footnote')]"/>
687 <element name="footer" namespace="&xhtml;">
688 <attribute name="class">
689 <text>backlinks</text>
690 </attribute>
691 <for-each select="$links[@id]">
692 <if test="position()>1">
693 <text> </text>
694 </if>
695 <element name="a" namespace="&xhtml;">
696 <attribute name="role">
697 <text>doc-backlink</text>
698 </attribute>
699 <attribute name="href">
700 <text>#</text>
701 <value-of select="@id"/>
702 </attribute>
703 <value-of select="position()"/>
704 </element>
705 </for-each>
706 </element>
707 </element>
708 </for-each>
709 </variable>
710 <variable name="used-footnotes" select="exsl:node-set($used-footnotes-fragment)/node()"/>
711 <element name="article" namespace="&xhtml;">
712 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
713 <attribute name="lang">
714 <value-of select="following-sibling::html:dd"/>
715 </attribute>
716 <attribute name="xml:lang">
717 <value-of select="following-sibling::html:dd"/>
718 </attribute>
719 </for-each>
720 <for-each select="$params/html:div/html:dt[string()='profile']">
721 <attribute name="data-lesml-profile">
722 <value-of select="following-sibling::html:dd"/>
723 </attribute>
724 </for-each>
725 <if test="$record-separators and exslset:difference(exslset:leading($doclines, $record-separators[last()]), $record-separators)[normalize-space()!='']">
726 <element name="footer" namespace="&xhtml;">
727 <attribute name="class">
728 <text>head</text>
729 </attribute>
730 <for-each select="$record-separators">
731 <variable name="position" select="position()"/>
732 <variable name="prev-separator" select="$record-separators[($position)-1]"/>
733 <variable name="fields" select="exslset:leading(exslset:trailing($doclines, $prev-separator), .)[normalize-space()!='']"/>
734 <if test="$fields">
735 <element name="dl" namespace="&xhtml;">
736 <for-each select="$fields">
737 <variable name="following" select="exslset:intersection($fields, following-sibling::*)"/>
738 <choose>
739 <when test="contains(' &#x9;', substring(., 1, 1)) and exslset:has-same-node($fields, preceding-sibling::*[1])"/>
740 <otherwise>
741 <variable name="next" select="$following[not(contains(' &#x9;', substring(., 1, 1)))][1]"/>
742 <element name="div" namespace="&xhtml;">
743 <element name="dt" namespace="&xhtml;">
744 <value-of select="normalize-space(substring-before(., ':'))"/>
745 </element>
746 <element name="dd" namespace="&xhtml;">
747 <variable name="firstline">
748 <choose>
749 <when test="contains(., ':')">
750 <value-of select="normalize-space(substring-after(., ':'))"/>
751 </when>
752 <otherwise>
753 <value-of select="normalize-space(.)"/>
754 </otherwise>
755 </choose>
756 </variable>
757 <choose>
758 <when test="substring($firstline, string-length($firstline))='\' and $following[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
759 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
760 </when>
761 <otherwise>
762 <value-of select="$firstline"/>
763 </otherwise>
764 </choose>
765 <for-each select="exslset:leading($following, $next)[contains(' &#x9;', substring(., 1, 1))]">
766 <variable name="nextline" select="normalize-space(.)"/>
767 <choose>
768 <when test="substring($nextline, string-length($nextline))='\' and exslset:intersection($fields, following-sibling::*)[position()=1 and contains(' &#x9;', substring(., 1, 1))]">
769 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
770 </when>
771 <otherwise>
772 <value-of select="$nextline"/>
773 </otherwise>
774 </choose>
775 </for-each>
776 </element>
777 </element>
778 </otherwise>
779 </choose>
780 </for-each>
781 </element>
782 </if>
783 <if test="substring-after(., '%%')!=''">
784 <call-template name="LesML:comment-out">
785 <with-param name="source" select="substring-after(., '%%')"/>
786 </call-template>
787 </if>
788 </for-each>
789 </element>
790 </if>
791 <element name="div" namespace="&xhtml;">
792 <attribute name="class">
793 <text>body</text>
794 </attribute>
795 <apply-templates select="$paragraphized-document/node()" mode="LesML:finalize">
796 <with-param name="used-footnotes" select="$used-footnotes"/>
797 </apply-templates>
798 </element>
799 <if test="$used-footnotes">
800 <element name="section" namespace="&xhtml;">
801 <attribute name="role">
802 <text>doc-endnotes</text>
803 </attribute>
804 <element name="ol" namespace="&xhtml;">
805 <apply-templates select="$used-footnotes" mode="LesML:finalize">
806 <with-param name="used-footnotes" select="$used-footnotes"/>
807 </apply-templates>
808 </element>
809 </element>
810 </if>
811 </element>
812 </if>
813 <if test="$docsep">
814 <call-template name="LesML:parse">
815 <with-param name="lines" select="$docsep|exslset:trailing($lines, $docsep)"/>
816 <with-param name="parent-params" select="$params"/>
817 </call-template>
818 </if>
819 </template>
820 <template match="html:script[@type='text/lesml']">
821 <variable name="source">
822 <for-each select=".//text()">
823 <value-of select="."/>
824 </for-each>
825 </variable>
826 <element name="div" namespace="&xhtml;">
827 <call-template name="LesML:parse">
828 <with-param name="lines" select="LesML:split($source)"/>
829 </call-template>
830 </element>
831 </template>
832 <template match="/" mode="LesML:blockify">
833 <variable name="nested-fragment">
834 <apply-templates mode="LesML:nesting-blocks"/>
835 </variable>
836 <variable name="nested-document" select="exsl:node-set($nested-fragment)"/>
837 <apply-templates select="exsl:node-set($nested-fragment)/node()" mode="LesML:inlinify">
838 <with-param name="footnote-ids" select="$nested-document/*/processing-instruction()[local-name()='LesML-Footnote']"/>
839 </apply-templates>
840 </template>
841 <template match="*[&level-pi;]" mode="LesML:nesting-blocks">
842 <variable name="current-level" select="number(&level-pi;)"/>
843 <if test="not(preceding-sibling::*[&level-pi; and $current-level>&level-pi;])">
844 <variable name="notatlevel" select="following-sibling::*[$current-level>=&level-pi;][1]"/>
845 <variable name="contents-fragment">
846 <copy-of select="node()"/>
847 <copy-of select="exslset:leading(following-sibling::*, $notatlevel)"/>
848 </variable>
849 <copy>
850 <copy-of select="@*"/>
851 <apply-templates select="exsl:node-set($contents-fragment)/node()" mode="LesML:nesting-blocks"/>
852 </copy>
853 </if>
854 </template>
855 <template match="node()" mode="LesML:nesting-blocks" priority="-1">
856 <copy>
857 <copy-of select="@*"/>
858 <apply-templates select="node()" mode="LesML:nesting-blocks"/>
859 </copy>
860 </template>
861 <template match="*[&level-pi;]" mode="LesML:inlinify">
862 <param name="footnote-ids" select="/.."/>
863 <copy>
864 <copy-of select="@*"/>
865 <apply-templates mode="LesML:inlinify">
866 <with-param name="footnote-ids" select="$footnote-ids|*/processing-instruction()[local-name()='LesML-Footnote']"/>
867 </apply-templates>
868 </copy>
869 </template>
870 <template match="node()" mode="LesML:inlinify" priority="-1">
871 <param name="footnote-ids" select="/.."/>
872 <apply-templates select="." mode="LesML:comment">
873 <with-param name="footnote-ids" select="$footnote-ids"/>
874 </apply-templates>
875 </template>
876 <template match="node()" mode="LesML:comment">
877 <param name="footnote-ids" select="/.."/>
878 <variable name="result-fragment">
879 <choose>
880 <when test="self::*">
881 <variable name="start-node" select="text()[contains(., '⌦')][1]"/>
882 <variable name="after-start">
883 <if test="$start-node">
884 <value-of select="substring-after($start-node, '⌦')"/>
885 </if>
886 </variable>
887 <variable name="has-end-node" select="contains($after-start, '⌫') or $start-node/following-sibling::text()[contains(., '⌫')]"/>
888 <choose>
889 <when test="$start-node and $has-end-node">
890 <variable name="following">
891 <value-of select="$after-start"/>
892 <copy-of select="$start-node/following-sibling::node()"/>
893 </variable>
894 <variable name="end-node" select="exsl:node-set($following)/text()[contains(., '⌫')][last()]"/>
895 <variable name="comment">
896 <for-each select="$end-node/preceding-sibling::node()">
897 <value-of select="."/>
898 </for-each>
899 <value-of select="substring-before($end-node, '⌫')"/>
900 </variable>
901 <variable name="rest-fragment">
902 <element name="span" namespace="&xhtml;">
903 <value-of select="substring-after($end-node, '⌫')"/>
904 <copy-of select="$end-node/following-sibling::node()"/>
905 </element>
906 </variable>
907 <variable name="commented-rest-fragment">
908 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
909 <with-param name="footnote-ids" select="$footnote-ids"/>
910 </apply-templates>
911 </variable>
912 <copy>
913 <copy-of select="@*"/>
914 <copy-of select="$start-node/preceding-sibling::node()"/>
915 <copy-of select="substring-before($start-node, '⌦')"/>
916 <call-template name="LesML:comment-out">
917 <with-param name="source" select="string($comment)"/>
918 </call-template>
919 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
920 </copy>
921 </when>
922 <when test="$start-node">
923 <variable name="rest-fragment">
924 <element name="div" namespace="&xhtml;">
925 <value-of select="substring-after($after-start, '⌦')"/>
926 <copy-of select="$start-node/following-sibling::node()"/>
927 </element>
928 </variable>
929 <variable name="commented-rest-fragment">
930 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:comment">
931 <with-param name="footnote-ids" select="$footnote-ids"/>
932 </apply-templates>
933 </variable>
934 <copy>
935 <copy-of select="@*"/>
936 <copy-of select="$start-node/preceding-sibling::node()"/>
937 <copy-of select="substring-before($start-node, '⌦')"/>
938 <text>^</text>
939 <copy-of select="exsl:node-set($commented-rest-fragment)/*/node()"/>
940 </copy>
941 </when>
942 <otherwise>
943 <copy>
944 <copy-of select="@*"/>
945 <apply-templates select="node()" mode="LesML:comment">
946 <with-param name="footnote-ids" select="$footnote-ids"/>
947 </apply-templates>
948 </copy>
949 </otherwise>
950 </choose>
951 </when>
952 <when test="self::text()[contains(., '⌧')]">
953 <for-each select="LesML:split(., '⌧')">
954 <value-of select="."/>
955 <if test="position()!=last()">
956 <call-template name="LesML:comment-out"/>
957 </if>
958 </for-each>
959 </when>
960 <otherwise>
961 <copy-of select="."/>
962 </otherwise>
963 </choose>
964 </variable>
965 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:attrify">
966 <with-param name="footnote-ids" select="$footnote-ids"/>
967 </apply-templates>
968 </template>
969 <template match="*" mode="LesML:partition">
970 <param name="start-sigil"/>
971 <param name="end-sigil"/>
972 <param name="separator"/>
973 <param name="ncname-keys" select="false()"/>
974 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
975 <variable name="has-start-node" select="$end-node/preceding-sibling::text()[contains(., $start-sigil)] or string-length(substring-after($end-node, $start-sigil))>string-length(substring-after($end-node, $end-sigil))"/>
976 <choose>
977 <when test="$end-node and $has-start-node">
978 <variable name="preceding-fragment">
979 <copy-of select="$end-node/preceding-sibling::node()"/>
980 <value-of select="substring-before($end-node, $end-sigil)"/>
981 </variable>
982 <variable name="preceding" select="exsl:node-set($preceding-fragment)/node()"/>
983 <variable name="start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()][not($ncname-keys) or not(following-sibling::*[not(self::html:br)] or following-sibling::comment())]"/>
984 <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
985 <variable name="innards-fragment">
986 <value-of select="$start-tokens[last()]"/>
987 <for-each select="$start-node/following-sibling::node()">
988 <choose>
989 <when test="$ncname-keys and self::html:br">
990 <text>&#xA;</text>
991 </when>
992 <otherwise>
993 <copy-of select="."/>
994 </otherwise>
995 </choose>
996 </for-each>
997 </variable>
998 <variable name="innards" select="exsl:node-set($innards-fragment)/node()"/>
999 <variable name="separator-node" select="($innards[self::text() and contains(., $separator)])[not($ncname-keys)*(last()-1)+1]"/>
1000 <choose>
1001 <when test="not($start-node) or $separator-node[following-sibling::* or following-sibling::comment()]">
1002 <variable name="bad-start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()]"/>
1003 <element name="span" namespace="&xhtml;">
1004 <copy-of select="$bad-start-node/preceding-sibling::node()"/>
1005 <for-each select="LesML:split($bad-start-node, $start-sigil)">
1006 <value-of select="."/>
1007 <if test="position()!=last()">
1008 <processing-instruction name="LesML-Token-Escape">
1009 <value-of select="$start-sigil"/>
1010 </processing-instruction>
1011 </if>
1012 </for-each>
1013 <copy-of select="$bad-start-node/following-sibling::node()"/>
1014 <value-of select="$end-sigil"/>
1015 <value-of select="substring-after($end-node, $end-sigil)"/>
1016 <copy-of select="$end-node/following-sibling::node()"/>
1017 </element>
1018 </when>
1019 <when test="$separator-node">
1020 <variable name="keyval" select="LesML:split($separator-node, $separator)"/>
1021 <variable name="key-fragment">
1022 <choose>
1023 <when test="$ncname-keys">
1024 <for-each select="$separator-node/preceding-sibling::node()">
1025 <value-of select="."/>
1026 </for-each>
1027 <value-of select="$keyval[1]"/>
1028 </when>
1029 <otherwise>
1030 <copy-of select="$separator-node/preceding-sibling::node()"/>
1031 <for-each select="$keyval[position()!=last()]">
1032 <value-of select="."/>
1033 <if test="position()!=last()">
1034 <value-of select="$separator"/>
1035 </if>
1036 </for-each>
1037 </otherwise>
1038 </choose>
1039 </variable>
1040 <variable name="value">
1041 <choose>
1042 <when test="$ncname-keys">
1043 <for-each select="$keyval[position()!=1]">
1044 <value-of select="."/>
1045 <if test="position()!=last()">
1046 <value-of select="$separator"/>
1047 </if>
1048 </for-each>
1049 </when>
1050 <otherwise>
1051 <value-of select="$keyval[last()]"/>
1052 </otherwise>
1053 </choose>
1054 <for-each select="$separator-node/following-sibling::node()">
1055 <value-of select="."/>
1056 </for-each>
1057 </variable>
1058 <choose>
1059 <when test="not($ncname-keys) or /self::node()[translate(normalize-space($key-fragment), ' /([,*', '')=$key-fragment and exsldyn:evaluate(concat('not(self::html:', $key-fragment, ')'))]">
1060 <element name="span" namespace="&xhtml;">
1061 <copy-of select="$start-node/preceding-sibling::node()"/>
1062 <for-each select="$start-tokens[position()!=last()]">
1063 <value-of select="."/>
1064 <if test="position()!=last()">
1065 <value-of select="$start-sigil"/>
1066 </if>
1067 </for-each>
1068 </element>
1069 <element name="span" namespace="&xhtml;">
1070 <copy-of select="$key-fragment"/>
1071 </element>
1072 <element name="span" namespace="&xhtml;">
1073 <value-of select="$value"/>
1074 </element>
1075 <element name="span" namespace="&xhtml;">
1076 <value-of select="substring-after($end-node, $end-sigil)"/>
1077 <copy-of select="$end-node/following-sibling::node()"/>
1078 </element>
1079 </when>
1080 <otherwise>
1081 <element name="span" namespace="&xhtml;">
1082 <copy-of select="$start-node/preceding-sibling::node()"/>
1083 <for-each select="$start-tokens[position()!=last()]">
1084 <value-of select="."/>
1085 <if test="position()!=last()">
1086 <value-of select="$start-sigil"/>
1087 </if>
1088 </for-each>
1089 <processing-instruction name="LesML-Token-Escape">
1090 <value-of select="$start-sigil"/>
1091 </processing-instruction>
1092 <value-of select="$start-tokens[last()]"/>
1093 <value-of select="$start-node/following-sibling::node()"/>
1094 <value-of select="$end-sigil"/>
1095 <value-of select="substring-after($end-node, $end-sigil)"/>
1096 <copy-of select="$end-node/following-sibling::node()"/>
1097 </element>
1098 </otherwise>
1099 </choose>
1100 </when>
1101 <otherwise>
1102 <element name="span" namespace="&xhtml;">
1103 <copy-of select="$start-node/preceding-sibling::node()"/>
1104 <for-each select="$start-tokens[position()!=last()]">
1105 <value-of select="."/>
1106 <if test="position()!=last()">
1107 <value-of select="$start-sigil"/>
1108 </if>
1109 </for-each>
1110 <processing-instruction name="LesML-Token-Escape">
1111 <value-of select="$start-sigil"/>
1112 </processing-instruction>
1113 <value-of select="$start-tokens[last()]"/>
1114 <copy-of select="$start-node/following-sibling::node()"/>
1115 <value-of select="$end-sigil"/>
1116 <value-of select="substring-after($end-node, $end-sigil)"/>
1117 <copy-of select="$end-node/following-sibling::node()"/>
1118 </element>
1119 </otherwise>
1120 </choose>
1121 </when>
1122 <when test="$end-node">
1123 <element name="span" namespace="&xhtml;">
1124 <copy-of select="$end-node/preceding-sibling::node()"/>
1125 <value-of select="substring-before($end-node, $end-sigil)"/>
1126 <processing-instruction name="LesML-Token-Escape">
1127 <value-of select="$end-sigil"/>
1128 </processing-instruction>
1129 <value-of select="substring-after($end-node, $end-sigil)"/>
1130 <copy-of select="$end-node/following-sibling::node()"/>
1131 </element>
1132 </when>
1133 <otherwise>
1134 <processing-instruction name="LesML-All-Done"/>
1135 </otherwise>
1136 </choose>
1137 </template>
1138 <template match="node()" mode="LesML:attrify">
1139 <param name="footnote-ids" select="/.."/>
1140 <variable name="result-fragment">
1141 <choose>
1142 <when test="self::*">
1143 <variable name="partitioned-fragment">
1144 <apply-templates mode="LesML:partition" select=".">
1145 <with-param name="start-sigil" select="'{@'"/>
1146 <with-param name="end-sigil" select="'&quot;}'"/>
1147 <with-param name="separator" select="'=&quot;'"/>
1148 <with-param name="ncname-keys" select="true()"/>
1149 </apply-templates>
1150 </variable>
1151 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1152 <choose>
1153 <when test="count($partitioned)>1">
1154 <variable name="processed">
1155 <copy>
1156 <copy-of select="@*"/>
1157 <copy-of select="$partitioned[1]/node()"/>
1158 <element name="LesML:attribute" namespace="&LesML;">
1159 <attribute name="{$partitioned[2]}">
1160 <value-of select="$partitioned[3]"/>
1161 </attribute>
1162 </element>
1163 <copy-of select="$partitioned[4]/node()"/>
1164 </copy>
1165 </variable>
1166 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1167 <with-param name="footnote-ids" select="$footnote-ids"/>
1168 </apply-templates>
1169 </when>
1170 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1171 <copy>
1172 <copy-of select="@*"/>
1173 <apply-templates select="node()" mode="LesML:attrify">
1174 <with-param name="footnote-ids" select="$footnote-ids"/>
1175 </apply-templates>
1176 </copy>
1177 </when>
1178 <otherwise>
1179 <variable name="processed">
1180 <copy>
1181 <copy-of select="@*"/>
1182 <copy-of select="$partitioned/node()"/>
1183 </copy>
1184 </variable>
1185 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:attrify">
1186 <with-param name="footnote-ids" select="$footnote-ids"/>
1187 </apply-templates>
1188 </otherwise>
1189 </choose>
1190 </when>
1191 <otherwise>
1192 <copy-of select="."/>
1193 </otherwise>
1194 </choose>
1195 </variable>
1196 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:linkify">
1197 <with-param name="footnote-ids" select="$footnote-ids"/>
1198 </apply-templates>
1199 </template>
1200 <template match="node()" mode="LesML:linkify">
1201 <param name="footnote-ids" select="/.."/>
1202 <variable name="result-fragment">
1203 <choose>
1204 <when test="processing-instruction()[local-name()='LesML-All-Done']">
1205 <copy>
1206 <copy-of select="@*|node()[not(self::processing-instruction() and local-name()='LesML-All-Done')]"/>
1207 </copy>
1208 </when>
1209 <when test="self::*">
1210 <variable name="partitioned-fragment">
1211 <apply-templates mode="LesML:partition" select=".">
1212 <with-param name="start-sigil" select="'{🔗'"/>
1213 <with-param name="end-sigil" select="'>}'"/>
1214 <with-param name="separator" select="'&lt;'"/>
1215 </apply-templates>
1216 </variable>
1217 <variable name="partitioned" select="exsl:node-set($partitioned-fragment)/node()"/>
1218 <choose>
1219 <when test="count($partitioned)>1">
1220 <variable name="processed">
1221 <copy>
1222 <copy-of select="@*"/>
1223 <copy-of select="$partitioned[1]/node()"/>
1224 <element name="a" namespace="&xhtml;">
1225 <attribute name="href">
1226 <value-of select="$partitioned[3]"/>
1227 </attribute>
1228 <processing-instruction name="LesML-All-Done"/>
1229 <choose>
1230 <when test="not($partitioned[2]/node())">
1231 <value-of select="$partitioned[3]"/>
1232 </when>
1233 <otherwise>
1234 <copy-of select="$partitioned[2]/node()"/>
1235 </otherwise>
1236 </choose>
1237 </element>
1238 <copy-of select="$partitioned[4]/node()"/>
1239 </copy>
1240 </variable>
1241 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1242 <with-param name="footnote-ids" select="$footnote-ids"/>
1243 </apply-templates>
1244 </when>
1245 <when test="$partitioned[self::processing-instruction() and local-name()='LesML-All-Done']">
1246 <copy>
1247 <copy-of select="@*"/>
1248 <apply-templates select="node()" mode="LesML:linkify">
1249 <with-param name="footnote-ids" select="$footnote-ids"/>
1250 </apply-templates>
1251 </copy>
1252 </when>
1253 <otherwise>
1254 <variable name="processed">
1255 <copy>
1256 <copy-of select="@*"/>
1257 <copy-of select="$partitioned/node()"/>
1258 </copy>
1259 </variable>
1260 <apply-templates select="exsl:node-set($processed)/node()" mode="LesML:linkify">
1261 <with-param name="footnote-ids" select="$footnote-ids"/>
1262 </apply-templates>
1263 </otherwise>
1264 </choose>
1265 </when>
1266 <otherwise>
1267 <copy-of select="."/>
1268 </otherwise>
1269 </choose>
1270 </variable>
1271 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:strikethrough">
1272 <with-param name="footnote-ids" select="$footnote-ids"/>
1273 </apply-templates>
1274 </template>
1275 <template match="node()" mode="LesML:inline">
1276 <param name="element-name"/>
1277 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
1278 <param name="start-sigil"/>
1279 <param name="end-sigil"/>
1280 <param name="class"/>
1281 <param name="role"/>
1282 <choose>
1283 <when test="self::*">
1284 <variable name="end-node" select="text()[contains(., $end-sigil)][1]"/>
1285 <variable name="has-start-node" select="$end-node/preceding-sibling::text()[contains(., $start-sigil)] or string-length(substring-after($end-node, $start-sigil))>string-length(substring-after($end-node, $end-sigil))"/>
1286 <choose>
1287 <when test="$end-node and $has-start-node">
1288 <variable name="preceding">
1289 <copy-of select="$end-node/preceding-sibling::node()"/>
1290 <value-of select="substring-before($end-node, $end-sigil)"/>
1291 </variable>
1292 <variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
1293 <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
1294 <variable name="wrapped">
1295 <copy>
1296 <copy-of select="@*"/>
1297 <copy-of select="$start-node/preceding-sibling::node()"/>
1298 <for-each select="$start-tokens[position()!=last()]">
1299 <value-of select="."/>
1300 <if test="position()!=last()">
1301 <value-of select="$start-sigil"/>
1302 </if>
1303 </for-each>
1304 <element name="{$element-name}" namespace="{$element-namespace}">
1305 <if test="string($role)!=''">
1306 <attribute name="role">
1307 <value-of select="$role"/>
1308 </attribute>
1309 </if>
1310 <if test="string($class)!=''">
1311 <attribute name="class">
1312 <value-of select="$class"/>
1313 </attribute>
1314 </if>
1315 <value-of select="$start-tokens[last()]"/>
1316 <copy-of select="$start-node/following-sibling::node()"/>
1317 </element>
1318 <value-of select="substring-after($end-node, $end-sigil)"/>
1319 <copy-of select="$end-node/following-sibling::node()"/>
1320 </copy>
1321 </variable>
1322 <apply-templates select="exsl:node-set($wrapped)/*" mode="LesML:inline">
1323 <with-param name="element-name" select="$element-name"/>
1324 <with-param name="element-namespace" select="$element-namespace"/>
1325 <with-param name="start-sigil" select="$start-sigil"/>
1326 <with-param name="end-sigil" select="$end-sigil"/>
1327 <with-param name="role" select="$role"/>
1328 </apply-templates>
1329 </when>
1330 <otherwise>
1331 <copy>
1332 <copy-of select="@*"/>
1333 <apply-templates select="node()" mode="LesML:inline">
1334 <with-param name="element-name" select="$element-name"/>
1335 <with-param name="element-namespace" select="$element-namespace"/>
1336 <with-param name="start-sigil" select="$start-sigil"/>
1337 <with-param name="end-sigil" select="$end-sigil"/>
1338 <with-param name="role" select="$role"/>
1339 </apply-templates>
1340 </copy>
1341 </otherwise>
1342 </choose>
1343 </when>
1344 <otherwise>
1345 <copy-of select="."/>
1346 </otherwise>
1347 </choose>
1348 </template>
1349 <template match="node()" mode="LesML:strikethrough">
1350 <param name="footnote-ids" select="/.."/>
1351 <variable name="result-fragment">
1352 <apply-templates select="." mode="LesML:inline">
1353 <with-param name="element-name" select="'s'"/>
1354 <with-param name="element-namespace" select="'&xhtml;'"/>
1355 <with-param name="start-sigil" select="'⸠'"/>
1356 <with-param name="end-sigil" select="'⸡'"/>
1357 </apply-templates>
1358 </variable>
1359 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:underline">
1360 <with-param name="footnote-ids" select="$footnote-ids"/>
1361 </apply-templates>
1362 </template>
1363 <template match="node()" mode="LesML:underline">
1364 <param name="footnote-ids" select="/.."/>
1365 <variable name="result-fragment">
1366 <apply-templates select="." mode="LesML:inline">
1367 <with-param name="element-name" select="'u'"/>
1368 <with-param name="element-namespace" select="'&xhtml;'"/>
1369 <with-param name="start-sigil" select="'⸤'"/>
1370 <with-param name="end-sigil" select="'⸥'"/>
1371 </apply-templates>
1372 </variable>
1373 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:noted">
1374 <with-param name="footnote-ids" select="$footnote-ids"/>
1375 </apply-templates>
1376 </template>
1377 <template match="node()" mode="LesML:noted">
1378 <param name="footnote-ids" select="/.."/>
1379 <variable name="result-fragment">
1380 <apply-templates select="." mode="LesML:inline">
1381 <with-param name="element-name" select="'small'"/>
1382 <with-param name="element-namespace" select="'&xhtml;'"/>
1383 <with-param name="start-sigil" select="'⟦'"/>
1384 <with-param name="end-sigil" select="'⟧'"/>
1385 <with-param name="role" select="'note'"/>
1386 </apply-templates>
1387 </variable>
1388 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:parenthetical">
1389 <with-param name="footnote-ids" select="$footnote-ids"/>
1390 </apply-templates>
1391 </template>
1392 <template match="node()" mode="LesML:parenthetical">
1393 <param name="footnote-ids" select="/.."/>
1394 <variable name="result-fragment">
1395 <apply-templates select="." mode="LesML:inline">
1396 <with-param name="element-name" select="'small'"/>
1397 <with-param name="element-namespace" select="'&xhtml;'"/>
1398 <with-param name="start-sigil" select="'⸨'"/>
1399 <with-param name="end-sigil" select="'⸩'"/>
1400 </apply-templates>
1401 </variable>
1402 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:code">
1403 <with-param name="footnote-ids" select="$footnote-ids"/>
1404 </apply-templates>
1405 </template>
1406 <template match="node()" mode="LesML:code">
1407 <param name="footnote-ids" select="/.."/>
1408 <variable name="result-fragment">
1409 <apply-templates select="." mode="LesML:inline">
1410 <with-param name="element-name" select="'code'"/>
1411 <with-param name="element-namespace" select="'&xhtml;'"/>
1412 <with-param name="start-sigil" select="'`'"/>
1413 <with-param name="end-sigil" select="'´'"/>
1414 </apply-templates>
1415 </variable>
1416 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:titled">
1417 <with-param name="footnote-ids" select="$footnote-ids"/>
1418 </apply-templates>
1419 </template>
1420 <template match="node()" mode="LesML:titled">
1421 <param name="footnote-ids" select="/.."/>
1422 <variable name="result-fragment">
1423 <apply-templates select="." mode="LesML:inline">
1424 <with-param name="element-name" select="'cite'"/>
1425 <with-param name="element-namespace" select="'&xhtml;'"/>
1426 <with-param name="start-sigil" select="'⟪'"/>
1427 <with-param name="end-sigil" select="'⟫'"/>
1428 </apply-templates>
1429 </variable>
1430 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:named">
1431 <with-param name="footnote-ids" select="$footnote-ids"/>
1432 </apply-templates>
1433 </template>
1434 <template match="node()" mode="LesML:named">
1435 <param name="footnote-ids" select="/.."/>
1436 <variable name="result-fragment">
1437 <apply-templates select="." mode="LesML:inline">
1438 <with-param name="element-name" select="'u'"/>
1439 <with-param name="element-namespace" select="'&xhtml;'"/>
1440 <with-param name="start-sigil" select="'⸶'"/>
1441 <with-param name="end-sigil" select="'⸷'"/>
1442 <with-param name="class" select="'name'"/>
1443 </apply-templates>
1444 </variable>
1445 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:offset">
1446 <with-param name="footnote-ids" select="$footnote-ids"/>
1447 </apply-templates>
1448 </template>
1449 <template match="node()" mode="LesML:offset">
1450 <param name="footnote-ids" select="/.."/>
1451 <variable name="result-fragment">
1452 <apply-templates select="." mode="LesML:inline">
1453 <with-param name="element-name" select="'i'"/>
1454 <with-param name="element-namespace" select="'&xhtml;'"/>
1455 <with-param name="start-sigil" select="'⟨'"/>
1456 <with-param name="end-sigil" select="'⟩'"/>
1457 </apply-templates>
1458 </variable>
1459 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:bolded">
1460 <with-param name="footnote-ids" select="$footnote-ids"/>
1461 </apply-templates>
1462 </template>
1463 <template match="node()" mode="LesML:bolded">
1464 <param name="footnote-ids" select="/.."/>
1465 <variable name="result-fragment">
1466 <apply-templates select="." mode="LesML:inline">
1467 <with-param name="element-name" select="'b'"/>
1468 <with-param name="element-namespace" select="'&xhtml;'"/>
1469 <with-param name="start-sigil" select="'⦃'"/>
1470 <with-param name="end-sigil" select="'⦄'"/>
1471 </apply-templates>
1472 </variable>
1473 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:important">
1474 <with-param name="footnote-ids" select="$footnote-ids"/>
1475 </apply-templates>
1476 </template>
1477 <template match="node()" mode="LesML:important">
1478 <param name="footnote-ids" select="/.."/>
1479 <variable name="result-fragment">
1480 <apply-templates select="." mode="LesML:inline">
1481 <with-param name="element-name" select="'strong'"/>
1482 <with-param name="element-namespace" select="'&xhtml;'"/>
1483 <with-param name="start-sigil" select="'☞'"/>
1484 <with-param name="end-sigil" select="'☜'"/>
1485 </apply-templates>
1486 </variable>
1487 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:emphasized">
1488 <with-param name="footnote-ids" select="$footnote-ids"/>
1489 </apply-templates>
1490 </template>
1491 <template match="node()" mode="LesML:emphasized">
1492 <param name="footnote-ids" select="/.."/>
1493 <variable name="result-fragment">
1494 <apply-templates select="." mode="LesML:inline">
1495 <with-param name="element-name" select="'em'"/>
1496 <with-param name="element-namespace" select="'&xhtml;'"/>
1497 <with-param name="start-sigil" select="'⹐'"/>
1498 <with-param name="end-sigil" select="'⹑'"/>
1499 </apply-templates>
1500 </variable>
1501 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:footnoted">
1502 <with-param name="footnote-ids" select="$footnote-ids"/>
1503 </apply-templates>
1504 </template>
1505 <template match="node()" mode="LesML:footnoted">
1506 <param name="footnote-ids" select="/.."/>
1507 <variable name="result-fragment">
1508 <choose>
1509 <when test="self::*">
1510 <variable name="start-node" select="text()[contains(., '[^')][1]"/>
1511 <variable name="after-start" select="substring-after($start-node, '[^')"/>
1512 <variable name="footnote-id" select="substring-before($after-start, ']')"/>
1513 <variable name="matched-footnote" select="$footnote-ids[.=$footnote-id]"/>
1514 <choose>
1515 <when test="$footnote-id!='' and $matched-footnote">
1516 <variable name="rest-fragment">
1517 <element name="div" namespace="&xhtml;">
1518 <value-of select="substring-after($after-start, ']')"/>
1519 <copy-of select="$start-node/following-sibling::node()"/>
1520 </element>
1521 </variable>
1522 <variable name="footnoted-rest-fragment">
1523 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1524 <with-param name="footnote-ids" select="$footnote-ids"/>
1525 </apply-templates>
1526 </variable>
1527 <copy>
1528 <copy-of select="@*"/>
1529 <copy-of select="$start-node/preceding-sibling::node()"/>
1530 <copy-of select="substring-before($start-node, '[^')"/>
1531 <element name="a" namespace="&xhtml;">
1532 <attribute name="id">
1533 <text>LesML.fnref.</text>
1534 <value-of select="generate-id($start-node)"/>
1535 </attribute>
1536 <attribute name="role">
1537 <text>doc-noteref</text>
1538 </attribute>
1539 <attribute name="href">
1540 <text>#</text>
1541 <value-of select="$footnote-id"/>
1542 </attribute>
1543 <attribute name="target">
1544 <text>_self</text>
1545 </attribute>
1546 </element>
1547 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1548 </copy>
1549 </when>
1550 <when test="$start-node">
1551 <variable name="rest-fragment">
1552 <element name="div" namespace="&xhtml;">
1553 <value-of select="substring-after($start-node, '[^')"/>
1554 <copy-of select="$start-node/following-sibling::node()"/>
1555 </element>
1556 </variable>
1557 <variable name="footnoted-rest-fragment">
1558 <apply-templates select="exsl:node-set($rest-fragment)/node()" mode="LesML:footnoted">
1559 <with-param name="footnote-ids" select="$footnote-ids"/>
1560 </apply-templates>
1561 </variable>
1562 <copy>
1563 <copy-of select="@*"/>
1564 <copy-of select="$start-node/preceding-sibling::node()"/>
1565 <copy-of select="substring-before($start-node, '[^')"/>
1566 <text>[^</text>
1567 <copy-of select="exsl:node-set($footnoted-rest-fragment)/*/node()"/>
1568 </copy>
1569 </when>
1570 <otherwise>
1571 <copy>
1572 <copy-of select="@*"/>
1573 <apply-templates select="node()" mode="LesML:footnoted">
1574 <with-param name="footnote-ids" select="$footnote-ids"/>
1575 </apply-templates>
1576 </copy>
1577 </otherwise>
1578 </choose>
1579 </when>
1580 <otherwise>
1581 <copy-of select="."/>
1582 </otherwise>
1583 </choose>
1584 </variable>
1585 <apply-templates select="exsl:node-set($result-fragment)/node()" mode="LesML:finish"/>
1586 </template>
1587 <template match="processing-instruction()[local-name()='LesML-All-Done']" mode="LesML:finish"/>
1588 <template match="processing-instruction()[local-name()='LesML-Token-Escape']" mode="LesML:finish">
1589 <value-of select="."/>
1590 </template>
1591 <template match="@*|node()" mode="LesML:finish" priority="-1">
1592 <copy>
1593 <apply-templates select="@*|node()" mode="LesML:finish"/>
1594 </copy>
1595 </template>
1596
1597 <!-->
1598 ❦ Templates in the `LesML:finalize´ and related modes
1599
1600 These templates finalize the resulting tree.
1601 </!-->
1602
1603 <template match="node()" mode="LesML:finalize-attributes">
1604 <param name="exclude-level" select="false()"/>
1605 <variable name="notattr" select="following-sibling::node()[not(self::LesML:attribute)]"/>
1606 <variable name="div" select="self::html:div|self::*[&block-types;]/node()[not(self::processing-instruction())][position()=1 and self::html:div]"/>
1607 <variable name="para" select="self::html:p|$div/node()[not(self::processing-instruction())][position()=1 and self::html:p]"/>
1608 <variable name="emptypara" select="$para[not(@*|node()[not(self::processing-instruction())])]"/>
1609 <for-each select="(.|$emptypara/..|exslset:leading(following-sibling::node(), $notattr)[self::LesML:attribute])/@*">
1610 <copy-of select="."/>
1611 <if test="local-name()='lang' and namespace-uri()=''">
1612 <attribute name="xml:lang">
1613 <value-of select="."/>
1614 </attribute>
1615 </if>
1616 </for-each>
1617 <if test="not($exclude-level) and &level-pi;!=0">
1618 <attribute name="data-level">
1619 <value-of select="&level-pi;"/>
1620 </attribute>
1621 </if>
1622 </template>
1623 <template match="html:li" mode="LesML:finalize-list">
1624 <param name="used-footnotes" select="/.."/>
1625 <variable name="current-class" select="string(@class)"/>
1626 <variable name="current-level" select="number(&level-pi;)"/>
1627 <variable name="wrapper">
1628 <choose>
1629 <when test="contains(concat(' ', @class, ' '), ' ordered ')">
1630 <text>ol</text>
1631 </when>
1632 <otherwise>
1633 <text>ul</text>
1634 </otherwise>
1635 </choose>
1636 </variable>
1637 <variable name="notinlist" select="following-sibling::node()[not(self::html:li and &level-pi;=$current-level and @class=$current-class)][1]"/>
1638 <element name="{$wrapper}" namespace="&xhtml;">
1639 <for-each select=".|exslset:leading(following-sibling::node(), $notinlist)">
1640 <copy>
1641 <apply-templates select="." mode="LesML:finalize-attributes"/>
1642 <apply-templates select="node()" mode="LesML:finalize">
1643 <with-param name="used-footnotes" select="$used-footnotes"/>
1644 </apply-templates>
1645 </copy>
1646 </for-each>
1647 </element>
1648 <if test="$notinlist/self::html:li">
1649 <apply-templates select="$notinlist" mode="LesML:finalize-list">
1650 <with-param name="used-footnotes" select="$used-footnotes"/>
1651 </apply-templates>
1652 </if>
1653 </template>
1654 <template match="*[processing-instruction()[local-name()='LesML-Footnote']]|html:div/node()[not(self::processing-instruction())][position()=1 and self::html:p and not(@*|node())]|LesML:attribute[preceding-sibling::node()[position()=1 and (self::text() or self::*)]]|processing-instruction()" mode="LesML:finalize" priority="2"/>
1655 <template match="html:div[not((node()[not(self::processing-instruction())])/following-sibling::node()[not(self::processing-instruction())])]" mode="LesML:finalize" priority="1">
1656 <param name="used-footnotes" select="/.."/>
1657 <variable name="context" select="."/>
1658 <variable name="result-fragment">
1659 <apply-templates select="node()" mode="LesML:finalize">
1660 <with-param name="used-footnotes" select="$used-footnotes"/>
1661 </apply-templates>
1662 </variable>
1663 <variable name="result" select="exsl:node-set($result-fragment)/node()"/>
1664 <choose>
1665 <when test="not(../&level-pi;) and &level-pi;!=0 or ../&level-pi; and &level-pi;-1!=../&level-pi;">
1666 <copy>
1667 <apply-templates select="$context" mode="LesML:finalize-attributes"/>
1668 <copy-of select="$result"/>
1669 </copy>
1670 </when>
1671 <when test="$result">
1672 <for-each select="$result">
1673 <copy>
1674 <apply-templates select="$context" mode="LesML:finalize-attributes">
1675 <with-param name="exclude-level" select="true()"/>
1676 </apply-templates>
1677 <copy-of select="@*|node()"/>
1678 </copy>
1679 </for-each>
1680 </when>
1681 <when test="* and (preceding-sibling::node()[not(self::processing-instruction())] or not(ancestor::*))">
1682 <for-each select="*">
1683 <copy>
1684 <apply-templates select="$context" mode="LesML:finalize-attributes">
1685 <with-param name="exclude-level" select="true()"/>
1686 </apply-templates>
1687 <copy-of select="@*|node()"/>
1688 </copy>
1689 </for-each>
1690 </when>
1691 <otherwise/>
1692 </choose>
1693 </template>
1694 <template match="LesML:attribute|text()[following-sibling::node()[position()=1 and self::LesML:attribute]]" mode="LesML:finalize" priority="1">
1695 <element name="span" namespace="&xhtml;">
1696 <apply-templates select="." mode="LesML:finalize-attributes"/>
1697 <if test="self::text()">
1698 <copy/>
1699 </if>
1700 </element>
1701 </template>
1702 <template match="html:blockquote[node()[position()=last() and self::html:footer]]" mode="LesML:finalize">
1703 <param name="used-footnotes" select="/.."/>
1704 <element name="figure" namespace="&xhtml;">
1705 <copy>
1706 <apply-templates select="." mode="LesML:finalize-attributes"/>
1707 <apply-templates select="node()[position()!=last()]" mode="LesML:finalize">
1708 <with-param name="used-footnotes" select="$used-footnotes"/>
1709 </apply-templates>
1710 </copy>
1711 <for-each select="node()[last()]">
1712 <element name="figcaption" namespace="&xhtml;">
1713 <apply-templates select="." mode="LesML:finalize-attributes">
1714 <with-param name="exclude-level" select="true()"/>
1715 </apply-templates>
1716 <apply-templates select="node()" mode="LesML:finalize">
1717 <with-param name="used-footnotes" select="$used-footnotes"/>
1718 </apply-templates>
1719 </element>
1720 </for-each>
1721 </element>
1722 </template>
1723 <template match="html:div[(self::*|html:div)[html:h1 or html:h2 or html:h3 or html:h4 or html:h5 or html:h6]]" mode="LesML:finalize">
1724 <param name="used-footnotes" select="/.."/>
1725 <element name="hgroup" namespace="&xhtml;">
1726 <apply-templates select="." mode="LesML:finalize-attributes"/>
1727 <apply-templates select="node()" mode="LesML:finalize">
1728 <with-param name="used-footnotes" select="$used-footnotes"/>
1729 </apply-templates>
1730 </element>
1731 </template>
1732 <template match="html:li" mode="LesML:finalize">
1733 <param name="used-footnotes" select="/.."/>
1734 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:li)]">
1735 <apply-templates select="." mode="LesML:finalize-list">
1736 <with-param name="used-footnotes" select="$used-footnotes"/>
1737 </apply-templates>
1738 </if>
1739 </template>
1740 <template match="html:pre" mode="LesML:finalize">
1741 <param name="used-footnotes" select="/.."/>
1742 <copy>
1743 <apply-templates select="." mode="LesML:finalize-attributes"/>
1744 <choose>
1745 <when test="@class='code'">
1746 <element name="code" namespace="&xhtml;">
1747 <apply-templates select="node()" mode="LesML:finalize">
1748 <with-param name="used-footnotes" select="$used-footnotes"/>
1749 </apply-templates>
1750 </element>
1751 </when>
1752 <otherwise>
1753 <apply-templates select="node()" mode="LesML:finalize">
1754 <with-param name="used-footnotes" select="$used-footnotes"/>
1755 </apply-templates>
1756 </otherwise>
1757 </choose>
1758 </copy>
1759 </template>
1760 <template match="html:a[@role='doc-noteref']" mode="LesML:finalize">
1761 <param name="used-footnotes" select="/.."/>
1762 <variable name="matching-note" select="$used-footnotes[concat('#', @id)=current()/@href]"/>
1763 <copy>
1764 <apply-templates select="." mode="LesML:finalize-attributes"/>
1765 <choose>
1766 <when test="$matching-note">
1767 <value-of select="$matching-note/@value"/>
1768 </when>
1769 <otherwise>
1770 <apply-templates select="node()" mode="LesML:finalize">
1771 <with-param name="used-footnotes" select="$used-footnotes"/>
1772 </apply-templates>
1773 </otherwise>
1774 </choose>
1775 </copy>
1776 </template>
1777 <template match="text()" mode="LesML:finalize">
1778 <call-template name="LesML:unescape">
1779 <with-param name="source" select="string()"/>
1780 </call-template>
1781 </template>
1782 <template match="node()" mode="LesML:finalize" priority="-1">
1783 <param name="used-footnotes" select="/.."/>
1784 <copy>
1785 <apply-templates select="." mode="LesML:finalize-attributes"/>
1786 <apply-templates select="node()" mode="LesML:finalize">
1787 <with-param name="used-footnotes" select="$used-footnotes"/>
1788 </apply-templates>
1789 </copy>
1790 </template>
1791 </transform>
This page took 0.505143 seconds and 3 git commands to generate.