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