]> Lady’s Gitweb - Shushe/blob - lib/catalog2transform.xslt
35f9c2bcd5a940a01f4fac5b6cacee6d326e3b9a
[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 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='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
122 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
123 <xslt:otherwise>
124 <xslt:attribute>
125 <attribute name="name">
126 <text>{@name}</text>
127 </attribute>
128 <attribute name="namespace">
129 <text>{@namespace-uri}</text>
130 </attribute>
131 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
132 <xslt:value-of select="."/>
133 <xslt:if test="position()!=last()">
134 <xslt:text>
135 <text> </text>
136 </xslt:text>
137 </xslt:if>
138 </xslt:for-each>
139 <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]">
140 <xslt:text>
141 <text> </text>
142 </xslt:text>
143 </xslt:if>
144 <xslt:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
145 <xslt:value-of select="."/>
146 <xslt:if test="position()!=last()">
147 <xslt:text>
148 <text> </text>
149 </xslt:text>
150 </xslt:if>
151 </xslt:for-each>
152 </xslt:attribute>
153 </xslt:otherwise>
154 </xslt:choose>
155 </xslt:for-each>
156 <xslt:copy-of select="node()"/>
157 </xslt:copy>
158 </xslt:when>
159 <xslt:otherwise>
160 <xslt:copy-of select="."/>
161 </xslt:otherwise>
162 </xslt:choose>
163 </xslt:for-each>
164 </xslt:template>
165 <xslt:template name="书社:wrap">
166 <xslt:param name="nodes" select="/.."/>
167 <xslt:variable name="modalinput">
168 <xslt:copy-of select="$nodes"/>
169 <xslt:copy-of select="document('')/xslt:transform/xslt:include"/>
170 </xslt:variable>
171 <xslt:variable name="metadata">
172 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
173 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:metadata"/>
174 </xslt:variable>
175 <html:html>
176 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
177 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
178 <xslt:attribute name="lang">
179 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
180 </xslt:attribute>
181 </xslt:if>
182 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
183 <xslt:attribute name="xml:lang">
184 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
185 </xslt:attribute>
186 </xslt:if>
187 <html:head>
188 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
189 <html:title>
190 <xslt:for-each select="exsl:node-set($metadata)/html:title">
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 </html:title>
199 <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::html:title)]"/>
200 <html:meta name="generator">
201 <xslt:attribute name="content">
202 <xslt:for-each select="exsl:node-set($metadata)/html:meta[@name='generator']">
203 <xslt:value-of select="@content"/>
204 <xslt:text>
205 <text>, </text>
206 </xslt:text>
207 </xslt:for-each>
208 <xslt:text>
209 <text>⛩️📰 书社</text>
210 </xslt:text>
211 <xslt:if test="$THISREV">
212 <xslt:text>
213 <text> (</text>
214 </xslt:text>
215 <xslt:value-of select="$THISREV"/>
216 <xslt:text>
217 <text>)</text>
218 </xslt:text>
219 </xslt:if>
220 </xslt:attribute>
221 </html:meta>
222 </html:head>
223 <html:body>
224 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
225 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:header"/>
226 <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()"/>
227 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:footer"/>
228 </html:body>
229 </html:html>
230 </xslt:template>
231 <xslt:template match="/" priority="1">
232 <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)])]"/>
233 <xslt:variable name="root-with-attributes">
234 <xslt:choose>
235 <xslt:when test="$result-nodes/@书社:disable-output-wrapping|exsl:node-set($书社:result)//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
236 <xslt:call-template name="书社:apply-attributes">
237 <xslt:with-param name="and-version" select="true()"/>
238 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
239 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
240 </xslt:call-template>
241 </xslt:when>
242 <xslt:otherwise>
243 <xslt:variable name="wrapped-result">
244 <xslt:call-template name="书社:wrap">
245 <xslt:with-param name="nodes" select="$result-nodes"/>
246 </xslt:call-template>
247 </xslt:variable>
248 <xslt:call-template name="书社:apply-attributes">
249 <xslt:with-param name="and-version" select="true()"/>
250 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
251 <xslt:with-param name="destination-nodes" select="exsl:node-set($wrapped-result)/node()"/>
252 </xslt:call-template>
253 </xslt:otherwise>
254 </xslt:choose>
255 </xslt:variable>
256 <xslt:apply-templates select="exsl:node-set($root-with-attributes)/node()" mode="书社:application"/>
257 </xslt:template>
258 <xslt:template match="@*|node()" priority="-1">
259 <xslt:copy>
260 <xslt:apply-templates select="@*|node()"/>
261 </xslt:copy>
262 </xslt:template>
263 <xslt:template match="@*|node()" mode="书社:application">
264 <xslt:copy>
265 <xslt:apply-templates select="@*|node()" mode="书社:application"/>
266 </xslt:copy>
267 </xslt:template>
268 <xslt:template match="@书社:destination|@书社:disable-output-wrapping" mode="书社:application" priority="1"/>
269 <xslt:template match="书社:apply-attributes" mode="书社:application" priority="1">
270 <xslt:variable name="children">
271 <xslt:apply-templates select="node()" mode="书社:application"/>
272 </xslt:variable>
273 <xslt:call-template name="书社:apply-attributes">
274 <xslt:with-param name="context-nodes" select="."/>
275 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
276 </xslt:call-template>
277 </xslt:template>
278 <xslt:template match="书社:apply-attributes-to-root" mode="书社:application" priority="1">
279 <xslt:apply-templates select="node()" mode="书社:application"/>
280 </xslt:template>
281 <xslt:template match="/node()" mode="书社:expand" priority="0">
282 <xslt:copy>
283 <xslt:attribute name="书社:identifier">
284 <xslt:value-of select="$IDENTIFIER"/>
285 </xslt:attribute>
286 <xslt:choose>
287 <xslt:when test="self::html:*">
288 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
289 <xslt:attribute name="itemtype">
290 <xslt:text>
291 <text>&书社;:document</text>
292 </xslt:text>
293 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
294 <xslt:text>
295 <text> </text>
296 </xslt:text>
297 <xslt:value-of select="."/>
298 </xslt:for-each>
299 </xslt:attribute>
300 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
301 </xslt:when>
302 <xslt:otherwise>
303 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
304 </xslt:otherwise>
305 </xslt:choose>
306 </xslt:copy>
307 </xslt:template>
308 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
309 <xslt:variable name="identifier" select="string(@xlink:href)"/>
310 <xslt:variable name="uri" select="substring-before(document($CATALOG)//catalog:uri[@name=$identifier]/@uri[1], '#')"/>
311 <xslt:choose>
312 <xslt:when test="$uri">
313 <xslt:variable name="expanded">
314 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
315 </xslt:variable>
316 <xslt:for-each select="exsl:node-set($expanded)/node()">
317 <xslt:copy>
318 <xslt:attribute name="书社:identifier">
319 <xslt:value-of select="$identifier"/>
320 </xslt:attribute>
321 <xslt:choose>
322 <xslt:when test="self::html:*">
323 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
324 <xslt:attribute name="itemtype">
325 <xslt:text>
326 <text>&书社;:embed</text>
327 </xslt:text>
328 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
329 <xslt:text>
330 <text> </text>
331 </xslt:text>
332 <xslt:value-of select="."/>
333 </xslt:for-each>
334 </xslt:attribute>
335 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='identifier')]|node()"/>
336 </xslt:when>
337 <xslt:otherwise>
338 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and local-name()='identifier')]|node()" mode="书社:expand"/>
339 </xslt:otherwise>
340 </xslt:choose>
341 </xslt:copy>
342 </xslt:for-each>
343 </xslt:when>
344 <xslt:otherwise>
345 <xslt:copy>
346 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
347 </xslt:copy>
348 </xslt:otherwise>
349 </xslt:choose>
350 </xslt:template>
351 <xslt:template match="@*|node()[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
352 <xslt:copy>
353 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
354 </xslt:copy>
355 </xslt:template>
356 <xslt:template match="text()" mode="书社:header"/>
357 <xslt:template match="text()" mode="书社:footer"/>
358 <xslt:template match="text()" mode="书社:metadata"/>
359 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>
360 </xslt:transform>
361 </template>
362 <output method="xml" encoding="UTF-8"/>
363 </transform>
This page took 0.096407 seconds and 3 git commands to generate.