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:variable name="application-result-fragment">
66 <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)])]"/>
67 <xslt:variable name="root-with-attributes">
68 <xslt:call-template name="书社:apply-attributes">
69 <xslt:with-param name="context-nodes" select="$document//书社:apply-attributes-to-root"/>
70 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
73 <xslt:apply-templates select="exsl:node-set($root-with-attributes)" mode="书社:apply"/>
75 <element name="exslfunc:result">
76 <attribute name="select">
77 <text>exsl:node-set($application-result-fragment)</text>
81 <xslt:variable name="书社:source" select="/"/>
82 <xslt:variable name="书社:about-fragment">
83 <apply-templates select="document($METADATA)" mode="书社:literally">
84 <with-param name="extension-element-namespaces" select="'http://exslt.org/common http://exslt.org/functions http://exslt.org/strings'"/>
87 <xslt:variable name="书社:about" select="exsl:node-set($书社:about-fragment)"/>
88 <xslt:variable name="书社:expansion-fragment">
89 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
91 <xslt:variable name="书社:expansion" select="书社:document-with-attributes-applied(exsl:node-set($书社:expansion-fragment))"/>
92 <xslt:variable name="书社:result-fragment">
93 <xslt:element name="书社:apply-attributes-to-root">
94 <xslt:attribute name="书社:version">
95 <xslt:value-of select="$THISREV"/>
97 <xslt:apply-templates select="$书社:expansion/node()"/>
100 <xslt:variable name="书社:result" select="书社:document-with-attributes-applied(exsl:node-set($书社:result-fragment))"/>
101 <xslt:variable name="书社:destination" select="string($书社:about//*[@rdf:about=$IDENTIFIER]/@书社vocab:destination)"/>
102 <for-each select="//catalog:uri">
103 <xslt:include href="{@uri}">
104 <attribute name="书社:id">
105 <value-of select="@name"/>
109 <xslt:template name="书社:apply-attributes">
110 <xslt:param name="context-nodes" select="/.."/>
111 <xslt:param name="destination-nodes" select="/.."/>
112 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
113 <xslt:for-each select="$destination-nodes">
114 <xslt:variable name="existing-attributes" select="@*"/>
116 <xslt:when test="self::*">
117 <xslt:variable name="context" select="."/>
118 <xslt:variable name="attribute-names">
119 <xslt:for-each select="$existing-attributes|$additional-attributes">
121 <attribute name="local-name">
122 <text>{local-name()}</text>
124 <attribute name="name">
125 <text>{name()}</text>
127 <attribute name="namespace-uri">
128 <text>{namespace-uri()}</text>
133 <xslt:variable name="lang">
135 <xslt:when test="(self::html:*|self::svg:*)/@lang">
136 <xslt:value-of select="@lang"/>
138 <xslt:when test="@xml:lang">
139 <xslt:value-of select="@xml:lang"/>
141 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
142 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
144 <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']">
145 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
147 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
148 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
153 <xslt:if test="string($lang)!=''">
154 <xslt:if test="self::html:* or self::svg:*">
155 <xslt:attribute name="lang">
156 <xslt:value-of select="$lang"/>
159 <xslt:attribute name="xml:lang">
160 <xslt:value-of select="$lang"/>
163 <xslt:for-each select="exsl:node-set($attribute-names)/*">
165 <xslt:when test="@namespace-uri='&xml;'"/>
166 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
167 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping')"/>
168 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
171 <attribute name="name">
174 <attribute name="namespace">
175 <text>{@namespace-uri}</text>
177 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
178 <xslt:value-of select="."/>
179 <xslt:if test="position()!=last()">
185 <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]">
190 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
191 <xslt:value-of select="."/>
192 <xslt:if test="position()!=last()">
202 <xslt:copy-of select="node()"/>
206 <xslt:copy-of select="."/>
211 <xslt:template name="书社:wrap">
212 <xslt:param name="nodes" select="/.."/>
213 <xslt:variable name="modalinput-fragment">
214 <xslt:copy-of select="$nodes"/>
215 <apply-templates select="exsl:node-set($unique-ids)" mode="书社:literally"/>
217 <xslt:variable name="modalinput" select="exsl:node-set($modalinput-fragment)"/>
218 <xslt:variable name="metadata-fragment">
219 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
220 <xslt:apply-templates select="$modalinput/node()" mode="书社:metadata"/>
222 <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
224 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
225 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
226 <xslt:attribute name="书社:archived-as">
227 <xslt:value-of select="$nodes/@书社:archived-as"/>
230 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
231 <xslt:attribute name="lang">
232 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
235 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
236 <xslt:attribute name="xml:lang">
237 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
241 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
243 <xslt:for-each select="$metadata/html:title">
244 <xslt:value-of select="."/>
245 <xslt:if test="position()!=last()">
252 <xslt:copy-of select="$metadata/node()[not(self::html:title or self::html:meta and @name='generator')]"/>
253 <html:meta name="generator">
254 <xslt:attribute name="content">
255 <xslt:for-each select="$metadata/html:meta[@name='generator']">
256 <xslt:value-of select="@content"/>
264 <xslt:if test="$THISREV">
268 <xslt:value-of select="$THISREV"/>
277 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
278 <xslt:apply-templates select="$modalinput/node()" mode="书社:header"/>
279 <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()"/>
280 <xslt:apply-templates select="$modalinput/node()" mode="书社:footer"/>
284 <xslt:template match="/">
285 <xslt:variable name="finalization-fragment">
286 <xslt:apply-templates select="$书社:result" mode="书社:finalize"/>
288 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
290 <xslt:template match="@*|node()" priority="-1">
292 <xslt:apply-templates select="@*|node()"/>
295 <xslt:template match="书社:apply-attributes" mode="书社:apply" priority="1">
296 <xslt:variable name="children">
297 <xslt:apply-templates mode="书社:apply"/>
299 <xslt:call-template name="书社:apply-attributes">
300 <xslt:with-param name="context-nodes" select="."/>
301 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
302 </xslt:call-template>
304 <xslt:template match="书社:apply-attributes-to-root" mode="书社:apply" priority="1">
305 <xslt:apply-templates mode="书社:apply"/>
307 <xslt:template match="@*|node()" mode="书社:apply" priority="-1">
309 <xslt:apply-templates select="@*|node()" mode="书社:apply"/>
312 <xslt:template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
313 <xslt:variable name="link" select="."/>
314 <xslt:variable name="identifier" select="string(@xlink:href)"/>
315 <xslt:variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
316 <xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
318 <xslt:when test="$included">
319 <xslt:for-each select="$included">
320 <xslt:sort select="@rdf:about" data-type="text" lang="zxx" case-order="upper-first"/>
321 <xslt:variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
322 <xslt:variable name="expanded">
323 <xslt:apply-templates select="document($uri)" mode="书社:expand">
324 <xslt:with-param name="identifier" select="string(@rdf:about)"/>
325 </xslt:apply-templates>
327 <xslt:for-each select="exsl:node-set($expanded)/node()">
330 <xslt:when test="self::html:*">
331 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
332 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
333 <xslt:attribute name="itemtype">
334 <xslt:for-each select="$existing-types/token[string()!='&书社;:document']">
335 <xslt:if test="position()!=1">
340 <xslt:value-of select="."/>
342 <xslt:if test="not($existing-types/token[string()='&书社;:embed'])">
343 <xslt:if test="$existing-types/token[string()!='&书社;:document']">
349 <text>&书社;:embed</text>
354 <xslt:when test="$link/@书社:archived-as">
355 <xslt:copy-of select="$link/@书社:archived-as"/>
357 <xslt:when test="@书社:archived-as">
358 <xslt:copy-of select="@书社:archived-as"/>
361 <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()"/>
365 <xslt:when test="self::* and $link/@书社:archived-as">
366 <xslt:copy-of select="$link/@书社:archived-as"/>
368 <xslt:when test="@书社:archived-as">
369 <xslt:copy-of select="@书社:archived-as"/>
372 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
381 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
386 <xslt:template match="/node()" mode="书社:expand" priority="0">
387 <xslt:param name="identifier" select="$IDENTIFIER"/>
389 <xslt:if test="self::*">
390 <xslt:attribute name="书社:cksum">
391 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
393 <xslt:attribute name="书社:identifier">
394 <xslt:value-of select="$identifier"/>
396 <xslt:attribute name="书社:mtime">
397 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:fileLastModified"/>
401 <xslt:when test="self::html:*">
402 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
403 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
404 <xslt:attribute name="itemtype">
405 <xslt:for-each select="$existing-types/token">
406 <xslt:if test="position()!=1">
411 <xslt:value-of select="."/>
413 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
414 <xslt:if test="$existing-types/token">
420 <text>&书社;:document</text>
424 <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"/>
427 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
432 <xslt:template match="@*|node()" mode="书社:expand" priority="-1">
434 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
437 <xslt:template match="text()" mode="书社:header"/>
438 <xslt:template match="书社:archive" mode="书社:finalize" priority="1">
440 <xslt:apply-templates select="@*" mode="书社:finalize"/>
441 <xslt:for-each select="node()">
443 <xslt:when test="self::*">
444 <xslt:variable name="component-fragment">
447 <xslt:when test="self::html:*">
448 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
449 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
450 <xslt:attribute name="itemtype">
451 <xslt:for-each select="$existing-types/token">
452 <xslt:if test="position()!=1">
457 <xslt:value-of select="."/>
459 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
460 <xslt:if test="$existing-types/token">
466 <text>&书社;:document</text>
470 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
473 <xslt:copy-of select="@*|node()"/>
478 <xslt:variable name="finalization-fragment">
479 <xslt:apply-templates select="exsl:node-set($component-fragment)" mode="书社:finalize"/>
481 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
484 <xslt:apply-templates select="." mode="书社:finalize"/>
490 <xslt:template match="@书社:destination|@书社:disable-output-wrapping" mode="书社:finalize" priority="1"/>
491 <xslt:template match="/" mode="书社:finalize">
493 <xslt:when test="not(html:*) or 书社:raw-text or 书社:base64-binary or 书社:archive or */@书社:disable-output-wrapping">
494 <xslt:apply-templates mode="书社:finalize"/>
497 <xslt:variable name="wrapped-result">
498 <xslt:call-template name="书社:wrap">
499 <xslt:with-param name="nodes" select="node()"/>
500 </xslt:call-template>
502 <xslt:apply-templates select="exsl:node-set($wrapped-result)/node()" mode="书社:finalize"/>
506 <xslt:template match="@*|node()" mode="书社:finalize" priority="-1">
508 <xslt:apply-templates select="@*|node()" mode="书社:finalize"/>
511 <xslt:template match="text()" mode="书社:footer"/>
512 <xslt:template match="text()" mode="书社:metadata"/>
513 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
516 <output method="xml" encoding="UTF-8"/>