]> Lady’s Gitweb - Shushe/blob - lib/catalog2parser.xslt
f3afd7fa945d8a763e30cbe22f792269910e290c
[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:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
21 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
22 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
24 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
25 exclude-result-prefixes="catalog"
26 extension-element-prefixes="exslstr"
27 version="1.0"
28 >
29 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
30 <template match="/">
31 <xslt:transform extension-element-prefixes="exsl" version="1.0">
32 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
33 <xslt:param name="IDENTIFIER" select="false()"/>
34 <xslt:param name="SRCREV" select="false()"/>
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="document('metadata')//*[@rdf:about=$IDENTIFIER]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
134 </xslt:attribute>
135 <xslt:attribute name="书社:identifier">
136 <xslt:value-of select="$IDENTIFIER"/>
137 </xslt:attribute>
138 <xslt:attribute name="书社:mtime">
139 <xslt:value-of select="document('metadata')//*[@rdf:about=$IDENTIFIER]/nfo:fileLastModified"/>
140 </xslt:attribute>
141 <xslt:copy-of select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4' or not(contains(' cksum identifier mtime ', concat(' ', local-name(), ' ')))]|node()"/>
142 </xslt:copy>
143 </xslt:when>
144 <xslt:otherwise>
145 <xslt:copy-of select="."/>
146 </xslt:otherwise>
147 </xslt:choose>
148 </xslt:for-each>
149 </xslt:template>
150 <xslt:template match="@*|node()" priority="-1">
151 <xslt:copy>
152 <xslt:apply-templates select="@*|node()" mode="书社:parse"/>
153 </xslt:copy>
154 </xslt:template>
155 <xslt:template match="html:script[@type]" mode="书社:parse" priority="1">
156 <xslt:variable name="parserdiv" select="exsl:node-set($书社:parsers)//html:div[html:dd=current()/@type]"/>
157 <xslt:choose>
158 <xslt:when test="$parserdiv">
159 <xslt:variable name="result">
160 <xslt:apply-templates select="."/>
161 </xslt:variable>
162 <xslt:variable name="reparsed-result">
163 <xslt:apply-templates select="exsl:node-set($result)/node()" mode="书社:parse"/>
164 </xslt:variable>
165 <xslt:call-template name="书社:apply-parsed-by">
166 <xslt:with-param name="id" select="string($parserdiv/html:dt)"/>
167 <xslt:with-param name="media-type" select="string(@type)"/>
168 <xslt:with-param name="result" select="exsl:node-set($reparsed-result)"/>
169 </xslt:call-template>
170 </xslt:when>
171 <xslt:otherwise>
172 <xslt:apply-templates select="."/>
173 </xslt:otherwise>
174 </xslt:choose>
175 </xslt:template>
176 <xslt:template match="@*|node()" mode="书社:parse">
177 <xslt:apply-templates select="."/>
178 </xslt:template>
179 </xslt:transform>
180 </template>
181 <output method="xml" encoding="UTF-8"/>
182 </transform>
This page took 0.053942 seconds and 3 git commands to generate.