+<?xml version="1.0"?>
+<!--
+SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
+SPDX-License-Identifier: MPL-2.0
+-->
+<!--
+⁌ ⛩️📰 书社 ∷ lib/serialize.xslt
+
+© 2024 Lady [@ Lady’s Computer].
+
+This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
+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/>.
+-->
+<transform
+ xmlns="http://www.w3.org/1999/XSL/Transform"
+ xmlns:exsl="http://exslt.org/common"
+ xmlns:exslstr="http://exslt.org/strings"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
+ extension-element-prefixes="exsl exslstr"
+ version="1.0"
+>
+ <template name="书社:sanitize-_amp_lt_gt">
+ <param name="source"/>
+ <choose>
+ <when test="contains($source, '&')">
+ <call-template name="书社:sanitize-_lt_gt">
+ <with-param name="source" select="substring-before($source, '&')"/>
+ </call-template>
+ <text>&amp;</text>
+ <call-template name="书社:sanitize-_amp_lt_gt">
+ <with-param name="source" select="substring-after($source, '&')"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <call-template name="书社:sanitize-_lt_gt">
+ <with-param name="source" select="$source"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="书社:sanitize-_amp_quot_lt_gt">
+ <param name="source"/>
+ <choose>
+ <when test="contains($source, '&')">
+ <call-template name="书社:sanitize-_quot_lt_gt">
+ <with-param name="source" select="substring-before($source, '&')"/>
+ </call-template>
+ <text>&amp;</text>
+ <call-template name="书社:sanitize-_amp_quot_lt_gt">
+ <with-param name="source" select="substring-after($source, '&')"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <call-template name="书社:sanitize-_quot_lt_gt">
+ <with-param name="source" select="$source"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="书社:sanitize-_gt">
+ <param name="source"/>
+ <choose>
+ <when test="contains($source, '>')">
+ <value-of select="substring-before($source, '>')"/>
+ <text>&gt;</text>
+ <call-template name="书社:sanitize-_gt">
+ <with-param name="source" select="substring-after($source, '>')"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <value-of select="$source"/>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="书社:sanitize-_lt_gt">
+ <param name="source"/>
+ <choose>
+ <when test="contains($source, '<')">
+ <call-template name="书社:sanitize-_gt">
+ <with-param name="source" select="substring-before($source, '<')"/>
+ </call-template>
+ <text>&lt;</text>
+ <call-template name="书社:sanitize-_lt_gt">
+ <with-param name="source" select="substring-after($source, '<')"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <call-template name="书社:sanitize-_gt">
+ <with-param name="source" select="$source"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="书社:sanitize-_quot_lt_gt">
+ <param name="source"/>
+ <choose>
+ <when test="contains($source, '"')">
+ <call-template name="书社:sanitize-_lt_gt">
+ <with-param name="source" select="substring-before($source, '"')"/>
+ </call-template>
+ <text>&quot;</text>
+ <call-template name="书社:sanitize-_quot_lt_gt">
+ <with-param name="source" select="substring-after($source, '"')"/>
+ </call-template>
+ </when>
+ <otherwise>
+ <call-template name="书社:sanitize-_lt_gt">
+ <with-param name="source" select="$source"/>
+ </call-template>
+ </otherwise>
+ </choose>
+ </template>
+ <template name="书社:serialize-attribute-value">
+ <param name="source"/>
+ <call-template name="书社:sanitize-_amp_quot_lt_gt">
+ <with-param name="source" select="string($source)"/>
+ </call-template>
+ </template>
+ <template name="书社:serialize-text-value">
+ <param name="source"/>
+ <call-template name="书社:sanitize-_amp_lt_gt">
+ <with-param name="source" select="string($source)"/>
+ </call-template>
+ </template>
+ <template match="node()" mode="书社:serialize">
+ <param name="namespace" select="''"/>
+ <param name="declare-namespaces" select="''"/>
+ <param name="prefix-map">
+ <html:dl>
+ <html:div>
+ <html:dt>xml</html:dt>
+ <html:dd>http://www.w3.org/XML/1998/namespace</html:dd>
+ </html:div>
+ </html:dl>
+ </param>
+ <variable name="namespaces-to-declare" select="exslstr:tokenize($declare-namespaces)"/>
+ <choose>
+ <when test="self::*">
+ <variable name="local-namespace" select="string(namespace::*[local-name()=''])"/>
+ <variable name="local-prefixes" select="namespace::*[local-name()!='' and local-name()!='xml']"/>
+ <variable name="local-prefixes-map">
+ <html:dl>
+ <html:div>
+ <html:dt>xml</html:dt>
+ <html:dd>http://www.w3.org/XML/1998/namespace</html:dd>
+ </html:div>
+ <for-each select="exsl:node-set($prefix-map)//html:div">
+ <if test="string(html:dt)!='xml' and not($local-prefixes[local-name()=string(current()/html:dt)])">
+ <copy-of select="."/>
+ </if>
+ </for-each>
+ <for-each select="$local-prefixes">
+ <html:div>
+ <html:dt>
+ <value-of select="local-name()"/>
+ </html:dt>
+ <html:dd>
+ <value-of select="string(.)"/>
+ </html:dd>
+ </html:div>
+ </for-each>
+ </html:dl>
+ </variable>
+ <variable name="qualified-name">
+ <choose>
+ <when test="$namespace=namespace-uri()">
+ <if test="$namespace='http://www.w3.org/XML/1998/namespace'">
+ <text>xml:</text>
+ </if>
+ <value-of select="local-name()"/>
+ </when>
+ <otherwise>
+ <value-of select="name()"/>
+ </otherwise>
+ </choose>
+ </variable>
+ <text><</text>
+ <value-of select="$qualified-name"/>
+ <if test="$local-namespace!=$namespace or $namespaces-to-declare[string(.)=$local-namespace]">
+ <text> xmlns="</text>
+ <call-template name="书社:serialize-attribute-value">
+ <with-param name="source" select="$local-namespace"/>
+ </call-template>
+ <text>"</text>
+ </if>
+ <for-each select="exsl:node-set($local-prefixes-map)//html:div">
+ <if test="$namespaces-to-declare[string(.)=string(current()/html:dd)] or string(html:dt)!='xml' and not(exsl:node-set($prefix-map)//html:div[string(html:dt)=string(current()/html:dt) and string(html:dd)=string(current()/html:dd)])">
+ <text> xmlns:</text>
+ <value-of select="html:dt"/>
+ <text>="</text>
+ <call-template name="书社:serialize-attribute-value">
+ <with-param name="source" select="string(html:dd)"/>
+ </call-template>
+ <text>"</text>
+ </if>
+ </for-each>
+ <for-each select="@*">
+ <text> </text>
+ <choose>
+ <when test="namespace-uri()='http://www.w3.org/XML/1998/namespace'">
+ <text>xml:</text>
+ <value-of select="local-name()"/>
+ </when>
+ <otherwise>
+ <value-of select="name()"/>
+ </otherwise>
+ </choose>
+ <text>="</text>
+ <call-template name="书社:serialize-attribute-value">
+ <with-param name="source" select="string(.)"/>
+ </call-template>
+ <text>"</text>
+ </for-each>
+ <choose>
+ <when test="node()">
+ <text>></text>
+ <apply-templates mode="书社:serialize">
+ <with-param name="namespace" select="$local-namespace"/>
+ <with-param name="prefix-map" select="$local-prefixes-map"/>
+ </apply-templates>
+ <text></</text>
+ <value-of select="$qualified-name"/>
+ <text>></text>
+ </when>
+ <otherwise>
+ <text>/></text>
+ </otherwise>
+ </choose>
+ </when>
+ <when test="node()">
+ <apply-templates mode="书社:serialize">
+ <with-param name="namespace" select="$namespace"/>
+ <with-param name="prefix-map" select="$prefix-map"/>
+ </apply-templates>
+ </when>
+ <when test="self::comment()">
+ <text><!--</text>
+ <value-of select="."/>
+ <text>--></text>
+ </when>
+ <when test="self::text()">
+ <call-template name="书社:serialize-text-value">
+ <with-param name="source" select="string(.)"/>
+ </call-template>
+ </when>
+ <when test="self::processing-instruction()">
+ <text><?</text>
+ <value-of select="local-name()"/>
+ <text> </text>
+ <value-of select="."/>
+ <text>?></text>
+ </when>
+ <otherwise/>
+ </choose>
+ </template>
+</transform>