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:nie="http://www.semanticdesktop.org/ontologies/2007/01/19/nie#"
18 xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
19 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
20 xmlns:xlink="http://www.w3.org/1999/xlink"
21 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
22 xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
23 extension-element-prefixes="exsl"
26 <variable name="builddir" select="//书社vocab:BuildDirectory/@nfo:fileUrl"/>
27 <variable name="files" select="//书社vocab:SourceFile|//书社vocab:IncludeFile"/>
28 <template name="书社:collect-dependency-paths">
29 <param name="path" select="/.."/>
30 <variable name="parent" select="string($path/*[last()])"/>
31 <variable name="children-fragment">
32 <for-each select="$files[@rdf:about=$parent and nie:interpretedAs/nfo:PlainTextDocument]">
33 <variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
34 <for-each select="document($uri)//书社:link[@xlink:show='embed']">
35 <variable name="identifier" select="string(@xlink:href)"/>
36 <variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
37 <for-each select="$files/@rdf:about[string(.)=$identifier or $is-dir and starts-with(., $identifier)]">
38 <sort select="." data-type="text" lang="zxx" case-order="upper-first"/>
40 <when test="$path/*[string(.)=string(current())]">
41 <书社:recursive-dependency>
42 <value-of select="."/>
43 </书社:recursive-dependency>
47 <value-of select="."/>
55 <variable name="children" select="exsl:node-set($children-fragment)"/>
57 <when test="$children/*">
58 <for-each select="$children/书社:recursive-dependency">
60 <copy-of select="$path[string(.)=string(current())]/preceding-sibling::*"/>
64 <for-each select="$children/书社:dependency">
65 <variable name="path-fragment">
66 <copy-of select="$path"/>
69 <call-template name="书社:collect-dependency-paths">
70 <with-param name="path" select="exsl:node-set($path-fragment)"/>
76 <copy-of select="$path"/>
81 <template match="nie:interpretedAs/*" priority="1">
83 <apply-templates select="@*|node()"/>
84 <for-each select="../../书社vocab:hasParsedFileWithMetadata">
85 <copy-of select="document(@nfo:fileUrl)/书社:parsed/书社:metadata/rdf:RDF/rdf:Description/node()"/>
89 <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
91 <apply-templates select="@*"/>
92 <attribute name="书社vocab:destination">
93 <value-of select="@书社vocab:path"/>
95 <apply-templates select="node()"/>
98 <template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
99 <variable name="parsed" select="document(书社vocab:hasParsedFile/@nfo:fileUrl)"/>
100 <variable name="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
101 <variable name="destination">
103 <when test="not(contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../'))">
104 <value-of select="$parsed/*/@书社:destination"/>
107 <value-of select="@书社vocab:path"/>
111 <variable name="dependencies-fragment">
112 <apply-templates select="." mode="书社:dependencies"/>
114 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
116 <apply-templates select="@*"/>
117 <attribute name="书社vocab:destination">
118 <value-of select="$destination"/>
120 <apply-templates select="node()"/>
121 <for-each select="$dependencies/书社:dependency">
122 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
124 <for-each select="$dependencies/书社:recursive-dependency">
125 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
129 <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
130 <variable name="dependencies-fragment">
131 <apply-templates select="." mode="书社:dependencies"/>
133 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
135 <apply-templates select="@*|node()"/>
136 <for-each select="$dependencies/书社:dependency">
137 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
139 <for-each select="$dependencies/书社:recursive-dependency">
140 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
144 <template match="书社vocab:hasParsedFileWithMetadata" priority="1"/>
146 <variable name="result-fragment">
149 <variable name="result" select="exsl:node-set($result-fragment)"/>
150 <copy-of select="$result/*"/>
151 <exsl:document href="dependencies" method="text" encoding="UTF-8">
152 <for-each select="$result/rdf:RDF/*[nie:interpretedAs/nfo:PlainTextDocument]">
153 <value-of select="@rdf:about"/>
155 <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
158 <value-of select="."/>
161 <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
163 <value-of select="."/>
168 <exsl:document href="destinations" method="text" encoding="UTF-8">
169 <for-each select="$result//书社vocab:SourceFile">
170 <value-of select="@rdf:about"/>
172 <value-of select="@书社vocab:destination"/>
177 <template match="@*|node()">
179 <apply-templates select="@*|node()"/>
182 <template match="书社vocab:SourceFile|书社vocab:IncludeFile" mode="书社:dependencies">
183 <if test="nie:interpretedAs/nfo:PlainTextDocument">
184 <variable name="path-fragment">
186 <value-of select="@rdf:about"/>
187 </书社:dependency-root>
189 <variable name="paths-fragment">
190 <call-template name="书社:collect-dependency-paths">
191 <with-param name="path" select="exsl:node-set($path-fragment)"/>
194 <for-each select="exsl:node-set($paths-fragment)/*/*[not(self::书社:dependency-root)]">
195 <if test="not(preceding::*[string(.)=string(current())])">
196 <copy-of select="."/>
201 <output method="xml" encoding="UTF-8"/>