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 xhtml "http://www.w3.org/1999/xhtml">
17 <!ENTITY xml "http://www.w3.org/XML/1998/namespace">
20 xmlns="http://www.w3.org/1999/XSL/Transform"
21 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
22 xmlns:exsl="http://exslt.org/common"
23 xmlns:exslfunc="http://exslt.org/functions"
24 xmlns:exslstr="http://exslt.org/strings"
26 xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
27 xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
28 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
29 xmlns:svg="http://www.w3.org/2000/svg"
30 xmlns:xlink="http://www.w3.org/1999/xlink"
31 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
32 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
33 xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
34 exclude-result-prefixes="catalog"
37 <include href="literally.xslt"/>
38 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
39 <param name="METADATA" select="'about:blank'"/>
40 <variable name="builddir" select="document($METADATA)//书社vocab:BuildDirectory/@nfo:fileUrl"/>
43 <for-each select="//catalog:uri[@name]">
45 <value-of select="@name"/>
49 <variable name="unique-ids">
50 <for-each select="exsl:node-set($ids)/*">
51 <if test="not(preceding-sibling::*[string(.)=string(current())])">
56 <xslt:transform exclude-result-prefixes="nie nfo" extension-element-prefixes="exsl exslfunc exslstr" version="1.0">
57 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
58 <xslt:param name="IDENTIFIER" select="false()"/>
59 <xslt:param name="SRCREV" select="false()"/>
60 <xslt:param name="THISREV" select="false()"/>
61 <element name="exslfunc:function">
62 <attribute name="name">
63 <text>书社:document-with-attributes-applied</text>
65 <xslt:param name="document" select="/.."/>
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="root-with-attributes">
69 <xslt:call-template name="书社:apply-attributes">
70 <xslt:with-param name="context-nodes" select="$document//书社:apply-attributes-to-root"/>
71 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
74 <xslt:apply-templates select="exsl:node-set($root-with-attributes)" mode="书社:apply"/>
76 <element name="exslfunc:result">
77 <attribute name="select">
78 <text>exsl:node-set($application-result-fragment)</text>
82 <xslt:variable name="书社:source" select="/"/>
83 <xslt:variable name="书社:about-fragment">
84 <apply-templates select="document($METADATA)" mode="书社:literally">
85 <with-param name="extension-element-namespaces" select="'http://exslt.org/common http://exslt.org/functions http://exslt.org/strings'"/>
88 <xslt:variable name="书社:about" select="exsl:node-set($书社:about-fragment)"/>
89 <xslt:variable name="书社:expansion-fragment">
90 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
92 <xslt:variable name="书社:expansion" select="书社:document-with-attributes-applied(exsl:node-set($书社:expansion-fragment))"/>
93 <xslt:variable name="书社:result-fragment">
94 <xslt:element name="书社:apply-attributes-to-root">
95 <xslt:attribute name="书社:version">
96 <xslt:value-of select="$THISREV"/>
98 <xslt:apply-templates select="$书社:expansion/node()"/>
101 <xslt:variable name="书社:result" select="书社:document-with-attributes-applied(exsl:node-set($书社:result-fragment))"/>
102 <xslt:variable name="书社:destination" select="string($书社:about//*[@rdf:about=$IDENTIFIER]/@书社vocab:destination)"/>
103 <for-each select="//catalog:uri">
104 <xslt:include href="{@uri}">
105 <attribute name="书社:id">
106 <value-of select="@name"/>
110 <xslt:template name="书社:apply-attributes">
111 <xslt:param name="context-nodes" select="/.."/>
112 <xslt:param name="destination-nodes" select="/.."/>
113 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
114 <xslt:for-each select="$destination-nodes">
115 <xslt:variable name="existing-attributes" select="@*"/>
117 <xslt:when test="self::*">
118 <xslt:variable name="context" select="."/>
119 <xslt:variable name="attribute-names">
120 <xslt:for-each select="$existing-attributes|$additional-attributes">
122 <attribute name="local-name">
123 <text>{local-name()}</text>
125 <attribute name="name">
126 <text>{name()}</text>
128 <attribute name="namespace-uri">
129 <text>{namespace-uri()}</text>
134 <xslt:variable name="lang">
136 <xslt:when test="(self::html:*|self::svg:*)/@lang">
137 <xslt:value-of select="@lang"/>
139 <xslt:when test="@xml:lang">
140 <xslt:value-of select="@xml:lang"/>
142 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
143 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
145 <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']">
146 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
148 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
149 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
154 <xslt:if test="string($lang)!=''">
155 <xslt:if test="self::html:* or self::svg:*">
156 <xslt:attribute name="lang">
157 <xslt:value-of select="$lang"/>
160 <xslt:attribute name="xml:lang">
161 <xslt:value-of select="$lang"/>
164 <xslt:for-each select="exsl:node-set($attribute-names)/*">
166 <xslt:when test="@namespace-uri='&xml;'"/>
167 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
168 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping')"/>
169 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
172 <attribute name="name">
175 <attribute name="namespace">
176 <text>{@namespace-uri}</text>
178 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
179 <xslt:value-of select="."/>
180 <xslt:if test="position()!=last()">
186 <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]">
191 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
192 <xslt:value-of select="."/>
193 <xslt:if test="position()!=last()">
203 <xslt:copy-of select="node()"/>
207 <xslt:copy-of select="."/>
212 <xslt:template name="书社:wrap">
213 <xslt:param name="nodes" select="/.."/>
214 <xslt:variable name="modalinput-fragment">
215 <xslt:copy-of select="$nodes"/>
216 <apply-templates select="exsl:node-set($unique-ids)" mode="书社:literally"/>
218 <xslt:variable name="modalinput" select="exsl:node-set($modalinput-fragment)"/>
219 <xslt:variable name="metadata-fragment">
220 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
221 <xslt:apply-templates select="$modalinput/node()" mode="书社:metadata"/>
223 <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
224 <xslt:element name="html" namespace="&xhtml;">
225 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
226 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
227 <xslt:attribute name="书社:archived-as">
228 <xslt:value-of select="$nodes/@书社:archived-as"/>
231 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
232 <xslt:attribute name="lang">
233 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
236 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
237 <xslt:attribute name="xml:lang">
238 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
241 <xslt:element name="head" namespace="&xhtml;">
242 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
243 <xslt:element name="title" namespace="&xhtml;">
244 <xslt:for-each select="$metadata/html:title">
245 <xslt:value-of select="."/>
246 <xslt:if test="position()!=last()">
253 <xslt:copy-of select="$metadata/node()[not(self::html:title or self::html:meta and @name='generator')]"/>
254 <xslt:element name="meta" namespace="&xhtml;">
255 <xslt:attribute name="name">
257 <text>generator</text>
260 <xslt:attribute name="content">
261 <xslt:for-each select="$metadata/html:meta[@name='generator']">
262 <xslt:value-of select="@content"/>
270 <xslt:if test="$THISREV">
274 <xslt:value-of select="$THISREV"/>
282 <xslt:element name="body" namespace="&xhtml;">
283 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
284 <xslt:apply-templates select="$modalinput/node()" mode="书社:header"/>
285 <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()"/>
286 <xslt:apply-templates select="$modalinput/node()" mode="书社:footer"/>
290 <xslt:template match="/">
291 <xslt:variable name="finalization-fragment">
292 <xslt:apply-templates select="$书社:result" mode="书社:finalize"/>
294 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
296 <xslt:template match="@*|node()" priority="-1">
298 <xslt:apply-templates select="@*|node()"/>
301 <xslt:template match="书社:apply-attributes" mode="书社:apply" priority="1">
302 <xslt:variable name="children">
303 <xslt:apply-templates mode="书社:apply"/>
305 <xslt:call-template name="书社:apply-attributes">
306 <xslt:with-param name="context-nodes" select="."/>
307 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
308 </xslt:call-template>
310 <xslt:template match="书社:apply-attributes-to-root" mode="书社:apply" priority="1">
311 <xslt:apply-templates mode="书社:apply"/>
313 <xslt:template match="@*|node()" mode="书社:apply" priority="-1">
315 <xslt:apply-templates select="@*|node()" mode="书社:apply"/>
318 <xslt:template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
319 <xslt:variable name="link" select="."/>
320 <xslt:variable name="identifier" select="string(@xlink:href)"/>
321 <xslt:variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
322 <xslt:variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
324 <xslt:when test="$included">
325 <xslt:for-each select="$included">
326 <xslt:sort select="@rdf:about" data-type="text" lang="zxx" case-order="upper-first"/>
327 <xslt:variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
328 <xslt:variable name="expanded">
329 <xslt:apply-templates select="document($uri)" mode="书社:expand">
330 <xslt:with-param name="identifier" select="string(@rdf:about)"/>
331 </xslt:apply-templates>
333 <xslt:for-each select="exsl:node-set($expanded)/node()">
336 <xslt:when test="self::html:*">
337 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
338 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
339 <xslt:attribute name="itemtype">
340 <xslt:for-each select="$existing-types/token[string()!='&书社;:document']">
341 <xslt:if test="position()!=1">
346 <xslt:value-of select="."/>
348 <xslt:if test="not($existing-types/token[string()='&书社;:embed'])">
349 <xslt:if test="$existing-types/token[string()!='&书社;:document']">
355 <text>&书社;:embed</text>
360 <xslt:when test="$link/@书社:archived-as">
361 <xslt:copy-of select="$link/@书社:archived-as"/>
363 <xslt:when test="@书社:archived-as">
364 <xslt:copy-of select="@书社:archived-as"/>
367 <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()"/>
371 <xslt:when test="self::* and $link/@书社:archived-as">
372 <xslt:copy-of select="$link/@书社:archived-as"/>
374 <xslt:when test="@书社:archived-as">
375 <xslt:copy-of select="@书社:archived-as"/>
378 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
387 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
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:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
409 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
410 <xslt:attribute name="itemtype">
411 <xslt:for-each select="$existing-types/token">
412 <xslt:if test="position()!=1">
417 <xslt:value-of select="."/>
419 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
420 <xslt:if test="$existing-types/token">
426 <text>&书社;:document</text>
430 <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"/>
433 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
438 <xslt:template match="@*|node()" mode="书社:expand" priority="-1">
440 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
443 <xslt:template match="text()" mode="书社:header"/>
444 <xslt:template match="书社:archive" mode="书社:finalize" priority="1">
446 <xslt:apply-templates select="@*" mode="书社:finalize"/>
447 <xslt:for-each select="node()">
449 <xslt:when test="self::*">
450 <xslt:variable name="component-fragment">
453 <xslt:when test="self::html:*">
454 <xslt:variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
455 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
456 <xslt:attribute name="itemtype">
457 <xslt:for-each select="$existing-types/token">
458 <xslt:if test="position()!=1">
463 <xslt:value-of select="."/>
465 <xslt:if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
466 <xslt:if test="$existing-types/token">
472 <text>&书社;:document</text>
476 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
479 <xslt:copy-of select="@*|node()"/>
484 <xslt:variable name="finalization-fragment">
485 <xslt:apply-templates select="exsl:node-set($component-fragment)" mode="书社:finalize"/>
487 <xslt:copy-of select="书社:document-with-attributes-applied(exsl:node-set($finalization-fragment))"/>
490 <xslt:apply-templates select="." mode="书社:finalize"/>
496 <xslt:template match="@书社:destination|@书社:disable-output-wrapping" mode="书社:finalize" priority="1"/>
497 <xslt:template match="/" mode="书社:finalize">
499 <xslt:when test="not(html:*) or 书社:raw-text or 书社:base64-binary or 书社:archive or */@书社:disable-output-wrapping">
500 <xslt:apply-templates mode="书社:finalize"/>
503 <xslt:variable name="wrapped-result">
504 <xslt:call-template name="书社:wrap">
505 <xslt:with-param name="nodes" select="node()"/>
506 </xslt:call-template>
508 <xslt:apply-templates select="exsl:node-set($wrapped-result)/node()" mode="书社:finalize"/>
512 <xslt:template match="@*|node()" mode="书社:finalize" priority="-1">
514 <xslt:apply-templates select="@*|node()" mode="书社:finalize"/>
517 <xslt:template match="text()" mode="书社:footer"/>
518 <xslt:template match="text()" mode="书社:metadata"/>
519 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
522 <output method="xml" encoding="UTF-8"/>