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