3 SPDX-FileCopyrightText: 2023, 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ ⛩📰 书社 ∷ lib/expandmetadata.xslt
9 © 2023–2025 Lady [@ Ladys Computer].
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/>.
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"
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"/>
41 <when test="$path/*[string(.)=string(current())]">
42 <书社:recursive-dependency>
43 <value-of select="."/>
44 </书社:recursive-dependency>
48 <value-of select="."/>
56 <variable name="children" select="exsl:node-set($children-fragment)"/>
58 <when test="$children/*">
59 <for-each select="$children/书社:recursive-dependency">
61 <copy-of select="$path[string(.)=string(current())]/preceding-sibling::*"/>
65 <for-each select="$children/书社:dependency">
66 <variable name="path-fragment">
67 <copy-of select="$path"/>
70 <call-template name="书社:collect-dependency-paths">
71 <with-param name="path" select="exsl:node-set($path-fragment)"/>
77 <copy-of select="$path"/>
82 <template match="nie:interpretedAs/*" priority="1">
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()"/>
90 <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
92 <apply-templates select="@*"/>
93 <apply-templates select="node()"/>
94 <element name="书社vocab:destination">
95 <value-of select="@书社vocab:path"/>
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="."/>
111 <variable name="dependencies-fragment">
112 <apply-templates select="." mode="书社:dependencies"/>
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="."/>
124 <variable name="bad-destinations" select="exsl:node-set($bad-destinations-fragment)/node()"/>
126 <apply-templates select="@*"/>
127 <apply-templates select="node()"/>
128 <for-each select="$dependencies/书社:dependency">
129 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
131 <for-each select="$dependencies/书社:recursive-dependency">
132 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
135 <when test="not($destinations)">
136 <element name="书社vocab:destination">
137 <value-of select="@书社vocab:path"/>
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">
148 <value-of select="."/>
152 <element name="书社vocab:destination">
153 <value-of select="@书社vocab:path"/>
157 <for-each select="$destinations">
158 <element name="书社vocab:destination">
159 <value-of select="."/>
166 <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
167 <variable name="dependencies-fragment">
168 <apply-templates select="." mode="书社:dependencies"/>
170 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
172 <apply-templates select="@*|node()"/>
173 <for-each select="$dependencies/书社:dependency">
174 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
176 <for-each select="$dependencies/书社:recursive-dependency">
177 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
181 <template match="书社vocab:hasParsedFileWithMetadata" priority="1"/>
183 <variable name="result-fragment">
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"/>
192 <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
195 <value-of select="."/>
198 <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
200 <value-of select="."/>
205 <exsl:document href="destinations" method="text" encoding="UTF-8">
206 <for-each select="$result//书社vocab:SourceFile">
207 <value-of select="@rdf:about"/>
209 <for-each select="书社vocab:destination">
210 <if test="position()>1">
213 <value-of select="."/>
219 <template match="@*|node()">
221 <apply-templates select="@*|node()"/>
224 <template match="书社vocab:SourceFile|书社vocab:IncludeFile" mode="书社:dependencies">
225 <if test="nie:interpretedAs/nfo:PlainTextDocument">
226 <variable name="path-fragment">
228 <value-of select="@rdf:about"/>
229 </书社:dependency-root>
231 <variable name="paths-fragment">
232 <call-template name="书社:collect-dependency-paths">
233 <with-param name="path" select="exsl:node-set($path-fragment)"/>
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="."/>
243 <output method="xml" encoding="UTF-8"/>