]> Lady’s Gitweb - LesML/blob - parser.xslt
Support language tag and profile
[LesML] / parser.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024 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 Lady [@ Lady’s 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 section-break '#*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'>
16 ]>
17 <transform
18 xmlns="http://www.w3.org/1999/XSL/Transform"
19 xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
20 xmlns:exsl="http://exslt.org/common"
21 xmlns:exslstr="http://exslt.org/strings"
22 xmlns:html="http://www.w3.org/1999/xhtml"
23 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
24 exclude-result-prefixes="LesML"
25 extension-element-prefixes="exsl exslstr"
26 version="1.0"
27 >
28 <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
29 <template name="LesML:split">
30 <param name="source"/>
31 <param name="separator" select="'&#xA;'"/>
32 <choose>
33 <when test="contains($source, $separator)">
34 <html:span>
35 <value-of select="substring-before($source, $separator)"/>
36 </html:span>
37 <call-template name="LesML:split">
38 <with-param name="source" select="substring-after($source, $separator)"/>
39 <with-param name="separator" select="$separator"/>
40 </call-template>
41 </when>
42 <otherwise>
43 <html:span>
44 <value-of select="$source"/>
45 </html:span>
46 </otherwise>
47 </choose>
48 </template>
49 <template name="LesML:unescape">
50 <param name="source"/>
51 <choose>
52 <when test="contains($source, '&lt;U+')">
53 <variable name="after" select="substring-after($source, '&lt;U+')"/>
54 <choose>
55 <when test="contains($after, '>')">
56 <variable name="inner" select="substring-before($after, '>')"/>
57 <variable name="components">
58 <call-template name="LesML:split">
59 <with-param name="source" select="$inner"/>
60 <with-param name="separator" select="'.'"/>
61 </call-template>
62 </variable>
63 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
64 <choose>
65 <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
66 <value-of select="substring-before($source, '&lt;U+')"/>
67 <text>&lt;U+</text>
68 <value-of select="$inner"/>
69 <text>></text>
70 <call-template name="LesML:unescape">
71 <with-param name="source" select="substring-after($after, '>')"/>
72 </call-template>
73 </when>
74 <otherwise>
75 <for-each select="$component-nodes">
76 <text disable-output-escaping="yes">&amp;#x</text>
77 <value-of select="."/>
78 <text>;</text>
79 </for-each>
80 <call-template name="LesML:unescape">
81 <with-param name="source" select="substring-after($after, '>')"/>
82 </call-template>
83 </otherwise>
84 </choose>
85 </when>
86 <otherwise>
87 <value-of select="substring-before($source, '&lt;U+')"/>
88 <text>&lt;U+</text>
89 <call-template name="LesML:unescape">
90 <with-param name="source" select="$after"/>
91 </call-template>
92 </otherwise>
93 </choose>
94 </when>
95 <otherwise>
96 <value-of select="$source"/>
97 </otherwise>
98 </choose>
99 </template>
100 <template name="LesML:id-and-contents">
101 <param name="source"/>
102 <choose>
103 <when test="starts-with($source, '¶')">
104 <choose>
105 <when test="contains($source, ' ')">
106 <attribute name="id">
107 <value-of select="substring-before(substring-after($source, '¶'), ' ')"/>
108 </attribute>
109 <value-of select="substring-after($source, ' ')"/>
110 </when>
111 <otherwise>
112 <attribute name="id">
113 <value-of select="substring-after($source, '¶')"/>
114 </attribute>
115 </otherwise>
116 </choose>
117 </when>
118 <otherwise>
119 <value-of select="$source"/>
120 </otherwise>
121 </choose>
122 </template>
123 <template name="LesML:parse">
124 <param name="source"/>
125 <param name="parent-params" select="/.."/>
126 <variable name="shebang">
127 <if test="starts-with($source, '#!lesml')">
128 <value-of select="substring-before($source, '&#xA;')"/>
129 </if>
130 </variable>
131 <variable name="noshebang">
132 <text>&#xA;</text>
133 <choose>
134 <when test="starts-with($source, '#!')">
135 <value-of select="substring-after($source, '&#xA;')"/>
136 </when>
137 <otherwise>
138 <value-of select="$source"/>
139 </otherwise>
140 </choose>
141 </variable>
142 <variable name="params-string">
143 <choose>
144 <when test="starts-with($shebang, '#!lesml@')">
145 <value-of select="substring-after($shebang, '$')"/>
146 </when>
147 <otherwise>
148 <value-of select="substring-after($shebang, '#!lesml')"/>
149 </otherwise>
150 </choose>
151 </variable>
152 <variable name="params-fragment">
153 <html:dl>
154 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
155 <html:div>
156 <html:dt>
157 <text> LANG </text>
158 </html:dt>
159 <html:dd>
160 <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
161 </html:dd>
162 </html:div>
163 </if>
164 <for-each select="exslstr:tokenize($params-string)">
165 <choose>
166 <when test="contains(., '=')">
167 <html:div>
168 <html:dt>
169 <value-of select="substring-before(., '=')"/>
170 </html:dt>
171 <html:dd>
172 <value-of select="substring-after(., '=')"/>
173 </html:dd>
174 </html:div>
175 </when>
176 <otherwise>
177 <html:div>
178 <html:dt>
179 <value-of select="."/>
180 </html:dt>
181 <html:dd/>
182 </html:div>
183 </otherwise>
184 </choose>
185 </for-each>
186 </html:dl>
187 </variable>
188 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
189 <variable name="records">
190 <call-template name="LesML:split">
191 <with-param name="source" select="$noshebang"/>
192 <with-param name="separator" select="'&#xA;%%'"/>
193 </call-template>
194 </variable>
195 <variable name="record-nodes" select="exsl:node-set($records)/*"/>
196 <html:article>
197 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
198 <attribute name="lang">
199 <value-of select="following-sibling::html:dd"/>
200 </attribute>
201 <attribute name="xml:lang">
202 <value-of select="following-sibling::html:dd"/>
203 </attribute>
204 </for-each>
205 <for-each select="$params/html:div/html:dt[string()='profile']">
206 <attribute name="data-lesml-profile">
207 <value-of select="following-sibling::html:dd"/>
208 </attribute>
209 </for-each>
210 <if test="count($record-nodes)>1">
211 <html:footer class="head">
212 <for-each select="$record-nodes[not(position()=last() or normalize-space(.)='')]">
213 <variable name="fields" select="exslstr:tokenize(., '&#xA;')"/>
214 <html:dl>
215 <for-each select="$fields">
216 <choose>
217 <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
218 <otherwise>
219 <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
220 <html:div>
221 <html:dt>
222 <value-of select="normalize-space(substring-before(., ':'))"/>
223 </html:dt>
224 <html:dd>
225 <variable name="firstline">
226 <choose>
227 <when test="contains(., ':')">
228 <value-of select="normalize-space(substring-after(., ':'))"/>
229 </when>
230 <otherwise>
231 <value-of select="normalize-space(.)"/>
232 </otherwise>
233 </choose>
234 </variable>
235 <choose>
236 <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
237 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
238 </when>
239 <otherwise>
240 <value-of select="$firstline"/>
241 </otherwise>
242 </choose>
243 <for-each select="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
244 <variable name="nextline" select="normalize-space(.)"/>
245 <choose>
246 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
247 <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
248 </when>
249 <otherwise>
250 <value-of select="$nextline"/>
251 </otherwise>
252 </choose>
253 </for-each>
254 </html:dd>
255 </html:div>
256 </otherwise>
257 </choose>
258 </for-each>
259 </html:dl>
260 </for-each>
261 </html:footer>
262 </if>
263 <html:div class="body">
264 <call-template name="LesML:paragraphize">
265 <with-param name="source" select="string($record-nodes[last()])"/>
266 </call-template>
267 </html:div>
268 </html:article>
269 </template>
270 <template name="LesML:paragraphize">
271 <param name="source"/>
272 <variable name="paragraphs">
273 <call-template name="LesML:split">
274 <with-param name="source" select="$source"/>
275 <with-param name="separator" select="'&#xA;&#xA;'"/>
276 </call-template>
277 </variable>
278 <variable name="blocked">
279 <for-each select="exsl:node-set($paragraphs)/*">
280 <variable name="lines">
281 <call-template name="LesML:split">
282 <with-param name="source" select="string()"/>
283 </call-template>
284 </variable>
285 <variable name="linespans" select="exsl:node-set($lines)/*"/>
286 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '&#x9;'))])"/>
287 <variable name="text">
288 <for-each select="$linespans">
289 <if test="normalize-space()!=''">
290 <value-of select="normalize-space()"/>
291 <if test="following-sibling::*[normalize-space()!='']">
292 <text> </text>
293 </if>
294 </if>
295 </for-each>
296 </variable>
297 <if test="string($text)!=''">
298 <variable name="par">
299 <choose>
300 <when test="starts-with($text, '⁌ ')">
301 <html:h1>
302 <call-template name="LesML:id-and-contents">
303 <with-param name="source" select="substring-after($text, '⁌ ')"/>
304 </call-template>
305 </html:h1>
306 </when>
307 <when test="starts-with($text, '§ ')">
308 <html:h2>
309 <call-template name="LesML:id-and-contents">
310 <with-param name="source" select="substring-after($text, '§ ')"/>
311 </call-template>
312 </html:h2>
313 </when>
314 <when test="starts-with($text, '❦ ')">
315 <html:h3>
316 <call-template name="LesML:id-and-contents">
317 <with-param name="source" select="substring-after($text, '❦ ')"/>
318 </call-template>
319 </html:h3>
320 </when>
321 <when test="starts-with($text, '✠ ')">
322 <html:h4>
323 <call-template name="LesML:id-and-contents">
324 <with-param name="source" select="substring-after($text, '✠ ')"/>
325 </call-template>
326 </html:h4>
327 </when>
328 <when test="starts-with($text, '• ')">
329 <html:li class="unordered" data-level="1">
330 <html:p>
331 <call-template name="LesML:id-and-contents">
332 <with-param name="source" select="substring-after($text, '• ')"/>
333 </call-template>
334 </html:p>
335 </html:li>
336 </when>
337 <when test="starts-with($text, '🔢 ')">
338 <html:li class="ordered" data-level="1">
339 <html:p>
340 <call-template name="LesML:id-and-contents">
341 <with-param name="source" select="substring-after($text, '🔢 ')"/>
342 </call-template>
343 </html:p>
344 </html:li>
345 </when>
346 <when test="starts-with($text, '◦ ')">
347 <html:li class="unordered" data-level="2">
348 <html:p>
349 <call-template name="LesML:id-and-contents">
350 <with-param name="source" select="substring-after($text, '◦ ')"/>
351 </call-template>
352 </html:p>
353 </html:li>
354 </when>
355 <when test="starts-with($text, '🔠 ')">
356 <html:li class="ordered" data-level="2">
357 <html:p>
358 <call-template name="LesML:id-and-contents">
359 <with-param name="source" select="substring-after($text, '🔠 ')"/>
360 </call-template>
361 </html:p>
362 </html:li>
363 </when>
364 <when test="starts-with($text, '▪ ')">
365 <html:li class="unordered" data-level="3">
366 <html:p>
367 <call-template name="LesML:id-and-contents">
368 <with-param name="source" select="substring-after($text, '▪ ')"/>
369 </call-template>
370 </html:p>
371 </html:li>
372 </when>
373 <when test="starts-with($text, '🔡 ')">
374 <html:li class="ordered" data-level="3">
375 <html:p>
376 <call-template name="LesML:id-and-contents">
377 <with-param name="source" select="substring-after($text, '🔡 ')"/>
378 </call-template>
379 </html:p>
380 </html:li>
381 </when>
382 <when test="starts-with($text, '⁃ ')">
383 <html:li class="unordered" data-level="4">
384 <html:p>
385 <call-template name="LesML:id-and-contents">
386 <with-param name="source" select="substring-after($text, '⁃ ')"/>
387 </call-template>
388 </html:p>
389 </html:li>
390 </when>
391 <when test="starts-with($text, '🔣 ')">
392 <html:li class="ordered" data-level="4">
393 <html:p>
394 <call-template name="LesML:id-and-contents">
395 <with-param name="source" select="substring-after($text, '🔣 ')"/>
396 </call-template>
397 </html:p>
398 </html:li>
399 </when>
400 <when test="starts-with($text, '🛈 ')">
401 <html:div role="note" class="info">
402 <html:p>
403 <call-template name="LesML:id-and-contents">
404 <with-param name="source" select="substring-after($text, '🛈 ')"/>
405 </call-template>
406 </html:p>
407 </html:div>
408 </when>
409 <when test="starts-with($text, '⯑ ')">
410 <html:div role="note" class="query">
411 <html:p>
412 <call-template name="LesML:id-and-contents">
413 <with-param name="source" select="substring-after($text, '⯑ ')"/>
414 </call-template>
415 </html:p>
416 </html:div>
417 </when>
418 <when test="starts-with($text, '⚠︎ ')">
419 <html:div role="note" class="warn">
420 <html:p>
421 <call-template name="LesML:id-and-contents">
422 <with-param name="source" select="substring-after($text, '⚠︎ ')"/>
423 </call-template>
424 </html:p>
425 </html:div>
426 </when>
427 <when test="starts-with($text, '※ ')">
428 <html:div role="note" class="note">
429 <html:p>
430 <call-template name="LesML:id-and-contents">
431 <with-param name="source" select="substring-after($text, '※ ')"/>
432 </call-template>
433 </html:p>
434 </html:div>
435 </when>
436 <when test="starts-with($text, '☡ ')">
437 <html:div role="note" class="caution">
438 <html:p>
439 <call-template name="LesML:id-and-contents">
440 <with-param name="source" select="substring-after($text, '☡ ')"/>
441 </call-template>
442 </html:p>
443 </html:div>
444 </when>
445 <when test="starts-with($text, '⋯ ')">
446 <html:div class="continuation">
447 <html:p>
448 <call-template name="LesML:id-and-contents">
449 <with-param name="source" select="substring-after($text, '⋯ ')"/>
450 </call-template>
451 </html:p>
452 </html:div>
453 </when>
454 <otherwise>
455 <html:p>
456 <call-template name="LesML:id-and-contents">
457 <with-param name="source" select="$text"/>
458 </call-template>
459 </html:p>
460 </otherwise>
461 </choose>
462 </variable>
463 <choose>
464 <when test="translate(string($text), '&section-break; ', '')=''">
465 <html:hr/>
466 </when>
467 <when test="$quoted">
468 <html:blockquote>
469 <copy-of select="$par"/>
470 </html:blockquote>
471 </when>
472 <otherwise>
473 <copy-of select="$par"/>
474 </otherwise>
475 </choose>
476 </if>
477 </for-each>
478 </variable>
479 <variable name="inlined">
480 <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
481 </variable>
482 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
483 </template>
484 <template match="html:script[@type='text/lesml']">
485 <variable name="source">
486 <for-each select=".//text()">
487 <value-of select="."/>
488 </for-each>
489 </variable>
490 <call-template name="LesML:parse">
491 <with-param name="source" select="string($source)"/>
492 </call-template>
493 </template>
494 <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
495 <copy>
496 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
497 </copy>
498 </template>
499 <template match="text()" mode="LesML:finalize-tree">
500 <call-template name="LesML:unescape">
501 <with-param name="source" select="string(.)"/>
502 </call-template>
503 </template>
504 <template match="html:blockquote" mode="LesML:finalize-tree">
505 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
506 <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
507 <variable name="contents">
508 <copy-of select="node()"/>
509 <for-each select="following-sibling::node()[not($notquote) or following-sibling::node()[generate-id()=generate-id($notquote)]]">
510 <copy-of select="node()"/>
511 </for-each>
512 </variable>
513 <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
514 <variable name="laststarttext" select="$content-nodes[last()]/self::html:p[not(@class) and not(@role)]/node()[self::text() or self::*][position()=1 and self::text()]"/>
515 <choose>
516 <when test="starts-with($laststarttext, '— ')">
517 <variable name="caption">
518 <copy-of select="$laststarttext/preceding-sibling::node()"/>
519 <value-of select="substring-after($laststarttext, '— ')"/>
520 <copy-of select="$laststarttext/following-sibling::node()"/>
521 </variable>
522 <html:figure>
523 <copy>
524 <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
525 </copy>
526 <html:figcaption>
527 <for-each select="$content-nodes[last()]">
528 <copy>
529 <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
530 </copy>
531 </for-each>
532 </html:figcaption>
533 </html:figure>
534 </when>
535 <otherwise>
536 <copy>
537 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
538 </copy>
539 </otherwise>
540 </choose>
541 </if>
542 </template>
543 <template match="html:div" mode="LesML:finalize-tree">
544 <if test="not(@class='continuation') or not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:div or self::html:li)]">
545 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
546 <copy>
547 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
548 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
549 <apply-templates select="node()" mode="LesML:finalize-tree"/>
550 </for-each>
551 </copy>
552 </if>
553 </template>
554 <template match="html:li" mode="LesML:finalize-tree">
555 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[not(preceding-sibling::* and self::html:div and @class='continuation')][position()=1 and not(self::html:li)]">
556 <apply-templates select="." mode="LesML:finalize-list"/>
557 </if>
558 </template>
559 <template match="html:li" mode="LesML:finalize-list">
560 <param name="parent-level" select="0"/>
561 <variable name="current-class" select="string(@class)"/>
562 <variable name="current-level" select="number(@data-level)"/>
563 <variable name="wrapper">
564 <choose>
565 <when test="@class='ordered'">
566 <text>ol</text>
567 </when>
568 <otherwise>
569 <text>ul</text>
570 </otherwise>
571 </choose>
572 </variable>
573 <variable name="notinlist" select="following-sibling::node()[not(self::html:div and @class='continuation' or self::html:li and (@data-level>$current-level or @data-level=$current-level and @class=$current-class))][1]"/>
574 <element name="html:{$wrapper}" namespace="http://www.w3.org/1999/xhtml">
575 <for-each select=".|following-sibling::html:li[@data-level=$current-level and (not($notinlist) or following-sibling::node()[generate-id()=generate-id($notinlist)])]">
576 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
577 <copy>
578 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
579 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
580 <apply-templates select="node()" mode="LesML:finalize-tree"/>
581 </for-each>
582 <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
583 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
584 <with-param name="parent-level" select="$current-level"/>
585 </apply-templates>
586 </if>
587 </copy>
588 </for-each>
589 </element>
590 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
591 <apply-templates select="$notinlist" mode="LesML:finalize-list">
592 <with-param name="parent-level" select="$parent-level"/>
593 </apply-templates>
594 </if>
595 </template>
596 <template match="node()" mode="LesML:inline">
597 <param name="element-name"/>
598 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
599 <param name="start-sigil"/>
600 <param name="end-sigil"/>
601 <param name="role"/>
602 <param name="langtag-supported" select="false()"/>
603 <choose>
604 <when test="self::*">
605 <copy>
606 <copy-of select="@*"/>
607 <variable name="start-node" select="text()[contains(., $start-sigil)][1]"/>
608 <choose>
609 <when test="$start-node">
610 <variable name="remaining">
611 <value-of select="substring-after($start-node, $start-sigil)"/>
612 <copy-of select="$start-node/following-sibling::node()"/>
613 </variable>
614 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., $end-sigil)][1]"/>
615 <choose>
616 <when test="$end-node">
617 <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
618 <variable name="maybe-langtag">
619 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
620 <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
621 </if>
622 </variable>
623 <variable name="langtag">
624 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
625 <value-of select="$maybe-langtag"/>
626 </if>
627 </variable>
628 <variable name="rest">
629 <html:div>
630 <choose>
631 <when test="string($langtag)!=''">
632 <value-of select="substring-after($restoftext, '$')"/>
633 </when>
634 <otherwise>
635 <value-of select="$restoftext"/>
636 </otherwise>
637 </choose>
638 <copy-of select="$end-node/following-sibling::node()"/>
639 </html:div>
640 </variable>
641 <variable name="processed-rest">
642 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:inline">
643 <with-param name="element-name" select="$element-name"/>
644 <with-param name="element-namespace" select="$element-namespace"/>
645 <with-param name="start-sigil" select="$start-sigil"/>
646 <with-param name="end-sigil" select="$end-sigil"/>
647 <with-param name="role" select="$role"/>
648 <with-param name="langtag-supported" select="$langtag-supported"/>
649 </apply-templates>
650 </variable>
651 <copy-of select="$start-node/preceding-sibling::node()"/>
652 <value-of select="substring-before($start-node, $start-sigil)"/>
653 <element name="{$element-name}" namespace="{$element-namespace}">
654 <if test="string($role)!=''">
655 <attribute name="role">
656 <value-of select="$role"/>
657 </attribute>
658 </if>
659 <if test="string($langtag)!=''">
660 <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
661 <attribute name="lang">
662 <value-of select="$langtag"/>
663 </attribute>
664 </if>
665 <attribute name="xml:lang">
666 <value-of select="$langtag"/>
667 </attribute>
668 </if>
669 <copy-of select="$end-node/preceding-sibling::node()"/>
670 <value-of select="substring-before($end-node, $end-sigil)"/>
671 </element>
672 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
673 </when>
674 <otherwise>
675 <apply-templates select="node()" mode="LesML:inline">
676 <with-param name="element-name" select="$element-name"/>
677 <with-param name="element-namespace" select="$element-namespace"/>
678 <with-param name="start-sigil" select="$start-sigil"/>
679 <with-param name="end-sigil" select="$end-sigil"/>
680 <with-param name="role" select="$role"/>
681 <with-param name="langtag-supported" select="$langtag-supported"/>
682 </apply-templates>
683 </otherwise>
684 </choose>
685 </when>
686 <otherwise>
687 <apply-templates select="node()" mode="LesML:inline">
688 <with-param name="element-name" select="$element-name"/>
689 <with-param name="element-namespace" select="$element-namespace"/>
690 <with-param name="start-sigil" select="$start-sigil"/>
691 <with-param name="end-sigil" select="$end-sigil"/>
692 <with-param name="role" select="$role"/>
693 <with-param name="langtag-supported" select="$langtag-supported"/>
694 </apply-templates>
695 </otherwise>
696 </choose>
697 </copy>
698 </when>
699 <otherwise>
700 <copy-of select="."/>
701 </otherwise>
702 </choose>
703 </template>
704 <template match="node()" mode="LesML:linkify">
705 <variable name="result">
706 <choose>
707 <when test="self::*">
708 <copy>
709 <copy-of select="@*"/>
710 <variable name="start-node" select="text()[contains(., '{🔗')][1]"/>
711 <choose>
712 <when test="$start-node">
713 <variable name="remaining">
714 <value-of select="substring-after($start-node, '{🔗')"/>
715 <copy-of select="$start-node/following-sibling::node()"/>
716 </variable>
717 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., '>}') and not(preceding-sibling::*)][1]"/>
718 <variable name="hyperlink">
719 <for-each select="$end-node/preceding-sibling::node()">
720 <value-of select="."/>
721 </for-each>
722 <value-of select="substring-before($end-node, '>}')"/>
723 </variable>
724 <choose>
725 <when test="contains($hyperlink, '&lt;')">
726 <variable name="ltcomponents">
727 <call-template name="LesML:split">
728 <with-param name="source" select="$hyperlink"/>
729 <with-param name="separator" select="'&lt;'"/>
730 </call-template>
731 </variable>
732 <variable name="ltcomponent-nodes" select="exsl:node-set($ltcomponents)/*"/>
733 <variable name="rest">
734 <html:div>
735 <value-of select="substring-after($end-node, '>}')"/>
736 <copy-of select="$end-node/following-sibling::node()"/>
737 </html:div>
738 </variable>
739 <variable name="processed-rest">
740 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
741 </variable>
742 <copy-of select="$start-node/preceding-sibling::node()"/>
743 <value-of select="substring-before($start-node, '{🔗')"/>
744 <html:a href="{$ltcomponent-nodes[last()]}">
745 <choose>
746 <when test="count($ltcomponent-nodes)>2 or normalize-space($ltcomponent-nodes[1])!=''">
747 <value-of select="$ltcomponent-nodes[1]"/>
748 <for-each select="$ltcomponent-nodes[position()>1 and position()!=last()]">
749 <text>&lt;</text>
750 <value-of select="."/>
751 </for-each>
752 </when>
753 <otherwise>
754 <value-of select="$ltcomponent-nodes[last()]"/>
755 </otherwise>
756 </choose>
757 </html:a>
758 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
759 </when>
760 <otherwise>
761 <variable name="rest">
762 <html:div>
763 <copy-of select="$remaining"/>
764 </html:div>
765 </variable>
766 <variable name="processed-rest">
767 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
768 </variable>
769 <copy-of select="$start-node/preceding-sibling::node()"/>
770 <value-of select="substring-before($start-node, '{🔗')"/>
771 <text>{🔗</text>
772 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
773 </otherwise>
774 </choose>
775 </when>
776 <otherwise>
777 <apply-templates select="node()" mode="LesML:linkify"/>
778 </otherwise>
779 </choose>
780 </copy>
781 </when>
782 <otherwise>
783 <copy-of select="."/>
784 </otherwise>
785 </choose>
786 </variable>
787 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
788 </template>
789 <template match="node()" mode="LesML:strikethrough">
790 <variable name="result">
791 <apply-templates select="." mode="LesML:inline">
792 <with-param name="element-name" select="'html:s'"/>
793 <with-param name="start-sigil" select="'⸠'"/>
794 <with-param name="end-sigil" select="'⸡'"/>
795 </apply-templates>
796 </variable>
797 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
798 </template>
799 <template match="node()" mode="LesML:underline">
800 <variable name="result">
801 <apply-templates select="." mode="LesML:inline">
802 <with-param name="element-name" select="'html:u'"/>
803 <with-param name="start-sigil" select="'⸤'"/>
804 <with-param name="end-sigil" select="'⸥'"/>
805 </apply-templates>
806 </variable>
807 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
808 </template>
809 <template match="node()" mode="LesML:noted">
810 <variable name="result">
811 <apply-templates select="." mode="LesML:inline">
812 <with-param name="element-name" select="'html:small'"/>
813 <with-param name="start-sigil" select="'⟦'"/>
814 <with-param name="end-sigil" select="'⟧'"/>
815 <with-param name="role" select="'note'"/>
816 </apply-templates>
817 </variable>
818 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
819 </template>
820 <template match="node()" mode="LesML:parenthetical">
821 <variable name="result">
822 <apply-templates select="." mode="LesML:inline">
823 <with-param name="element-name" select="'html:small'"/>
824 <with-param name="start-sigil" select="'⸨'"/>
825 <with-param name="end-sigil" select="'⸩'"/>
826 </apply-templates>
827 </variable>
828 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
829 </template>
830 <template match="node()" mode="LesML:important">
831 <variable name="result">
832 <apply-templates select="." mode="LesML:inline">
833 <with-param name="element-name" select="'html:strong'"/>
834 <with-param name="start-sigil" select="'☞'"/>
835 <with-param name="end-sigil" select="'☜'"/>
836 </apply-templates>
837 </variable>
838 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
839 </template>
840 <template match="node()" mode="LesML:emphasized">
841 <variable name="result">
842 <apply-templates select="." mode="LesML:inline">
843 <with-param name="element-name" select="'html:em'"/>
844 <with-param name="start-sigil" select="'⹐'"/>
845 <with-param name="end-sigil" select="'⹑'"/>
846 </apply-templates>
847 </variable>
848 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
849 </template>
850 <template match="node()" mode="LesML:titled">
851 <variable name="result">
852 <apply-templates select="." mode="LesML:inline">
853 <with-param name="element-name" select="'html:cite'"/>
854 <with-param name="start-sigil" select="'⟪'"/>
855 <with-param name="end-sigil" select="'⟫'"/>
856 </apply-templates>
857 </variable>
858 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
859 </template>
860 <template match="node()" mode="LesML:offset">
861 <variable name="result">
862 <apply-templates select="." mode="LesML:inline">
863 <with-param name="element-name" select="'html:i'"/>
864 <with-param name="start-sigil" select="'⟨'"/>
865 <with-param name="end-sigil" select="'⟩'"/>
866 <with-param name="langtag-supported" select="true()"/>
867 </apply-templates>
868 </variable>
869 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
870 </template>
871 <template match="node()" mode="LesML:bolded">
872 <variable name="result">
873 <apply-templates select="." mode="LesML:inline">
874 <with-param name="element-name" select="'html:b'"/>
875 <with-param name="start-sigil" select="'⦃'"/>
876 <with-param name="end-sigil" select="'⦄'"/>
877 </apply-templates>
878 </variable>
879 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
880 </template>
881 <template match="node()" mode="LesML:code">
882 <apply-templates select="." mode="LesML:inline">
883 <with-param name="element-name" select="'html:code'"/>
884 <with-param name="start-sigil" select="'`'"/>
885 <with-param name="end-sigil" select="'´'"/>
886 </apply-templates>
887 </template>
888 </transform>
This page took 0.118461 seconds and 5 git commands to generate.