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