]> Lady’s Gitweb - Shushe/blob - lib/catalog2transform.xslt
Drop CKSUM and SRCTIME params; add as attributes
[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 [@ Lady’s 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 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
36 <template match="/">
37 <xslt:transform exclude-result-prefixes="nie nfo" extension-element-prefixes="exsl exslstr" version="1.0">
38 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
39 <xslt:param name="IDENTIFIER" select="false()"/>
40 <xslt:param name="METADATA" select="'metadata'"/>
41 <xslt:param name="PATH" select="'/unknown'"/>
42 <xslt:param name="SRCREV" select="false()"/>
43 <xslt:param name="THISREV" select="false()"/>
44 <xslt:variable name="书社:source" select="/"/>
45 <xslt:variable name="书社:expansion">
46 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
47 </xslt:variable>
48 <xslt:variable name="书社:result">
49 <xslt:apply-templates select="exsl:node-set($书社:expansion)/node()"/>
50 </xslt:variable>
51 <xslt:variable name="书社:destination">
52 <xslt:choose>
53 <xslt:when test="string($书社:source/@书社:destination)!=''">
54 <xslt:value-of select="$书社:source/@书社:destination"/>
55 </xslt:when>
56 <xslt:when test="starts-with($PATH, '/')">
57 <xslt:value-of select="substring-after($PATH, '/')"/>
58 </xslt:when>
59 <xslt:otherwise>
60 <xslt:value-of select="$PATH"/>
61 </xslt:otherwise>
62 </xslt:choose>
63 </xslt:variable>
64 <for-each select="//catalog:uri">
65 <xslt:include href="{@uri}">
66 <if test="contains(@name, ':')">
67 <attribute name="书社:id">
68 <value-of select="@name"/>
69 </attribute>
70 </if>
71 </xslt:include>
72 </for-each>
73 <xslt:template name="书社:apply-attributes">
74 <xslt:param name="and-version" select="false()"/>
75 <xslt:param name="context-nodes" select="/.."/>
76 <xslt:param name="destination-nodes" select="/.."/>
77 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
78 <xslt:for-each select="$destination-nodes">
79 <xslt:variable name="existing-attributes" select="@*"/>
80 <xslt:choose>
81 <xslt:when test="self::*">
82 <xslt:variable name="context" select="."/>
83 <xslt:variable name="attribute-names">
84 <xslt:for-each select="$existing-attributes|$additional-attributes">
85 <书社:attribute>
86 <attribute name="local-name">
87 <text>{local-name()}</text>
88 </attribute>
89 <attribute name="name">
90 <text>{name()}</text>
91 </attribute>
92 <attribute name="namespace-uri">
93 <text>{namespace-uri()}</text>
94 </attribute>
95 </书社:attribute>
96 </xslt:for-each>
97 </xslt:variable>
98 <xslt:variable name="lang">
99 <xslt:choose>
100 <xslt:when test="(self::html:*|self::svg:*)/@lang">
101 <xslt:value-of select="@lang"/>
102 </xslt:when>
103 <xslt:when test="@xml:lang">
104 <xslt:value-of select="@xml:lang"/>
105 </xslt:when>
106 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
107 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
108 </xslt:when>
109 <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']">
110 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
111 </xslt:when>
112 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
113 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
114 </xslt:when>
115 </xslt:choose>
116 </xslt:variable>
117 <xslt:copy>
118 <xslt:if test="$and-version and $THISREV">
119 <xslt:attribute name="书社:version">
120 <xslt:value-of select="$THISREV"/>
121 </xslt:attribute>
122 </xslt:if>
123 <xslt:if test="string($lang)!=''">
124 <xslt:if test="self::html:* or self::svg:*">
125 <xslt:attribute name="lang">
126 <xslt:value-of select="$lang"/>
127 </xslt:attribute>
128 </xslt:if>
129 <xslt:attribute name="xml:lang">
130 <xslt:value-of select="$lang"/>
131 </xslt:attribute>
132 </xslt:if>
133 <xslt:for-each select="exsl:node-set($attribute-names)/*">
134 <xslt:choose>
135 <xslt:when test="@namespace-uri='&xml;'"/>
136 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
137 <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])"/>
138 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
139 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
140 <xslt:otherwise>
141 <xslt:attribute>
142 <attribute name="name">
143 <text>{@name}</text>
144 </attribute>
145 <attribute name="namespace">
146 <text>{@namespace-uri}</text>
147 </attribute>
148 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
149 <xslt:value-of select="."/>
150 <xslt:if test="position()!=last()">
151 <xslt:text>
152 <text> </text>
153 </xslt:text>
154 </xslt:if>
155 </xslt:for-each>
156 <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]">
157 <xslt:text>
158 <text> </text>
159 </xslt:text>
160 </xslt:if>
161 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
162 <xslt:value-of select="."/>
163 <xslt:if test="position()!=last()">
164 <xslt:text>
165 <text> </text>
166 </xslt:text>
167 </xslt:if>
168 </xslt:for-each>
169 </xslt:attribute>
170 </xslt:otherwise>
171 </xslt:choose>
172 </xslt:for-each>
173 <xslt:copy-of select="node()"/>
174 </xslt:copy>
175 </xslt:when>
176 <xslt:otherwise>
177 <xslt:copy-of select="."/>
178 </xslt:otherwise>
179 </xslt:choose>
180 </xslt:for-each>
181 </xslt:template>
182 <xslt:template name="书社:wrap">
183 <xslt:param name="nodes" select="/.."/>
184 <xslt:variable name="modalinput">
185 <xslt:copy-of select="$nodes"/>
186 <xslt:copy-of select="document('')/xslt:transform/xslt:include"/>
187 </xslt:variable>
188 <xslt:variable name="metadata">
189 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
190 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:metadata"/>
191 </xslt:variable>
192 <html:html>
193 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
194 <xslt:if test="not($nodes[self::html:html]/@书社:archived-as) and $nodes/@书社:archived-as">
195 <xslt:attribute name="书社:archived-as">
196 <xslt:value-of select="$nodes/@书社:archived-as"/>
197 </xslt:attribute>
198 </xslt:if>
199 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
200 <xslt:attribute name="lang">
201 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
202 </xslt:attribute>
203 </xslt:if>
204 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
205 <xslt:attribute name="xml:lang">
206 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
207 </xslt:attribute>
208 </xslt:if>
209 <html:head>
210 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
211 <html:title>
212 <xslt:for-each select="exsl:node-set($metadata)/html:title">
213 <xslt:value-of select="."/>
214 <xslt:if test="position()!=last()">
215 <xslt:text>
216 <text> </text>
217 </xslt:text>
218 </xslt:if>
219 </xslt:for-each>
220 </html:title>
221 <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::html:title)]"/>
222 <html:meta name="generator">
223 <xslt:attribute name="content">
224 <xslt:for-each select="exsl:node-set($metadata)/html:meta[@name='generator']">
225 <xslt:value-of select="@content"/>
226 <xslt:text>
227 <text>, </text>
228 </xslt:text>
229 </xslt:for-each>
230 <xslt:text>
231 <text>⛩️📰 书社</text>
232 </xslt:text>
233 <xslt:if test="$THISREV">
234 <xslt:text>
235 <text> (</text>
236 </xslt:text>
237 <xslt:value-of select="$THISREV"/>
238 <xslt:text>
239 <text>)</text>
240 </xslt:text>
241 </xslt:if>
242 </xslt:attribute>
243 </html:meta>
244 </html:head>
245 <html:body>
246 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
247 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:header"/>
248 <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()"/>
249 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:footer"/>
250 </html:body>
251 </html:html>
252 </xslt:template>
253 <xslt:template match="/" priority="1">
254 <xslt:variable name="result-nodes" select="exsl:node-set($书社:result)/node()[not(self::书社:apply-attributes-to-root)]|exsl:node-set($书社:result)/书社:apply-attributes-to-root/descendant::node()[not(self::书社:apply-attributes-to-root) and not(ancestor::*[not(self::书社:apply-attributes-to-root)])]"/>
255 <xslt:variable name="root-with-attributes">
256 <xslt:choose>
257 <xslt:when test="$result-nodes/self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|$result-nodes/@书社:disable-output-wrapping|exsl:node-set($书社:result)//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
258 <xslt:call-template name="书社:apply-attributes">
259 <xslt:with-param name="and-version" select="true()"/>
260 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
261 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
262 </xslt:call-template>
263 </xslt:when>
264 <xslt:otherwise>
265 <xslt:variable name="wrapped-result">
266 <xslt:call-template name="书社:wrap">
267 <xslt:with-param name="nodes" select="$result-nodes"/>
268 </xslt:call-template>
269 </xslt:variable>
270 <xslt:call-template name="书社:apply-attributes">
271 <xslt:with-param name="and-version" select="true()"/>
272 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
273 <xslt:with-param name="destination-nodes" select="exsl:node-set($wrapped-result)/node()"/>
274 </xslt:call-template>
275 </xslt:otherwise>
276 </xslt:choose>
277 </xslt:variable>
278 <xslt:apply-templates select="exsl:node-set($root-with-attributes)/node()" mode="书社:application"/>
279 </xslt:template>
280 <xslt:template match="@*|node()" priority="-1">
281 <xslt:copy>
282 <xslt:apply-templates select="@*|node()"/>
283 </xslt:copy>
284 </xslt:template>
285 <xslt:template match="@*|node()" mode="书社:application">
286 <xslt:copy>
287 <xslt:apply-templates select="@*|node()" mode="书社:application"/>
288 </xslt:copy>
289 </xslt:template>
290 <xslt:template match="@书社:destination|@书社:disable-output-wrapping|@书社:archived-as[../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]]" mode="书社:application" priority="1"/>
291 <xslt:template match="书社:archive" mode="书社:application" priority="1">
292 <xslt:copy>
293 <xslt:for-each select="@*">
294 <xslt:choose>
295 <xslt:when test="local-name()='archived-as' and namespace-uri()='&书社;' and ../ancestor::*[not(self::书社:apply-attributes-to-root or self::书社:apply-attributes)]"/>
296 <xslt:otherwise>
297 <xslt:apply-templates select="." mode="书社:application"/>
298 </xslt:otherwise>
299 </xslt:choose>
300 </xslt:for-each>
301 <xslt:for-each select="node()">
302 <xslt:choose>
303 <xslt:when test="self::*">
304 <xslt:variable name="component">
305 <xslt:choose>
306 <xslt:when test="self::书社:*[local-name()='raw-text' or local-name()='base64-binary' or local-name()='archive']|@书社:disable-output-wrapping">
307 <xslt:copy-of select="."/>
308 </xslt:when>
309 <xslt:otherwise>
310 <xslt:call-template name="书社:wrap">
311 <xslt:with-param name="nodes" select="."/>
312 </xslt:call-template>
313 </xslt:otherwise>
314 </xslt:choose>
315 </xslt:variable>
316 <xslt:apply-templates select="exsl:node-set($component)/node()" mode="书社:application"/>
317 </xslt:when>
318 <xslt:otherwise>
319 <xslt:apply-templates select="." mode="书社:application"/>
320 </xslt:otherwise>
321 </xslt:choose>
322 </xslt:for-each>
323 </xslt:copy>
324 </xslt:template>
325 <xslt:template match="书社:apply-attributes" mode="书社:application" priority="1">
326 <xslt:variable name="children">
327 <xslt:apply-templates mode="书社:application"/>
328 </xslt:variable>
329 <xslt:call-template name="书社:apply-attributes">
330 <xslt:with-param name="context-nodes" select="."/>
331 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
332 </xslt:call-template>
333 </xslt:template>
334 <xslt:template match="书社:apply-attributes-to-root" mode="书社:application" priority="1">
335 <xslt:apply-templates mode="书社:application"/>
336 </xslt:template>
337 <xslt:template match="/node()" mode="书社:expand" priority="0">
338 <xslt:copy>
339 <xslt:choose>
340 <xslt:when test="self::html:*">
341 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
342 <xslt:attribute name="itemtype">
343 <xslt:text>
344 <text>&书社;:document</text>
345 </xslt:text>
346 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
347 <xslt:text>
348 <text> </text>
349 </xslt:text>
350 <xslt:value-of select="."/>
351 </xslt:for-each>
352 </xslt:attribute>
353 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
354 </xslt:when>
355 <xslt:otherwise>
356 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
357 </xslt:otherwise>
358 </xslt:choose>
359 </xslt:copy>
360 </xslt:template>
361 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
362 <xslt:variable name="identifier" select="string(@xlink:href)"/>
363 <xslt:variable name="uri" select="document($METADATA)//*[@rdf:about=$identifier]/dct:hasFormat/*[nie:interpretedAs/*[@nie:mimeType='application/xml']]/@nfo:fileUrl[1]"/>
364 <xslt:choose>
365 <xslt:when test="$uri">
366 <xslt:variable name="expanded">
367 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
368 </xslt:variable>
369 <xslt:for-each select="exsl:node-set($expanded)/node()">
370 <xslt:copy>
371 <xslt:choose>
372 <xslt:when test="self::html:*">
373 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
374 <xslt:attribute name="itemtype">
375 <xslt:text>
376 <text>&书社;:embed</text>
377 </xslt:text>
378 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
379 <xslt:text>
380 <text> </text>
381 </xslt:text>
382 <xslt:value-of select="."/>
383 </xslt:for-each>
384 </xslt:attribute>
385 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
386 </xslt:when>
387 <xslt:otherwise>
388 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
389 </xslt:otherwise>
390 </xslt:choose>
391 </xslt:copy>
392 </xslt:for-each>
393 </xslt:when>
394 <xslt:otherwise>
395 <xslt:copy>
396 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
397 </xslt:copy>
398 </xslt:otherwise>
399 </xslt:choose>
400 </xslt:template>
401 <xslt:template match="@*|node()[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
402 <xslt:copy>
403 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
404 </xslt:copy>
405 </xslt:template>
406 <xslt:template match="text()" mode="书社:header"/>
407 <xslt:template match="text()" mode="书社:footer"/>
408 <xslt:template match="text()" mode="书社:metadata"/>
409 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea 书社:raw-output 书社:raw-text"/>
410 </xslt:transform>
411 </template>
412 <output method="xml" encoding="UTF-8"/>
413 </transform>
This page took 0.069138 seconds and 5 git commands to generate.