]> Lady’s Gitweb - Caudex/blob - transforms/index.xslt
Initial commit; minimal working implementation
[Caudex] / transforms / index.xslt
1 <?xml version="1.0"?>
2 <!--
3 ⁌ 🪾📰 Caudex ∷ transforms/entry.xslt
4
5 © 2024 Lady [@ Lady’s Computer]
6
7 This Source Code Form is subject to the terms of the Mozilla Public License, v 2.0.
8 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/>.
9 -->
10 <!DOCTYPE transform [
11 <!ENTITY Caudex "urn:fdc:ladys.computer:20240204:Caudex:">
12 <!ENTITY 书社 "urn:fdc:ladys.computer:20231231:Shu1She4:">
13 ]>
14 <transform
15 xmlns="http://www.w3.org/1999/XSL/Transform"
16 xmlns:Caudex="urn:fdc:ladys.computer:20240204:Caudex"
17 xmlns:exsl="http://exslt.org/common"
18 xmlns:html="http://www.w3.org/1999/xhtml"
19 xmlns:书社="urn:fdc:ladys.computer:20231231:Shu1She4"
20 exclude-result-prefixes="exsl"
21 version="1.0"
22 >
23 <import href="../lib/split.xslt"/>
24 <书社:id>&Caudex;index.xslt</书社:id>
25 <template match="/html:div[@书社:parsed-by='&Caudex;catalog.xslt'][@class='index' or @class='fullindex']">
26 <html:body>
27 <for-each select="@*[namespace-uri()!='urn:fdc:ladys.computer:20231231:Shu1She4']">
28 <copy/>
29 </for-each>
30 <variable name="metadata" select="html:div[@书社:parsed-by='&书社;record-jar.xslt']"/>
31 <html:meta itemprop="&书社;title" content="{$metadata//html:dt[string()='TITLE']/following-sibling::html:dd}"/>
32 <html:main>
33 <html:nav>
34 <html:ul>
35 <for-each select=".//html:div[@书社:parsed-by='&Caudex;catalog.xslt'][@class='category']">
36 <variable name="category-metadata" select="html:div[@id='@']/html:div[@书社:parsed-by='&书社;record-jar.xslt']"/>
37 <html:li>
38 <html:strong>
39 <choose>
40 <when test="$category-metadata//html:dt[string()='TITLE']">
41 <value-of select="$category-metadata//html:dt[string()='TITLE']/following-sibling::html:dd"/>
42 </when>
43 <otherwise>
44 <value-of select="../@id"/>
45 </otherwise>
46 </choose>
47 </html:strong>
48 <html:ul>
49 <for-each select="html:div[@id!='@']/html:div[@书社:parsed-by='&Caudex;codex-entry.xslt']">
50 <sort select="html:div[@书社:parsed-by='&书社;record-jar.xslt']/html:dl[1]//html:dt[string()='TITLE']/following-sibling::html:dd"/>
51 <sort select="../@id"/>
52 <variable name="entry-metadata" select="html:div[@书社:parsed-by='&书社;record-jar.xslt']/html:dl[1]"/>
53 <html:li>
54 <html:a href="{../@id}.xhtml" data-identifier="{../@id}" data-cksum="{@书社:cksum}">
55 <value-of select="$entry-metadata//html:dt[string()='TITLE']/following-sibling::html:dd"/>
56 <text> </text>
57 <html:small>
58 <text>(</text>
59 <value-of select="../@id"/>
60 <text>)</text>
61 </html:small>
62 </html:a>
63 </html:li>
64 </for-each>
65 </html:ul>
66 </html:li>
67 </for-each>
68 </html:ul>
69 </html:nav>
70 <html:div id="pane">
71 <if test="@class='fullindex'">
72 <for-each select=".//html:div[@书社:parsed-by='&Caudex;catalog.xslt'][@class='category']/html:div[@id!='@']/html:div[@书社:parsed-by='&Caudex;codex-entry.xslt']">
73 <variable name="context" select="."/>
74 <variable name="entry">
75 <html:div 书社:parsed-by="&Caudex;catalog.xslt" class="entry">
76 <html:div id="@">
77 <copy-of select="."/>
78 </html:div>
79 </html:div>
80 </variable>
81 <variable name="transformed-entry">
82 <apply-templates select="exsl:node-set($entry)/*"/>
83 </variable>
84 <for-each select="exsl:node-set($transformed-entry)//html:article">
85 <html:article id="{$context/../@id}" hidden="hidden">
86 <copy-of select="@*|node()"/>
87 </html:article>
88 </for-each>
89 </for-each>
90 </if>
91 </html:div>
92 </html:main>
93 <html:script type="text/javascript">
94 <choose>
95 <when test="@class='fullindex'">
96 <text><![CDATA[#!javascript
97 ~function(links){
98 var i=0
99 for(;i<links.length;++i){
100 ~function(link){
101 var identifier=link.getAttribute("data-identifier")
102 var cksum=link.getAttribute("data-cksum")
103 if(!(identifier&&cksum))return
104 link.addEventListener("click",function(event){
105 var j=0
106 var k=0
107 var pane=document.getElementById("pane")
108 var articles=pane.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","article")
109 for(;j<articles.length;++j){
110 ~function(article){
111 if(article.getAttribute("id")==identifier){
112 article.removeAttribute("hidden")
113 link.setAttribute("class","cached read")
114 try{
115 localStorage.setItem(identifier,cksum)
116 }catch(e){}
117 }
118 else article.setAttribute("hidden","hidden")
119 }(articles.item(j))
120 }
121 for(;k<links.length;++k){
122 ~function(linkk){
123 var parent=linkk.parentNode
124 if(linkk==link)parent.setAttribute("class","selected")
125 else parent.setAttribute("class","")
126 }(links.item(k))
127 }
128 event.preventDefault()
129 pane.focus()
130 },false)
131 try{
132 var lastReadCksum=localStorage.getItem(identifier)
133 if(lastReadCksum==cksum)link.setAttribute("class","cached read")
134 else if(lastReadCksum)link.setAttribute("class","cached updated")
135 else link.setAttribute("class","cached new")
136 }catch(e){}
137 }(links.item(i))
138 }
139 }(document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","a"))
140 ]]></text>
141 </when>
142 <otherwise>
143 <text><![CDATA[#!javascript
144 ~function(links){
145 var i=0
146 var cache={}
147 for(;i<links.length;++i){
148 ~function(link){
149 var identifier=link.getAttribute("data-identifier")
150 var cksum=link.getAttribute("data-cksum")
151 if(!(identifier&&cksum))return
152 link.addEventListener("click",function(event){
153 var pane=document.getElementById("pane")
154 var request
155 if(identifier in cache){
156 pane.textContent=""
157 pane.appendChild(document.importNode(cache[identifier],true))
158 }else{
159 pane.textContent="Loading…"
160 request=new XMLHttpRequest
161 request.open("GET",link.href)
162 request.addEventListener("load",function(){
163 var k=0
164 var article=request.responseXML.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","article").item(0)
165 cache[identifier]=article
166 pane.textContent=""
167 pane.appendChild(document.importNode(article,true))
168 for(;k<links.length;++k){
169 ~function(linkk){
170 var parent=linkk.parentNode
171 if(linkk==link)parent.setAttribute("class","selected")
172 else parent.setAttribute("class","")
173 }(links.item(k))
174 }
175 link.setAttribute("class","cached read")
176 try{
177 localStorage.setItem(identifier,cksum)
178 }catch(e){}
179 },false)
180 request.responseType="document"
181 request.send()
182 }
183 event.preventDefault()
184 pane.focus()
185 },false)
186 try{
187 var lastReadCksum=localStorage.getItem(identifier)
188 if(lastReadCksum==cksum)link.setAttribute("class","read")
189 else if(lastReadCksum)link.setAttribute("class","updated")
190 else link.setAttribute("class","new")
191 }catch(e){}
192 }(links[i])
193 }
194 }(document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml","a"))
195 ]]></text>
196 </otherwise>
197 </choose>
198 </html:script>
199 </html:body>
200 </template>
201 </transform>
This page took 0.068835 seconds and 5 git commands to generate.