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