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:dct="http://purl.org/dc/terms/"
17 xmlns:exsl="http://exslt.org/common"
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"
27 <variable name="builddir" select="//*[@rdf:about='about:shushe?builddir']/@nfo:fileUrl"/>
28 <variable name="files" select="/rdf:RDF/nfo:LocalFileDataObject[not(nie:interpretedAs/nfo:Folder)]"/>
29 <template name="书社:process-dependencies">
30 <param name="processed"/>
31 <param name="unprocessed"/>
32 <variable name="queue">
33 <copy-of select="exsl:node-set($unprocessed)/书社:dependency-root"/>
34 <for-each select="exsl:node-set($unprocessed)/书社:dependency">
35 <if test="not((exsl:node-set($processed)/书社:*|preceding-sibling::书社:*|following-sibling::书社:recursive-dependency)[string()=string(current())])">
41 <copy-of select="exsl:node-set($processed)/书社:dependency-root"/>
42 <copy-of select="exsl:node-set($processed)/书社:recursive-dependency"/>
43 <for-each select="exsl:node-set($unprocessed)/书社:recursive-dependency">
44 <if test="not((exsl:node-set($processed)/书社:recursive-dependency|preceding-sibling::书社:recursive-dependency)[string()=string(current())])">
48 <for-each select="exsl:node-set($processed)/书社:dependency">
49 <if test="not(exsl:node-set($unprocessed)/书社:recursive-dependency[string()=string(current())])">
53 <copy-of select="$queue"/>
56 <for-each select="exsl:node-set($queue)/书社:*">
57 <for-each select="$files[@rdf:about=string(current()) and nie:interpretedAs/nfo:PlainTextDocument]">
58 <variable name="parent" select="@rdf:about"/>
59 <variable name="subdir">
61 <when test="starts-with($parent, 'about:shushe?include=')">
62 <text>/includes/</text>
64 <when test="starts-with($parent, 'about:shushe?source=')">
65 <text>/sources/</text>
69 <for-each select="document(concat($builddir, $subdir, @nfo:fileName), .)//书社:link[@xlink:show='embed']">
70 <if test="exsl:node-set($old)/书社:dependency-root[string()=string(current()/@xlink:href)]">
71 <书社:recursive-dependency>
72 <value-of select="$parent"/>
73 </书社:recursive-dependency>
75 <if test="$files/@rdf:about[string()=string(current()/@xlink:href)]">
77 <value-of select="@xlink:href"/>
85 <when test="exsl:node-set($new)/书社:dependency">
86 <call-template name="书社:process-dependencies">
87 <with-param name="processed">
88 <copy-of select="$old"/>
90 <with-param name="unprocessed">
91 <copy-of select="$new"/>
96 <copy-of select="$old"/>
100 <template match="rdf:RDF/nfo:LocalFileDataObject[not(nie:interpretedAs/nfo:Folder or nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
102 <apply-templates select="@*|node()"/>
103 <if test="starts-with(@rdf:about, 'about:shushe?source=')">
105 <nfo:LocalFileDataObject dct:creator="urn:fdc:ladys.computer:20231231:Shu1She4" nfo:fileName="{substring-after(@rdf:about, 'about:shushe?source=')}"/>
110 <template match="rdf:RDF/nfo:LocalFileDataObject[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
111 <variable name="parsed" select="document(concat($builddir, '/sources/', @nfo:fileName), .)"/>
112 <variable name="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
113 <variable name="destination">
115 <when test="not(starts-with(@rdf:about, 'about:shushe?source='))"/>
116 <when test="not(contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../'))">
117 <value-of select="$parsed/*/@书社:destination"/>
120 <value-of select="substring-after(@rdf:about, 'about:shushe?source=')"/>
124 <variable name="dependencies-fragment">
125 <apply-templates select="." mode="书社:dependencies"/>
127 <variable name="dependencies" select="exsl:node-set($dependencies)"/>
129 <apply-templates select="@*|node()"/>
130 <for-each select="$dependencies/书社:dependency">
131 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
133 <for-each select="$dependencies/书社:recursive-dependency">
134 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
136 <if test="$destination!=''">
138 <nfo:LocalFileDataObject dct:creator="urn:fdc:ladys.computer:20231231:Shu1She4" nfo:fileName="{$destination}">
139 </nfo:LocalFileDataObject>
144 <template match="@*|node()">
146 <apply-templates select="@*|node()"/>
149 <template match="nfo:LocalFileDataObject" mode="书社:dependencies">
150 <if test="nie:interpretedAs/nfo:PlainTextDocument">
151 <call-template name="书社:process-dependencies">
152 <with-param name="unprocessed">
154 <value-of select="@rdf:about"/>
155 </书社:dependency-root>