]> Lady’s Gitweb - Shushe/blob - transforms/expansion.xslt
Move expansion into its own transform
[Shushe] / transforms / expansion.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2023, 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ ⛩📰 书社 ∷ transforms/expansion.xslt
8
9 © 2023–2025 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 <!DOCTYPE transform [
15 <!ENTITY 书社 'urn:fdc:ladys.computer:20231231:Shu1She4'>
16 ]>
17 <transform
18 xmlns="http://www.w3.org/1999/XSL/Transform"
19 xmlns:exsl="http://exslt.org/common"
20 xmlns:exslstr="http://exslt.org/strings"
21 xmlns:html="http://www.w3.org/1999/xhtml"
22 xmlns:nfo="http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#"
23 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
24 xmlns:xlink="http://www.w3.org/1999/xlink"
25 xmlns:书社="&书社;"
26 xmlns:书社vocab="urn:fdc:ladys.computer:20231231:Shu1She4:vocab:"
27 exclude-result-prefixes="nfo 书社vocab"
28 extension-element-prefixes="exsl exslstr"
29 version="1.0"
30 >
31 <书社:id>urn:fdc:ladys.computer:20231231:Shu1She4:expansion.xslt</书社:id>
32 <template match="书社:link[@xlink:show='embed' and (not(@xlink:actuate) or @xlink:actuate='none')]" mode="书社:expand" priority="1">
33 <variable name="link" select="."/>
34 <variable name="identifier" select="string(@xlink:href)"/>
35 <variable name="is-dir" select="substring($identifier, string-length($identifier))='/'"/>
36 <variable name="included" select="$书社:about//*[@rdf:about=$identifier or $is-dir and starts-with(@rdf:about, $identifier)]"/>
37 <choose>
38 <when test="$included">
39 <for-each select="$included">
40 <sort select="@rdf:about" data-type="text" lang="zxx" case-order="upper-first"/>
41 <variable name="uri" select="书社vocab:hasParsedFile/@nfo:fileUrl"/>
42 <variable name="expanded">
43 <apply-templates select="document($uri)" mode="书社:expand">
44 <with-param name="identifier" select="string(@rdf:about)"/>
45 </apply-templates>
46 </variable>
47 <for-each select="exsl:node-set($expanded)/node()">
48 <copy>
49 <choose>
50 <when test="self::html:*">
51 <variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
52 <attribute name="itemscope">itemscope</attribute>
53 <attribute name="itemtype">
54 <for-each select="$existing-types/token[string()!='&书社;:document']">
55 <if test="position()!=1">
56 <text> </text>
57 </if>
58 <value-of select="."/>
59 </for-each>
60 <if test="not($existing-types/token[string()='&书社;:embed'])">
61 <if test="$existing-types/token[string()!='&书社;:document']">
62 <text> </text>
63 </if>
64 <text>&书社;:embed</text>
65 </if>
66 </attribute>
67 <choose>
68 <when test="$link/@书社:archived-as">
69 <copy-of select="$link/@书社:archived-as"/>
70 </when>
71 <when test="@书社:archived-as">
72 <copy-of select="@书社:archived-as"/>
73 </when>
74 </choose>
75 <copy-of select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype')) and not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
76 </when>
77 <otherwise>
78 <choose>
79 <when test="self::* and $link/@书社:archived-as">
80 <copy-of select="$link/@书社:archived-as"/>
81 </when>
82 <when test="@书社:archived-as">
83 <copy-of select="@书社:archived-as"/>
84 </when>
85 </choose>
86 <copy-of select="@*[not(namespace-uri()='&书社;' and local-name()='archived-as')]|node()"/>
87 </otherwise>
88 </choose>
89 </copy>
90 </for-each>
91 </for-each>
92 </when>
93 <otherwise>
94 <copy>
95 <apply-templates select="@*|node()" mode="书社:expand"/>
96 </copy>
97 </otherwise>
98 </choose>
99 </template>
100 <template match="/node()" mode="书社:expand" priority="0">
101 <param name="identifier" select="$IDENTIFIER"/>
102 <copy>
103 <if test="self::*">
104 <attribute name="书社:cksum">
105 <value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:hasHash[@nfo:hashAlgorithm='CRC32']/@nfo:hashValue"/>
106 </attribute>
107 <attribute name="书社:identifier">
108 <value-of select="$identifier"/>
109 </attribute>
110 <attribute name="书社:mtime">
111 <value-of select="$书社:about//*[@rdf:about=$identifier]/nfo:fileLastModified"/>
112 </attribute>
113 </if>
114 <choose>
115 <when test="self::html:*">
116 <variable name="existing-types" select="exslstr:tokenize(@itemtype)"/>
117 <attribute name="itemscope">itemscope</attribute>
118 <attribute name="itemtype">
119 <for-each select="$existing-types/token">
120 <if test="position()!=1">
121 <text> </text>
122 </if>
123 <value-of select="."/>
124 </for-each>
125 <if test="not($existing-types/token[string()='&书社;:embed' or string()='&书社;:document'])">
126 <if test="$existing-types/token">
127 <text> </text>
128 </if>
129 <text>&书社;:document</text>
130 </if>
131 </attribute>
132 <apply-templates select="@*[not(namespace-uri()='' and (local-name()='itemscope' or local-name()='itemtype') or namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
133 </when>
134 <otherwise>
135 <apply-templates select="@*[not(namespace-uri()='&书社;' and (local-name()='cksum' or local-name()='identifier' or local-name()='mtime'))]|node()" mode="书社:expand"/>
136 </otherwise>
137 </choose>
138 </copy>
139 </template>
140 </transform>
This page took 0.217876 seconds and 5 git commands to generate.