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