3 ⁌ ⛩️📰 书社 ∷ lib/catalog2parser.xslt
5 © 2023–2024 Lady [@ Lady’s Computer]
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/>.
11 xmlns="http://www.w3.org/1999/XSL/Transform"
12 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
13 xmlns:exsl="http://exslt.org/common"
14 xmlns:exslstr="http://exslt.org/strings"
15 xmlns:html="http://www.w3.org/1999/xhtml"
16 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
17 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
18 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
19 exclude-result-prefixes="catalog exslstr"
22 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
24 <xslt:transform version="1.0">
25 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
26 <xslt:param name="CKSUM" select="false"/>
27 <xslt:param name="IDENTIFIER" select="false"/>
28 <xslt:param name="SRCREV" select="false"/>
29 <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
30 <xslt:param name="THISREV" select="false"/>
31 <xslt:variable name="书社:parsers">
33 <for-each select="//catalog:uri">
34 <variable name="parser" select="document(@uri, .)"/>
37 <value-of select="@name"/>
40 <when test="$parser/*/@书社:supported-media-types">
41 <for-each select="exslstr:tokenize($parser/*/@书社:supported-media-types)">
42 <if test="not(translate(., '0123456789abcdefghijklmnopqrstuvwxyz!#$&-^_.+/', ''))">
44 <value-of select="."/>
50 <for-each select="$parser//xsl:template[not(@name) and not(@mode)]">
51 <variable name="match" select="@match"/>
52 <for-each select="namespace::*[local-name() and string()='http://www.w3.org/1999/xhtml']">
53 <variable name="matchstart">
54 <value-of select="local-name()"/>
56 <text>script[@type=</text>
58 <if test="starts-with($match, $matchstart) and substring($match, string-length($match))=']' and contains($match, '/')">
59 <variable name="inner" select="substring-before(substring-after($match, $matchstart), ']')"/>
60 <if test="starts-with($inner, '"') and substring($inner, string-length($inner))='"' or starts-with($inner, "'") and substring($inner, string-length($inner))="'"">
61 <variable name="type" select="substring($inner, 2, string-length($inner)-2)"/>
62 <if test="not(translate($type, '0123456789abcdefghijklmnopqrstuvwxyz!#$&-^_.+/', ''))">
64 <value-of select="$type"/>
77 <for-each select="//catalog:uri">
78 <xslt:include href="{@uri}">
79 <if test="contains(@name, ':')">
80 <attribute name="书社:id">
81 <value-of select="@name"/>
86 <xslt:template name="书社:apply-parsed-by">
87 <xslt:param name="id"/>
88 <xslt:param name="media-type"/>
89 <xslt:param name="result" select="/.."/>
90 <xslt:for-each select="$result/node()">
92 <xslt:when test="self::*">
94 <xslt:if test="string($id)!=''">
95 <xslt:attribute name="书社:parsed-by">
96 <xslt:value-of select="$id"/>
97 <xslt:if test="@书社:parsed-by">
101 <xslt:value-of select="@书社:parsed-by"/>
105 <xslt:if test="string($media-type)!=''">
106 <xslt:attribute name="书社:media-type">
107 <xslt:value-of select="$media-type"/>
110 <xslt:copy-of select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4' or local-name()!='parsed-by' and local-name()!='media-type']|node()"/>
114 <xslt:copy-of select="."/>
119 <xslt:template match="/">
120 <xslt:variable name="parsedroot">
121 <xslt:apply-templates select="node()" mode="书社:parse"/>
123 <xslt:for-each select="exsl:node-set($parsedroot)/node()">
125 <xslt:when test="self::*">
127 <xslt:attribute name="书社:cksum">
128 <xslt:value-of select="$CKSUM"/>
130 <xslt:copy-of select="@*|node()"/>
134 <xslt:copy-of select="."/>
139 <xslt:template match="@*|node()" priority="-1">
141 <xslt:apply-templates select="@*|node()" mode="书社:parse"/>
144 <xslt:template match="html:script[@type]" mode="书社:parse" priority="1">
145 <xslt:variable name="parserdiv" select="exsl:node-set($书社:parsers)//html:div[html:dd=current()/@type]"/>
147 <xslt:when test="$parserdiv">
148 <xslt:variable name="result">
149 <xslt:apply-templates select="."/>
151 <xslt:variable name="reparsed-result">
152 <xslt:apply-templates select="exsl:node-set($result)/node()" mode="书社:parse"/>
154 <xslt:call-template name="书社:apply-parsed-by">
155 <xslt:with-param name="id" select="string($parserdiv/html:dt)"/>
156 <xslt:with-param name="media-type" select="string(@type)"/>
157 <xslt:with-param name="result" select="exsl:node-set($reparsed-result)"/>
158 </xslt:call-template>
161 <xslt:apply-templates select="."/>
165 <xslt:template match="@*|node()" mode="书社:parse">
166 <xslt:apply-templates select="."/>
170 <output method="xml" encoding="UTF-8"/>