]> Lady’s Gitweb - Shushe/blob - lib/expandmetadata.xslt
423924a3d35eb889c8ab4bd46e46a937e6d54c02
[Shushe] / lib / expandmetadata.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2023, 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ ⛩📰 书社 ∷ lib/expandmetadata.xslt
8
9 © 2023–2025 Lady [@ Ladys 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:exsl="http://exslt.org/common"
17 xmlns:exslstr="http://exslt.org/strings"
18 xmlns:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
19 xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
20 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
21 xmlns:xlink="http://www.w3.org/1999/xlink"
22 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
23 xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
24 extension-element-prefixes="exsl exslstr"
25 version="1.0"
26 >
27 <variable name="builddir" select="//书社vocab:BuildDirectory/@nfo:fileUrl"/>
28 <variable name="files" select="//书社vocab:SourceFile|//书社vocab:IncludeFile"/>
29 <template name="书社:collect-dependency-paths">
30 <param name="path" select="/.."/>
31 <variable name="parent" select="string($path/*[last()])"/>
32 <variable name="children-fragment">
33 <for-each select="$files[@rdf:about=$parent and nie:interpretedAs/nfo:PlainTextDocument]">
34 <variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
35 <for-each select="document($uri)//书社:link[@xlink:show='embed']">
36 <variable name="identifier" select="string(@xlink:href)"/>
37 <variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
38 <for-each select="$files/@rdf:about[string(.)=$identifier or $is-dir and starts-with(., $identifier)]">
39 <sort select="." data-type="text" lang="zxx" case-order="upper-first"/>
40 <choose>
41 <when test="$path/*[string(.)=string(current())]">
42 <书社:recursive-dependency>
43 <value-of select="."/>
44 </书社:recursive-dependency>
45 </when>
46 <otherwise>
47 <书社:dependency>
48 <value-of select="."/>
49 </书社:dependency>
50 </otherwise>
51 </choose>
52 </for-each>
53 </for-each>
54 </for-each>
55 </variable>
56 <variable name="children" select="exsl:node-set($children-fragment)"/>
57 <choose>
58 <when test="$children/*">
59 <for-each select="$children/书社:recursive-dependency">
60 <书社:dependency-path>
61 <copy-of select="$path[string(.)=string(current())]/preceding-sibling::*"/>
62 <copy-of select="."/>
63 </书社:dependency-path>
64 </for-each>
65 <for-each select="$children/书社:dependency">
66 <variable name="path-fragment">
67 <copy-of select="$path"/>
68 <copy-of select="."/>
69 </variable>
70 <call-template name="书社:collect-dependency-paths">
71 <with-param name="path" select="exsl:node-set($path-fragment)"/>
72 </call-template>
73 </for-each>
74 </when>
75 <otherwise>
76 <书社:dependency-path>
77 <copy-of select="$path"/>
78 </书社:dependency-path>
79 </otherwise>
80 </choose>
81 </template>
82 <template match="nie:interpretedAs/*" priority="1">
83 <copy>
84 <apply-templates select="@*|node()"/>
85 <for-each select="../../书社vocab:hasParsedFileWithMetadata">
86 <copy-of select="document(@nfo:fileUrl)/书社:parsed/书社:metadata/rdf:RDF/rdf:Description/node()"/>
87 </for-each>
88 </copy>
89 </template>
90 <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
91 <copy>
92 <apply-templates select="@*"/>
93 <apply-templates select="node()"/>
94 <element name="书社vocab:destination">
95 <value-of select="@书社vocab:path"/>
96 </element>
97 </copy>
98 </template>
99 <template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
100 <variable name="parsed" select="document(书社vocab:hasParsedFile/@nfo:fileUrl)"/>
101 <variable name="provided-destinations" select="normalize-space($parsed/*/@书社:destination)"/>
102 <variable name="destinations-fragment">
103 <if test="$provided-destinations!=''">
104 <for-each select="exslstr:tokenize($provided-destinations)">
105 <element name="书社vocab:destination">
106 <value-of select="."/>
107 </element>
108 </for-each>
109 </if>
110 </variable>
111 <variable name="dependencies-fragment">
112 <apply-templates select="." mode="书社:dependencies"/>
113 </variable>
114 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
115 <variable name="destinations" select="exsl:node-set($destinations-fragment)/node()"/>
116 <variable name="bad-destinations-fragment">
117 <for-each select="$destinations">
118 <variable name="destination-delim" select="concat('/', ., '/')"/>
119 <if test="contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../')">
120 <copy-of select="."/>
121 </if>
122 </for-each>
123 </variable>
124 <variable name="bad-destinations" select="exsl:node-set($bad-destinations-fragment)/node()"/>
125 <copy>
126 <apply-templates select="@*"/>
127 <apply-templates select="node()"/>
128 <for-each select="$dependencies/书社:dependency">
129 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
130 </for-each>
131 <for-each select="$dependencies/书社:recursive-dependency">
132 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
133 </for-each>
134 <choose>
135 <when test="not($destinations)">
136 <element name="书社vocab:destination">
137 <value-of select="@书社vocab:path"/>
138 </element>
139 </when>
140 <when test="$bad-destinations">
141 <message terminate="no">
142 <text>Bad destinations: </text>
143 <for-each select="$bad-destinations">
144 <if test="position()>1">
145 <text> </text>
146 </if>
147 <text>&lt;</text>
148 <value-of select="."/>
149 <text>></text>
150 </for-each>
151 </message>
152 <element name="书社vocab:destination">
153 <value-of select="@书社vocab:path"/>
154 </element>
155 </when>
156 <otherwise>
157 <for-each select="$destinations">
158 <element name="书社vocab:destination">
159 <value-of select="."/>
160 </element>
161 </for-each>
162 </otherwise>
163 </choose>
164 </copy>
165 </template>
166 <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
167 <variable name="dependencies-fragment">
168 <apply-templates select="." mode="书社:dependencies"/>
169 </variable>
170 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
171 <copy>
172 <apply-templates select="@*|node()"/>
173 <for-each select="$dependencies/书社:dependency">
174 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
175 </for-each>
176 <for-each select="$dependencies/书社:recursive-dependency">
177 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
178 </for-each>
179 </copy>
180 </template>
181 <template match="书社vocab:hasParsedFileWithMetadata" priority="1"/>
182 <template match="/">
183 <variable name="result-fragment">
184 <apply-templates/>
185 </variable>
186 <variable name="result" select="exsl:node-set($result-fragment)"/>
187 <copy-of select="$result/*"/>
188 <exsl:document href="dependencies" method="text" encoding="UTF-8">
189 <for-each select="$result/rdf:RDF/*[nie:interpretedAs/nfo:PlainTextDocument]">
190 <value-of select="@rdf:about"/>
191 <text>&#xA;</text>
192 <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
193 <text>&#x9;</text>
194 <text>-</text>
195 <value-of select="."/>
196 <text>&#xA;</text>
197 </for-each>
198 <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
199 <text>&#x9;</text>
200 <value-of select="."/>
201 <text>&#xA;</text>
202 </for-each>
203 </for-each>
204 </exsl:document>
205 <exsl:document href="destinations" method="text" encoding="UTF-8">
206 <for-each select="$result//书社vocab:SourceFile">
207 <value-of select="@rdf:about"/>
208 <text>|</text>
209 <for-each select="书社vocab:destination">
210 <if test="position()>1">
211 <text>;</text>
212 </if>
213 <value-of select="."/>
214 </for-each>
215 <text>&#xA;</text>
216 </for-each>
217 </exsl:document>
218 </template>
219 <template match="@*|node()">
220 <copy>
221 <apply-templates select="@*|node()"/>
222 </copy>
223 </template>
224 <template match="书社vocab:SourceFile|书社vocab:IncludeFile" mode="书社:dependencies">
225 <if test="nie:interpretedAs/nfo:PlainTextDocument">
226 <variable name="path-fragment">
227 <书社:dependency-root>
228 <value-of select="@rdf:about"/>
229 </书社:dependency-root>
230 </variable>
231 <variable name="paths-fragment">
232 <call-template name="书社:collect-dependency-paths">
233 <with-param name="path" select="exsl:node-set($path-fragment)"/>
234 </call-template>
235 </variable>
236 <for-each select="exsl:node-set($paths-fragment)/*/*[not(self::书社:dependency-root)]">
237 <if test="not(preceding::*[string(.)=string(current())])">
238 <copy-of select="."/>
239 </if>
240 </for-each>
241 </if>
242 </template>
243 <output method="xml" encoding="UTF-8"/>
244 </transform>
This page took 0.460007 seconds and 3 git commands to generate.