]> Lady’s Gitweb - Shushe/blobdiff - transforms/serialization.xslt
Add support for manually serializing X·M·L
[Shushe] / transforms / serialization.xslt
diff --git a/transforms/serialization.xslt b/transforms/serialization.xslt
new file mode 100644 (file)
index 0000000..09f595e
--- /dev/null
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!--
+SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
+SPDX-License-Identifier: MPL-2.0
+-->
+<!--
+⁌ ⛩️📰 书社 ∷ transforms/serialization.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"
+>
+       <import href="../lib/serialize.xslt"/>
+       <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:serialization.xslt</书社:id>
+       <template match="书社:serialize-xml" mode="书社:application" priority="1">
+               <variable name="namespaces" select="namespace::*"/>
+               <variable name="contents">
+                       <apply-templates mode="书社:application"/>
+               </variable>
+               <variable name="passthru-namespaces" select="exslstr:tokenize(string(@with-namespaces))"/>
+               <apply-templates select="exsl:node-set($contents)" mode="书社:serialize">
+                       <with-param name="namespace">
+                               <value-of select="namespace::*[local-name()='']"/>
+                       </with-param>
+                       <with-param name="declare-namespaces">
+                               <if test="$passthru-namespaces[string(.)='xml']">
+                                       <text> http://www.w3.org/XML/1998/namespace</text>
+                               </if>
+                               <for-each select="namespace::*[local-name()!='xml']">
+                                       <if test="local-name()='' and $passthru-namespaces[string(.)='#default'] or $passthru-namespaces[string(.)=local-name(current())]">
+                                               <text> </text>
+                                               <value-of select="string(.)"/>
+                                       </if>
+                               </for-each>
+                               <text> </text>
+                       </with-param>
+                       <with-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>
+                                       <for-each select="namespace::*[local-name()!='' and local-name()!='xml']">
+                                               <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>
+                       </with-param>
+               </apply-templates>
+       </template>
+</transform>
This page took 0.069462 seconds and 4 git commands to generate.