3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ ⛩📰 书社 ∷ lib/catalog2parser.xslt
9 © 2023–2024 Lady [@ Lady’s Computer].
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/>.
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"
29 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
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">
38 <for-each select="//catalog:uri">
39 <variable name="parser" select="document(@uri, .)"/>
42 <value-of select="@name"/>
45 <when test="$parser/*/@书社:supported-media-types">
46 <for-each select="exslstr:tokenize($parser/*/@书社:supported-media-types)">
47 <if test="not(translate(., '0123456789abcdefghijklmnopqrstuvwxyz!#$&-^_.+/', ''))">
49 <value-of select="."/>
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()"/>
61 <text>script[@type=</text>
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, '"') and substring($inner, string-length($inner))='"' or starts-with($inner, "'") and substring($inner, string-length($inner))="'"">
66 <variable name="type" select="substring($inner, 2, string-length($inner)-2)"/>
67 <if test="not(translate($type, '0123456789abcdefghijklmnopqrstuvwxyz!#$&-^_.+/', ''))">
69 <value-of select="$type"/>
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"/>
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()">
97 <xslt:when test="self::*">
99 <xslt:if test="string($id)!=''">
100 <xslt:attribute name="书社:parsed-by">
101 <xslt:value-of select="$id"/>
102 <xslt:if test="@书社:parsed-by">
106 <xslt:value-of select="@书社:parsed-by"/>
110 <xslt:if test="string($media-type)!=''">
111 <xslt:attribute name="书社:media-type">
112 <xslt:value-of select="$media-type"/>
115 <xslt:copy-of select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4' or local-name()!='parsed-by' and local-name()!='media-type']|node()"/>
119 <xslt:copy-of select="."/>
124 <xslt:template match="/">
125 <xslt:apply-templates select="node()" mode="书社:parse"/>
127 <xslt:template match="@*|node()" priority="-1">
129 <xslt:apply-templates select="@*|node()" mode="书社:parse"/>
132 <xslt:template match="html:script[@type]" mode="书社:parse" priority="1">
133 <xslt:variable name="parserdiv" select="exsl:node-set($书社:parsers)//html:div[html:dd=current()/@type]"/>
135 <xslt:when test="$parserdiv">
136 <xslt:variable name="result">
137 <xslt:apply-templates select="."/>
139 <xslt:variable name="reparsed-result">
140 <xslt:apply-templates select="exsl:node-set($result)/node()" mode="书社:parse"/>
142 <xslt:call-template name="书社:apply-parsed-by">
143 <xslt:with-param name="id" select="string($parserdiv/html:dt)"/>
144 <xslt:with-param name="media-type" select="string(@type)"/>
145 <xslt:with-param name="result" select="exsl:node-set($reparsed-result)"/>
146 </xslt:call-template>
149 <xslt:apply-templates select="."/>
153 <xslt:template match="@*|node()" mode="书社:parse">
154 <xslt:apply-templates select="."/>
158 <output method="xml" encoding="UTF-8"/>