]> Lady’s Gitweb - Shushe/blob - lib/expandmetadata.xslt
“Simplify” the restart mechanism using $?
[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="subdir">
59 <choose>
60 <when test="starts-with($parent, 'about:shushe?include=')">
61 <text>/includes/</text>
62 </when>
63 <when test="starts-with($parent, 'about:shushe?source=')">
64 <text>/sources/</text>
65 </when>
66 </choose>
67 </variable>
68 <for-each select="document(concat($builddir, $subdir, @书社vocab:path), .)//书社:link[@xlink:show='embed']">
69 <if test="exsl:node-set($old)/书社:dependency-root[string()=string(current()/@xlink:href)]">
70 <书社:recursive-dependency>
71 <value-of select="$parent"/>
72 </书社:recursive-dependency>
73 </if>
74 <if test="$files/@rdf:about[string()=string(current()/@xlink:href)]">
75 <书社:dependency>
76 <value-of select="@xlink:href"/>
77 </书社:dependency>
78 </if>
79 </for-each>
80 </for-each>
81 </for-each>
82 </variable>
83 <choose>
84 <when test="exsl:node-set($new)/书社:dependency">
85 <call-template name="书社:process-dependencies">
86 <with-param name="processed">
87 <copy-of select="$old"/>
88 </with-param>
89 <with-param name="unprocessed">
90 <copy-of select="$new"/>
91 </with-param>
92 </call-template>
93 </when>
94 <otherwise>
95 <copy-of select="$old"/>
96 </otherwise>
97 </choose>
98 </template>
99 <template match="//书社vocab:SourceFile[not(nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
100 <copy>
101 <apply-templates select="@*"/>
102 <attribute name="书社vocab:destination">
103 <value-of select="@书社vocab:path"/>
104 </attribute>
105 <apply-templates select="node()"/>
106 </copy>
107 </template>
108 <template match="//书社vocab:SourceFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
109 <variable name="parsed" select="document(concat($builddir, '/sources/', @书社vocab:path), .)"/>
110 <variable name="destination-delim" select="concat('/', $parsed/*/@书社:destination, '/')"/>
111 <variable name="destination">
112 <choose>
113 <when test="not(contains($destination-delim, '//') or contains($destination-delim, '/./') or contains($destination-delim, '/../'))">
114 <value-of select="$parsed/*/@书社:destination"/>
115 </when>
116 <otherwise>
117 <value-of select="@书社vocab:path"/>
118 </otherwise>
119 </choose>
120 </variable>
121 <variable name="dependencies-fragment">
122 <apply-templates select="." mode="书社:dependencies"/>
123 </variable>
124 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
125 <copy>
126 <apply-templates select="@*"/>
127 <attribute name="书社vocab:destination">
128 <value-of select="$destination"/>
129 </attribute>
130 <apply-templates select="node()"/>
131 <for-each select="$dependencies/书社:dependency">
132 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
133 </for-each>
134 <for-each select="$dependencies/书社:recursive-dependency">
135 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
136 </for-each>
137 </copy>
138 </template>
139 <template match="//书社vocab:IncludeFile[nie:interpretedAs/nfo:PlainTextDocument]" priority="1">
140 <variable name="dependencies-fragment">
141 <apply-templates select="." mode="书社:dependencies"/>
142 </variable>
143 <variable name="dependencies" select="exsl:node-set($dependencies-fragment)"/>
144 <copy>
145 <apply-templates select="@*|node()"/>
146 <for-each select="$dependencies/书社:dependency">
147 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
148 </for-each>
149 <for-each select="$dependencies/书社:recursive-dependency">
150 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
151 </for-each>
152 </copy>
153 </template>
154 <template match="/">
155 <variable name="result-fragment">
156 <apply-templates/>
157 </variable>
158 <variable name="result" select="exsl:node-set($result-fragment)"/>
159 <copy-of select="$result/*"/>
160 <exsl:document href="dependencies" method="text" encoding="UTF-8">
161 <for-each select="$result/rdf:RDF/*[nie:interpretedAs/nfo:PlainTextDocument]">
162 <value-of select="@rdf:about"/>
163 <text>&#xA;</text>
164 <for-each select="书社vocab:hasRecursiveDependencyOn/@rdf:resource">
165 <text>&#x9;</text>
166 <text>-</text>
167 <value-of select="."/>
168 <text>&#xA;</text>
169 </for-each>
170 <for-each select="书社vocab:hasDependencyOn/@rdf:resource">
171 <text>&#x9;</text>
172 <value-of select="."/>
173 <text>&#xA;</text>
174 </for-each>
175 </for-each>
176 </exsl:document>
177 <exsl:document href="destinations" method="text" encoding="UTF-8">
178 <for-each select="$result//书社vocab:SourceFile">
179 <value-of select="@rdf:about"/>
180 <text>|</text>
181 <value-of select="@书社vocab:destination"/>
182 <text>&#xA;</text>
183 </for-each>
184 </exsl:document>
185 </template>
186 <template match="@*|node()">
187 <copy>
188 <apply-templates select="@*|node()"/>
189 </copy>
190 </template>
191 <template match="书社vocab:SourceFile|书社vocab:IncludeFile" mode="书社:dependencies">
192 <if test="nie:interpretedAs/nfo:PlainTextDocument">
193 <call-template name="书社:process-dependencies">
194 <with-param name="unprocessed">
195 <书社:dependency-root>
196 <value-of select="@rdf:about"/>
197 </书社:dependency-root>
198 </with-param>
199 </call-template>
200 </if>
201 </template>
202 <output method="xml" encoding="UTF-8"/>
203 </transform>
This page took 0.072828 seconds and 5 git commands to generate.