]> Lady’s Gitweb - Caudex/blob - transforms/index.xslt
Make repository REUSE‐compliant
[Caudex] / transforms / index.xslt
1 <?xml version="1.0"?>
2 <!--
3 SPDX-FileCopyrightText: 2024 Lady <https://www.ladys.computer/about/#lady>
4 SPDX-License-Identifier: MPL-2.0
5 -->
6 <!--
7 ⁌ 🪾📰 Caudex ∷ transforms/index.xslt
8
9 © 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 <!DOCTYPE transform [
15 <!ENTITY Caudex "urn:fdc:ladys.computer:20240204:Caudex:">
16 <!ENTITY LesML "urn:fdc:ladys.computer:20240512:LesML:">
17 <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4:">
18 ]>
19 <transform
20 xmlns="http://www.w3.org/1999/XSL/Transform"
21 xmlns:Caudex="urn:fdc:ladys.computer:20240204:Caudex"
22 xmlns:exsl="http://exslt.org/common"
23 xmlns:html="http://www.w3.org/1999/xhtml"
24 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
25 exclude-result-prefixes="exsl"
26 version="1.0"
27 >
28 <书社:id>&Caudex;index.xslt</书社:id>
29 <template match="/html:div[@书社:parsed-by='&Caudex;catalog.xslt'][@class='index' or @class='fullindex']">
30 <html:body>
31 <for-each select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4']">
32 <copy/>
33 </for-each>
34 <variable name="metadata" select="html:div[@书社:parsed-by='&书社;record-jar.xslt']"/>
35 <html:meta itemprop="&书社;title" content="{$metadata//html:dt[string()='TITLE']/following-sibling::html:dd}"/>
36 <html:main>
37 <html:nav>
38 <html:ul>
39 <for-each select=".//html:div[@书社:parsed-by='&Caudex;catalog.xslt'][@class='category']">
40 <variable name="category-metadata" select="html:div[@id='@']/html:div[@书社:parsed-by='&书社;record-jar.xslt']"/>
41 <html:li>
42 <html:strong>
43 <choose>
44 <when test="$category-metadata//html:dt[string()='TITLE']">
45 <value-of select="$category-metadata//html:dt[string()='TITLE']/following-sibling::html:dd"/>
46 </when>
47 <otherwise>
48 <value-of select="../@id"/>
49 </otherwise>
50 </choose>
51 </html:strong>
52 <html:ul>
53 <for-each select="html:div[@id!='@']/html:article[@书社:parsed-by='&LesML;parser.xslt']">
54 <sort select="html:footer[@class='head']/html:dl[1]//html:dt[string()='TITLE']/following-sibling::html:dd"/>
55 <sort select="../@id"/>
56 <variable name="entry-metadata" select="html:footer[@class='head']/html:dl[1]"/>
57 <html:li>
58 <html:a href="{../@id}.xhtml" data-identifier="{../@id}" data-cksum="{@书社:cksum}">
59 <value-of select="$entry-metadata//html:dt[string()='TITLE']/following-sibling::html:dd"/>
60 <text> </text>
61 <html:small>
62 <text>(</text>
63 <value-of select="../@id"/>
64 <text>)</text>
65 </html:small>
66 </html:a>
67 </html:li>
68 </for-each>
69 </html:ul>
70 </html:li>
71 </for-each>
72 </html:ul>
73 </html:nav>
74 <html:div id="pane">
75 <if test="@class='fullindex'">
76 <for-each select=".//html:div[@书社:parsed-by='&Caudex;catalog.xslt'][@class='category']/html:div[@id!='@']/html:article[@书社:parsed-by='&LesML;parser.xslt']">
77 <variable name="context" select="."/>
78 <variable name="entry">
79 <html:div 书社:parsed-by="&Caudex;catalog.xslt" class="entry">
80 <html:div id="@">
81 <copy-of select="."/>
82 </html:div>
83 </html:div>
84 </variable>
85 <variable name="transformed-entry">
86 <apply-templates select="exsl:node-set($entry)/*"/>
87 </variable>
88 <for-each select="exsl:node-set($transformed-entry)//html:article">
89 <html:article id="{$context/../@id}" hidden="hidden">
90 <copy-of select="@*|node()"/>
91 </html:article>
92 </for-each>
93 </for-each>
94 </if>
95 </html:div>
96 </html:main>
97 <html:script type="text/javascript">
98 <choose>
99 <when test="@class='fullindex'">
100 <text><![CDATA[#!javascript
101 ~function(links){
102 var i=0
103 for(;i<links.length;++i){
104 ~function(link){
105 var identifier=link.getAttribute("data-identifier")
106 var cksum=link.getAttribute("data-cksum")
107 if(!(identifier&&cksum))return
108 link.addEventListener("click",function(event){
109 var j=0
110 var k=0
111 var pane=document.getElementById("pane")
112 var articles=pane.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","article")
113 for(;j<articles.length;++j){
114 ~function(article){
115 if(article.getAttribute("id")==identifier){
116 article.removeAttribute("hidden")
117 link.setAttribute("class","cached read")
118 try{
119 localStorage.setItem(identifier,cksum)
120 }catch(e){}
121 }
122 else article.setAttribute("hidden","hidden")
123 }(articles.item(j))
124 }
125 for(;k<links.length;++k){
126 ~function(linkk){
127 var parent=linkk.parentNode
128 if(linkk==link)parent.setAttribute("class","selected")
129 else parent.setAttribute("class","")
130 }(links.item(k))
131 }
132 event.preventDefault()
133 pane.focus()
134 },false)
135 try{
136 var lastReadCksum=localStorage.getItem(identifier)
137 if(lastReadCksum==cksum)link.setAttribute("class","cached read")
138 else if(lastReadCksum)link.setAttribute("class","cached updated")
139 else link.setAttribute("class","cached new")
140 }catch(e){}
141 }(links.item(i))
142 }
143 }(document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","a"))
144 ]]></text>
145 </when>
146 <otherwise>
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("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","a"))
199 ]]></text>
200 </otherwise>
201 </choose>
202 </html:script>
203 </html:body>
204 </template>
205 </transform>
This page took 0.057103 seconds and 5 git commands to generate.