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