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