3 SPDX-FileCopyrightText: 2023, 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ ⛩📰 书社 ∷ lib/catalog2transform.xslt
9 © 2023–2025 Lady [@ Ladys 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 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
16 <!ENTITY xhtml "http://www.w3.org/1999/xhtml">
17 <!ENTITY xml "http://www.w3.org/XML/1998/namespace">
20 xmlns="http://www.w3.org/1999/XSL/Transform"
21 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
22 xmlns:exsl="http://exslt.org/common"
23 xmlns:exslfunc="http://exslt.org/functions"
24 xmlns:exslstr="http://exslt.org/strings"
26 xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
27 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
28 xmlns:svg="http://www.w3.org/2000/svg"
29 xmlns:xlink="http://www.w3.org/1999/xlink"
30 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
31 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
32 xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
33 exclude-result-prefixes="catalog"
36 <include href="literally.xslt"/>
37 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
38 <param name="METADATA" select="'about:blank'"/>
39 <variable name="builddir" select="document($METADATA)//书社vocab:BuildDirectory/@nfo:fileUrl"/>
42 <for-each select="//catalog:uri[@name]">
44 <value-of select="@name"/>
48 <variable name="unique-ids">
49 <for-each select="exsl:node-set($ids)/*">
50 <if test="not(preceding-sibling::*[string(.)=string(current())])">
55 <xslt:transform exclude-result-prefixes="nfo 书社vocab" extension-element-prefixes="exsl exslfunc exslstr" version="1.0">
56 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
57 <xslt:param name="DESTINATION" select="false()"/>
58 <xslt:param name="IDENTIFIER" select="false()"/>
59 <xslt:param name="SRCREV" select="false()"/>
60 <xslt:param name="THISREV" select="false()"/>
61 <element name="exslfunc:function">
62 <attribute name="name">
63 <text>书社:document-with-attributes-applied</text>
65 <xslt:param name="document" select="/.."/>
66 <xslt:variable name="application-result-fragment">
67 <xslt:variable name="result-nodes" select="$document/node()[not(self::书社:apply-attributes-to-root)]|$document/书社:apply-attributes-to-root//node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
68 <xslt:variable name="root-with-attributes">
69 <xslt:call-template name="书社:apply-attributes">
70 <xslt:with-param name="context-nodes" select="$document//书社:apply-attributes-to-root"/>
71 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
74 <xslt:apply-templates select="exsl:node-set($root-with-attributes)" mode="书社:apply"/>
76 <element name="exslfunc:result">
77 <attribute name="select">
78 <text>exsl:node-set($application-result-fragment)</text>
82 <xslt:variable name="书社:source" select="/"/>
83 <xslt:variable name="书社:about-fragment">
84 <apply-templates select="document($METADATA)" mode="书社:literally">
85 <with-param name="extension-element-namespaces" select="'http://exslt.org/common http://exslt.org/functions http://exslt.org/strings'"/>
88 <xslt:variable name="书社:about" select="exsl:node-set($书社:about-fragment)"/>
89 <for-each select="//catalog:uri">
90 <xslt:include href="{@uri}">
91 <attribute name="书社:id">
92 <value-of select="@name"/>
96 <xslt:variable name="书社:expansion-fragment">
97 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
99 <xslt:variable name="书社:expansion" select="书社:document-with-attributes-applied(exsl:node-set($书社:expansion-fragment))"/>
100 <xslt:variable name="书社:result-fragment">
101 <xslt:element name="书社:apply-attributes-to-root">
102 <xslt:attribute name="书社:version">
103 <xslt:value-of select="$THISREV"/>
105 <xslt:apply-templates select="$书社:expansion/node()"/>
108 <xslt:variable name="书社:result" select="书社:document-with-attributes-applied(exsl:node-set($书社:result-fragment))"/>
109 <xslt:variable name="书社:destination" select="string($书社:about//*[@rdf:about=$IDENTIFIER]/@书社vocab:destination)"/>
110 <xslt:template name="书社:apply-attributes">
111 <xslt:param name="context-nodes" select="/.."/>
112 <xslt:param name="destination-nodes" select="/.."/>
113 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
114 <xslt:for-each select="$destination-nodes">
115 <xslt:variable name="existing-attributes" select="@*"/>
117 <xslt:when test="self::*">
118 <xslt:variable name="context" select="."/>
119 <xslt:variable name="attribute-names">
120 <xslt:for-each select="$existing-attributes|$additional-attributes">
122 <attribute name="local-name">
123 <text>{local-name()}</text>
125 <attribute name="name">
126 <text>{name()}</text>
128 <attribute name="namespace-uri">
129 <text>{namespace-uri()}</text>
134 <xslt:variable name="lang">
136 <xslt:when test="(self::html:*|self::svg:*)/@lang">
137 <xslt:value-of select="@lang"/>
139 <xslt:when test="@xml:lang">
140 <xslt:value-of select="@xml:lang"/>
142 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
143 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
145 <xslt:when test="(self::html:* or self::svg:*) and $additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']">
146 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
148 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
149 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
154 <xslt:if test="string($lang)!=''">
155 <xslt:if test="self::html:* or self::svg:*">
156 <xslt:attribute name="lang">
157 <xslt:value-of select="$lang"/>
160 <xslt:attribute name="xml:lang">
161 <xslt:value-of select="$lang"/>
164 <xslt:for-each select="exsl:node-set($attribute-names)/*">
166 <xslt:when test="@namespace-uri='&xml;'"/>
167 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
168 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping')"/>
169 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
172 <attribute name="name">
175 <attribute name="namespace">
176 <text>{@namespace-uri}</text>
178 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
179 <xslt:value-of select="."/>
180 <xslt:if test="position()!=last()">
186 <xslt:if test="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri] and $additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
191 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
192 <xslt:value-of select="."/>
193 <xslt:if test="position()!=last()">
203 <xslt:copy-of select="node()"/>
207 <xslt:copy-of select="."/>
212 <xslt:template name="书社:wrap">
213 <xslt:param name="nodes" select="/.."/>
214 <xslt:variable name="modalinput-fragment">
215 <xslt:copy-of select="$nodes"/>
216 <apply-templates select="exsl:node-set($unique-ids)" mode="书社:literally"/>
218 <xslt:variable name="modalinput" select="exsl:node-set($modalinput-fragment)"/>
219 <xslt:variable name="metadata-fragment">
220 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
221 <xslt:apply-templates select="$modalinput/node()" mode="书社:metadata"/>
223 <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
224 <xslt:element name="html" namespace="&xhtml;">
225 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
226 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
227 <xslt:attribute name="书社:archived-as">
228 <xslt:value-of select="$nodes/@书社:archived-as"/>
231 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
232 <xslt:attribute name="lang">
233 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
236 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
237 <xslt:attribute name="xml:lang">
238 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
241 <xslt:element name="head" namespace="&xhtml;">
242 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
243 <xslt:element name="title" namespace="&xhtml;">
244 <xslt:for-each select="$metadata/html:title">
245 <xslt:value-of select="."/>
246 <xslt:if test="position()!=last()">
253 <xslt:copy-of select="$metadata/node()[not(self::html:title or self::html:meta and @name='generator')]"/>
254 <xslt:element name="meta" namespace="&xhtml;">
255 <xslt:attribute name="name">
257 <text>generator</text>
260 <xslt:attribute name="content">
261 <xslt:for-each select="$metadata/html:meta[@name='generator']">
262 <xslt:value-of select="@content"/>
270 <xslt:if test="$THISREV">
274 <xslt:value-of select="$THISREV"/>
282 <xslt:element name="body" namespace="&xhtml;">
283 <xslt:copy-of select="($nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*)[not(namespace-uri()='&书社;' and local-name()='archived-as')]"/>
284 <xslt:apply-templates select="$modalinput/node()" mode="书社:header"/>
285 <xslt:for-each select="$nodes[not(self::html:html or self::html:head or self::html:body)]|$nodes[self::html:html]/node()[not(self::html:head or self::html:body)]|$nodes[self::html:html]/html:body/node()|$nodes[self::html:body]/node()">
287 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
290 <xslt:apply-templates select="$modalinput/node()" mode="书社:footer"/>
294 <xslt:template match="/">
295 <xslt:variable name="finalization-fragment">
296 <xslt:apply-templates select="$书社:result" mode="书社:finalize"/>
298 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
300 <xslt:template match="@*|node()" priority="-1">
302 <xslt:apply-templates select="@*|node()"/>
305 <xslt:template match="书社:apply-attributes" mode="书社:apply" priority="1">
306 <xslt:variable name="children">
307 <xslt:apply-templates mode="书社:apply"/>
309 <xslt:call-template name="书社:apply-attributes">
310 <xslt:with-param name="context-nodes" select="."/>
311 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
312 </xslt:call-template>
314 <xslt:template match="书社:apply-attributes-to-root" mode="书社:apply" priority="1">
315 <xslt:apply-templates mode="书社:apply"/>
317 <xslt:template match="@*|node()" mode="书社:apply" priority="-1">
319 <xslt:apply-templates select="@*|node()" mode="书社:apply"/>
322 <xslt:template match="@*|node()" mode="书社:expand" priority="-1">
324 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
327 <xslt:template match="text()" mode="书社:header" priority="-1"/>
328 <xslt:template match="书社:archive" mode="书社:finalize" priority="1">
330 <xslt:apply-templates select="@*" mode="书社:finalize"/>
331 <xslt:for-each select="node()">
333 <xslt:when test="self::*">
334 <xslt:variable name="component-fragment">
337 <xslt:when test="self::html:*">
338 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
339 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
340 <xslt:attribute name="itemtype">
341 <xslt:for-each select="$existing-types/token">
342 <xslt:if test="position()!=1">
347 <xslt:value-of select="."/>
349 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
350 <xslt:if test="$existing-types/token">
356 <text>&书社;:document</text>
360 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
363 <xslt:copy-of select="@*|node()"/>
368 <xslt:variable name="finalization-fragment">
369 <xslt:apply-templates select="exsl:node-set($component-fragment)" mode="书社:finalize"/>
371 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
374 <xslt:apply-templates select="." mode="书社:finalize"/>
380 <xslt:template match="@书社:destination|@书社:disable-output-wrapping" mode="书社:finalize" priority="1"/>
381 <xslt:template match="/" mode="书社:finalize">
383 <xslt:when test="not(html:*) or 书社:raw-text or 书社:base64-binary or 书社:archive or */@书社:disable-output-wrapping">
384 <xslt:apply-templates mode="书社:finalize"/>
387 <xslt:variable name="wrapped-result">
388 <xslt:call-template name="书社:wrap">
389 <xslt:with-param name="nodes" select="node()"/>
390 </xslt:call-template>
392 <xslt:apply-templates select="exsl:node-set($wrapped-result)/node()" mode="书社:finalize"/>
396 <xslt:template match="@*|node()" mode="书社:finalize" priority="-1">
398 <xslt:apply-templates select="@*|node()" mode="书社:finalize"/>
401 <xslt:template match="text()" mode="书社:footer" priority="-1"/>
402 <xslt:template match="text()" mode="书社:metadata" priority="-1"/>
403 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
406 <output method="xml" encoding="UTF-8"/>