]> Lady’s Gitweb - Shushe/blob - lib/catalog2parser.xslt
ad38990122665126b0c1419320e4254907f17c67
[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="CKSUM" select="false"/>
27 <xslt:param name="GENERATOR" select="false"/>
28 <xslt:param name="SRCREV" select="false"/>
29 <xslt:param name="SRCTIME" select="'1972-12-31T00:00:00Z'"/>
30 <xslt:param name="VERSION" select="false"/>
31 <xslt:variable name="书社:parsers">
32 <html:dl>
33 <for-each select="//catalog:uri">
34 <variable name="parser" select="document(@uri, .)"/>
35 <html:div>
36 <html:dt>
37 <value-of select="@name"/>
38 </html:dt>
39 <choose>
40 <when test="$parser/*/@书社:supported-media-types">
41 <for-each select="exslstr:tokenize($parser/*/@书社:supported-media-types)">
42 <if test="not(translate(., '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
43 <html:dd>
44 <value-of select="."/>
45 </html:dd>
46 </if>
47 </for-each>
48 </when>
49 <otherwise>
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()"/>
55 <text>:</text>
56 <text>script[@type=</text>
57 </variable>
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, '&#x22;') and substring($inner, string-length($inner))='&#x22;' or starts-with($inner, &#x22;'&#x22;) and substring($inner, string-length($inner))=&#x22;'&#x22;">
61 <variable name="type" select="substring($inner, 2, string-length($inner)-2)"/>
62 <if test="not(translate($type, '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
63 <html:dd>
64 <value-of select="$type"/>
65 </html:dd>
66 </if>
67 </if>
68 </if>
69 </for-each>
70 </for-each>
71 </otherwise>
72 </choose>
73 </html:div>
74 </for-each>
75 </html:dl>
76 </xslt:variable>
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"/>
82 </attribute>
83 </if>
84 </xslt:include>
85 </for-each>
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()">
91 <xslt:copy>
92 <xslt:if test="string($id)!=''">
93 <xslt:attribute name="书社:parsed-by">
94 <xslt:value-of select="$id"/>
95 <xslt:if test="@书社:parsed-by">
96 <xslt:text> </xslt:text>
97 <xslt:value-of select="@书社:parsed-by"/>
98 </xslt:if>
99 </xslt:attribute>
100 </xslt:if>
101 <xslt:if test="string($media-type)!=''">
102 <xslt:attribute name="书社:media-type">
103 <xslt:value-of select="$media-type"/>
104 </xslt:attribute>
105 </xslt:if>
106 <xslt:copy-of select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4' or local-name()!='parsed-by' and local-name()!='media-type']|node()"/>
107 </xslt:copy>
108 </xslt:for-each>
109 </xslt:template>
110 <xslt:template match="/">
111 <xslt:variable name="parsedroot">
112 <xslt:apply-templates select="node()" mode="书社:parse"/>
113 </xslt:variable>
114 <xslt:for-each select="exsl:node-set($parsedroot)/node()">
115 <xslt:choose>
116 <xslt:when test="self::*">
117 <xslt:copy>
118 <xslt:attribute name="书社:cksum">
119 <xslt:value-of select="$CKSUM"/>
120 </xslt:attribute>
121 <xslt:copy-of select="@*|node()"/>
122 </xslt:copy>
123 </xslt:when>
124 <xslt:otherwise>
125 <xslt:copy-of select="."/>
126 </xslt:otherwise>
127 </xslt:choose>
128 </xslt:for-each>
129 </xslt:template>
130 <xslt:template match="@*|node()" priority="-1">
131 <xslt:copy>
132 <xslt:apply-templates select="@*|node()" mode="书社:parse"/>
133 </xslt:copy>
134 </xslt:template>
135 <xslt:template match="html:script[@type]" mode="书社:parse" priority="1">
136 <xslt:variable name="parserdiv" select="exsl:node-set($书社:parsers)//html:div[html:dd=current()/@type]"/>
137 <xslt:choose>
138 <xslt:when test="$parserdiv">
139 <xslt:variable name="result">
140 <xslt:apply-templates select="."/>
141 </xslt:variable>
142 <xslt:variable name="reparsed-result">
143 <xslt:apply-templates select="exsl:node-set($result)/node()" mode="书社:parse"/>
144 </xslt:variable>
145 <xslt:call-template name="书社:apply-parsed-by">
146 <xslt:with-param name="id" select="string($parserdiv/html:dt)"/>
147 <xslt:with-param name="media-type" select="string(@type)"/>
148 <xslt:with-param name="result" select="exsl:node-set($reparsed-result)"/>
149 </xslt:call-template>
150 </xslt:when>
151 <xslt:otherwise>
152 <xslt:apply-templates select="."/>
153 </xslt:otherwise>
154 </xslt:choose>
155 </xslt:template>
156 <xslt:template match="@*|node()" mode="书社:parse">
157 <xslt:apply-templates select="."/>
158 </xslt:template>
159 </xslt:transform>
160 </template>
161 <output method="xml" encoding="UTF-8"/>
162 </transform>
This page took 0.05736 seconds and 3 git commands to generate.