]> Lady’s Gitweb - Caudex/blob - transform.xslt
Enable manual ordering
[Caudex] / transform.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024, 2025 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ 🪾📰 Caudex ∷ transform.xslt
8
9 © 2024–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 xhtml 'http://www.w3.org/1999/xhtml'>
16 <!ENTITY 书社 'urn:fdc:ladys.computer:20231231:Shu1She4'>
17 ]>
18 <transform
19 xmlns="http://www.w3.org/1999/XSL/Transform"
20 xmlns:Caudex="urn:fdc:ladys.computer:20240204:Caudex"
21 xmlns:awol="http://bblfish.net/work/atom-owl/2006-06-06/#"
22 xmlns:dcterms="http://purl.org/dc/terms/"
23 xmlns:exsl="http://exslt.org/common"
24 xmlns:exslstr="http://exslt.org/strings"
25 xmlns:html="&xhtml;"
26 xmlns:ladys="https://vocab.ladys.computer/terms/"
27 xmlns:ore="http://www.openarchives.org/ore/terms/"
28 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
29 xmlns:skos="http://www.w3.org/2004/02/skos/core#"
30 xmlns:书社="&书社;"
31 extension-element-prefixes="exsl exslstr"
32 version="1.0"
33 >
34 <书社:id>urn:fdc:ladys.computer:20240204:Caudex:transform.xslt</书社:id>
35 <template match="@id" mode="Caudex:codex-entry" priority="0">
36 <attribute name="id">
37 <value-of select="ancestor::*[skos:notation][1]/skos:notation"/>
38 <text>.</text>
39 <value-of select="."/>
40 </attribute>
41 </template>
42 <template match="@href[starts-with(., '#')]" mode="Caudex:codex-entry" priority="0">
43 <attribute name="href">
44 <text>#</text>
45 <value-of select="ancestor::*[skos:notation][1]/skos:notation"/>
46 <text>.</text>
47 <value-of select="substring-after(., '#')"/>
48 </attribute>
49 </template>
50 <template match="@*|node()" mode="Caudex:codex-entry" priority="-1">
51 <copy>
52 <apply-templates select="@*|node()" mode="Caudex:codex-entry"/>
53 </copy>
54 </template>
55 <template match="Caudex:codex" mode="书社:expand" priority="1">
56 <variable name="codex-fragment">
57 <apply-templates select="node()" mode="书社:expand"/>
58 </variable>
59 <variable name="codex" select="exsl:node-set($codex-fragment)"/>
60 <variable name="codex-rdf" select="$codex//ore:Aggregation[@rdf:nodeID='codex']"/>
61 <element name="书社:archive">
62 <attribute name="书社:expanded"/>
63 <for-each select="$codex-rdf">
64 <variable name="title-fragment">
65 <if test="@dcterms:title">
66 <element name="meta" namespace="&xhtml;">
67 <attribute name="itemprop">
68 <text>urn:fdc:ladys.computer:20231231:Shu1She4:title</text>
69 </attribute>
70 <attribute name="content">
71 <value-of select="@dcterms:title"/>
72 </attribute>
73 </element>
74 </if>
75 </variable>
76 <variable name="navigation-fragment">
77 <element name="nav" namespace="&xhtml;">
78 <element name="ul" namespace="&xhtml;">
79 <for-each select="$codex//awol:Category">
80 <sort select="ladys:order" data-type="number"/>
81 <sort select="@awol:term"/>
82 <variable name="category-id" select="string(@rdf:nodeID)"/>
83 <element name="li" namespace="&xhtml;">
84 <element name="strong" namespace="&xhtml;">
85 <value-of select="@awol:term"/>
86 </element>
87 <element name="ul" namespace="&xhtml;">
88 <for-each select="$codex//ore:Proxy[ore:proxyIn/@rdf:nodeID='codex' and awol:category/@rdf:nodeID=$category-id]">
89 <sort select="ladys:order" data-type="number"/>
90 <sort select="@dcterms:title"/>
91 <sort select="skos:notation"/>
92 <element name="li" namespace="&xhtml;">
93 <element name="a" namespace="&xhtml;">
94 <attribute name="href">
95 <text>./</text>
96 <value-of select="skos:notation"/>
97 <text>.xhtml</text>
98 </attribute>
99 <attribute name="data-identifier">
100 <value-of select="skos:notation"/>
101 </attribute>
102 <attribute name="data-cksum">
103 <value-of select="@书社:cksum"/>
104 </attribute>
105 <if test="@dcterms:title">
106 <value-of select="@dcterms:title"/>
107 <text> </text>
108 </if>
109 <element name="small" namespace="&xhtml;">
110 <text>(</text>
111 <element name="code" namespace="&xhtml;">
112 <attribute name="lang">
113 <text>zxx</text>
114 </attribute>
115 <attribute name="xml:lang">
116 <text>zxx</text>
117 </attribute>
118 <value-of select="skos:notation"/>
119 </element>
120 <text>)</text>
121 </element>
122 </element>
123 </element>
124 </for-each>
125 </element>
126 </element>
127 </for-each>
128 </element>
129 </element>
130 </variable>
131 <element name="div" namespace="&xhtml;">
132 <attribute name="Caudex:page">
133 <text>index</text>
134 </attribute>
135 <attribute name="书社:archived-as">
136 <text>index.xhtml</text>
137 </attribute>
138 <copy-of select="$title-fragment"/>
139 <element name="main" namespace="&xhtml;">
140 <copy-of select="$navigation-fragment"/>
141 <element name="div" namespace="&xhtml;">
142 <attribute name="id">
143 <text>Caudex.pane</text>
144 </attribute>
145 </element>
146 </element>
147 <element name="script" namespace="&xhtml;">
148 <attribute name="type">
149 <text>text/javascript</text>
150 </attribute>
151 <text><![CDATA[#!javascript
152 ~function(links){
153 var i=0
154 var cache={}
155 for(;i<links.length;++i){
156 ~function(link){
157 var identifier=link.getAttribute("data-identifier")
158 var cksum=link.getAttribute("data-cksum")
159 if(!(identifier&&cksum))return
160 link.addEventListener("click",function(event){
161 var pane=document.getElementById("Caudex.pane")
162 var request
163 if(identifier in cache){
164 pane.textContent=""
165 pane.appendChild(document.importNode(cache[identifier],true))
166 }else{
167 pane.textContent="Loading…"
168 request=new XMLHttpRequest
169 request.open("GET",link.href)
170 request.addEventListener("load",function(){
171 var k=0
172 var article=request.responseXML.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","article").item(0)
173 cache[identifier]=article
174 pane.textContent=""
175 pane.appendChild(document.importNode(article,true))
176 for(;k<links.length;++k){
177 ~function(linkk){
178 var parent=linkk.parentNode
179 if(linkk==link)parent.setAttribute("class","selected")
180 else parent.setAttribute("class","")
181 }(links.item(k))
182 }
183 link.setAttribute("class","cached read")
184 try{
185 localStorage.setItem(identifier,cksum)
186 }catch(e){}
187 },false)
188 request.responseType="document"
189 request.send()
190 }
191 event.preventDefault()
192 pane.focus()
193 },false)
194 try{
195 var lastReadCksum=localStorage.getItem(identifier)
196 if(lastReadCksum==cksum)link.setAttribute("class","read")
197 else if(lastReadCksum)link.setAttribute("class","updated")
198 else link.setAttribute("class","new")
199 }catch(e){}
200 }(links[i])
201 }
202 }(document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","main")[0].children[0].getElementsByTagNameNS("http://www.w3.org/1999/xhtml","a"))
203 ]]></text>
204 </element>
205 </element>
206 <element name="div" namespace="&xhtml;">
207 <attribute name="Caudex:page">
208 <text>standalone</text>
209 </attribute>
210 <attribute name="书社:archived-as">
211 <text>standalone.xhtml</text>
212 </attribute>
213 <copy-of select="$title-fragment"/>
214 <element name="main" namespace="&xhtml;">
215 <copy-of select="$navigation-fragment"/>
216 <element name="div" namespace="&xhtml;">
217 <attribute name="id">
218 <text>Caudex.pane</text>
219 </attribute>
220 <for-each select="$codex//ore:Proxy">
221 <element name="article" namespace="&xhtml;">
222 <attribute name="id">
223 <value-of select="skos:notation"/>
224 </attribute>
225 <attribute name="hidden">
226 <text>hidden</text>
227 </attribute>
228 <apply-templates select="ore:proxyFor/*/awol:content/awol:body/node()" mode="Caudex:codex-entry"/>
229 </element>
230 </for-each>
231 </element>
232 </element>
233 <element name="script" namespace="&xhtml;">
234 <attribute name="type">
235 <text>text/javascript</text>
236 </attribute>
237 <text><![CDATA[#!javascript
238 ~function(links){
239 var i=0
240 for(;i<links.length;++i){
241 ~function(link){
242 var identifier=link.getAttribute("data-identifier")
243 var cksum=link.getAttribute("data-cksum")
244 if(!(identifier&&cksum))return
245 link.addEventListener("click",function(event){
246 var j=0
247 var k=0
248 var pane=document.getElementById("Caudex.pane")
249 var articles=pane.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","article")
250 for(;j<articles.length;++j){
251 ~function(article){
252 if(article.getAttribute("id")==identifier){
253 article.removeAttribute("hidden")
254 link.setAttribute("class","cached read")
255 try{
256 localStorage.setItem(identifier,cksum)
257 }catch(e){}
258 }
259 else article.setAttribute("hidden","hidden")
260 }(articles.item(j))
261 }
262 for(;k<links.length;++k){
263 ~function(linkk){
264 var parent=linkk.parentNode
265 if(linkk==link)parent.setAttribute("class","selected")
266 else parent.setAttribute("class","")
267 }(links.item(k))
268 }
269 event.preventDefault()
270 pane.focus()
271 },false)
272 try{
273 var lastReadCksum=localStorage.getItem(identifier)
274 if(lastReadCksum==cksum)link.setAttribute("class","cached read")
275 else if(lastReadCksum)link.setAttribute("class","cached updated")
276 else link.setAttribute("class","cached new")
277 }catch(e){}
278 }(links.item(i))
279 }
280 }(document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","main")[0].children[0].getElementsByTagNameNS("http://www.w3.org/1999/xhtml","a"))
281 ]]></text>
282 </element>
283 </element>
284 </for-each>
285 <for-each select="$codex//ore:Proxy">
286 <element name="article" namespace="&xhtml;">
287 <attribute name="Caudex:page">
288 <value-of select="skos:notation"/>
289 </attribute>
290 <attribute name="书社:archived-as">
291 <value-of select="skos:notation"/>
292 <text>.xhtml</text>
293 </attribute>
294 <if test="@dcterms:title">
295 <element name="meta" namespace="&xhtml;">
296 <attribute name="itemprop">
297 <text>urn:fdc:ladys.computer:20231231:Shu1She4:title</text>
298 </attribute>
299 <attribute name="content">
300 <value-of select="@dcterms:title"/>
301 </attribute>
302 </element>
303 </if>
304 <apply-templates select="ore:proxyFor/*/awol:content/awol:body/node()" mode="Caudex:codex-entry"/>
305 </element>
306 </for-each>
307 </element>
308 </template>
309 <template match="html:div[@itemtype='&书社;:document' and @Caudex:page]" mode="书社:metadata" priority="0">
310 <element name="style" namespace="&xhtml;">
311 <text><![CDATA[@charset "UTF-8";
312 @namespace "http://www.w3.org/1999/xhtml";
313 *[hidden]{Display:None}
314 ]]></text>
315 <if test="@Caudex:page='index' or @Caudex:page='standalone'">
316 <text><![CDATA[/*Index styling*/
317 main{Display:Block;Width:100%;Height:100%}
318 main>*{Display:Inline-Block;Box-Sizing:Border-Box;Border:.5EM Transparent None;Height:100%;Width:50%;Vertical-Align:Top;Overflow:Auto}
319 main>nav{Border-Right-Style:Solid;Overflow:Scroll}
320 main>div{Border-Left-Style:Solid}
321 ]]></text>
322 </if>
323 </element>
324 </template>
325 </transform>
This page took 0.06927 seconds and 5 git commands to generate.