3 SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
 
   4 SPDX-License-Identifier: MPL-2.0
 
   7 ⁌ 💄📝 Les·M·L ∷ parser.xslt
 
   9 © 2024 Lady [@ Lady’s Computer]
 
  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/>.
 
  15         <!ENTITY section-break "*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~">
 
  16         <!ENTITY sigiled-text "(string-length($text)=1 or substring($text, 2, 1)=' ')">
 
  17         <!ENTITY unsigiled-text "substring($text, 3, string-length($text)-2)">
 
  20         xmlns="http://www.w3.org/1999/XSL/Transform"
 
  21         xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
 
  22         xmlns:exsl="http://exslt.org/common"
 
  23         xmlns:exslstr="http://exslt.org/strings"
 
  24         xmlns:html="http://www.w3.org/1999/xhtml"
 
  25         xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
 
  26         exclude-result-prefixes="LesML"
 
  27         extension-element-prefixes="exsl exslstr"
 
  30         <书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
 
  31         <template name="LesML:split">
 
  32                 <param name="source"/>
 
  33                 <param name="separator" select="'
'"/>
 
  35                         <when test="contains($source, $separator)">
 
  37                                         <value-of select="substring-before($source, $separator)"/>
 
  39                                 <call-template name="LesML:split">
 
  40                                         <with-param name="source" select="substring-after($source, $separator)"/>
 
  41                                         <with-param name="separator" select="$separator"/>
 
  46                                         <value-of select="$source"/>
 
  51         <template name="LesML:unescape">
 
  52                 <param name="source"/>
 
  54                         <when test="contains($source, '<U+')">
 
  55                                 <variable name="after" select="substring-after($source, '<U+')"/>
 
  57                                         <when test="contains($after, '>')">
 
  58                                                 <variable name="inner" select="substring-before($after, '>')"/>
 
  59                                                 <variable name="components">
 
  60                                                         <call-template name="LesML:split">
 
  61                                                                 <with-param name="source" select="$inner"/>
 
  62                                                                 <with-param name="separator" select="'.'"/>
 
  65                                                 <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
 
  67                                                         <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
 
  68                                                                 <value-of select="substring-before($source, '<U+')"/>
 
  70                                                                 <value-of select="$inner"/>
 
  72                                                                 <call-template name="LesML:unescape">
 
  73                                                                         <with-param name="source" select="substring-after($after, '>')"/>
 
  77                                                                 <for-each select="$component-nodes">
 
  78                                                                         <text disable-output-escaping="yes">&#x</text>
 
  79                                                                         <value-of select="."/>
 
  82                                                                 <call-template name="LesML:unescape">
 
  83                                                                         <with-param name="source" select="substring-after($after, '>')"/>
 
  89                                                 <value-of select="substring-before($source, '<U+')"/>
 
  91                                                 <call-template name="LesML:unescape">
 
  92                                                         <with-param name="source" select="$after"/>
 
  98                                 <value-of select="$source"/>
 
 102         <template name="LesML:id-and-contents">
 
 103                 <param name="source"/>
 
 105                         <when test="starts-with($source, '¶')">
 
 107                                         <when test="contains($source, ' ')">
 
 108                                                 <variable name="id" select="substring-before(substring-after($source, '¶'), ' ')"/>
 
 110                                                         <attribute name="id">
 
 111                                                                 <value-of select="$id"/>
 
 114                                                 <value-of select="substring-after($source, ' ')"/>
 
 117                                                 <attribute name="id">
 
 118                                                         <value-of select="substring-after($source, '¶')"/>
 
 124                                 <value-of select="$source"/>
 
 128         <template name="LesML:parse">
 
 129                 <param name="lines" select="/.."/>
 
 130                 <param name="parent-params" select="/.."/>
 
 131                 <variable name="first-line" select="$lines[1]"/>
 
 132                 <variable name="shebang">
 
 133                         <if test="starts-with($first-line, '#!lesml')">
 
 134                                 <value-of select="$first-line"/>
 
 137                 <variable name="params-string">
 
 139                                 <when test="starts-with($shebang, '#!lesml@')">
 
 140                                         <value-of select="substring-after($shebang, '$')"/>
 
 143                                         <value-of select="substring-after($shebang, '#!lesml')"/>
 
 147                 <variable name="params-fragment">
 
 149                                 <when test="$shebang!=''">
 
 151                                                 <if test="starts-with($shebang, '#!lesml@') and contains($shebang, '$')">
 
 157                                                                         <value-of select="substring-before(substring-after($shebang, '#!lesml@'), '$')"/>
 
 161                                                 <for-each select="exslstr:tokenize($params-string)">
 
 163                                                                 <when test="contains(., '=')">
 
 166                                                                                         <value-of select="substring-before(., '=')"/>
 
 169                                                                                         <value-of select="substring-after(., '=')"/>
 
 176                                                                                         <value-of select="."/>
 
 185                                 <when test="$parent-params">
 
 186                                         <copy-of select="$parent-params"/>
 
 193                 <variable name="params" select="exsl:node-set($params-fragment)/*"/>
 
 194                 <variable name="noshebang" select="$lines[position()>1 or not(starts-with(., '#!lesml') or starts-with(., '##'))]"/>
 
 195                 <variable name="docsep" select="$noshebang[starts-with(., '#!lesml') or starts-with(., '##')][1]"/>
 
 196                 <variable name="doclines" select="$noshebang[not($docsep) or following-sibling::*[generate-id()=generate-id($docsep)]]"/>
 
 197                 <if test="starts-with($first-line, '##') and $first-line!='##'">
 
 199                                 <value-of select="substring-after($first-line, '##')"/>
 
 202                 <if test="$shebang!='' or $doclines[normalize-space()!='']">
 
 203                         <variable name="record-separators" select="$doclines[starts-with(., '%%')]"/>
 
 205                                 <for-each select="$params/html:div/html:dt[string()=' LANG ']">
 
 206                                         <attribute name="lang">
 
 207                                                 <value-of select="following-sibling::html:dd"/>
 
 209                                         <attribute name="xml:lang">
 
 210                                                 <value-of select="following-sibling::html:dd"/>
 
 213                                 <for-each select="$params/html:div/html:dt[string()='profile']">
 
 214                                         <attribute name="data-lesml-profile">
 
 215                                                 <value-of select="following-sibling::html:dd"/>
 
 218                                 <if test="$record-separators[preceding-sibling::*[normalize-space()!='']]">
 
 219                                         <html:footer class="head">
 
 220                                                 <for-each select="$record-separators">
 
 221                                                         <variable name="position" select="position()"/>
 
 222                                                         <variable name="prev-separator" select="$record-separators[($position)-1]"/>
 
 223                                                         <variable name="fields" select="$noshebang[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-separator) or preceding-sibling::*[generate-id()=generate-id($prev-separator)])]"/>
 
 226                                                                         <for-each select="$fields">
 
 228                                                                                         <when test="starts-with(., ' ') and $fields[generate-id()=generate-id(current()/preceding-sibling::*[1])]"/>
 
 230                                                                                                 <variable name="next" select="following-sibling::*[not(starts-with(., ' '))]"/>
 
 233                                                                                                                 <value-of select="normalize-space(substring-before(., ':'))"/>
 
 236                                                                                                                 <variable name="firstline">
 
 238                                                                                                                                 <when test="contains(., ':')">
 
 239                                                                                                                                         <value-of select="normalize-space(substring-after(., ':'))"/>
 
 242                                                                                                                                         <value-of select="normalize-space(.)"/>
 
 247                                                                                                                         <when test="substring($firstline, string-length($firstline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
 
 248                                                                                                                                 <value-of select="substring($firstline, 1, string-length($firstline)-1)"/>
 
 251                                                                                                                                 <value-of select="$firstline"/>
 
 254                                                                                                                 <for-each select="following-sibling::*[starts-with(., ' ') and not(preceding-sibling::*[generate-id()=generate-id($next)])]">
 
 255                                                                                                                         <variable name="nextline" select="normalize-space(.)"/>
 
 257                                                                                                                                 <when test="substring($nextline, string-length($nextline))='\' and following-sibling::*[position()=1 and starts-with(., ' ')]">
 
 258                                                                                                                                         <value-of select="substring($nextline, 1, string-length($nextline)-1)"/>
 
 261                                                                                                                                         <value-of select="$nextline"/>
 
 274                                                                         <value-of select="substring-after(., '%%')"/>
 
 280                                 <html:div class="body">
 
 281                                         <call-template name="LesML:paragraphize">
 
 282                                                 <with-param name="lines" select="$doclines[not($record-separators) or preceding-sibling::*[generate-id()=generate-id($record-separators[last()])]]"/>
 
 288                         <call-template name="LesML:parse">
 
 289                                 <with-param name="lines" select="$docsep|$lines[preceding-sibling::*[generate-id()=generate-id($docsep)]]"/>
 
 290                                 <with-param name="parent-params" select="$params"/>
 
 294         <template name="LesML:paragraphize">
 
 295                 <param name="lines" select="/.."/>
 
 296                 <variable name="last-lines" select="$lines[normalize-space()!='' and normalize-space(following-sibling::*[1])='']|$lines[last()]"/>
 
 297                 <variable name="blocked">
 
 298                         <for-each select="$last-lines">
 
 299                                 <variable name="position" select="position()"/>
 
 300                                 <variable name="prev-last" select="$last-lines[($position)-1]"/>
 
 301                                 <variable name="linespans" select="$lines[following-sibling::*[generate-id()=generate-id(current())] and (not($prev-last) or preceding-sibling::*[generate-id()=generate-id($prev-last)]) and normalize-space()!='']|."/>
 
 302                                 <variable name="quoted" select="not($linespans[not(starts-with(., ' ') or starts-with(., '	'))])"/>
 
 303                                 <variable name="text">
 
 304                                         <for-each select="$linespans">
 
 305                                                 <value-of select="normalize-space()"/>
 
 306                                                 <if test="position()!=count($linespans)">
 
 311                                 <if test="string($text)!=''">
 
 312                                         <variable name="par">
 
 314                                                         <when test="starts-with($text, '⁌') and &sigiled-text;">
 
 316                                                                         <call-template name="LesML:id-and-contents">
 
 317                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 321                                                         <when test="starts-with($text, '§') and &sigiled-text;">
 
 323                                                                         <call-template name="LesML:id-and-contents">
 
 324                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 328                                                         <when test="starts-with($text, '❦') and &sigiled-text;">
 
 330                                                                         <call-template name="LesML:id-and-contents">
 
 331                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 335                                                         <when test="starts-with($text, '✠') and &sigiled-text;">
 
 337                                                                         <call-template name="LesML:id-and-contents">
 
 338                                                                                 <with-param name="source" select="&unsigiled-text;"/>
 
 342                                                         <when test="starts-with($text, '•') and &sigiled-text;">
 
 343                                                                 <html:li class="unordered" data-level="1">
 
 345                                                                                 <call-template name="LesML:id-and-contents">
 
 346                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 351                                                         <when test="starts-with($text, '🔢') and &sigiled-text;">
 
 352                                                                 <html:li class="ordered" data-level="1">
 
 354                                                                                 <call-template name="LesML:id-and-contents">
 
 355                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 360                                                         <when test="starts-with($text, '◦') and &sigiled-text;">
 
 361                                                                 <html:li class="unordered" data-level="2">
 
 363                                                                                 <call-template name="LesML:id-and-contents">
 
 364                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 369                                                         <when test="starts-with($text, '🔠') and &sigiled-text;">
 
 370                                                                 <html:li class="ordered" data-level="2">
 
 372                                                                                 <call-template name="LesML:id-and-contents">
 
 373                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 378                                                         <when test="starts-with($text, '▪') and &sigiled-text;">
 
 379                                                                 <html:li class="unordered" data-level="3">
 
 381                                                                                 <call-template name="LesML:id-and-contents">
 
 382                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 387                                                         <when test="starts-with($text, '🔡') and &sigiled-text;">
 
 388                                                                 <html:li class="ordered" data-level="3">
 
 390                                                                                 <call-template name="LesML:id-and-contents">
 
 391                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 396                                                         <when test="starts-with($text, '⁃') and &sigiled-text;">
 
 397                                                                 <html:li class="unordered" data-level="4">
 
 399                                                                                 <call-template name="LesML:id-and-contents">
 
 400                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 405                                                         <when test="starts-with($text, '🔣') and &sigiled-text;">
 
 406                                                                 <html:li class="ordered" data-level="4">
 
 408                                                                                 <call-template name="LesML:id-and-contents">
 
 409                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 414                                                         <when test="starts-with($text, '🛈') and &sigiled-text;">
 
 415                                                                 <html:div role="note" class="info">
 
 417                                                                                 <call-template name="LesML:id-and-contents">
 
 418                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 423                                                         <when test="starts-with($text, '⯑') and &sigiled-text;">
 
 424                                                                 <html:div role="note" class="query">
 
 426                                                                                 <call-template name="LesML:id-and-contents">
 
 427                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 432                                                         <when test="starts-with($text, '⚠︎') and &sigiled-text;">
 
 433                                                                 <html:div role="note" class="warn">
 
 435                                                                                 <call-template name="LesML:id-and-contents">
 
 436                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 441                                                         <when test="starts-with($text, '※') and &sigiled-text;">
 
 442                                                                 <html:div role="note" class="note">
 
 444                                                                                 <call-template name="LesML:id-and-contents">
 
 445                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 450                                                         <when test="starts-with($text, '☡') and &sigiled-text;">
 
 451                                                                 <html:div role="note" class="caution">
 
 453                                                                                 <call-template name="LesML:id-and-contents">
 
 454                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 459                                                         <when test="starts-with($text, '⋯') and &sigiled-text;">
 
 460                                                                 <html:div class="continuation">
 
 462                                                                                 <call-template name="LesML:id-and-contents">
 
 463                                                                                         <with-param name="source" select="&unsigiled-text;"/>
 
 468                                                         <when test="starts-with($text, '#') and &sigiled-text;">
 
 470                                                                         <value-of select="&unsigiled-text;"/>
 
 475                                                                         <call-template name="LesML:id-and-contents">
 
 476                                                                                 <with-param name="source" select="$text"/>
 
 483                                                 <when test="translate(string($text), '§ion-break; ', '')=''">
 
 486                                                 <when test="$quoted">
 
 488                                                                 <copy-of select="$par"/>
 
 492                                                         <copy-of select="$par"/>
 
 498                 <variable name="inlined">
 
 499                         <apply-templates select="exsl:node-set($blocked)/node()" mode="LesML:linkify"/>
 
 501                 <apply-templates select="exsl:node-set($inlined)/node()" mode="LesML:finalize-tree"/>
 
 503         <template match="html:script[@type='text/lesml']">
 
 504                 <variable name="lines-fragment">
 
 505                         <call-template name="LesML:split">
 
 506                                 <with-param name="source">
 
 507                                         <for-each select=".//text()">
 
 508                                                 <value-of select="."/>
 
 513                 <call-template name="LesML:parse">
 
 514                         <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
 
 517         <template match="@*|node()" mode="LesML:finalize-tree" priority="-1">
 
 519                         <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
 
 522         <template match="text()" mode="LesML:finalize-tree">
 
 523                 <call-template name="LesML:unescape">
 
 524                         <with-param name="source" select="string(.)"/>
 
 527         <template match="html:blockquote" mode="LesML:finalize-tree">
 
 528                 <if test="not(preceding-sibling::node()) or preceding-sibling::node()[position()=1 and not(self::html:blockquote)]">
 
 529                         <variable name="notquote" select="following-sibling::node()[not(self::html:blockquote)][1]"/>
 
 530                         <variable name="contents">
 
 531                                 <copy-of select="node()"/>
 
 532                                 <for-each select="following-sibling::node()[not($notquote) or following-sibling::node()[generate-id()=generate-id($notquote)]]">
 
 533                                         <copy-of select="node()"/>
 
 536                         <variable name="content-nodes" select="exsl:node-set($contents)/node()"/>
 
 537                         <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()]"/>
 
 539                                 <when test="starts-with($laststarttext, '— ')">
 
 540                                         <variable name="caption">
 
 541                                                 <copy-of select="$laststarttext/preceding-sibling::node()"/>
 
 542                                                 <value-of select="substring-after($laststarttext, '— ')"/>
 
 543                                                 <copy-of select="$laststarttext/following-sibling::node()"/>
 
 547                                                         <apply-templates select="@*|$content-nodes[position()!=last()]" mode="LesML:finalize-tree"/>
 
 550                                                         <for-each select="$content-nodes[last()]">
 
 552                                                                         <apply-templates select="@*|exsl:node-set($caption)/node()" mode="LesML:finalize-tree"/>
 
 560                                                 <apply-templates select="@*|$content-nodes" mode="LesML:finalize-tree"/>
 
 566         <template match="html:div" mode="LesML:finalize-tree">
 
 567                 <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)]">
 
 568                         <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
 
 570                                 <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
 
 571                                 <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
 
 572                                         <apply-templates select="node()" mode="LesML:finalize-tree"/>
 
 577         <template match="html:li" mode="LesML:finalize-tree">
 
 578                 <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)]">
 
 579                         <apply-templates select="." mode="LesML:finalize-list"/>
 
 582         <template match="html:li" mode="LesML:finalize-list">
 
 583                 <param name="parent-level" select="0"/>
 
 584                 <variable name="current-class" select="string(@class)"/>
 
 585                 <variable name="current-level" select="number(@data-level)"/>
 
 586                 <variable name="wrapper">
 
 588                                 <when test="@class='ordered'">
 
 596                 <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]"/>
 
 597                 <element name="html:{$wrapper}" namespace="http://www.w3.org/1999/xhtml">
 
 598                         <for-each select=".|following-sibling::html:li[@data-level=$current-level and (not($notinlist) or following-sibling::node()[generate-id()=generate-id($notinlist)])]">
 
 599                                 <variable name="notcontinuation" select="following-sibling::node()[not(self::html:div and @class='continuation')][1]"/>
 
 601                                         <apply-templates select="@*|node()" mode="LesML:finalize-tree"/>
 
 602                                         <for-each select="following-sibling::node()[not($notcontinuation) or following-sibling::node()[generate-id()=generate-id($notcontinuation)]]">
 
 603                                                 <apply-templates select="node()" mode="LesML:finalize-tree"/>
 
 605                                         <if test="$notcontinuation/self::html:li[@data-level>$current-level]">
 
 606                                                 <apply-templates select="$notcontinuation" mode="LesML:finalize-list">
 
 607                                                         <with-param name="parent-level" select="$current-level"/>
 
 613                 <if test="$notinlist/self::html:li[@data-level>$parent-level]">
 
 614                         <apply-templates select="$notinlist" mode="LesML:finalize-list">
 
 615                                 <with-param name="parent-level" select="$parent-level"/>
 
 619         <template match="node()" mode="LesML:inline">
 
 620                 <param name="element-name"/>
 
 621                 <param name="element-namespace" select="'http://www.w3.org/1999/xhtml'"/>
 
 622                 <param name="start-sigil"/>
 
 623                 <param name="end-sigil"/>
 
 625                 <param name="langtag-supported" select="false()"/>
 
 627                         <when test="self::*">
 
 629                                         <copy-of select="@*"/>
 
 630                                         <variable name="start-node" select="text()[contains(., $start-sigil)][1]"/>
 
 632                                                 <when test="$start-node">
 
 633                                                         <variable name="remaining">
 
 634                                                                 <value-of select="substring-after($start-node, $start-sigil)"/>
 
 635                                                                 <copy-of select="$start-node/following-sibling::node()"/>
 
 637                                                         <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., $end-sigil)][1]"/>
 
 639                                                                 <when test="$end-node">
 
 640                                                                         <variable name="restoftext" select="substring-after($end-node, $end-sigil)"/>
 
 641                                                                         <variable name="maybe-langtag">
 
 642                                                                                 <if test="$langtag-supported and starts-with($restoftext, '@') and contains($restoftext, '$')">
 
 643                                                                                         <value-of select="substring-before(substring-after($restoftext, '@'), '$')"/>
 
 646                                                                         <variable name="langtag">
 
 647                                                                                 <if test="translate($maybe-langtag, '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-', '')=''">
 
 648                                                                                         <value-of select="$maybe-langtag"/>
 
 651                                                                         <variable name="rest">
 
 654                                                                                                 <when test="string($langtag)!=''">
 
 655                                                                                                         <value-of select="substring-after($restoftext, '$')"/>
 
 658                                                                                                         <value-of select="$restoftext"/>
 
 661                                                                                         <copy-of select="$end-node/following-sibling::node()"/>
 
 664                                                                         <variable name="processed-rest">
 
 665                                                                                 <apply-templates select="exsl:node-set($rest)/*" mode="LesML:inline">
 
 666                                                                                         <with-param name="element-name" select="$element-name"/>
 
 667                                                                                         <with-param name="element-namespace" select="$element-namespace"/>
 
 668                                                                                         <with-param name="start-sigil" select="$start-sigil"/>
 
 669                                                                                         <with-param name="end-sigil" select="$end-sigil"/>
 
 670                                                                                         <with-param name="role" select="$role"/>
 
 671                                                                                         <with-param name="langtag-supported" select="$langtag-supported"/>
 
 674                                                                         <copy-of select="$start-node/preceding-sibling::node()"/>
 
 675                                                                         <value-of select="substring-before($start-node, $start-sigil)"/>
 
 676                                                                         <element name="{$element-name}" namespace="{$element-namespace}">
 
 677                                                                                 <if test="string($role)!=''">
 
 678                                                                                         <attribute name="role">
 
 679                                                                                                 <value-of select="$role"/>
 
 682                                                                                 <if test="string($langtag)!=''">
 
 683                                                                                         <if test="$element-namespace='http://www.w3.org/1999/xhtml'">
 
 684                                                                                                 <attribute name="lang">
 
 685                                                                                                         <value-of select="$langtag"/>
 
 688                                                                                         <attribute name="xml:lang">
 
 689                                                                                                 <value-of select="$langtag"/>
 
 692                                                                                 <copy-of select="$end-node/preceding-sibling::node()"/>
 
 693                                                                                 <value-of select="substring-before($end-node, $end-sigil)"/>
 
 695                                                                         <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
 
 698                                                                         <apply-templates select="node()" mode="LesML:inline">
 
 699                                                                                 <with-param name="element-name" select="$element-name"/>
 
 700                                                                                 <with-param name="element-namespace" select="$element-namespace"/>
 
 701                                                                                 <with-param name="start-sigil" select="$start-sigil"/>
 
 702                                                                                 <with-param name="end-sigil" select="$end-sigil"/>
 
 703                                                                                 <with-param name="role" select="$role"/>
 
 704                                                                                 <with-param name="langtag-supported" select="$langtag-supported"/>
 
 710                                                         <apply-templates select="node()" mode="LesML:inline">
 
 711                                                                 <with-param name="element-name" select="$element-name"/>
 
 712                                                                 <with-param name="element-namespace" select="$element-namespace"/>
 
 713                                                                 <with-param name="start-sigil" select="$start-sigil"/>
 
 714                                                                 <with-param name="end-sigil" select="$end-sigil"/>
 
 715                                                                 <with-param name="role" select="$role"/>
 
 716                                                                 <with-param name="langtag-supported" select="$langtag-supported"/>
 
 723                                 <copy-of select="."/>
 
 727         <template match="node()" mode="LesML:linkify">
 
 728                 <variable name="result">
 
 730                                 <when test="self::*">
 
 732                                                 <copy-of select="@*"/>
 
 733                                                 <variable name="start-node" select="text()[contains(., '{🔗')][1]"/>
 
 735                                                         <when test="$start-node">
 
 736                                                                 <variable name="remaining">
 
 737                                                                         <value-of select="substring-after($start-node, '{🔗')"/>
 
 738                                                                         <copy-of select="$start-node/following-sibling::node()"/>
 
 740                                                                 <variable name="end-node" select="exsl:node-set($remaining)/node()[self::text() and contains(., '>}') and not(preceding-sibling::*)][1]"/>
 
 741                                                                 <variable name="hyperlink">
 
 742                                                                         <for-each select="$end-node/preceding-sibling::node()">
 
 743                                                                                 <value-of select="."/>
 
 745                                                                         <value-of select="substring-before($end-node, '>}')"/>
 
 748                                                                         <when test="contains($hyperlink, '<')">
 
 749                                                                                 <variable name="ltcomponents">
 
 750                                                                                         <call-template name="LesML:split">
 
 751                                                                                                 <with-param name="source" select="$hyperlink"/>
 
 752                                                                                                 <with-param name="separator" select="'<'"/>
 
 755                                                                                 <variable name="ltcomponent-nodes" select="exsl:node-set($ltcomponents)/*"/>
 
 756                                                                                 <variable name="rest">
 
 758                                                                                                 <value-of select="substring-after($end-node, '>}')"/>
 
 759                                                                                                 <copy-of select="$end-node/following-sibling::node()"/>
 
 762                                                                                 <variable name="processed-rest">
 
 763                                                                                         <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
 
 765                                                                                 <copy-of select="$start-node/preceding-sibling::node()"/>
 
 766                                                                                 <value-of select="substring-before($start-node, '{🔗')"/>
 
 767                                                                                 <html:a href="{$ltcomponent-nodes[last()]}">
 
 769                                                                                                 <when test="count($ltcomponent-nodes)>2 or normalize-space($ltcomponent-nodes[1])!=''">
 
 770                                                                                                         <value-of select="$ltcomponent-nodes[1]"/>
 
 771                                                                                                         <for-each select="$ltcomponent-nodes[position()>1 and position()!=last()]">
 
 773                                                                                                                 <value-of select="."/>
 
 777                                                                                                         <value-of select="$ltcomponent-nodes[last()]"/>
 
 781                                                                                 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
 
 784                                                                                 <variable name="rest">
 
 786                                                                                                 <copy-of select="$remaining"/>
 
 789                                                                                 <variable name="processed-rest">
 
 790                                                                                         <apply-templates select="exsl:node-set($rest)/*" mode="LesML:linkify"/>
 
 792                                                                                 <copy-of select="$start-node/preceding-sibling::node()"/>
 
 793                                                                                 <value-of select="substring-before($start-node, '{🔗')"/>
 
 795                                                                                 <copy-of select="exsl:node-set($processed-rest)/*/node()"/>
 
 800                                                                 <apply-templates select="node()" mode="LesML:linkify"/>
 
 806                                         <copy-of select="."/>
 
 810                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:strikethrough"/>
 
 812         <template match="node()" mode="LesML:strikethrough">
 
 813                 <variable name="result">
 
 814                         <apply-templates select="." mode="LesML:inline">
 
 815                                 <with-param name="element-name" select="'html:s'"/>
 
 816                                 <with-param name="start-sigil" select="'⸠'"/>
 
 817                                 <with-param name="end-sigil" select="'⸡'"/>
 
 820                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:underline"/>
 
 822         <template match="node()" mode="LesML:underline">
 
 823                 <variable name="result">
 
 824                         <apply-templates select="." mode="LesML:inline">
 
 825                                 <with-param name="element-name" select="'html:u'"/>
 
 826                                 <with-param name="start-sigil" select="'⸤'"/>
 
 827                                 <with-param name="end-sigil" select="'⸥'"/>
 
 830                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:noted"/>
 
 832         <template match="node()" mode="LesML:noted">
 
 833                 <variable name="result">
 
 834                         <apply-templates select="." mode="LesML:inline">
 
 835                                 <with-param name="element-name" select="'html:small'"/>
 
 836                                 <with-param name="start-sigil" select="'⟦'"/>
 
 837                                 <with-param name="end-sigil" select="'⟧'"/>
 
 838                                 <with-param name="role" select="'note'"/>
 
 841                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:parenthetical"/>
 
 843         <template match="node()" mode="LesML:parenthetical">
 
 844                 <variable name="result">
 
 845                         <apply-templates select="." mode="LesML:inline">
 
 846                                 <with-param name="element-name" select="'html:small'"/>
 
 847                                 <with-param name="start-sigil" select="'⸨'"/>
 
 848                                 <with-param name="end-sigil" select="'⸩'"/>
 
 851                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:important"/>
 
 853         <template match="node()" mode="LesML:important">
 
 854                 <variable name="result">
 
 855                         <apply-templates select="." mode="LesML:inline">
 
 856                                 <with-param name="element-name" select="'html:strong'"/>
 
 857                                 <with-param name="start-sigil" select="'☞'"/>
 
 858                                 <with-param name="end-sigil" select="'☜'"/>
 
 861                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:emphasized"/>
 
 863         <template match="node()" mode="LesML:emphasized">
 
 864                 <variable name="result">
 
 865                         <apply-templates select="." mode="LesML:inline">
 
 866                                 <with-param name="element-name" select="'html:em'"/>
 
 867                                 <with-param name="start-sigil" select="'⹐'"/>
 
 868                                 <with-param name="end-sigil" select="'⹑'"/>
 
 871                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:titled"/>
 
 873         <template match="node()" mode="LesML:titled">
 
 874                 <variable name="result">
 
 875                         <apply-templates select="." mode="LesML:inline">
 
 876                                 <with-param name="element-name" select="'html:cite'"/>
 
 877                                 <with-param name="start-sigil" select="'⟪'"/>
 
 878                                 <with-param name="end-sigil" select="'⟫'"/>
 
 881                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:offset"/>
 
 883         <template match="node()" mode="LesML:offset">
 
 884                 <variable name="result">
 
 885                         <apply-templates select="." mode="LesML:inline">
 
 886                                 <with-param name="element-name" select="'html:i'"/>
 
 887                                 <with-param name="start-sigil" select="'⟨'"/>
 
 888                                 <with-param name="end-sigil" select="'⟩'"/>
 
 889                                 <with-param name="langtag-supported" select="true()"/>
 
 892                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:bolded"/>
 
 894         <template match="node()" mode="LesML:bolded">
 
 895                 <variable name="result">
 
 896                         <apply-templates select="." mode="LesML:inline">
 
 897                                 <with-param name="element-name" select="'html:b'"/>
 
 898                                 <with-param name="start-sigil" select="'⦃'"/>
 
 899                                 <with-param name="end-sigil" select="'⦄'"/>
 
 902                 <apply-templates select="exsl:node-set($result)/node()" mode="LesML:code"/>
 
 904         <template match="node()" mode="LesML:code">
 
 905                 <apply-templates select="." mode="LesML:inline">
 
 906                         <with-param name="element-name" select="'html:code'"/>
 
 907                         <with-param name="start-sigil" select="'`'"/>
 
 908                         <with-param name="end-sigil" select="'´'"/>