]> Lady’s Gitweb - Shushe/blob - lib/catalog2parser.xslt
Fix base64 output
[Shushe] / lib / catalog2parser.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/catalog2parser.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 <transform
15 xmlns="http://www.w3.org/1999/XSL/Transform"
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:html="http://www.w3.org/1999/xhtml"
20 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
21 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
22 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
23 exclude-result-prefixes="catalog exslstr"
24 version="1.0"
25 >
26 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
27 <template match="/">
28 <xslt:transform 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="IDENTIFIER" select="false()"/>
32 <xslt:param name="SRCREV" select="false()"/>
33 <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
34 <xslt:param name="THISREV" select="false()"/>
35 <xslt:variable name="书社:parsers">
36 <html:dl>
37 <for-each select="//catalog:uri">
38 <variable name="parser" select="document(@uri, .)"/>
39 <html:div>
40 <html:dt>
41 <value-of select="@name"/>
42 </html:dt>
43 <choose>
44 <when test="$parser/*/@书社:supported-media-types">
45 <for-each select="exslstr:tokenize($parser/*/@书社:supported-media-types)">
46 <if test="not(translate(., '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
47 <html:dd>
48 <value-of select="."/>
49 </html:dd>
50 </if>
51 </for-each>
52 </when>
53 <otherwise>
54 <for-each select="$parser//xsl:template[not(@name) and not(@mode)]">
55 <variable name="match" select="@match"/>
56 <for-each select="namespace::*[local-name() and string()='http://www.w3.org/1999/xhtml']">
57 <variable name="matchstart">
58 <value-of select="local-name()"/>
59 <text>:</text>
60 <text>script[@type=</text>
61 </variable>
62 <if test="starts-with($match, $matchstart) and substring($match, string-length($match))=']' and contains($match, '/')">
63 <variable name="inner" select="substring-before(substring-after($match, $matchstart), ']')"/>
64 <if test="starts-with($inner, '&#x22;') and substring($inner, string-length($inner))='&#x22;' or starts-with($inner, &#x22;'&#x22;) and substring($inner, string-length($inner))=&#x22;'&#x22;">
65 <variable name="type" select="substring($inner, 2, string-length($inner)-2)"/>
66 <if test="not(translate($type, '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
67 <html:dd>
68 <value-of select="$type"/>
69 </html:dd>
70 </if>
71 </if>
72 </if>
73 </for-each>
74 </for-each>
75 </otherwise>
76 </choose>
77 </html:div>
78 </for-each>
79 </html:dl>
80 </xslt:variable>
81 <for-each select="//catalog:uri">
82 <xslt:include href="{@uri}">
83 <if test="contains(@name, ':')">
84 <attribute name="书社:id">
85 <value-of select="@name"/>
86 </attribute>
87 </if>
88 </xslt:include>
89 </for-each>
90 <xslt:template name="书社:apply-parsed-by">
91 <xslt:param name="id"/>
92 <xslt:param name="media-type"/>
93 <xslt:param name="result" select="/.."/>
94 <xslt:for-each select="$result/node()">
95 <xslt:choose>
96 <xslt:when test="self::*">
97 <xslt:copy>
98 <xslt:if test="string($id)!=''">
99 <xslt:attribute name="书社:parsed-by">
100 <xslt:value-of select="$id"/>
101 <xslt:if test="@书社:parsed-by">
102 <xslt:text>
103 <text> </text>
104 </xslt:text>
105 <xslt:value-of select="@书社:parsed-by"/>
106 </xslt:if>
107 </xslt:attribute>
108 </xslt:if>
109 <xslt:if test="string($media-type)!=''">
110 <xslt:attribute name="书社:media-type">
111 <xslt:value-of select="$media-type"/>
112 </xslt:attribute>
113 </xslt:if>
114 <xslt:copy-of select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4' or local-name()!='parsed-by' and local-name()!='media-type']|node()"/>
115 </xslt:copy>
116 </xslt:when>
117 <xslt:otherwise>
118 <xslt:copy-of select="."/>
119 </xslt:otherwise>
120 </xslt:choose>
121 </xslt:for-each>
122 </xslt:template>
123 <xslt:template match="/">
124 <xslt:variable name="parsedroot">
125 <xslt:apply-templates select="node()" mode="书社:parse"/>
126 </xslt:variable>
127 <xslt:for-each select="exsl:node-set($parsedroot)/node()">
128 <xslt:choose>
129 <xslt:when test="self::*">
130 <xslt:copy>
131 <xslt:attribute name="书社:cksum">
132 <xslt:value-of select="$CKSUM"/>
133 </xslt:attribute>
134 <xslt:copy-of select="@*|node()"/>
135 </xslt:copy>
136 </xslt:when>
137 <xslt:otherwise>
138 <xslt:copy-of select="."/>
139 </xslt:otherwise>
140 </xslt:choose>
141 </xslt:for-each>
142 </xslt:template>
143 <xslt:template match="@*|node()" priority="-1">
144 <xslt:copy>
145 <xslt:apply-templates select="@*|node()" mode="书社:parse"/>
146 </xslt:copy>
147 </xslt:template>
148 <xslt:template match="html:script[@type]" mode="书社:parse" priority="1">
149 <xslt:variable name="parserdiv" select="exsl:node-set($书社:parsers)//html:div[html:dd=current()/@type]"/>
150 <xslt:choose>
151 <xslt:when test="$parserdiv">
152 <xslt:variable name="result">
153 <xslt:apply-templates select="."/>
154 </xslt:variable>
155 <xslt:variable name="reparsed-result">
156 <xslt:apply-templates select="exsl:node-set($result)/node()" mode="书社:parse"/>
157 </xslt:variable>
158 <xslt:call-template name="书社:apply-parsed-by">
159 <xslt:with-param name="id" select="string($parserdiv/html:dt)"/>
160 <xslt:with-param name="media-type" select="string(@type)"/>
161 <xslt:with-param name="result" select="exsl:node-set($reparsed-result)"/>
162 </xslt:call-template>
163 </xslt:when>
164 <xslt:otherwise>
165 <xslt:apply-templates select="."/>
166 </xslt:otherwise>
167 </xslt:choose>
168 </xslt:template>
169 <xslt:template match="@*|node()" mode="书社:parse">
170 <xslt:apply-templates select="."/>
171 </xslt:template>
172 </xslt:transform>
173 </template>
174 <output method="xml" encoding="UTF-8"/>
175 </transform>
This page took 0.063898 seconds and 5 git commands to generate.