]> Lady’s Gitweb - Shushe/blob - lib/catalog2transform.xslt
Better wrapper support for plural result trees
[Shushe] / lib / catalog2transform.xslt
1 <?xml version="1.0"?>
2 <!--
3 ⁌ ⛩️📰 书社 ∷ lib/catalog2transform.xslt
4
5 © 2023–2024 Lady [@ Lady’s Computer]
6
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/>.
9 -->
10 <!DOCTYPE transform [
11 <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4">
12 ]>
13 <transform
14 xmlns="http://www.w3.org/1999/XSL/Transform"
15 xmlns:html="http://www.w3.org/1999/xhtml"
16 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
17 xmlns:exsl="http://exslt.org/common"
18 xmlns:exslstr="http://exslt.org/strings"
19 xmlns:svg="http://www.w3.org/2000/svg"
20 xmlns:xlink="http://www.w3.org/1999/xlink"
21 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
22 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
23 version="1.0"
24 >
25 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
26 <template match="/">
27 <xslt:transform exclude-result-prefixes="catalog exsl exslstr" version="1.0">
28 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
29 <xslt:param name="CATALOG" select="'catalog'"/>
30 <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
31 <xslt:param name="PATH" select="'/unknown'"/>
32 <xslt:param name="VERSION" select="false"/>
33 <xslt:param name="SRCREV" select="false"/>
34 <xslt:variable name="书社:expansion">
35 <xslt:apply-templates select="/" mode="书社:expand"/>
36 </xslt:variable>
37 <xslt:variable name="书社:result">
38 <xslt:apply-templates select="exsl:node-set($书社:expansion)/*"/>
39 </xslt:variable>
40 <for-each select="//catalog:uri">
41 <xslt:include href="{@uri}">
42 <if test="contains(@name, ':')">
43 <attribute name="书社:id">
44 <value-of select="@name"/>
45 </attribute>
46 </if>
47 </xslt:include>
48 </for-each>
49 <xslt:template match="/" priority="1">
50 <xslt:choose>
51 <xslt:when test="exsl:node-set($书社:result)/*[@书社:disable-output-wrapping]">
52 <xslt:for-each select="exsl:node-set($书社:result)/*">
53 <xslt:copy>
54 <xslt:if test="$VERSION">
55 <xslt:attribute name="书社:version">
56 <xslt:value-of select="$VERSION"/>
57 </xslt:attribute>
58 </xslt:if>
59 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and contains('disable-output-wrapping version', local-name()))]|node()"/>
60 </xslt:copy>
61 </xslt:for-each>
62 </xslt:when>
63 <xslt:otherwise>
64 <xslt:apply-templates select="exsl:node-set($书社:result)" mode="书社:wrap"/>
65 </xslt:otherwise>
66 </xslt:choose>
67 </xslt:template>
68 <xslt:template match="/*/*//@书社:disable-output-wrapping|//@书社:destination" priority="0"/>
69 <xslt:template match="@*|node()" priority="-1">
70 <xslt:copy>
71 <xslt:apply-templates select="@*|node()"/>
72 </xslt:copy>
73 </xslt:template>
74 <xslt:template match="/*" mode="书社:expand" priority="0">
75 <xslt:copy>
76 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
77 <xslt:attribute name="itemtype">
78 <xslt:text>&书社;:document</xslt:text>
79 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
80 <xslt:text> </xslt:text>
81 <xslt:value-of select="."/>
82 </xslt:for-each>
83 </xslt:attribute>
84 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
85 </xslt:copy>
86 </xslt:template>
87 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
88 <xslt:variable name="uri" select="substring-before(document($CATALOG)//catalog:uri[@name=current()/@xlink:href]/@uri[1], '#')"/>
89 <xslt:choose>
90 <xslt:when test="$uri">
91 <xslt:variable name="expanded">
92 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
93 </xslt:variable>
94 <xslt:for-each select="exsl:node-set($expanded)/*">
95 <xslt:copy>
96 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
97 <xslt:attribute name="itemtype">
98 <xslt:text>&书社;:embed</xslt:text>
99 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
100 <xslt:text> </xslt:text>
101 <xslt:value-of select="."/>
102 </xslt:for-each>
103 </xslt:attribute>
104 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
105 </xslt:copy>
106 </xslt:for-each>
107 </xslt:when>
108 <xslt:otherwise>
109 <xslt:copy>
110 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
111 </xslt:copy>
112 </xslt:otherwise>
113 </xslt:choose>
114 </xslt:template>
115 <xslt:template match="@*|text()|*[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
116 <xslt:copy>
117 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
118 </xslt:copy>
119 </xslt:template>
120 <xslt:template match="text()" mode="书社:header"/>
121 <xslt:template match="text()" mode="书社:footer"/>
122 <xslt:template match="text()" mode="书社:metadata"/>
123 <xslt:template match="/" mode="书社:wrap">
124 <xslt:variable name="metadata">
125 <xslt:copy-of select="html:html/html:head/node()|html:head/node()"/>
126 <xslt:apply-templates select="." mode="书社:metadata"/>
127 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:metadata"/>
128 </xslt:variable>
129 <html:html>
130 <xslt:if test="$VERSION">
131 <xslt:attribute name="书社:version">
132 <xslt:value-of select="$VERSION"/>
133 </xslt:attribute>
134 </xslt:if>
135 <xslt:copy-of select="html:html/@*"/>
136 <xslt:if test="not(html:html/@lang) and (html:*/@lang|svg:*/@lang|*/@xml:lang)">
137 <xslt:attribute name="lang">
138 <xslt:value-of select="html:*/@lang|svg:*/@lang|*/@xml:lang"/>
139 </xslt:attribute>
140 </xslt:if>
141 <xslt:if test="not(html:html/@xml:lang) and (html:*/@lang|svg:*/@lang|*/@xml:lang)">
142 <xslt:attribute name="xml:lang">
143 <xslt:value-of select="html:*/@lang|svg:*/@lang|*/@xml:lang"/>
144 </xslt:attribute>
145 </xslt:if>
146 <html:head>
147 <xslt:copy-of select="html:html/html:head/@*|html:head/@*"/>
148 <html:title>
149 <xslt:for-each select="exsl:node-set($metadata)/html:title">
150 <xslt:value-of select="."/>
151 </xslt:for-each>
152 </html:title>
153 <xslt:copy-of select="exsl:node-set($metadata)/node()[not(self::*) or not(self::html:title)]"/>
154 <xslt:if test="not(exsl:node-set($metadata)/html:meta[@name='generator'])">
155 <html:meta name="generator">
156 <xslt:attribute name="content">
157 <xslt:text>⛩️📰 书社</xslt:text>
158 <xslt:if test="$VERSION">
159 <xslt:text> (</xslt:text>
160 <xslt:value-of select="$VERSION"/>
161 <xslt:text>)</xslt:text>
162 </xslt:if>
163 </xslt:attribute>
164 </html:meta>
165 </xslt:if>
166 </html:head>
167 <html:body>
168 <xslt:copy-of select="html:html/html:body/@*|html:body/@*"/>
169 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:header"/>
170 <xslt:apply-templates select="." mode="书社:header"/>
171 <xslt:copy-of select="node()[not(self::html:html or self::html:head or self::html:body)]|html:html/node()[not(self::html:head or self::html:body)]|html:html/html:body/node()|html:body/node()"/>
172 <xslt:apply-templates select="." mode="书社:footer"/>
173 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:footer"/>
174 </html:body>
175 </html:html>
176 </xslt:template>
177 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>
178 </xslt:transform>
179 </template>
180 <output method="xml" encoding="UTF-8"/>
181 </transform>
This page took 0.080708 seconds and 5 git commands to generate.