]> Lady’s Gitweb - Shushe/blob - lib/catalog2transform.xslt
2a3bc711f64b047fefbeb0f15bfdda0d6278af46
[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:xlink="http://www.w3.org/1999/xlink"
20 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
21 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
22 version="1.0"
23 >
24 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
25 <template match="/">
26 <xslt:transform exclude-result-prefixes="catalog exsl exslstr" version="1.0">
27 <xslt:param name="catalog" select="'catalog'"/>
28 <xslt:variable name="书社:expansion">
29 <xslt:apply-templates select="/" mode="书社:expand"/>
30 </xslt:variable>
31 <xslt:variable name="书社:result">
32 <xslt:apply-templates select="exsl:node-set($书社:expansion)/*"/>
33 </xslt:variable>
34 <for-each select="//catalog:uri">
35 <xslt:include href="{@uri}">
36 <if test="contains(@name, ':')">
37 <attribute name="书社:id">
38 <value-of select="@name"/>
39 </attribute>
40 </if>
41 </xslt:include>
42 </for-each>
43 <xslt:template match="/" priority="1">
44 <xslt:choose>
45 <xslt:when test="exsl:node-set($书社:result)/*[@书社:disable-output-wrapping]">
46 <xslt:for-each select="exsl:node-set($书社:result)/*">
47 <xslt:copy>
48 <xslt:copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='disable-output-wrapping')]|node()"/>
49 </xslt:copy>
50 </xslt:for-each>
51 </xslt:when>
52 <xslt:otherwise>
53 <xslt:apply-templates select="exsl:node-set($书社:result)" mode="书社:wrap"/>
54 </xslt:otherwise>
55 </xslt:choose>
56 </xslt:template>
57 <xslt:template match="/*/*//@书社:disable-output-wrapping" priority="0"/>
58 <xslt:template match="@*|node()" priority="-1">
59 <xslt:copy>
60 <xslt:apply-templates select="@*|node()"/>
61 </xslt:copy>
62 </xslt:template>
63 <xslt:template match="/*" mode="书社:expand" priority="0">
64 <xslt:copy>
65 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
66 <xslt:attribute name="itemtype">
67 <xslt:text>&书社;:document</xslt:text>
68 <xslt:for-each select="exslstr:tokenize(@itemtype)/token">
69 <xslt:text> </xslt:text>
70 <xslt:value-of select="."/>
71 </xslt:for-each>
72 </xslt:attribute>
73 <xslt:apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()" mode="书社:expand"/>
74 </xslt:copy>
75 </xslt:template>
76 <xslt:template match="书社:link[@xlink:show='embed']" mode="书社:expand" priority="1">
77 <xslt:variable name="uri" select="substring-before(document($catalog)//catalog:uri[@name=current()/@xlink:href]/@uri[1], '#')"/>
78 <xslt:choose>
79 <xslt:when test="$uri">
80 <xslt:variable name="expanded">
81 <xslt:apply-templates select="document($uri)" mode="书社:expand"/>
82 </xslt:variable>
83 <xslt:for-each select="exsl:node-set($expanded)/*">
84 <xslt:copy>
85 <xslt:attribute name="itemscope">itemscope</xslt:attribute>
86 <xslt:attribute name="itemtype">
87 <xslt:text>&书社;:embed</xslt:text>
88 <xslt:for-each select="exslstr:tokenize(@itemtype)/token[string()!='&书社;:document']">
89 <xslt:text> </xslt:text>
90 <xslt:value-of select="."/>
91 </xslt:for-each>
92 </xslt:attribute>
93 <xslt:copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype'))]|node()"/>
94 </xslt:copy>
95 </xslt:for-each>
96 </xslt:when>
97 <xslt:otherwise>
98 <xslt:copy>
99 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
100 </xslt:copy>
101 </xslt:otherwise>
102 </xslt:choose>
103 </xslt:template>
104 <xslt:template match="@*|text()|*[not(self::书社:link) or not(@xlink:show='embed')]" mode="书社:expand" priority="-1">
105 <xslt:copy>
106 <xslt:apply-templates select="@*|node()" mode="书社:expand"/>
107 </xslt:copy>
108 </xslt:template>
109 <xslt:template match="text()" mode="书社:header"/>
110 <xslt:template match="text()" mode="书社:footer"/>
111 <xslt:template match="text()" mode="书社:metadata"/>
112 <xslt:template match="/" mode="书社:wrap">
113 <xslt:variable name="metadata">
114 <xslt:copy-of select="html/head/*"/>
115 <xslt:apply-templates select="." mode="书社:metadata"/>
116 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:metadata"/>
117 </xslt:variable>
118 <html:html>
119 <xslt:copy-of select="html:html/@*"/>
120 <html:head>
121 <xslt:copy-of select="html:html/html:head/@*"/>
122 <html:title>
123 <xslt:for-each select="exsl:node-set($metadata)/html:title">
124 <xslt:value-of select="."/>
125 </xslt:for-each>
126 </html:title>
127 <xslt:copy-of select="exsl:node-set($metadata)/node()[self::comment() or self::* and not(self::html:title)]"/>
128 <xslt:if test="not(exsl:node-set($metadata)/html:meta[@name='generator'])">
129 <html:meta name="generator" content="⛩️📰 书社"/>
130 </xslt:if>
131 </html:head>
132 <html:body>
133 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:header"/>
134 <xslt:apply-templates select="." mode="书社:header"/>
135 <xslt:copy-of select="*[not(self::html:html or self::html:body)]|html:html/*[not(self::html:head or self::html:body)]|html:html/html:body/*|html:body/*"/>
136 <xslt:apply-templates select="." mode="书社:footer"/>
137 <xslt:apply-templates select="document('')/xslt:transform/xslt:include" mode="书社:footer"/>
138 </html:body>
139 </html:html>
140 </xslt:template>
141 <xslt:output method="xml" encoding="UTF-8" cdata-section-elements="html:script html:style html:textarea"/>
142 </xslt:transform>
143 </template>
144 </transform>
This page took 0.052036 seconds and 3 git commands to generate.