]> Lady’s Gitweb - Shushe/blob - lib/catalog2transform.xslt
6479216fb915a8439b5194ba306bfa741ec66dc2
[Shushe] / lib / catalog2transform.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ ⛩📰 书社 ∷ lib/catalog2transform.xslt
8
9 © 2023–2024 Lady [@ Ladys Computer].
10
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/>.
13 -->
14 <!DOCTYPE transform [
15 <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
16 <!ENTITY xml "http://www.w3.org/XML/1998/namespace">
17 ]>
18 <transform
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 exclude-result-prefixes="catalog"
33 version="1.0"
34 >
35 <include href="literally.xslt"/>
36 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
37 <param name="METADATA" select="'about:blank'"/>
38 <template match="/">
39 <xslt:transform exclude-result-prefixes="nie nfo" extension-element-prefixes="exsl exslstr" version="1.0">
40 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
41 <xslt:param name="IDENTIFIER" select="false()"/>
42 <xslt:param name="PATH" select="'/unknown'"/>
43 <xslt:param name="SRCREV" select="false()"/>
44 <xslt:param name="THISREV" select="false()"/>
45 <xslt:variable name="书社:source" select="/"/>
46 <xslt:variable name="书社:about-fragment">
47 <apply-templates select="document($METADATA)" mode="书社:literally">
48 <with-param name="extension-element-namespaces" select="'http://exslt.org/common http://exslt.org/strings'"/>
49 </apply-templates>
50 </xslt:variable>
51 <xslt:variable name="书社:about" select="exsl:node-set($书社:about-fragment)"/>
52 <xslt:variable name="书社:expansion-fragment">
53 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
54 </xslt:variable>
55 <xslt:variable name="书社:expansion" select="exsl:node-set($书社:expansion-fragment)"/>
56 <xslt:variable name="书社:result-fragment">
57 <xslt:apply-templates select="$书社:expansion/node()"/>
58 </xslt:variable>
59 <xslt:variable name="书社:result" select="exsl:node-set($书社:result-fragment)"/>
60 <xslt:variable name="书社:destination">
61 <xslt:choose>
62 <xslt:when test="string($书社:source/@书社:destination)!=''">
63 <xslt:value-of select="$书社:source/@书社:destination"/>
64 </xslt:when>
65 <xslt:when test="starts-with($PATH, '/')">
66 <xslt:value-of select="substring-after($PATH, '/')"/>
67 </xslt:when>
68 <xslt:otherwise>
69 <xslt:value-of select="$PATH"/>
70 </xslt:otherwise>
71 </xslt:choose>
72 </xslt:variable>
73 <for-each select="//catalog:uri">
74 <xslt:include href="{@uri}">
75 <if test="contains(@name, ':')">
76 <attribute name="书社:id">
77 <value-of select="@name"/>
78 </attribute>
79 </if>
80 </xslt:include>
81 </for-each>
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="@*"/>
89 <xslt:choose>
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">
94 <书社:attribute>
95 <attribute name="local-name">
96 <text>{local-name()}</text>
97 </attribute>
98 <attribute name="name">
99 <text>{name()}</text>
100 </attribute>
101 <attribute name="namespace-uri">
102 <text>{namespace-uri()}</text>
103 </attribute>
104 </书社:attribute>
105 </xslt:for-each>
106 </xslt:variable>
107 <xslt:variable name="lang">
108 <xslt:choose>
109 <xslt:when test="(self::html:*|self::svg:*)/@lang">
110 <xslt:value-of select="@lang"/>
111 </xslt:when>
112 <xslt:when test="@xml:lang">
113 <xslt:value-of select="@xml:lang"/>
114 </xslt:when>
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']"/>
117 </xslt:when>
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']"/>
120 </xslt:when>
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']"/>
123 </xslt:when>
124 </xslt:choose>
125 </xslt:variable>
126 <xslt:copy>
127 <xslt:if test="$and-version and $THISREV">
128 <xslt:attribute name="书社:version">
129 <xslt:value-of select="$THISREV"/>
130 </xslt:attribute>
131 </xslt:if>
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"/>
136 </xslt:attribute>
137 </xslt:if>
138 <xslt:attribute name="xml:lang">
139 <xslt:value-of select="$lang"/>
140 </xslt:attribute>
141 </xslt:if>
142 <xslt:for-each select="exsl:node-set($attribute-names)/*">
143 <xslt:choose>
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="@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])"/>
147 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
148 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
149 <xslt:otherwise>
150 <xslt:attribute>
151 <attribute name="name">
152 <text>{@name}</text>
153 </attribute>
154 <attribute name="namespace">
155 <text>{@namespace-uri}</text>
156 </attribute>
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()">
160 <xslt:text>
161 <text> </text>
162 </xslt:text>
163 </xslt:if>
164 </xslt:for-each>
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]">
166 <xslt:text>
167 <text> </text>
168 </xslt:text>
169 </xslt:if>
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()">
173 <xslt:text>
174 <text> </text>
175 </xslt:text>
176 </xslt:if>
177 </xslt:for-each>
178 </xslt:attribute>
179 </xslt:otherwise>
180 </xslt:choose>
181 </xslt:for-each>
182 <xslt:copy-of select="node()"/>
183 </xslt:copy>
184 </xslt:when>
185 <xslt:otherwise>
186 <xslt:copy-of select="."/>
187 </xslt:otherwise>
188 </xslt:choose>
189 </xslt:for-each>
190 </xslt:template>
191 <xslt:template name="书社:wrap">
192 <xslt:param name="nodes" select="/.."/>
193 <xslt:variable name="modalinput-fragment">
194 <xslt:copy-of select="$nodes"/>
195 <xslt:copy-of select="document('')/xslt:transform/xslt:include"/>
196 </xslt:variable>
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"/>
201 </xslt:variable>
202 <xslt:variable name="metadata" select="exsl:node-set($metadata-fragment)"/>
203 <html:html>
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"/>
208 </xslt:attribute>
209 </xslt:if>
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"/>
213 </xslt:attribute>
214 </xslt:if>
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"/>
218 </xslt:attribute>
219 </xslt:if>
220 <html:head>
221 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
222 <html:title>
223 <xslt:for-each select="$metadata/html:title">
224 <xslt:value-of select="."/>
225 <xslt:if test="position()!=last()">
226 <xslt:text>
227 <text> </text>
228 </xslt:text>
229 </xslt:if>
230 </xslt:for-each>
231 </html:title>
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"/>
237 <xslt:text>
238 <text>, </text>
239 </xslt:text>
240 </xslt:for-each>
241 <xslt:text>
242 <text>⛩📰 书社</text>
243 </xslt:text>
244 <xslt:if test="$THISREV">
245 <xslt:text>
246 <text> (</text>
247 </xslt:text>
248 <xslt:value-of select="$THISREV"/>
249 <xslt:text>
250 <text>)</text>
251 </xslt:text>
252 </xslt:if>
253 </xslt:attribute>
254 </html:meta>
255 </html:head>
256 <html:body>
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"/>
261 </html:body>
262 </html:html>
263 </xslt:template>
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/descendant::node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
266 <xslt:variable name="root-with-attributes">
267 <xslt:choose>
268 <xslt:when test="$result-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|$result-nodes/@书社:disable-output-wrapping|$书社:result//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
269 <xslt:call-template name="书社:apply-attributes">
270 <xslt:with-param name="and-version" select="true()"/>
271 <xslt:with-param name="context-nodes" select="$书社:result//书社:apply-attributes-to-root"/>
272 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
273 </xslt:call-template>
274 </xslt:when>
275 <xslt:otherwise>
276 <xslt:variable name="wrapped-result">
277 <xslt:call-template name="书社:wrap">
278 <xslt:with-param name="nodes" select="$result-nodes"/>
279 </xslt:call-template>
280 </xslt:variable>
281 <xslt:call-template name="书社:apply-attributes">
282 <xslt:with-param name="and-version" select="true()"/>
283 <xslt:with-param name="context-nodes" select="$书社:result//书社:apply-attributes-to-root"/>
284 <xslt:with-param name="destination-nodes" select="exsl:node-set($wrapped-result)/node()"/>
285 </xslt:call-template>
286 </xslt:otherwise>
287 </xslt:choose>
288 </xslt:variable>
289 <xslt:apply-templates select="exsl:node-set($root-with-attributes)/node()" mode="书社:apply"/>
290 </xslt:template>
291 <xslt:template match="@*|node()" priority="-1">
292 <xslt:copy>
293 <xslt:apply-templates select="@*|node()"/>
294 </xslt:copy>
295 </xslt:template>
296 <xslt:template match="@*|node()" mode="书社:apply">
297 <xslt:copy>
298 <xslt:apply-templates select="@*|node()" mode="书社:apply"/>
299 </xslt:copy>
300 </xslt:template>
301 <xslt:template match="@书社:destination|@书社:disable-output-wrapping|@书社:archived-as[../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]]" mode="书社:apply" priority="1"/>
302 <xslt:template match="书社:archive" mode="书社:apply" priority="1">
303 <xslt:copy>
304 <xslt:for-each select="@*">
305 <xslt:choose>
306 <xslt:when test="local-name()='archived-as' and namespace-uri()='&书社;' and ../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]"/>
307 <xslt:otherwise>
308 <xslt:apply-templates select="." mode="书社:apply"/>
309 </xslt:otherwise>
310 </xslt:choose>
311 </xslt:for-each>
312 <xslt:for-each select="node()">
313 <xslt:choose>
314 <xslt:when test="self::*">
315 <xslt:variable name="component">
316 <xslt:choose>
317 <xslt:when test="self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|@书社:disable-output-wrapping">
318 <xslt:copy-of select="."/>
319 </xslt:when>
320 <xslt:otherwise>
321 <xslt:call-template name="书社:wrap">
322 <xslt:with-param name="nodes" select="."/>
323 </xslt:call-template>
324 </xslt:otherwise>
325 </xslt:choose>
326 </xslt:variable>
327 <xslt:apply-templates select="exsl:node-set($component)/node()" mode="书社:apply"/>
328 </xslt:when>
329 <xslt:otherwise>
330 <xslt:apply-templates select="." mode="书社:apply"/>
331 </xslt:otherwise>
332 </xslt:choose>
333 </xslt:for-each>
334 </xslt:copy>
335 </xslt:template>
336 <xslt:template match="书社:apply-attributes" mode="书社:apply" priority="1">
337 <xslt:variable name="children">
338 <xslt:apply-templates mode="书社:apply"/>
339 </xslt:variable>
340 <xslt:call-template name="书社:apply-attributes">
341 <xslt:with-param name="context-nodes" select="."/>
342 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
343 </xslt:call-template>
344 </xslt:template>
345 <xslt:template match="书社:apply-attributes-to-root" mode="书社:apply" priority="1">
346 <xslt:apply-templates mode="书社:apply"/>
347 </xslt:template>
348 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
349 <xslt:variable name="identifier" select="string(@xlink:href)"/>
350 <xslt:variable name="uri" select="document($METADATA)//*[@rdf:about=$identifier]/dct:hasFormat/*[nie:interpretedAs/*[@nie:mimeType='application/xml']]/@nfo:fileUrl[1]"/>
351 <xslt:choose>
352 <xslt:when test="$uri">
353 <xslt:variable name="expanded">
354 <xslt:apply-templates select="document($uri)" mode="书社:expand">
355 <xslt:with-param name="identifier" select="$identifier"/>
356 </xslt:apply-templates>
357 </xslt:variable>
358 <xslt:for-each select="exsl:node-set($expanded)/node()">
359 <xslt:copy>
360 <xslt:choose>
361 <xslt:when test="self::html:*">
362 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
363 <xslt:attribute name="itemtype">
364 <xslt:text>
365 <text>&书社;:embed</text>
366 </xslt:text>
367 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
368 <xslt:text>
369 <text> </text>
370 </xslt:text>
371 <xslt:value-of select="."/>
372 </xslt:for-each>
373 </xslt:attribute>
374 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
375 </xslt:when>
376 <xslt:otherwise>
377 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
378 </xslt:otherwise>
379 </xslt:choose>
380 </xslt:copy>
381 </xslt:for-each>
382 </xslt:when>
383 <xslt:otherwise>
384 <xslt:copy>
385 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
386 </xslt:copy>
387 </xslt:otherwise>
388 </xslt:choose>
389 </xslt:template>
390 <xslt:template match="/node()" mode="书社:expand" priority="0">
391 <xslt:param name="identifier" select="$IDENTIFIER"/>
392 <xslt:copy>
393 <xslt:if test="self::*">
394 <xslt:attribute name="书社:cksum">
395 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
396 </xslt:attribute>
397 <xslt:attribute name="书社:identifier">
398 <xslt:value-of select="$identifier"/>
399 </xslt:attribute>
400 <xslt:attribute name="书社:mtime">
401 <xslt:value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:fileLastModified"/>
402 </xslt:attribute>
403 </xslt:if>
404 <xslt:choose>
405 <xslt:when test="self::html:*">
406 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
407 <xslt:attribute name="itemtype">
408 <xslt:text>
409 <text>&书社;:document</text>
410 </xslt:text>
411 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
412 <xslt:text>
413 <text> </text>
414 </xslt:text>
415 <xslt:value-of select="."/>
416 </xslt:for-each>
417 </xslt:attribute>
418 <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"/>
419 </xslt:when>
420 <xslt:otherwise>
421 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
422 </xslt:otherwise>
423 </xslt:choose>
424 </xslt:copy>
425 </xslt:template>
426 <xslt:template match="@*|node()[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
427 <xslt:copy>
428 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
429 </xslt:copy>
430 </xslt:template>
431 <xslt:template match="text()" mode="书社:header"/>
432 <xslt:template match="text()" mode="书社:footer"/>
433 <xslt:template match="text()" mode="书社:metadata"/>
434 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
435 </xslt:transform>
436 </template>
437 <output method="xml" encoding="UTF-8"/>
438 </transform>
This page took 0.072405 seconds and 3 git commands to generate.