]> Lady’s Gitweb - Shushe/blob - lib/expandmetadata.xslt
Provide the location of parsed files in metadata
[Shushe] / lib / expandmetadata.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2023, 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ ⛩📰 书社 ∷ lib/expandmetadata.xslt
8
9 © 2023–2024 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: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"
24 version="1.0"
25 >
26 <variable name="builddir" select="//书社vocab:BuildDirectory/@nfo:fileUrl"/>
27 <variable name="files" select="//书社vocab:SourceFile|//书社vocab:IncludeFile"/>
28 <template name="书社:process-dependencies">
29 <param name="processed"/>
30 <param name="unprocessed"/>
31 <variable name="queue">
32 <copy-of select="exsl:node-set($unprocessed)/书社:dependency-root"/>
33 <for-each select="exsl:node-set($unprocessed)/书社:dependency">
34 <if test="not((exsl:node-set($processed)/书社:*|preceding-sibling::书社:*|following-sibling::书社:recursive-dependency)[string()=string(current())])">
35 <copy-of select="."/>
36 </if>
37 </for-each>
38 </variable>
39 <variable name="old">
40 <copy-of select="exsl:node-set($processed)/书社:dependency-root"/>
41 <copy-of select="exsl:node-set($processed)/书社:recursive-dependency"/>
42 <for-each select="exsl:node-set($unprocessed)/书社:recursive-dependency">
43 <if test="not((exsl:node-set($processed)/书社:recursive-dependency|preceding-sibling::书社:recursive-dependency)[string()=string(current())])">
44 <copy-of select="."/>
45 </if>
46 </for-each>
47 <for-each select="exsl:node-set($processed)/书社:dependency">
48 <if test="not(exsl:node-set($unprocessed)/书社:recursive-dependency[string()=string(current())])">
49 <copy-of select="."/>
50 </if>
51 </for-each>
52 <copy-of select="$queue"/>
53 </variable>
54 <variable name="new">
55 <for-each select="exsl:node-set($queue)/书社:*">
56 <for-each select="$files[@rdf:about=string(current()) and nie:interpretedAs/nfo:PlainTextDocument]">
57 <variable name="parent" select="@rdf:about"/>
58 <variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
59 <for-each select="document($uri)//书社:link[@xlink:show='embed']">
60 <if test="exsl:node-set($old)/书社:dependency-root[string()=string(current()/@xlink:href)]">
61 <书社:recursive-dependency>
62 <value-of select="$parent"/>
63 </书社:recursive-dependency>
64 </if>
65 <if test="$files/@rdf:about[string()=string(current()/@xlink:href)]">
66 <书社:dependency>
67 <value-of select="@xlink:href"/>
68 </书社:dependency>
69 </if>
70 </for-each>
71 </for-each>
72 </for-each>
73 </variable>
74 <choose>
75 <when test="exsl:node-set($new)/书社:dependency">
76 <call-template name="书社:process-dependencies">
77 <with-param name="processed">
78 <copy-of select="$old"/>
79 </with-param>
80 <with-param name="unprocessed">
81 <copy-of select="$new"/>
82 </with-param>
83 </call-template>
84 </when>
85 <otherwise>
86 <copy-of select="$old"/>
87 </otherwise>
88 </choose>
89 </template>
90 <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
91 <copy>
92 <apply-templates select="@*"/>
93 <attribute name="书社vocab:destination">
94 <value-of select="@书社vocab:path"/>
95 </attribute>
96 <apply-templates select="node()"/>
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="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
102 <variable name="destination">
103 <choose>
104 <when test="not(contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../'))">
105 <value-of select="$parsed/*/@书社:destination"/>
106 </when>
107 <otherwise>
108 <value-of select="@书社vocab:path"/>
109 </otherwise>
110 </choose>
111 </variable>
112 <variable name="dependencies-fragment">
113 <apply-templates select="." mode="书社:dependencies"/>
114 </variable>
115 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
116 <copy>
117 <apply-templates select="@*"/>
118 <attribute name="书社vocab:destination">
119 <value-of select="$destination"/>
120 </attribute>
121 <apply-templates select="node()"/>
122 <for-each select="$dependencies/书社:dependency">
123 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
124 </for-each>
125 <for-each select="$dependencies/书社:recursive-dependency">
126 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
127 </for-each>
128 </copy>
129 </template>
130 <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
131 <variable name="dependencies-fragment">
132 <apply-templates select="." mode="书社:dependencies"/>
133 </variable>
134 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
135 <copy>
136 <apply-templates select="@*|node()"/>
137 <for-each select="$dependencies/书社:dependency">
138 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
139 </for-each>
140 <for-each select="$dependencies/书社:recursive-dependency">
141 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
142 </for-each>
143 </copy>
144 </template>
145 <template match="/">
146 <variable name="result-fragment">
147 <apply-templates/>
148 </variable>
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"/>
154 <text>&#xA;</text>
155 <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
156 <text>&#x9;</text>
157 <text>-</text>
158 <value-of select="."/>
159 <text>&#xA;</text>
160 </for-each>
161 <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
162 <text>&#x9;</text>
163 <value-of select="."/>
164 <text>&#xA;</text>
165 </for-each>
166 </for-each>
167 </exsl:document>
168 <exsl:document href="destinations" method="text" encoding="UTF-8">
169 <for-each select="$result//书社vocab:SourceFile">
170 <value-of select="@rdf:about"/>
171 <text>|</text>
172 <value-of select="@书社vocab:destination"/>
173 <text>&#xA;</text>
174 </for-each>
175 </exsl:document>
176 </template>
177 <template match="@*|node()">
178 <copy>
179 <apply-templates select="@*|node()"/>
180 </copy>
181 </template>
182 <template match="书社vocab:SourceFile|书社vocab:IncludeFile" mode="书社:dependencies">
183 <if test="nie:interpretedAs/nfo:PlainTextDocument">
184 <call-template name="书社:process-dependencies">
185 <with-param name="unprocessed">
186 <书社:dependency-root>
187 <value-of select="@rdf:about"/>
188 </书社:dependency-root>
189 </with-param>
190 </call-template>
191 </if>
192 </template>
193 <output method="xml" encoding="UTF-8"/>
194 </transform>
This page took 0.114409 seconds and 5 git commands to generate.