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:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
21 xmlns:exsl="http://exslt.org/common"
22 xmlns:exslfunc="http://exslt.org/functions"
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 exslfunc 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 <element name="exslfunc:function">
61 <attribute name="name">
62 <text>书社:document-with-attributes-applied</text>
64 <xslt:param name="document" select="/.."/>
65 <xslt:param name="and-version" select="false()"/>
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="significant-nodes" select="$result-nodes/descendant-or-self::*[not(self::书社:apply-attributes) and not(ancestor::*[not(self::书社:apply-attributes)])]"/>
69 <xslt:variable name="root-with-attributes">
70 <xslt:call-template name="书社:apply-attributes">
71 <xslt:with-param name="and-version" select="$and-version"/>
72 <xslt:with-param name="context-nodes" select="$document//书社:apply-attributes-to-root"/>
73 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
76 <xslt:apply-templates select="exsl:node-set($root-with-attributes)" mode="书社:apply"/>
78 <element name="exslfunc:result">
79 <attribute name="select">
80 <text>exsl:node-set($application-result-fragment)</text>
84 <xslt:variable name="书社:source" select="/"/>
85 <xslt:variable name="书社:about-fragment">
86 <apply-templates select="document($METADATA)" mode="书社:literally">
87 <with-param name="extension-element-namespaces" select="'http://exslt.org/common http://exslt.org/functions http://exslt.org/strings'"/>
90 <xslt:variable name="书社:about" select="exsl:node-set($书社:about-fragment)"/>
91 <xslt:variable name="书社:expansion-fragment">
92 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
94 <xslt:variable name="书社:expansion" select="书社:document-with-attributes-applied(exsl:node-set($书社:expansion-fragment))"/>
95 <xslt:variable name="书社:result-fragment">
96 <xslt:apply-templates select="$书社:expansion/node()"/>
98 <xslt:variable name="书社:result" select="书社:document-with-attributes-applied(exsl:node-set($书社:result-fragment))"/>
99 <xslt:variable name="书社:destination" select="string($书社:about//*[@rdf:about=$IDENTIFIER]/@书社vocab:destination)"/>
100 <for-each select="//catalog:uri">
101 <xslt:include href="{@uri}">
102 <attribute name="书社:id">
103 <value-of select="@name"/>
107 <xslt:template name="书社:apply-attributes">
108 <xslt:param name="and-version" select="false()"/>
109 <xslt:param name="context-nodes" select="/.."/>
110 <xslt:param name="destination-nodes" select="/.."/>
111 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
112 <xslt:for-each select="$destination-nodes">
113 <xslt:variable name="existing-attributes" select="@*"/>
115 <xslt:when test="self::*">
116 <xslt:variable name="context" select="."/>
117 <xslt:variable name="attribute-names">
118 <xslt:for-each select="$existing-attributes|$additional-attributes">
120 <attribute name="local-name">
121 <text>{local-name()}</text>
123 <attribute name="name">
124 <text>{name()}</text>
126 <attribute name="namespace-uri">
127 <text>{namespace-uri()}</text>
132 <xslt:variable name="lang">
134 <xslt:when test="(self::html:*|self::svg:*)/@lang">
135 <xslt:value-of select="@lang"/>
137 <xslt:when test="@xml:lang">
138 <xslt:value-of select="@xml:lang"/>
140 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
141 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
143 <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']">
144 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
146 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
147 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
152 <xslt:if test="$and-version and $THISREV">
153 <xslt:attribute name="书社:version">
154 <xslt:value-of select="$THISREV"/>
157 <xslt:if test="string($lang)!=''">
158 <xslt:if test="self::html:* or self::svg:*">
159 <xslt:attribute name="lang">
160 <xslt:value-of select="$lang"/>
163 <xslt:attribute name="xml:lang">
164 <xslt:value-of select="$lang"/>
167 <xslt:for-each select="exsl:node-set($attribute-names)/*">
169 <xslt:when test="@namespace-uri='&xml;'"/>
170 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
171 <xslt:when test="$and-version and $THISREV and @namespace-uri='&书社;' and @local-name='version'"/>
172 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping')"/>
173 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
176 <attribute name="name">
179 <attribute name="namespace">
180 <text>{@namespace-uri}</text>
182 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
183 <xslt:value-of select="."/>
184 <xslt:if test="position()!=last()">
190 <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]">
195 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
196 <xslt:value-of select="."/>
197 <xslt:if test="position()!=last()">
207 <xslt:copy-of select="node()"/>
211 <xslt:copy-of select="."/>
216 <xslt:template name="书社:wrap">
217 <xslt:param name="nodes" select="/.."/>
218 <xslt:variable name="modalinput-fragment">
219 <xslt:copy-of select="$nodes"/>
220 <apply-templates select="exsl:node-set($unique-ids)" mode="书社:literally"/>
222 <xslt:variable name="modalinput" select="exsl:node-set($modalinput-fragment)"/>
223 <xslt:variable name="metadata-fragment">
224 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
225 <xslt:apply-templates select="$modalinput/node()" mode="书社:metadata"/>
227 <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
229 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
230 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
231 <xslt:attribute name="书社:archived-as">
232 <xslt:value-of select="$nodes/@书社:archived-as"/>
235 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
236 <xslt:attribute name="lang">
237 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
240 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
241 <xslt:attribute name="xml:lang">
242 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
246 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
248 <xslt:for-each select="$metadata/html:title">
249 <xslt:value-of select="."/>
250 <xslt:if test="position()!=last()">
257 <xslt:copy-of select="$metadata/node()[not(self::html:title or self::html:meta and @name='generator')]"/>
258 <html:meta name="generator">
259 <xslt:attribute name="content">
260 <xslt:for-each select="$metadata/html:meta[@name='generator']">
261 <xslt:value-of select="@content"/>
269 <xslt:if test="$THISREV">
273 <xslt:value-of select="$THISREV"/>
282 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
283 <xslt:apply-templates select="$modalinput/node()" mode="书社:header"/>
284 <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()"/>
285 <xslt:apply-templates select="$modalinput/node()" mode="书社:footer"/>
289 <xslt:template match="/">
290 <xslt:variable name="finalization-fragment">
291 <xslt:apply-templates select="$书社:result" mode="书社:finalize"/>
293 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
295 <xslt:template match="@*|node()" priority="-1">
297 <xslt:apply-templates select="@*|node()"/>
300 <xslt:template match="书社:apply-attributes" mode="书社:apply" priority="1">
301 <xslt:variable name="children">
302 <xslt:apply-templates mode="书社:apply"/>
304 <xslt:call-template name="书社:apply-attributes">
305 <xslt:with-param name="context-nodes" select="."/>
306 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
307 </xslt:call-template>
309 <xslt:template match="书社:apply-attributes-to-root" mode="书社:apply" priority="1">
310 <xslt:apply-templates mode="书社:apply"/>
312 <xslt:template match="@*|node()" mode="书社:apply" priority="-1">
314 <xslt:apply-templates select="@*|node()" mode="书社:apply"/>
317 <xslt:template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
318 <xslt:variable name="link" select="."/>
319 <xslt:variable name="identifier" select="string(@xlink:href)"/>
320 <xslt:variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
321 <xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
323 <xslt:when test="$included">
324 <xslt:for-each select="$included">
325 <xslt:sort select="@rdf:about" data-type="text" lang="zxx" case-order="upper-first"/>
326 <xslt:variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
327 <xslt:variable name="expanded">
328 <xslt:apply-templates select="document($uri)" mode="书社:expand">
329 <xslt:with-param name="identifier" select="string(@rdf:about)"/>
330 </xslt:apply-templates>
332 <xslt:for-each select="exsl:node-set($expanded)/node()">
335 <xslt:when test="self::html:*">
336 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
337 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
338 <xslt:attribute name="itemtype">
339 <xslt:for-each select="$existing-types/token[string()!='&书社;:document']">
340 <xslt:if test="position()!=1">
345 <xslt:value-of select="."/>
347 <xslt:if test="not($existing-types/token[string()='&书社;:embed'])">
348 <xslt:if test="$existing-types/token[string()!='&书社;:document']">
354 <text>&书社;:embed</text>
359 <xslt:when test="$link/@书社:archived-as">
360 <xslt:copy-of select="$link/@书社:archived-as"/>
362 <xslt:when test="@书社:archived-as">
363 <xslt:copy-of select="@书社:archived-as"/>
366 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
370 <xslt:when test="self::* and $link/@书社:archived-as">
371 <xslt:copy-of select="$link/@书社:archived-as"/>
373 <xslt:when test="@书社:archived-as">
374 <xslt:copy-of select="@书社:archived-as"/>
377 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
386 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
391 <xslt:template match="/node()" mode="书社:expand" priority="0">
392 <xslt:param name="identifier" select="$IDENTIFIER"/>
394 <xslt:if test="self::*">
395 <xslt:attribute name="书社:cksum">
396 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
398 <xslt:attribute name="书社:identifier">
399 <xslt:value-of select="$identifier"/>
401 <xslt:attribute name="书社:mtime">
402 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:fileLastModified"/>
406 <xslt:when test="self::html:*">
407 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
408 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
409 <xslt:attribute name="itemtype">
410 <xslt:for-each select="$existing-types/token">
411 <xslt:if test="position()!=1">
416 <xslt:value-of select="."/>
418 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
419 <xslt:if test="$existing-types/token">
425 <text>&书社;:document</text>
429 <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"/>
432 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
437 <xslt:template match="@*|node()" mode="书社:expand" priority="-1">
439 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
442 <xslt:template match="text()" mode="书社:header"/>
443 <xslt:template match="书社:archive" mode="书社:finalize" priority="1">
445 <xslt:apply-templates select="@*" mode="书社:finalize"/>
446 <xslt:for-each select="node()">
448 <xslt:when test="self::*">
449 <xslt:variable name="component-fragment">
452 <xslt:when test="self::html:*">
453 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
454 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
455 <xslt:attribute name="itemtype">
456 <xslt:for-each select="$existing-types/token">
457 <xslt:if test="position()!=1">
462 <xslt:value-of select="."/>
464 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
465 <xslt:if test="$existing-types/token">
471 <text>&书社;:document</text>
475 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
478 <xslt:copy-of select="@*|node()"/>
483 <xslt:variable name="finalization-fragment">
484 <xslt:apply-templates select="exsl:node-set($component-fragment)" mode="书社:finalize"/>
486 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
489 <xslt:apply-templates select="." mode="书社:finalize"/>
495 <xslt:template match="@书社:destination|@书社:disable-output-wrapping" mode="书社:finalize" priority="1"/>
496 <xslt:template match="/" mode="书社:finalize">
498 <xslt:when test="not(html:*) or 书社:raw-text or 书社:base64-binary or 书社:archive or */@书社:disable-output-wrapping">
499 <xslt:apply-templates mode="书社:finalize"/>
502 <xslt:variable name="wrapped-result">
503 <xslt:call-template name="书社:wrap">
504 <xslt:with-param name="nodes" select="node()"/>
505 </xslt:call-template>
507 <xslt:apply-templates select="exsl:node-set($wrapped-result)/node()" mode="书社:finalize"/>
511 <xslt:template match="@*|node()" mode="书社:finalize" priority="-1">
513 <xslt:apply-templates select="@*|node()" mode="书社:finalize"/>
516 <xslt:template match="text()" mode="书社:footer"/>
517 <xslt:template match="text()" mode="书社:metadata"/>
518 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
521 <output method="xml" encoding="UTF-8"/>