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