3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
7 ⁌ ⛩📰 书社 ∷ lib/expandmetadata.xslt
9 © 2023–2024 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="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
83 <apply-templates select="@*"/>
84 <attribute name="书社vocab:destination">
85 <value-of select="@书社vocab:path"/>
87 <apply-templates select="node()"/>
90 <template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
91 <variable name="parsed" select="document(书社vocab:hasParsedFile/@nfo:fileUrl)"/>
92 <variable name="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
93 <variable name="destination">
95 <when test="not(contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../'))">
96 <value-of select="$parsed/*/@书社:destination"/>
99 <value-of select="@书社vocab:path"/>
103 <variable name="dependencies-fragment">
104 <apply-templates select="." mode="书社:dependencies"/>
106 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
108 <apply-templates select="@*"/>
109 <attribute name="书社vocab:destination">
110 <value-of select="$destination"/>
112 <apply-templates select="node()"/>
113 <for-each select="$dependencies/书社:dependency">
114 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
116 <for-each select="$dependencies/书社:recursive-dependency">
117 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
121 <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
122 <variable name="dependencies-fragment">
123 <apply-templates select="." mode="书社:dependencies"/>
125 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
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="{.}"/>
137 <variable name="result-fragment">
140 <variable name="result" select="exsl:node-set($result-fragment)"/>
141 <copy-of select="$result/*"/>
142 <exsl:document href="dependencies" method="text" encoding="UTF-8">
143 <for-each select="$result/rdf:RDF/*[nie:interpretedAs/nfo:PlainTextDocument]">
144 <value-of select="@rdf:about"/>
146 <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
149 <value-of select="."/>
152 <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
154 <value-of select="."/>
159 <exsl:document href="destinations" method="text" encoding="UTF-8">
160 <for-each select="$result//书社vocab:SourceFile">
161 <value-of select="@rdf:about"/>
163 <value-of select="@书社vocab:destination"/>
168 <template match="@*|node()">
170 <apply-templates select="@*|node()"/>
173 <template match="书社vocab:SourceFile|书社vocab:IncludeFile" mode="书社:dependencies">
174 <if test="nie:interpretedAs/nfo:PlainTextDocument">
175 <variable name="path-fragment">
177 <value-of select="@rdf:about"/>
178 </书社:dependency-root>
180 <variable name="paths-fragment">
181 <call-template name="书社:collect-dependency-paths">
182 <with-param name="path" select="exsl:node-set($path-fragment)"/>
185 <for-each select="exsl:node-set($paths-fragment)/*/*[not(self::书社:dependency-root)]">
186 <if test="not(preceding::*[string(.)=string(current())])">
187 <copy-of select="."/>
192 <output method="xml" encoding="UTF-8"/>