]> Lady’s Gitweb - Shushe/blob - lib/catalog2parser.xslt
647482304deee15e44f388c2cdcab3e8419c60d9
[Shushe] / lib / catalog2parser.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ ⛩📰 书社 ∷ lib/catalog2parser.xslt
8
9 © 2023–2024 Lady [@ Lady’s Computer].
10
11 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
12 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/>.
13 -->
14 <transform
15 xmlns="http://www.w3.org/1999/XSL/Transform"
16 xmlns:catalog="urn:oasis:names:tc:entity:xmlns:xml:catalog"
17 xmlns:exsl="http://exslt.org/common"
18 xmlns:exslstr="http://exslt.org/strings"
19 xmlns:html="http://www.w3.org/1999/xhtml"
20 xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
21 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
22 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23 xmlns:xslt="http://www.w3.org/1999/XSL/TransformAlias"
24 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
25 exclude-result-prefixes="catalog"
26 extension-element-prefixes="exslstr"
27 version="1.0"
28 >
29 <namespace-alias stylesheet-prefix="xslt" result-prefix="#default"/>
30 <template match="/">
31 <xslt:transform extension-element-prefixes="exsl" version="1.0">
32 <xslt:param name="BUILDTIME" select="'1972-12-31T00:00:00Z'"/>
33 <xslt:param name="IDENTIFIER" select="false()"/>
34 <xslt:param name="SRCREV" select="false()"/>
35 <xslt:param name="THISREV" select="false()"/>
36 <xslt:variable name="书社:parsers">
37 <html:dl>
38 <for-each select="//catalog:uri">
39 <variable name="parser" select="document(@uri, .)"/>
40 <html:div>
41 <html:dt>
42 <value-of select="@name"/>
43 </html:dt>
44 <choose>
45 <when test="$parser/*/@书社:supported-media-types">
46 <for-each select="exslstr:tokenize($parser/*/@书社:supported-media-types)">
47 <if test="not(translate(., '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
48 <html:dd>
49 <value-of select="."/>
50 </html:dd>
51 </if>
52 </for-each>
53 </when>
54 <otherwise>
55 <for-each select="$parser//xsl:template[not(@name) and not(@mode)]">
56 <variable name="match" select="@match"/>
57 <for-each select="namespace::*[local-name() and string()='http://www.w3.org/1999/xhtml']">
58 <variable name="matchstart">
59 <value-of select="local-name()"/>
60 <text>:</text>
61 <text>script[@type=</text>
62 </variable>
63 <if test="starts-with($match, $matchstart) and substring($match, string-length($match))=']' and contains($match, '/')">
64 <variable name="inner" select="substring-before(substring-after($match, $matchstart), ']')"/>
65 <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;">
66 <variable name="type" select="substring($inner, 2, string-length($inner)-2)"/>
67 <if test="not(translate($type, '0123456789abcdefghijklmnopqrstuvwxyz!#$&#x26;-^_.+/', ''))">
68 <html:dd>
69 <value-of select="$type"/>
70 </html:dd>
71 </if>
72 </if>
73 </if>
74 </for-each>
75 </for-each>
76 </otherwise>
77 </choose>
78 </html:div>
79 </for-each>
80 </html:dl>
81 </xslt:variable>
82 <for-each select="//catalog:uri">
83 <xslt:include href="{@uri}">
84 <if test="contains(@name, ':')">
85 <attribute name="书社:id">
86 <value-of select="@name"/>
87 </attribute>
88 </if>
89 </xslt:include>
90 </for-each>
91 <xslt:template name="书社:apply-parsed-by">
92 <xslt:param name="id"/>
93 <xslt:param name="media-type"/>
94 <xslt:param name="result" select="/.."/>
95 <xslt:for-each select="$result/node()">
96 <xslt:choose>
97 <xslt:when test="self::*">
98 <xslt:copy>
99 <xslt:if test="string($id)!=''">
100 <xslt:attribute name="书社:parsed-by">
101 <xslt:value-of select="$id"/>
102 <xslt:if test="@书社:parsed-by">
103 <xslt:text>
104 <text> </text>
105 </xslt:text>
106 <xslt:value-of select="@书社:parsed-by"/>
107 </xslt:if>
108 </xslt:attribute>
109 </xslt:if>
110 <xslt:if test="string($media-type)!=''">
111 <xslt:attribute name="书社:media-type">
112 <xslt:value-of select="$media-type"/>
113 </xslt:attribute>
114 </xslt:if>
115 <xslt:copy-of select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4' or local-name()!='parsed-by' and local-name()!='media-type']|node()"/>
116 </xslt:copy>
117 </xslt:when>
118 <xslt:otherwise>
119 <xslt:copy-of select="."/>
120 </xslt:otherwise>
121 </xslt:choose>
122 </xslt:for-each>
123 </xslt:template>
124 <xslt:template match="/">
125 <xslt:apply-templates select="node()" mode="书社:parse"/>
126 </xslt:template>
127 <xslt:template match="@*|node()" priority="-1">
128 <xslt:copy>
129 <xslt:apply-templates select="@*|node()" mode="书社:parse"/>
130 </xslt:copy>
131 </xslt:template>
132 <xslt:template match="html:script[@type]" mode="书社:parse" priority="1">
133 <xslt:variable name="parserdiv" select="exsl:node-set($书社:parsers)//html:div[html:dd=current()/@type]"/>
134 <xslt:choose>
135 <xslt:when test="$parserdiv">
136 <xslt:variable name="result">
137 <xslt:apply-templates select="."/>
138 </xslt:variable>
139 <xslt:variable name="reparsed-result">
140 <xslt:apply-templates select="exsl:node-set($result)/node()" mode="书社:parse"/>
141 </xslt:variable>
142 <xslt:call-template name="书社:apply-parsed-by">
143 <xslt:with-param name="id" select="string($parserdiv/html:dt)"/>
144 <xslt:with-param name="media-type" select="string(@type)"/>
145 <xslt:with-param name="result" select="exsl:node-set($reparsed-result)"/>
146 </xslt:call-template>
147 </xslt:when>
148 <xslt:otherwise>
149 <xslt:apply-templates select="."/>
150 </xslt:otherwise>
151 </xslt:choose>
152 </xslt:template>
153 <xslt:template match="@*|node()" mode="书社:parse">
154 <xslt:apply-templates select="."/>
155 </xslt:template>
156 </xslt:transform>
157 </template>
158 <output method="xml" encoding="UTF-8"/>
159 </transform>
This page took 0.047877 seconds and 3 git commands to generate.