]> Lady’s Gitweb - Shushe/blob - lib/expandmetadata.xslt
Generate destinations and dependencies as 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: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"
25 version="1.0"
26 >
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())])">
36 <copy-of select="."/>
37 </if>
38 </for-each>
39 </variable>
40 <variable name="old">
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())])">
45 <copy-of select="."/>
46 </if>
47 </for-each>
48 <for-each select="exsl:node-set($processed)/书社:dependency">
49 <if test="not(exsl:node-set($unprocessed)/书社:recursive-dependency[string()=string(current())])">
50 <copy-of select="."/>
51 </if>
52 </for-each>
53 <copy-of select="$queue"/>
54 </variable>
55 <variable name="new">
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">
60 <choose>
61 <when test="starts-with($parent, 'about:shushe?include=')">
62 <text>/includes/</text>
63 </when>
64 <when test="starts-with($parent, 'about:shushe?source=')">
65 <text>/sources/</text>
66 </when>
67 </choose>
68 </variable>
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>
74 </if>
75 <if test="$files/@rdf:about[string()=string(current()/@xlink:href)]">
76 <书社:dependency>
77 <value-of select="@xlink:href"/>
78 </书社:dependency>
79 </if>
80 </for-each>
81 </for-each>
82 </for-each>
83 </variable>
84 <choose>
85 <when test="exsl:node-set($new)/书社:dependency">
86 <call-template name="书社:process-dependencies">
87 <with-param name="processed">
88 <copy-of select="$old"/>
89 </with-param>
90 <with-param name="unprocessed">
91 <copy-of select="$new"/>
92 </with-param>
93 </call-template>
94 </when>
95 <otherwise>
96 <copy-of select="$old"/>
97 </otherwise>
98 </choose>
99 </template>
100 <template match="rdf:RDF/nfo:LocalFileDataObject[not(nie:interpretedAs/nfo:Folder or nie:interpretedAs/nfo:PlainTextDocument)]" priority="1">
101 <copy>
102 <apply-templates select="@*|node()"/>
103 <if test="starts-with(@rdf:about, 'about:shushe?source=')">
104 <dct:hasFormat>
105 <nfo:LocalFileDataObject dct:creator="urn:fdc:ladys.computer:20231231:Shu1She4" nfo:fileName="{substring-after(@rdf:about, 'about:shushe?source=')}"/>
106 </dct:hasFormat>
107 </if>
108 </copy>
109 </template>
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">
114 <choose>
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"/>
118 </when>
119 <otherwise>
120 <value-of select="substring-after(@rdf:about, 'about:shushe?source=')"/>
121 </otherwise>
122 </choose>
123 </variable>
124 <variable name="dependencies-fragment">
125 <apply-templates select="." mode="书社:dependencies"/>
126 </variable>
127 <variable name="dependencies" select="exsl:node-set($dependencies)"/>
128 <copy>
129 <apply-templates select="@*|node()"/>
130 <for-each select="$dependencies/书社:dependency">
131 <书社vocab:hasDependencyOn rdf:resource="{.}"/>
132 </for-each>
133 <for-each select="$dependencies/书社:recursive-dependency">
134 <书社vocab:hasRecursiveDependencyOn rdf:resource="{.}"/>
135 </for-each>
136 <if test="$destination!=''">
137 <dct:hasFormat>
138 <nfo:LocalFileDataObject dct:creator="urn:fdc:ladys.computer:20231231:Shu1She4" nfo:fileName="{$destination}">
139 </nfo:LocalFileDataObject>
140 </dct:hasFormat>
141 </if>
142 </copy>
143 </template>
144 <template match="@*|node()">
145 <copy>
146 <apply-templates select="@*|node()"/>
147 </copy>
148 </template>
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">
153 <书社:dependency-root>
154 <value-of select="@rdf:about"/>
155 </书社:dependency-root>
156 </with-param>
157 </call-template>
158 </if>
159 </template>
160 </transform>
This page took 0.07605 seconds and 5 git commands to generate.