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 [@ 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 xml "http://www.w3.org/XML/1998/namespace">
19 xmlns="http://www.w3.org/1999/XSL/Transform"
20 xmlns:dct="http://purl.org/dc/terms/"
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:html="http://www.w3.org/1999/xhtml"
25 xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
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="nie nfo" extension-element-prefixes="exsl exslstr" version="1.0">
56 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
57 <xslt:param name="IDENTIFIER" select="false()"/>
58 <xslt:param name="SRCREV" select="false()"/>
59 <xslt:param name="THISREV" select="false()"/>
60 <xslt:variable name="书社:source" select="/"/>
61 <xslt:variable name="书社:about-fragment">
62 <apply-templates select="document($METADATA)" mode="书社:literally">
63 <with-param name="extension-element-namespaces" select="'http://exslt.org/common http://exslt.org/strings'"/>
66 <xslt:variable name="书社:about" select="exsl:node-set($书社:about-fragment)"/>
67 <xslt:variable name="书社:expansion-fragment">
68 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
70 <xslt:variable name="书社:expansion" select="exsl:node-set($书社:expansion-fragment)"/>
71 <xslt:variable name="书社:result-fragment">
72 <xslt:apply-templates select="$书社:expansion/node()"/>
74 <xslt:variable name="书社:result" select="exsl:node-set($书社:result-fragment)"/>
75 <xslt:variable name="书社:destination" select="string($书社:about//*[@rdf:about=$IDENTIFIER]/@书社vocab:destination)"/>
76 <for-each select="//catalog:uri">
77 <xslt:include href="{@uri}">
78 <attribute name="书社:id">
79 <value-of select="@name"/>
83 <xslt:template name="书社:apply-attributes">
84 <xslt:param name="and-version" select="false()"/>
85 <xslt:param name="context-nodes" select="/.."/>
86 <xslt:param name="destination-nodes" select="/.."/>
87 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
88 <xslt:for-each select="$destination-nodes">
89 <xslt:variable name="existing-attributes" select="@*"/>
91 <xslt:when test="self::*">
92 <xslt:variable name="context" select="."/>
93 <xslt:variable name="attribute-names">
94 <xslt:for-each select="$existing-attributes|$additional-attributes">
96 <attribute name="local-name">
97 <text>{local-name()}</text>
99 <attribute name="name">
100 <text>{name()}</text>
102 <attribute name="namespace-uri">
103 <text>{namespace-uri()}</text>
108 <xslt:variable name="lang">
110 <xslt:when test="(self::html:*|self::svg:*)/@lang">
111 <xslt:value-of select="@lang"/>
113 <xslt:when test="@xml:lang">
114 <xslt:value-of select="@xml:lang"/>
116 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
117 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
119 <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']">
120 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
122 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
123 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
128 <xslt:if test="$and-version and $THISREV">
129 <xslt:attribute name="书社:version">
130 <xslt:value-of select="$THISREV"/>
133 <xslt:if test="string($lang)!=''">
134 <xslt:if test="self::html:* or self::svg:*">
135 <xslt:attribute name="lang">
136 <xslt:value-of select="$lang"/>
139 <xslt:attribute name="xml:lang">
140 <xslt:value-of select="$lang"/>
143 <xslt:for-each select="exsl:node-set($attribute-names)/*">
145 <xslt:when test="@namespace-uri='&xml;'"/>
146 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
147 <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])"/>
148 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
149 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
152 <attribute name="name">
155 <attribute name="namespace">
156 <text>{@namespace-uri}</text>
158 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
159 <xslt:value-of select="."/>
160 <xslt:if test="position()!=last()">
166 <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]">
171 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
172 <xslt:value-of select="."/>
173 <xslt:if test="position()!=last()">
183 <xslt:copy-of select="node()"/>
187 <xslt:copy-of select="."/>
192 <xslt:template name="书社:wrap">
193 <xslt:param name="nodes" select="/.."/>
194 <xslt:variable name="modalinput-fragment">
195 <xslt:copy-of select="$nodes"/>
196 <apply-templates select="exsl:node-set($unique-ids)" mode="书社:literally"/>
198 <xslt:variable name="modalinput" select="exsl:node-set($modalinput-fragment)"/>
199 <xslt:variable name="metadata-fragment">
200 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
201 <xslt:apply-templates select="$modalinput/node()" mode="书社:metadata"/>
203 <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
205 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
206 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
207 <xslt:attribute name="书社:archived-as">
208 <xslt:value-of select="$nodes/@书社:archived-as"/>
211 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
212 <xslt:attribute name="lang">
213 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
216 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
217 <xslt:attribute name="xml:lang">
218 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
222 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
224 <xslt:for-each select="$metadata/html:title">
225 <xslt:value-of select="."/>
226 <xslt:if test="position()!=last()">
233 <xslt:copy-of select="$metadata/node()[not(self::html:title or self::html:meta and @name='generator')]"/>
234 <html:meta name="generator">
235 <xslt:attribute name="content">
236 <xslt:for-each select="$metadata/html:meta[@name='generator']">
237 <xslt:value-of select="@content"/>
245 <xslt:if test="$THISREV">
249 <xslt:value-of select="$THISREV"/>
258 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
259 <xslt:apply-templates select="$modalinput/node()" mode="书社:header"/>
260 <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()"/>
261 <xslt:apply-templates select="$modalinput/node()" mode="书社:footer"/>
265 <xslt:template match="/" priority="1">
266 <xslt:variable name="result-nodes" select="$书社:result/node()[not(self::书社:apply-attributes-to-root)]|$书社:result/书社:apply-attributes-to-root/descendant::node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
267 <xslt:variable name="root-with-attributes">
269 <xslt:when test="not($result-nodes/self::html:*) or $result-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $result-nodes/@书社:disable-output-wrapping or $书社:result//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
270 <xslt:call-template name="书社:apply-attributes">
271 <xslt:with-param name="and-version" select="true()"/>
272 <xslt:with-param name="context-nodes" select="$书社:result//书社:apply-attributes-to-root"/>
273 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
274 </xslt:call-template>
277 <xslt:variable name="wrapped-result">
278 <xslt:call-template name="书社:wrap">
279 <xslt:with-param name="nodes" select="$result-nodes"/>
280 </xslt:call-template>
282 <xslt:call-template name="书社:apply-attributes">
283 <xslt:with-param name="and-version" select="true()"/>
284 <xslt:with-param name="context-nodes" select="$书社:result//书社:apply-attributes-to-root"/>
285 <xslt:with-param name="destination-nodes" select="exsl:node-set($wrapped-result)/node()"/>
286 </xslt:call-template>
290 <xslt:apply-templates select="exsl:node-set($root-with-attributes)/node()" mode="书社:apply"/>
292 <xslt:template match="@*|node()" priority="-1">
294 <xslt:apply-templates select="@*|node()"/>
297 <xslt:template match="@书社:destination|@书社:disable-output-wrapping|@书社:archived-as[../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]]" mode="书社:apply" priority="1"/>
298 <xslt:template match="书社:archive" mode="书社:apply" priority="1">
300 <xslt:for-each select="@*">
302 <xslt:when test="local-name()='archived-as' and namespace-uri()='&书社;' and ../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]"/>
304 <xslt:apply-templates select="." mode="书社:apply"/>
308 <xslt:for-each select="node()">
310 <xslt:when test="self::*">
311 <xslt:variable name="component">
313 <xslt:when test="self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|@书社:disable-output-wrapping">
314 <xslt:copy-of select="."/>
317 <xslt:call-template name="书社:wrap">
318 <xslt:with-param name="nodes" select="."/>
319 </xslt:call-template>
323 <xslt:apply-templates select="exsl:node-set($component)/node()" mode="书社:apply"/>
326 <xslt:apply-templates select="." mode="书社:apply"/>
332 <xslt:template match="书社:apply-attributes" mode="书社:apply" priority="1">
333 <xslt:variable name="children">
334 <xslt:apply-templates mode="书社:apply"/>
336 <xslt:call-template name="书社:apply-attributes">
337 <xslt:with-param name="context-nodes" select="."/>
338 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
339 </xslt:call-template>
341 <xslt:template match="书社:apply-attributes-to-root" mode="书社:apply" priority="1">
342 <xslt:apply-templates mode="书社:apply"/>
344 <xslt:template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
345 <xslt:variable name="identifier" select="string(@xlink:href)"/>
346 <xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier]"/>
348 <xslt:when test="$included">
349 <xslt:variable name="uri" select="$included/书社vocab:hasParsedFile/@nfo:fileUrl"/>
350 <xslt:variable name="expanded">
351 <xslt:apply-templates select="document($uri)" mode="书社:expand">
352 <xslt:with-param name="identifier" select="$identifier"/>
353 </xslt:apply-templates>
355 <xslt:for-each select="exsl:node-set($expanded)/node()">
358 <xslt:when test="self::html:*">
359 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
360 <xslt:attribute name="itemtype">
362 <text>&书社;:embed</text>
364 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
368 <xslt:value-of select="."/>
371 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
374 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
382 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
387 <xslt:template match="@*|node()" mode="书社:apply" priority="-1">
389 <xslt:apply-templates select="@*|node()" mode="书社:apply"/>
392 <xslt:template match="/node()" mode="书社:expand" priority="0">
393 <xslt:param name="identifier" select="$IDENTIFIER"/>
395 <xslt:if test="self::*">
396 <xslt:attribute name="书社:cksum">
397 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
399 <xslt:attribute name="书社:identifier">
400 <xslt:value-of select="$identifier"/>
402 <xslt:attribute name="书社:mtime">
403 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:fileLastModified"/>
407 <xslt:when test="self::html:*">
408 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
409 <xslt:attribute name="itemtype">
411 <text>&书社;:document</text>
413 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
417 <xslt:value-of select="."/>
420 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype') or namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
423 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
428 <xslt:template match="@*|node()" mode="书社:expand" priority="-1">
430 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
433 <xslt:template match="text()" mode="书社:header"/>
434 <xslt:template match="text()" mode="书社:footer"/>
435 <xslt:template match="text()" mode="书社:metadata"/>
436 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
439 <output method="xml" encoding="UTF-8"/>