3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ ⛩️📰 书社 ∷ lib/catalog2transform.xslt
9 © 2023–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 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
16 <!ENTITY xml "http://www.w3.org/XML/1998/namespace">
19 xmlns="http://www.w3.org/1999/XSL/Transform"
20 xmlns:html="http://www.w3.org/1999/xhtml"
21 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
22 xmlns:exsl="http://exslt.org/common"
23 xmlns:exslstr="http://exslt.org/strings"
24 xmlns:svg="http://www.w3.org/2000/svg"
25 xmlns:xlink="http://www.w3.org/1999/xlink"
26 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
27 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
30 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
32 <xslt:transform exclude-result-prefixes="catalog" extension-element-prefixes="exsl exslstr" version="1.0">
33 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
34 <xslt:param name="CKSUM" select="false()"/>
35 <xslt:param name="CATALOG" select="'catalog'"/>
36 <xslt:param name="IDENTIFIER" select="false()"/>
37 <xslt:param name="PATH" select="'/unknown'"/>
38 <xslt:param name="SRCREV" select="false()"/>
39 <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
40 <xslt:param name="THISREV" select="false()"/>
41 <xslt:variable name="书社:source" select="/"/>
42 <xslt:variable name="书社:expansion">
43 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
45 <xslt:variable name="书社:result">
46 <xslt:apply-templates select="exsl:node-set($书社:expansion)/node()"/>
48 <xslt:variable name="书社:destination">
50 <xslt:when test="string($书社:source/@书社:destination)!=''">
51 <xslt:value-of select="$书社:source/@书社:destination"/>
53 <xslt:when test="starts-with($PATH, '/')">
54 <xslt:value-of select="substring-after($PATH, '/')"/>
57 <xslt:value-of select="$PATH"/>
61 <for-each select="//catalog:uri">
62 <xslt:include href="{@uri}">
63 <if test="contains(@name, ':')">
64 <attribute name="书社:id">
65 <value-of select="@name"/>
70 <xslt:template name="书社:apply-attributes">
71 <xslt:param name="and-version" select="false()"/>
72 <xslt:param name="context-nodes" select="/.."/>
73 <xslt:param name="destination-nodes" select="/.."/>
74 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
75 <xslt:for-each select="$destination-nodes">
76 <xslt:variable name="existing-attributes" select="@*"/>
78 <xslt:when test="self::*">
79 <xslt:variable name="context" select="."/>
80 <xslt:variable name="attribute-names">
81 <xslt:for-each select="$existing-attributes|$additional-attributes">
83 <attribute name="local-name">
84 <text>{local-name()}</text>
86 <attribute name="name">
89 <attribute name="namespace-uri">
90 <text>{namespace-uri()}</text>
95 <xslt:variable name="lang">
97 <xslt:when test="(self::html:*|self::svg:*)/@lang">
98 <xslt:value-of select="@lang"/>
100 <xslt:when test="@xml:lang">
101 <xslt:value-of select="@xml:lang"/>
103 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
104 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
106 <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']">
107 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
109 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
110 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
115 <xslt:if test="$and-version and $THISREV">
116 <xslt:attribute name="书社:version">
117 <xslt:value-of select="$THISREV"/>
120 <xslt:if test="string($lang)!=''">
121 <xslt:if test="self::html:* or self::svg:*">
122 <xslt:attribute name="lang">
123 <xslt:value-of select="$lang"/>
126 <xslt:attribute name="xml:lang">
127 <xslt:value-of select="$lang"/>
130 <xslt:for-each select="exsl:node-set($attribute-names)/*">
132 <xslt:when test="@namespace-uri='&xml;'"/>
133 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
134 <xslt:when test="@namespace-uri='&书社;' and @local-name='archived-as' and not($context-nodes/ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)][1][self::书社:archive])"/>
135 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
136 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
139 <attribute name="name">
142 <attribute name="namespace">
143 <text>{@namespace-uri}</text>
145 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
146 <xslt:value-of select="."/>
147 <xslt:if test="position()!=last()">
153 <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]">
158 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
159 <xslt:value-of select="."/>
160 <xslt:if test="position()!=last()">
170 <xslt:copy-of select="node()"/>
174 <xslt:copy-of select="."/>
179 <xslt:template name="书社:wrap">
180 <xslt:param name="nodes" select="/.."/>
181 <xslt:variable name="modalinput">
182 <xslt:copy-of select="$nodes"/>
183 <xslt:copy-of select="document('')/xslt:transform/xslt:include"/>
185 <xslt:variable name="metadata">
186 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
187 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:metadata"/>
190 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
191 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
192 <xslt:attribute name="书社:archived-as">
193 <xslt:value-of select="$nodes/@书社:archived-as"/>
196 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
197 <xslt:attribute name="lang">
198 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
201 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
202 <xslt:attribute name="xml:lang">
203 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
207 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
209 <xslt:for-each select="exsl:node-set($metadata)/html:title">
210 <xslt:value-of select="."/>
211 <xslt:if test="position()!=last()">
218 <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::html:title)]"/>
219 <html:meta name="generator">
220 <xslt:attribute name="content">
221 <xslt:for-each select="exsl:node-set($metadata)/html:meta[@name='generator']">
222 <xslt:value-of select="@content"/>
230 <xslt:if test="$THISREV">
234 <xslt:value-of select="$THISREV"/>
243 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
244 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:header"/>
245 <xslt:copy-of 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()"/>
246 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:footer"/>
250 <xslt:template match="/" priority="1">
251 <xslt:variable name="result-nodes" select="exsl:node-set($书社:result)/node()[not(self::书社:apply-attributes-to-root)]|exsl:node-set($书社:result)/书社:apply-attributes-to-root/descendant::node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
252 <xslt:variable name="root-with-attributes">
254 <xslt:when test="$result-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|$result-nodes/@书社:disable-output-wrapping|exsl:node-set($书社:result)//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
255 <xslt:call-template name="书社:apply-attributes">
256 <xslt:with-param name="and-version" select="true()"/>
257 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
258 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
259 </xslt:call-template>
262 <xslt:variable name="wrapped-result">
263 <xslt:call-template name="书社:wrap">
264 <xslt:with-param name="nodes" select="$result-nodes"/>
265 </xslt:call-template>
267 <xslt:call-template name="书社:apply-attributes">
268 <xslt:with-param name="and-version" select="true()"/>
269 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
270 <xslt:with-param name="destination-nodes" select="exsl:node-set($wrapped-result)/node()"/>
271 </xslt:call-template>
275 <xslt:apply-templates select="exsl:node-set($root-with-attributes)/node()" mode="书社:application"/>
277 <xslt:template match="@*|node()" priority="-1">
279 <xslt:apply-templates select="@*|node()"/>
282 <xslt:template match="@*|node()" mode="书社:application">
284 <xslt:apply-templates select="@*|node()" mode="书社:application"/>
287 <xslt:template match="@书社:destination|@书社:disable-output-wrapping|@书社:archived-as[../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]]" mode="书社:application" priority="1"/>
288 <xslt:template match="书社:archive" mode="书社:application" priority="1">
290 <xslt:for-each select="@*">
292 <xslt:when test="local-name()='archived-as' and namespace-uri()='&书社;' and ../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]"/>
294 <xslt:apply-templates select="." mode="书社:application"/>
298 <xslt:for-each select="node()">
300 <xslt:when test="self::*">
301 <xslt:variable name="component">
303 <xslt:when test="self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|@书社:disable-output-wrapping">
304 <xslt:copy-of select="."/>
307 <xslt:call-template name="书社:wrap">
308 <xslt:with-param name="nodes" select="."/>
309 </xslt:call-template>
313 <xslt:apply-templates select="exsl:node-set($component)/node()" mode="书社:application"/>
316 <xslt:apply-templates select="." mode="书社:application"/>
322 <xslt:template match="书社:apply-attributes" mode="书社:application" priority="1">
323 <xslt:variable name="children">
324 <xslt:apply-templates mode="书社:application"/>
326 <xslt:call-template name="书社:apply-attributes">
327 <xslt:with-param name="context-nodes" select="."/>
328 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
329 </xslt:call-template>
331 <xslt:template match="书社:apply-attributes-to-root" mode="书社:application" priority="1">
332 <xslt:apply-templates mode="书社:application"/>
334 <xslt:template match="/node()" mode="书社:expand" priority="0">
336 <xslt:attribute name="书社:identifier">
337 <xslt:value-of select="$IDENTIFIER"/>
340 <xslt:when test="self::html:*">
341 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
342 <xslt:attribute name="itemtype">
344 <text>&书社;:document</text>
346 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
350 <xslt:value-of select="."/>
353 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
356 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
361 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
362 <xslt:variable name="identifier" select="string(@xlink:href)"/>
363 <xslt:variable name="uri" select="substring-before(document($CATALOG)//catalog:uri[@name=$identifier]/@uri[1], '#')"/>
365 <xslt:when test="$uri">
366 <xslt:variable name="expanded">
367 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
369 <xslt:for-each select="exsl:node-set($expanded)/node()">
371 <xslt:attribute name="书社:identifier">
372 <xslt:value-of select="$identifier"/>
375 <xslt:when test="self::html:*">
376 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
377 <xslt:attribute name="itemtype">
379 <text>&书社;:embed</text>
381 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
385 <xslt:value-of select="."/>
388 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='identifier')]|node()"/>
391 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and local-name()='identifier')]|node()" mode="书社:expand"/>
399 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
404 <xslt:template match="@*|node()[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
406 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
409 <xslt:template match="text()" mode="书社:header"/>
410 <xslt:template match="text()" mode="书社:footer"/>
411 <xslt:template match="text()" mode="书社:metadata"/>
412 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
415 <output method="xml" encoding="UTF-8"/>