This simplifies the implementation a bit.
xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
xmlns:exsl="http://exslt.org/common"
xmlns:exsldyn="http://exslt.org/dynamic"
xmlns:LesML="urn:fdc:ladys.computer:20240512:LesML"
xmlns:exsl="http://exslt.org/common"
xmlns:exsldyn="http://exslt.org/dynamic"
+ xmlns:exslfunc="http://exslt.org/functions"
xmlns:exslset="http://exslt.org/sets"
xmlns:exslstr="http://exslt.org/strings"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
exclude-result-prefixes="LesML"
xmlns:exslset="http://exslt.org/sets"
xmlns:exslstr="http://exslt.org/strings"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
exclude-result-prefixes="LesML"
- extension-element-prefixes="exsl exsldyn exslset exslstr"
+ extension-element-prefixes="exsl exsldyn exslfunc exslset exslstr"
version="1.0"
>
<书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
<param name="LESML_SECTION_BREAK_CHARS" select="'*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'"/>
version="1.0"
>
<书社:id>urn:fdc:ladys.computer:20240512:LesML:parser.xslt</书社:id>
<param name="LESML_SECTION_BREAK_CHARS" select="'*-.=_~·․‥…⁂⋯─━┄┅┈┉╌╍═╴╶╸╺☙❧ ・*-.=_~'"/>
- <template name="LesML:split">
+ <exslfunc:function name="LesML:split">
+ <param name="source" select="string()"/>
+ <param name="separator" select="'
'"/>
+ <variable name="result-fragment">
+ <call-template name="LesML:do-split">
+ <with-param name="source" select="$source"/>
+ <with-param name="separator" select="$separator"/>
+ </call-template>
+ </variable>
+ <exslfunc:result select="exsl:node-set($result-fragment)/node()"/>
+ </exslfunc:function>
+ <template name="LesML:do-split">
<param name="source"/>
<param name="separator" select="'
'"/>
<choose>
<param name="source"/>
<param name="separator" select="'
'"/>
<choose>
<html:span>
<value-of select="substring-before($source, $separator)"/>
</html:span>
<html:span>
<value-of select="substring-before($source, $separator)"/>
</html:span>
- <call-template name="LesML:split">
+ <call-template name="LesML:do-split">
<with-param name="source" select="substring-after($source, $separator)"/>
<with-param name="separator" select="$separator"/>
</call-template>
<with-param name="source" select="substring-after($source, $separator)"/>
<with-param name="separator" select="$separator"/>
</call-template>
</template>
<template name="LesML:break-and-unescape">
<param name="source"/>
</template>
<template name="LesML:break-and-unescape">
<param name="source"/>
- <variable name="broken-fragment">
- <call-template name="LesML:split">
- <with-param name="source" select="$source"/>
- <with-param name="separator" select="'
'"/>
- </call-template>
- </variable>
- <variable name="broken" select="exsl:node-set($broken-fragment)/node()"/>
- <for-each select="$broken">
+ <for-each select="LesML:split($source)">
<call-template name="LesML:unescape">
<with-param name="source" select="string()"/>
</call-template>
<call-template name="LesML:unescape">
<with-param name="source" select="string()"/>
</call-template>
- <if test="position()!=count($broken)">
+ <if test="position()!=last()">
<element name="br" namespace="&xhtml;"/>
</if>
</for-each>
<element name="br" namespace="&xhtml;"/>
</if>
</for-each>
<choose>
<when test="contains($after, '}')">
<variable name="inner" select="substring-before($after, '}')"/>
<choose>
<when test="contains($after, '}')">
<variable name="inner" select="substring-before($after, '}')"/>
- <variable name="components">
- <call-template name="LesML:split">
- <with-param name="source" select="$inner"/>
- <with-param name="separator" select="'.'"/>
- </call-template>
- </variable>
- <variable name="component-nodes" select="exsl:node-set($components)/node()"/>
+ <variable name="components" select="LesML:split($inner, '.')"/>
<value-of select="substring-before($source, '{U+')"/>
<choose>
<value-of select="substring-before($source, '{U+')"/>
<choose>
- <when test="$component-nodes[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
+ <when test="$components[string(.)='' or translate(., '0123456789ABCDEF', '')!='']">
<text>{U+</text>
<value-of select="$inner"/>
<text>}</text>
<text>{U+</text>
<value-of select="$inner"/>
<text>}</text>
</call-template>
</when>
<otherwise>
</call-template>
</when>
<otherwise>
- <for-each select="$component-nodes">
+ <for-each select="$components">
<text disable-output-escaping="yes">&#x</text>
<value-of select="."/>
<text>;</text>
<text disable-output-escaping="yes">&#x</text>
<value-of select="."/>
<text>;</text>
</template>
<template name="LesML:comment-out">
<param name="source"/>
</template>
<template name="LesML:comment-out">
<param name="source"/>
- <variable name="comment-split-fragment">
- <call-template name="LesML:split">
- <with-param name="source" select="$source"/>
- <with-param name="separator" select="'--'"/>
- </call-template>
- </variable>
- <for-each select="exsl:node-set($comment-split-fragment)/*">
+ <for-each select="LesML:split($source, '--')">
<if test="string()='' or starts-with(., '‐')">
<text>͏</text>
</if>
<if test="string()='' or starts-with(., '‐')">
<text>͏</text>
</if>
</variable>
<variable name="maybe-langtag">
<if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
</variable>
<variable name="maybe-langtag">
<if test="substring($id-and-lang, string-length($id-and-lang), 1)='$' and contains($id-and-lang, '@')">
- <variable name="split-tag-fragment">
- <call-template name="LesML:split">
- <with-param name="source" select="substring($id-and-lang, 2, string-length($id-and-lang)-2)"/>
- <with-param name="separator" select="'@'"/>
- </call-template>
- </variable>
- <value-of select="exsl:node-set($split-tag-fragment)/*[last()]"/>
+ <value-of select="LesML:split(substring($id-and-lang, 2, string-length($id-and-lang)-2), '@')[last()]"/>
</if>
</variable>
<variable name="langtag">
</if>
</variable>
<variable name="langtag">
<apply-templates select="exsl:node-set($inlined-fragment)/node()" mode="LesML:finalize-tree"/>
</template>
<template match="html:script[@type='text/lesml']">
<apply-templates select="exsl:node-set($inlined-fragment)/node()" mode="LesML:finalize-tree"/>
</template>
<template match="html:script[@type='text/lesml']">
- <variable name="lines-fragment">
- <call-template name="LesML:split">
- <with-param name="source">
- <for-each select=".//text()">
- <value-of select="."/>
- </for-each>
- </with-param>
- </call-template>
+ <variable name="source">
+ <for-each select=".//text()">
+ <value-of select="."/>
+ </for-each>
</variable>
<element name="div" namespace="&xhtml;">
<call-template name="LesML:parse">
</variable>
<element name="div" namespace="&xhtml;">
<call-template name="LesML:parse">
- <with-param name="lines" select="exsl:node-set($lines-fragment)/*"/>
+ <with-param name="lines" select="LesML:split($source)"/>
</call-template>
</element>
</template>
</call-template>
</element>
</template>
<value-of select="substring-before($end-node, $end-sigil)"/>
</variable>
<variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
<value-of select="substring-before($end-node, $end-sigil)"/>
</variable>
<variable name="start-node" select="exsl:node-set($preceding)/text()[contains(., $start-sigil)][last()]"/>
- <variable name="start-tokens-fragment">
- <call-template name="LesML:split">
- <with-param name="source" select="string($start-node)"/>
- <with-param name="separator" select="$start-sigil"/>
- </call-template>
- </variable>
- <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
+ <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
<variable name="wrapped">
<copy>
<copy-of select="@*"/>
<variable name="wrapped">
<copy>
<copy-of select="@*"/>
</variable>
<variable name="preceding" select="exsl:node-set($preceding-fragment)/node()"/>
<variable name="start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()][not($ncname-keys) or not(following-sibling::* or following-sibling::comment())]"/>
</variable>
<variable name="preceding" select="exsl:node-set($preceding-fragment)/node()"/>
<variable name="start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()][not($ncname-keys) or not(following-sibling::* or following-sibling::comment())]"/>
- <variable name="start-tokens-fragment">
- <if test="$start-node">
- <call-template name="LesML:split">
- <with-param name="source" select="string($start-node)"/>
- <with-param name="separator" select="$start-sigil"/>
- </call-template>
- </if>
- </variable>
- <variable name="start-tokens" select="exsl:node-set($start-tokens-fragment)/*"/>
+ <variable name="start-tokens" select="LesML:split($start-node, $start-sigil)"/>
<variable name="innards-fragment">
<value-of select="$start-tokens[last()]"/>
<copy-of select="$start-node/following-sibling::node()"/>
<variable name="innards-fragment">
<value-of select="$start-tokens[last()]"/>
<copy-of select="$start-node/following-sibling::node()"/>
<choose>
<when test="not($start-node) or $separator-node[following-sibling::* or following-sibling::comment()]">
<variable name="bad-start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()]"/>
<choose>
<when test="not($start-node) or $separator-node[following-sibling::* or following-sibling::comment()]">
<variable name="bad-start-node" select="($preceding[self::text() and contains(., $start-sigil)])[last()]"/>
- <variable name="bad-start-tokens-fragment">
- <call-template name="LesML:split">
- <with-param name="source" select="string($bad-start-node)"/>
- <with-param name="separator" select="$start-sigil"/>
- </call-template>
- </variable>
<element name="span" namespace="&xhtml;">
<copy-of select="$bad-start-node/preceding-sibling::node()"/>
<element name="span" namespace="&xhtml;">
<copy-of select="$bad-start-node/preceding-sibling::node()"/>
- <for-each select="exsl:node-set($bad-start-tokens-fragment)/*">
+ <for-each select="LesML:split($bad-start-node, $start-sigil)">
<value-of select="."/>
<if test="position()!=last()">
<processing-instruction name="LesML-Token-Escape">
<value-of select="."/>
<if test="position()!=last()">
<processing-instruction name="LesML-Token-Escape">
</element>
</when>
<when test="$separator-node">
</element>
</when>
<when test="$separator-node">
- <variable name="keyval-fragment">
- <call-template name="LesML:split">
- <with-param name="source" select="$separator-node"/>
- <with-param name="separator" select="$separator"/>
- </call-template>
- </variable>
- <variable name="keyval" select="exsl:node-set($keyval-fragment)/*"/>
+ <variable name="keyval" select="LesML:split($separator-node, $separator)"/>
<variable name="key-fragment">
<choose>
<when test="$ncname-keys">
<variable name="key-fragment">
<choose>
<when test="$ncname-keys">
</choose>
</when>
<when test="self::text()[contains(., '⌧')]">
</choose>
</when>
<when test="self::text()[contains(., '⌧')]">
- <variable name="split-fragment">
- <call-template name="LesML:split">
- <with-param name="source" select="string()"/>
- <with-param name="separator" select="'⌧'"/>
- </call-template>
- </variable>
- <for-each select="exsl:node-set($split-fragment)/node()">
+ <for-each select="LesML:split(., '⌧')">
<value-of select="."/>
<if test="position()!=last()">
<call-template name="LesML:comment-out"/>
<value-of select="."/>
<if test="position()!=last()">
<call-template name="LesML:comment-out"/>