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