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:exslstr="http://exslt.org/strings"
23 xmlns:html="http://www.w3.org/1999/xhtml"
24 xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
25 xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
26 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
27 xmlns:svg="http://www.w3.org/2000/svg"
28 xmlns:xlink="http://www.w3.org/1999/xlink"
29 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
30 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
31 xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
32 exclude-result-prefixes="catalog"
35 <include href="literally.xslt"/>
36 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
37 <param name="METADATA" select="'about:blank'"/>
38 <variable name="builddir" select="document($METADATA)//书社vocab:BuildDirectory/@nfo:fileUrl"/>
41 <for-each select="//catalog:uri[@name]">
43 <value-of select="@name"/>
47 <variable name="unique-ids">
48 <for-each select="exsl:node-set($ids)/*">
49 <if test="not(preceding-sibling::*[string(.)=string(current())])">
54 <xslt:transform exclude-result-prefixes="nie nfo" extension-element-prefixes="exsl exslstr" version="1.0">
55 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
56 <xslt:param name="IDENTIFIER" select="false()"/>
57 <xslt:param name="SRCREV" select="false()"/>
58 <xslt:param name="THISREV" select="false()"/>
59 <xslt:variable name="书社:source" select="/"/>
60 <xslt:variable name="书社:about-fragment">
61 <apply-templates select="document($METADATA)" mode="书社:literally">
62 <with-param name="extension-element-namespaces" select="'http://exslt.org/common http://exslt.org/strings'"/>
65 <xslt:variable name="书社:about" select="exsl:node-set($书社:about-fragment)"/>
66 <xslt:variable name="书社:expansion-fragment">
67 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
69 <xslt:variable name="书社:expansion" select="exsl:node-set($书社:expansion-fragment)"/>
70 <xslt:variable name="书社:result-fragment">
71 <xslt:apply-templates select="$书社:expansion/node()"/>
73 <xslt:variable name="书社:result" select="exsl:node-set($书社:result-fragment)"/>
74 <xslt:variable name="书社:destination" select="string($书社:about//*[@rdf:about=$IDENTIFIER]/@书社vocab:destination)"/>
75 <for-each select="//catalog:uri">
76 <xslt:include href="{@uri}">
77 <attribute name="书社:id">
78 <value-of select="@name"/>
82 <xslt:template name="书社:apply-attributes">
83 <xslt:param name="and-version" select="false()"/>
84 <xslt:param name="context-nodes" select="/.."/>
85 <xslt:param name="destination-nodes" select="/.."/>
86 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
87 <xslt:for-each select="$destination-nodes">
88 <xslt:variable name="existing-attributes" select="@*"/>
90 <xslt:when test="self::*">
91 <xslt:variable name="context" select="."/>
92 <xslt:variable name="attribute-names">
93 <xslt:for-each select="$existing-attributes|$additional-attributes">
95 <attribute name="local-name">
96 <text>{local-name()}</text>
98 <attribute name="name">
101 <attribute name="namespace-uri">
102 <text>{namespace-uri()}</text>
107 <xslt:variable name="lang">
109 <xslt:when test="(self::html:*|self::svg:*)/@lang">
110 <xslt:value-of select="@lang"/>
112 <xslt:when test="@xml:lang">
113 <xslt:value-of select="@xml:lang"/>
115 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
116 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
118 <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']">
119 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
121 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
122 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
127 <xslt:if test="$and-version and $THISREV">
128 <xslt:attribute name="书社:version">
129 <xslt:value-of select="$THISREV"/>
132 <xslt:if test="string($lang)!=''">
133 <xslt:if test="self::html:* or self::svg:*">
134 <xslt:attribute name="lang">
135 <xslt:value-of select="$lang"/>
138 <xslt:attribute name="xml:lang">
139 <xslt:value-of select="$lang"/>
142 <xslt:for-each select="exsl:node-set($attribute-names)/*">
144 <xslt:when test="@namespace-uri='&xml;'"/>
145 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
146 <xslt:when test="$and-version and $THISREV and @namespace-uri='&书社;' and @local-name='version'"/>
147 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping')"/>
148 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
151 <attribute name="name">
154 <attribute name="namespace">
155 <text>{@namespace-uri}</text>
157 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
158 <xslt:value-of select="."/>
159 <xslt:if test="position()!=last()">
165 <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]">
170 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
171 <xslt:value-of select="."/>
172 <xslt:if test="position()!=last()">
182 <xslt:copy-of select="node()"/>
186 <xslt:copy-of select="."/>
191 <xslt:template name="书社:wrap">
192 <xslt:param name="nodes" select="/.."/>
193 <xslt:variable name="modalinput-fragment">
194 <xslt:copy-of select="$nodes"/>
195 <apply-templates select="exsl:node-set($unique-ids)" mode="书社:literally"/>
197 <xslt:variable name="modalinput" select="exsl:node-set($modalinput-fragment)"/>
198 <xslt:variable name="metadata-fragment">
199 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
200 <xslt:apply-templates select="$modalinput/node()" mode="书社:metadata"/>
202 <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
204 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
205 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
206 <xslt:attribute name="书社:archived-as">
207 <xslt:value-of select="$nodes/@书社:archived-as"/>
210 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
211 <xslt:attribute name="lang">
212 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
215 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
216 <xslt:attribute name="xml:lang">
217 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
221 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
223 <xslt:for-each select="$metadata/html:title">
224 <xslt:value-of select="."/>
225 <xslt:if test="position()!=last()">
232 <xslt:copy-of select="$metadata/node()[not(self::html:title or self::html:meta and @name='generator')]"/>
233 <html:meta name="generator">
234 <xslt:attribute name="content">
235 <xslt:for-each select="$metadata/html:meta[@name='generator']">
236 <xslt:value-of select="@content"/>
244 <xslt:if test="$THISREV">
248 <xslt:value-of select="$THISREV"/>
257 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
258 <xslt:apply-templates select="$modalinput/node()" mode="书社:header"/>
259 <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()"/>
260 <xslt:apply-templates select="$modalinput/node()" mode="书社:footer"/>
264 <xslt:template match="/" priority="1">
265 <xslt:variable name="result-nodes" select="$书社:result/node()[not(self::书社:apply-attributes-to-root)]|$书社:result/书社:apply-attributes-to-root//node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
266 <xslt:variable name="significant-nodes" select="$result-nodes/descendant-or-self::*[not(self::书社:apply-attributes) and not(ancestor::*[not(self::书社:apply-attributes)])]"/>
267 <xslt:variable name="root-with-attributes">
269 <xslt:when test="not($significant-nodes/self::html:*) or $significant-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $significant-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" mode="书社:apply" priority="1"/>
298 <xslt:template match="书社:archive" mode="书社:apply" priority="1">
300 <xslt:apply-templates select="@*" mode="书社:apply"/>
301 <xslt:for-each select="node()">
303 <xslt:when test="self::*">
304 <xslt:variable name="component-fragment">
307 <xslt:when test="self::html:*">
308 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
309 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
310 <xslt:attribute name="itemtype">
311 <xslt:for-each select="$existing-types/token">
312 <xslt:if test="position()!=1">
317 <xslt:value-of select="."/>
319 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
320 <xslt:if test="$existing-types/token">
326 <text>&书社;:document</text>
330 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
333 <xslt:copy-of select="@*|node()"/>
338 <xslt:variable name="wrapped-component-fragment">
339 <xslt:for-each select="exsl:node-set($component-fragment)/*">
340 <xslt:variable name="result-nodes" select="self::*[not(self::书社:apply-attributes-to-root)]|self::书社:apply-attributes-to-root//node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
341 <xslt:variable name="significant-nodes" select="$result-nodes/descendant-or-self::*[not(self::书社:apply-attributes) and not(ancestor::*[not(self::书社:apply-attributes)])]"/>
343 <xslt:when test="not($significant-nodes/self::html:*) or $significant-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive'] or $significant-nodes/@书社:disable-output-wrapping">
344 <xslt:copy-of select="."/>
347 <xslt:call-template name="书社:wrap">
348 <xslt:with-param name="nodes" select="$result-nodes"/>
349 </xslt:call-template>
354 <xslt:apply-templates select="exsl:node-set($wrapped-component-fragment)/node()" mode="书社:apply"/>
357 <xslt:apply-templates select="." mode="书社:apply"/>
363 <xslt:template match="书社:apply-attributes" mode="书社:apply" priority="1">
364 <xslt:variable name="children">
365 <xslt:apply-templates mode="书社:apply"/>
367 <xslt:call-template name="书社:apply-attributes">
368 <xslt:with-param name="context-nodes" select="."/>
369 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
370 </xslt:call-template>
372 <xslt:template match="书社:apply-attributes-to-root" mode="书社:apply" priority="1">
373 <xslt:apply-templates mode="书社:apply"/>
375 <xslt:template match="@*|node()" mode="书社:apply" priority="-1">
377 <xslt:apply-templates select="@*|node()" mode="书社:apply"/>
380 <xslt:template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
381 <xslt:variable name="link" select="."/>
382 <xslt:variable name="identifier" select="string(@xlink:href)"/>
383 <xslt:variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
384 <xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
386 <xslt:when test="$included">
387 <xslt:for-each select="$included">
388 <xslt:sort select="@rdf:about" data-type="text" lang="zxx" case-order="upper-first"/>
389 <xslt:variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
390 <xslt:variable name="expanded">
391 <xslt:apply-templates select="document($uri)" mode="书社:expand">
392 <xslt:with-param name="identifier" select="string(@rdf:about)"/>
393 </xslt:apply-templates>
395 <xslt:for-each select="exsl:node-set($expanded)/node()">
398 <xslt:when test="self::html:*">
399 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
400 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
401 <xslt:attribute name="itemtype">
402 <xslt:for-each select="$existing-types/token[string()!='&书社;:document']">
403 <xslt:if test="position()!=1">
408 <xslt:value-of select="."/>
410 <xslt:if test="not($existing-types/token[string()='&书社;:embed'])">
411 <xslt:if test="$existing-types/token[string()!='&书社;:document']">
417 <text>&书社;:embed</text>
422 <xslt:when test="$link/@书社:archived-as">
423 <xslt:copy-of select="$link/@书社:archived-as"/>
425 <xslt:when test="@书社:archived-as">
426 <xslt:copy-of select="@书社:archived-as"/>
429 <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()"/>
433 <xslt:when test="self::* and $link/@书社:archived-as">
434 <xslt:copy-of select="$link/@书社:archived-as"/>
436 <xslt:when test="@书社:archived-as">
437 <xslt:copy-of select="@书社:archived-as"/>
440 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
449 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
454 <xslt:template match="/node()" mode="书社:expand" priority="0">
455 <xslt:param name="identifier" select="$IDENTIFIER"/>
457 <xslt:if test="self::*">
458 <xslt:attribute name="书社:cksum">
459 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
461 <xslt:attribute name="书社:identifier">
462 <xslt:value-of select="$identifier"/>
464 <xslt:attribute name="书社:mtime">
465 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:fileLastModified"/>
469 <xslt:when test="self::html:*">
470 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
471 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
472 <xslt:attribute name="itemtype">
473 <xslt:for-each select="$existing-types/token">
474 <xslt:if test="position()!=1">
479 <xslt:value-of select="."/>
481 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
482 <xslt:if test="$existing-types/token">
488 <text>&书社;:document</text>
492 <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"/>
495 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
500 <xslt:template match="@*|node()" mode="书社:expand" priority="-1">
502 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
505 <xslt:template match="text()" mode="书社:header"/>
506 <xslt:template match="text()" mode="书社:footer"/>
507 <xslt:template match="text()" mode="书社:metadata"/>
508 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
511 <output method="xml" encoding="UTF-8"/>