3 ⁌ ⛩️📰 书社 ∷ lib/catalog2transform.xslt
5 © 2023–2024 Lady [@ Lady’s Computer]
7 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
8 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/>.
11 <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
12 <!ENTITY xml "http://www.w3.org/XML/1998/namespace">
15 xmlns="http://www.w3.org/1999/XSL/Transform"
16 xmlns:html="http://www.w3.org/1999/xhtml"
17 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
18 xmlns:exsl="http://exslt.org/common"
19 xmlns:exslstr="http://exslt.org/strings"
20 xmlns:svg="http://www.w3.org/2000/svg"
21 xmlns:xlink="http://www.w3.org/1999/xlink"
22 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
23 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
26 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
28 <xslt:transform exclude-result-prefixes="catalog exsl exslstr" version="1.0">
29 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
30 <xslt:param name="CKSUM" select="false"/>
31 <xslt:param name="CATALOG" select="'catalog'"/>
32 <xslt:param name="IDENTIFIER" select="false"/>
33 <xslt:param name="PATH" select="'/unknown'"/>
34 <xslt:param name="SRCREV" select="false"/>
35 <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
36 <xslt:param name="THISREV" select="false"/>
37 <xslt:variable name="书社:source" select="/"/>
38 <xslt:variable name="书社:expansion">
39 <xslt:apply-templates select="$书社:source/node()" mode="书社:expand"/>
41 <xslt:variable name="书社:result">
42 <xslt:apply-templates select="exsl:node-set($书社:expansion)/node()"/>
44 <for-each select="//catalog:uri">
45 <xslt:include href="{@uri}">
46 <if test="contains(@name, ':')">
47 <attribute name="书社:id">
48 <value-of select="@name"/>
53 <xslt:template name="书社:apply-attributes">
54 <xslt:param name="and-version" select="false"/>
55 <xslt:param name="context-nodes" select="/.."/>
56 <xslt:param name="destination-nodes" select="/.."/>
57 <xslt:variable name="additional-attributes" select="$context-nodes/@*"/>
58 <xslt:for-each select="$destination-nodes">
59 <xslt:variable name="existing-attributes" select="@*"/>
61 <xslt:when test="self::*">
62 <xslt:variable name="context" select="."/>
63 <xslt:variable name="attribute-names">
64 <xslt:for-each select="$existing-attributes|$additional-attributes">
66 <attribute name="local-name">
67 <text>{local-name()}</text>
69 <attribute name="name">
72 <attribute name="namespace-uri">
73 <text>{namespace-uri()}</text>
78 <xslt:variable name="lang">
80 <xslt:when test="(self::html:*|self::svg:*)/@lang">
81 <xslt:value-of select="@lang"/>
83 <xslt:when test="@xml:lang">
84 <xslt:value-of select="@xml:lang"/>
86 <xslt:when test="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']">
87 <xslt:value-of select="$additional-attributes[(parent::html:* or parent::svg:*) and namespace-uri()='' and local-name()='lang']"/>
89 <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']">
90 <xslt:value-of select="$additional-attributes[(parent::书社:apply-attributes or parent::书社:apply-attributes-to-root) and namespace-uri()='' and local-name()='lang']"/>
92 <xslt:when test="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']">
93 <xslt:value-of select="$additional-attributes[namespace-uri()='&xml;' and local-name()='lang']"/>
98 <xslt:if test="$and-version and $THISREV">
99 <xslt:attribute name="书社:version">
100 <xslt:value-of select="$THISREV"/>
103 <xslt:if test="string($lang)!=''">
104 <xslt:if test="self::html:* or self::svg:*">
105 <xslt:attribute name="lang">
106 <xslt:value-of select="$lang"/>
109 <xslt:attribute name="xml:lang">
110 <xslt:value-of select="$lang"/>
113 <xslt:for-each select="exsl:node-set($attribute-names)/*">
115 <xslt:when test="@namespace-uri='&xml;'"/>
116 <xslt:when test="$context[self::html:* or self::svg:*] and @namespace-uri='' and @local-name='lang'"/>
117 <xslt:when test="@namespace-uri='&书社;' and (@local-name='destination' or @local-name='disable-output-wrapping' or @local-name='version')"/>
118 <xslt:when test="preceding-sibling::*[@local-name=current()/@local-name and @namespace-uri=current()/@namespace-uri]"/>
121 <attribute name="name">
124 <attribute name="namespace">
125 <text>{@namespace-uri}</text>
127 <xslt:for-each select="$existing-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
128 <xslt:value-of select="."/>
129 <xslt:if test="position()!=last()">
135 <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:for-each select="$additional-attributes[local-name()=current()/@local-name and namespace-uri()=current()/@namespace-uri]">
141 <xslt:value-of select="."/>
142 <xslt:if test="position()!=last()">
152 <xslt:copy-of select="node()"/>
156 <xslt:copy-of select="."/>
161 <xslt:template name="书社:wrap">
162 <xslt:param name="nodes" select="/.."/>
163 <xslt:variable name="modalinput">
164 <xslt:copy-of select="$nodes"/>
165 <xslt:copy-of select="document('')/xslt:transform/xslt:include"/>
167 <xslt:variable name="metadata">
168 <xslt:copy-of select="$nodes[self::html:html]/html:head/node()|$nodes[self::html:head]/node()"/>
169 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:metadata"/>
172 <xslt:copy-of select="$nodes[self::html:html]/@*"/>
173 <xslt:if test="not($nodes[self::html:html]/@lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
174 <xslt:attribute name="lang">
175 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
178 <xslt:if test="not($nodes[self::html:html]/@xml:lang) and $nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang">
179 <xslt:attribute name="xml:lang">
180 <xslt:value-of select="$nodes[self::html:*]/@lang|$nodes[self::svg:*]/@lang|$nodes/@xml:lang"/>
184 <xslt:copy-of select="$nodes[self::html:html]/html:head/@*|$nodes[self::html:head]/@*"/>
186 <xslt:for-each select="exsl:node-set($metadata)/html:title">
187 <xslt:value-of select="."/>
188 <xslt:if test="position()!=last()">
195 <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::html:title)]"/>
196 <html:meta name="generator">
197 <xslt:attribute name="content">
198 <xslt:for-each select="exsl:node-set($metadata)/html:meta[@name='generator']">
199 <xslt:value-of select="@content"/>
207 <xslt:if test="$THISREV">
211 <xslt:value-of select="$THISREV"/>
220 <xslt:copy-of select="$nodes[self::html:html]/html:body/@*|$nodes[self::html:body]/@*"/>
221 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:header"/>
222 <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()"/>
223 <xslt:apply-templates select="exsl:node-set($modalinput)/node()" mode="书社:footer"/>
227 <xslt:template match="/" priority="1">
228 <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)])]"/>
229 <xslt:variable name="root-with-attributes">
231 <xslt:when test="$result-nodes/@书社:disable-output-wrapping|exsl:node-set($书社:result)//书社:apply-attributes-to-root/@书社:disable-output-wrapping">
232 <xslt:call-template name="书社:apply-attributes">
233 <xslt:with-param name="and-version" select="true"/>
234 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
235 <xslt:with-param name="destination-nodes" select="$result-nodes"/>
236 </xslt:call-template>
239 <xslt:variable name="wrapped-result">
240 <xslt:call-template name="书社:wrap">
241 <xslt:with-param name="nodes" select="$result-nodes"/>
242 </xslt:call-template>
244 <xslt:call-template name="书社:apply-attributes">
245 <xslt:with-param name="and-version" select="true"/>
246 <xslt:with-param name="context-nodes" select="exsl:node-set($书社:result)//书社:apply-attributes-to-root"/>
247 <xslt:with-param name="destination-nodes" select="exsl:node-set($wrapped-result)/node()"/>
248 </xslt:call-template>
252 <xslt:apply-templates select="exsl:node-set($root-with-attributes)/node()" mode="书社:application"/>
254 <xslt:template match="@*|node()" priority="-1">
256 <xslt:apply-templates select="@*|node()"/>
259 <xslt:template match="@*|node()" mode="书社:application">
261 <xslt:apply-templates select="@*|node()" mode="书社:application"/>
264 <xslt:template match="@书社:destination|@书社:disable-output-wrapping" mode="书社:application" priority="1"/>
265 <xslt:template match="书社:apply-attributes" mode="书社:application" priority="1">
266 <xslt:variable name="children">
267 <xslt:apply-templates select="node()" mode="书社:application"/>
269 <xslt:call-template name="书社:apply-attributes">
270 <xslt:with-param name="context-nodes" select="."/>
271 <xslt:with-param name="destination-nodes" select="exsl:node-set($children)/node()"/>
272 </xslt:call-template>
274 <xslt:template match="书社:apply-attributes-to-root" mode="书社:application" priority="1">
275 <xslt:apply-templates select="node()" mode="书社:application"/>
277 <xslt:template match="/node()" mode="书社:expand" priority="0">
279 <xslt:attribute name="书社:identifier">
280 <xslt:value-of select="$IDENTIFIER"/>
283 <xslt:when test="self::html:*">
284 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
285 <xslt:attribute name="itemtype">
287 <text>&书社;:document</text>
289 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
293 <xslt:value-of select="."/>
296 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
299 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
304 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
305 <xslt:variable name="identifier" select="string(@xlink:href)"/>
306 <xslt:variable name="uri" select="substring-before(document($CATALOG)//catalog:uri[@name=$identifier]/@uri[1], '#')"/>
308 <xslt:when test="$uri">
309 <xslt:variable name="expanded">
310 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
312 <xslt:for-each select="exsl:node-set($expanded)/node()">
314 <xslt:attribute name="书社:identifier">
315 <xslt:value-of select="$identifier"/>
318 <xslt:when test="self::html:*">
319 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
320 <xslt:attribute name="itemtype">
322 <text>&书社;:embed</text>
324 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
328 <xslt:value-of select="."/>
331 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='identifier')]|node()"/>
334 <xslt:apply-templates select="@*[not(namespace-uri()='&书社;' and local-name()='identifier')]|node()" mode="书社:expand"/>
342 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
347 <xslt:template match="@*|node()[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
349 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
352 <xslt:template match="text()" mode="书社:header"/>
353 <xslt:template match="text()" mode="书社:footer"/>
354 <xslt:template match="text()" mode="书社:metadata"/>
355 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>
358 <output method="xml" encoding="UTF-8"/>