]> Lady’s Gitweb - Shushe/blob - lib/catalog2parser.xslt
Remove classes from parse results
[Shushe] / lib / catalog2parser.xslt
1 <?xml version="1.0"?>
2 <!--
3 ⁌ ⛩️📰 书社 ∷ lib/catalog2parser.xslt
4
5 © 2023–2024 Lady [@ Lady’s Computer]
6
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/>.
9 -->
10 <transform
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"
20 version="1.0"
21 >
22 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
23 <template match="/">
24 <xslt:transform version="1.0">
25 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
26 <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
27 <xslt:param name="VERSION" select="false"/>
28 <xslt:param name="SRCREV" select="false"/>
29 <xslt:variable name="书社:parsers">
30 <html:dl>
31 <for-each select="//catalog:uri">
32 <variable name="parser" select="document(@uri, .)"/>
33 <html:div>
34 <html:dt>
35 <value-of select="@name"/>
36 </html:dt>
37 <choose>
38 <when test="$parser/*/@书社:supported-media-types">
39 <for-each select="exslstr:tokenize($parser/*/@书社:supported-media-types)">
40 <if test="not(translate(., '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
41 <html:dd>
42 <value-of select="."/>
43 </html:dd>
44 </if>
45 </for-each>
46 </when>
47 <otherwise>
48 <for-each select="$parser//xsl:template[not(@name) and not(@mode)]">
49 <variable name="match" select="@match"/>
50 <for-each select="namespace::*[local-name() and string()='http://www.w3.org/1999/xhtml']">
51 <variable name="matchstart">
52 <value-of select="local-name()"/>
53 <text>:</text>
54 <text>script[@type=</text>
55 </variable>
56 <if test="starts-with($match, $matchstart) and substring($match, string-length($match))=']' and contains($match, '/')">
57 <variable name="inner" select="substring-before(substring-after($match, $matchstart), ']')"/>
58 <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;">
59 <variable name="type" select="substring($inner, 2, string-length($inner)-2)"/>
60 <if test="not(translate($type, '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
61 <html:dd>
62 <value-of select="$type"/>
63 </html:dd>
64 </if>
65 </if>
66 </if>
67 </for-each>
68 </for-each>
69 </otherwise>
70 </choose>
71 </html:div>
72 </for-each>
73 </html:dl>
74 </xslt:variable>
75 <for-each select="//catalog:uri">
76 <xslt:include href="{@uri}">
77 <if test="contains(@name, ':')">
78 <attribute name="书社:id">
79 <value-of select="@name"/>
80 </attribute>
81 </if>
82 </xslt:include>
83 </for-each>
84 <xslt:template name="书社:apply-parsed-by">
85 <xslt:param name="id"/>
86 <xslt:param name="result" select="/.."/>
87 <xslt:for-each select="$result/node()">
88 <xslt:copy>
89 <xslt:attribute name="书社:parsed-by">
90 <xslt:value-of select="$id"/>
91 <xslt:if test="@书社:parsed-by">
92 <xslt:text> </xslt:text>
93 <xslt:value-of select="@书社:parsed-by"/>
94 </xslt:if>
95 </xslt:attribute>
96 <xslt:copy-of select="@*[not(namespace-uri()='urn:fdc:ladys.computer:20231231:Shu1She4' and local-name()='parsed-by')]|node()"/>
97 </xslt:copy>
98 </xslt:for-each>
99 </xslt:template>
100 <xslt:template match="/">
101 <xslt:apply-templates select="node()" mode="书社:parse"/>
102 </xslt:template>
103 <xslt:template match="@*|node()" priority="-1">
104 <xslt:copy>
105 <xslt:apply-templates select="@*|node()" mode="书社:parse"/>
106 </xslt:copy>
107 </xslt:template>
108 <xslt:template match="html:script[@type]" mode="书社:parse" priority="1">
109 <xslt:variable name="parserdiv" select="exsl:node-set($书社:parsers)//html:div[html:dd=current()/@type]"/>
110 <xslt:choose>
111 <xslt:when test="$parserdiv">
112 <xslt:variable name="result">
113 <xslt:apply-templates select="."/>
114 </xslt:variable>
115 <xslt:variable name="reparsed-result">
116 <xslt:apply-templates select="exsl:node-set($result)/node()" mode="书社:parse"/>
117 </xslt:variable>
118 <xslt:call-template name="书社:apply-parsed-by">
119 <xslt:with-param name="id" select="$parserdiv/html:dt"/>
120 <xslt:with-param name="result" select="exsl:node-set($reparsed-result)"/>
121 </xslt:call-template>
122 </xslt:when>
123 <xslt:otherwise>
124 <xslt:apply-templates select="."/>
125 </xslt:otherwise>
126 </xslt:choose>
127 </xslt:template>
128 <xslt:template match="@*|node()" mode="书社:parse">
129 <xslt:apply-templates select="."/>
130 </xslt:template>
131 </xslt:transform>
132 </template>
133 <output method="xml" encoding="UTF-8"/>
134 </transform>
This page took 0.056699 seconds and 5 git commands to generate.