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