]> Lady’s Gitweb - Shushe/blob - lib/metadata2dependencies.xslt
Remove variation selectors from sigil
[Shushe] / lib / metadata2dependencies.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/metadata2dependencies.xslt
8
9 © 2023–2024 Lady [@ Lady’s 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 version="1.0"
24 >
25 <variable name="files" select="/rdf:RDF/nfo:LocalFileDataObject"/>
26 <template name="书社:process-dependencies">
27 <param name="processed"/>
28 <param name="unprocessed"/>
29 <variable name="queue">
30 <copy-of select="exsl:node-set($unprocessed)/书社:dependency-root"/>
31 <for-each select="exsl:node-set($unprocessed)/书社:dependency">
32 <if test="not((exsl:node-set($processed)/书社:*|preceding-sibling::书社:*|following-sibling::书社:recursive-dependency)[string()=string(current())])">
33 <copy-of select="."/>
34 </if>
35 </for-each>
36 </variable>
37 <variable name="old">
38 <copy-of select="exsl:node-set($processed)/书社:dependency-root"/>
39 <copy-of select="exsl:node-set($processed)/书社:recursive-dependency"/>
40 <for-each select="exsl:node-set($unprocessed)/书社:recursive-dependency">
41 <if test="not((exsl:node-set($processed)/书社:recursive-dependency|preceding-sibling::书社:recursive-dependency)[string()=string(current())])">
42 <copy-of select="."/>
43 </if>
44 </for-each>
45 <for-each select="exsl:node-set($processed)/书社:dependency">
46 <if test="not(exsl:node-set($unprocessed)/书社:recursive-dependency[string()=string(current())])">
47 <copy-of select="."/>
48 </if>
49 </for-each>
50 <copy-of select="$queue"/>
51 </variable>
52 <variable name="new">
53 <for-each select="exsl:node-set($queue)/书社:*">
54 <for-each select="$files[@rdf:about=string(current()) and nie:interpretedAs/nfo:PlainTextDocument and dct:hasFormat/*/nie:interpretedAs/*[@nie:mimeType='application/xml']]">
55 <variable name="parent" select="@rdf:about"/>
56 <for-each select="document(dct:hasFormat/*[nie:interpretedAs/*[@nie:mimeType='application/xml']]/@nfo:fileUrl[1])//书社:link[@xlink:show='embed']">
57 <if test="exsl:node-set($old)/书社:dependency-root[string()=string(current()/@xlink:href)]">
58 <书社:recursive-dependency>
59 <value-of select="$parent"/>
60 </书社:recursive-dependency>
61 </if>
62 <if test="$files/@rdf:about[string()=string(current()/@xlink:href)]">
63 <书社:dependency>
64 <value-of select="@xlink:href"/>
65 </书社:dependency>
66 </if>
67 </for-each>
68 </for-each>
69 </for-each>
70 </variable>
71 <choose>
72 <when test="exsl:node-set($new)/书社:dependency">
73 <call-template name="书社:process-dependencies">
74 <with-param name="processed">
75 <copy-of select="$old"/>
76 </with-param>
77 <with-param name="unprocessed">
78 <copy-of select="$new"/>
79 </with-param>
80 </call-template>
81 </when>
82 <otherwise>
83 <copy-of select="$old"/>
84 </otherwise>
85 </choose>
86 </template>
87 <template match="nfo:LocalFileDataObject" mode="书社:dependencies">
88 <if test="nie:interpretedAs/nfo:PlainTextDocument">
89 <call-template name="书社:process-dependencies">
90 <with-param name="unprocessed">
91 <书社:dependency-root>
92 <value-of select="@rdf:about"/>
93 </书社:dependency-root>
94 </with-param>
95 </call-template>
96 </if>
97 </template>
98 <template match="/">
99 <for-each select="$files[nie:interpretedAs/nfo:PlainTextDocument]">
100 <variable name="parent" select="@rdf:about"/>
101 <variable name="dependencies">
102 <apply-templates select="." mode="书社:dependencies"/>
103 </variable>
104 <value-of select="@rdf:about"/>
105 <text>&#xA;</text>
106 <for-each select="exsl:node-set($dependencies)/书社:recursive-dependency">
107 <text>&#x9;</text>
108 <text>-</text>
109 <value-of select="."/>
110 <text>&#xA;</text>
111 </for-each>
112 <for-each select="exsl:node-set($dependencies)/书社:dependency">
113 <text>&#x9;</text>
114 <value-of select="."/>
115 <text>&#xA;</text>
116 </for-each>
117 </for-each>
118 </template>
119 <output method="text" encoding="UTF-8"/>
120 </transform>
This page took 0.062239 seconds and 5 git commands to generate.