]> git.stg.codes - stg.git/blob - doc/xslt/website/toc-tabular.xsl
Limited waiting for response.
[stg.git] / doc / xslt / website / toc-tabular.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 version="1.0">
4
5 <xsl:output method="html"/>
6
7 <xsl:param name="nav.graphics" select="1"/>
8 <xsl:param name="nav.pointer" select="1"/>
9 <xsl:param name="nav.revisionflag" select="1"/>
10
11 <xsl:param name="toc.spacer.text">&#160;&#160;&#160;</xsl:param>
12 <xsl:param name="toc.spacer.image">graphics/blank.gif</xsl:param>
13
14 <xsl:param name="nav.icon.path">graphics/navicons/</xsl:param>
15 <xsl:param name="nav.icon.extension">.gif</xsl:param>
16
17 <!-- styles: folder, folder16, plusminus, triangle, arrow -->
18 <xsl:param name="nav.icon.style">triangle</xsl:param>
19
20 <xsl:param name="nav.text.spacer">&#160;</xsl:param>
21 <xsl:param name="nav.text.current.open">+</xsl:param>
22 <xsl:param name="nav.text.current.page">+</xsl:param>
23 <xsl:param name="nav.text.other.open">&#160;</xsl:param>
24 <xsl:param name="nav.text.other.closed">&#160;</xsl:param>
25 <xsl:param name="nav.text.other.page">&#160;</xsl:param>
26 <xsl:param name="nav.text.revisionflag.added">New</xsl:param>
27 <xsl:param name="nav.text.revisionflag.changed">Changed</xsl:param>
28 <xsl:param name="nav.text.revisionflag.deleted"></xsl:param>
29 <xsl:param name="nav.text.revisionflag.off"></xsl:param>
30
31 <xsl:param name="nav.text.pointer">&lt;-</xsl:param>
32
33 <xsl:param name="toc.expand.depth" select="1"/>
34
35 <!-- ==================================================================== --> 
36
37 <xsl:template match="toc/title|tocentry/title|titleabbrev">
38   <xsl:apply-templates/>
39 </xsl:template>
40
41 <xsl:template match="toc">
42   <xsl:param name="pageid" select="@id"/>
43
44   <xsl:variable name="relpath">
45     <xsl:call-template name="toc-rel-path">
46       <xsl:with-param name="pageid" select="$pageid"/>
47     </xsl:call-template>
48   </xsl:variable>
49
50   <xsl:variable name="homebanner"
51                 select="/autolayout/config[@param='homebanner-tabular'][1]"/>
52
53   <xsl:variable name="banner"
54                 select="/autolayout/config[@param='banner-tabular'][1]"/>
55
56   <xsl:choose>
57     <xsl:when test="$pageid = @id">
58       <img align="left" border="0">
59         <xsl:attribute name="src">
60           <xsl:value-of select="$relpath"/>
61           <xsl:value-of select="$homebanner/@value"/>
62         </xsl:attribute>
63         <xsl:attribute name="alt">
64           <xsl:value-of select="$homebanner/@altval"/>
65         </xsl:attribute>
66       </img>
67       <br clear="all"/>
68       <br/>
69     </xsl:when>
70     <xsl:otherwise>
71       <a href="{$relpath}{@dir}{$filename-prefix}{@filename}">
72         <img align="left" border="0">
73           <xsl:attribute name="src">
74             <xsl:value-of select="$relpath"/>
75             <xsl:value-of select="$banner/@value"/>
76           </xsl:attribute>
77           <xsl:attribute name="alt">
78             <xsl:value-of select="$banner/@altval"/>
79           </xsl:attribute>
80         </img>
81       </a>
82       <br clear="all"/>
83       <br/>
84     </xsl:otherwise>
85   </xsl:choose>
86
87   <xsl:apply-templates select="tocentry">
88     <xsl:with-param name="pageid" select="$pageid"/>
89     <xsl:with-param name="relpath" select="$relpath"/>
90   </xsl:apply-templates>
91   <br/>
92 </xsl:template>
93
94 <!-- ==================================================================== -->
95
96 <xsl:template match="tocentry">
97   <xsl:param name="pageid" select="@id"/>
98   <xsl:param name="toclevel" select="count(ancestor::*)"/>
99   <xsl:param name="relpath" select="''"/>
100   <xsl:param name="revisionflag" select="@revisionflag"/>
101
102   <xsl:variable name="page" select="."/>
103   <xsl:variable name="target"
104                 select="($page/descendant-or-self::tocentry[not(@tocskip) or @tocskip = '0']
105                        |$page/following::tocentry[@tocskip and @tocskip='0'])[1]"/>
106
107   <xsl:variable name="depth" select="count(ancestor::*)-1"/>
108
109   <xsl:variable name="isdescendant">
110     <xsl:choose>
111       <xsl:when test="ancestor::*[@id=$pageid]">1</xsl:when>
112       <xsl:otherwise>0</xsl:otherwise>
113     </xsl:choose>
114   </xsl:variable>
115
116   <xsl:variable name="hasdescendant">
117     <xsl:choose>
118       <xsl:when test="descendant::tocentry != ''">1</xsl:when>
119       <xsl:otherwise>0</xsl:otherwise>
120     </xsl:choose>
121   </xsl:variable>
122
123   <xsl:variable name="isancestor">
124     <xsl:choose>
125       <xsl:when test="descendant::*[@id=$pageid]">1</xsl:when>
126       <xsl:otherwise>0</xsl:otherwise>
127     </xsl:choose>
128   </xsl:variable>
129
130   <xsl:variable name="use.toc.expand.depth">
131     <xsl:variable name="config-param" select="ancestor::autolayout/config[@param='toc.expand.depth']/@value"/>
132     <xsl:choose>
133       <!-- toc.expand.depth attribute is not in DTD -->
134       <xsl:when test="ancestor::toc/@toc.expand.depth">
135         <xsl:value-of select="ancestor::toc/@toc.expand.depth"/>
136       </xsl:when>
137       <xsl:when test="floor($config-param) > 0">
138         <xsl:value-of select="$config-param"/>
139       </xsl:when>
140       <xsl:otherwise>
141         <xsl:value-of select="$toc.expand.depth"/>
142       </xsl:otherwise>
143     </xsl:choose>
144   </xsl:variable>
145
146   <xsl:variable name="is.open">
147     <xsl:choose>
148       <xsl:when test="$pageid = @id
149                       or $isancestor='1'
150                       or $depth &lt; $use.toc.expand.depth">1</xsl:when>
151       <xsl:otherwise>0</xsl:otherwise>
152     </xsl:choose>
153   </xsl:variable>
154
155   <!-- For any entry in the TOC:
156        1. It is the current page
157           a. it is a leaf             current/leaf
158           b. it is an open page       current/open
159        2. It is not the current page
160           a. it is a leaf             other/leaf
161           b. it is an open page       other/open
162           c. it is a closed page      other/closed
163   -->
164
165   <xsl:variable name="preceding-icon">
166     <xsl:value-of select="$relpath"/>
167     <xsl:value-of select="$nav.icon.path"/>
168     <xsl:value-of select="$nav.icon.style"/>
169     <xsl:choose>
170       <xsl:when test="$pageid=@id">
171         <xsl:choose>
172           <xsl:when test="$hasdescendant != 0">
173             <xsl:text>/current/open</xsl:text>
174           </xsl:when>
175           <xsl:otherwise>
176             <xsl:text>/current/leaf</xsl:text>
177           </xsl:otherwise>
178         </xsl:choose>
179       </xsl:when>
180       <xsl:otherwise>
181         <xsl:choose>
182           <xsl:when test="$hasdescendant = 0">
183             <xsl:text>/other/leaf</xsl:text>
184           </xsl:when>
185           <xsl:when test="$is.open != 0">
186             <xsl:text>/other/open</xsl:text>
187           </xsl:when>
188           <xsl:otherwise>
189             <xsl:text>/other/closed</xsl:text>
190           </xsl:otherwise>
191         </xsl:choose>
192       </xsl:otherwise>
193     </xsl:choose>
194     <xsl:value-of select="$nav.icon.extension"/>
195   </xsl:variable>
196
197   <xsl:variable name="preceding-text">
198     <xsl:choose>
199       <xsl:when test="$pageid=@id">
200         <xsl:choose>
201           <xsl:when test="$hasdescendant != 0">
202             <xsl:value-of select="$nav.text.current.open"/>
203           </xsl:when>
204           <xsl:otherwise>
205             <xsl:value-of select="$nav.text.current.page"/>
206           </xsl:otherwise>
207         </xsl:choose>
208       </xsl:when>
209       <xsl:otherwise>
210         <xsl:choose>
211           <xsl:when test="$isancestor != 0">
212             <xsl:value-of select="$nav.text.other.open"/>
213           </xsl:when>
214           <xsl:when test="$hasdescendant != 0">
215             <xsl:value-of select="$nav.text.other.closed"/>
216           </xsl:when>
217           <xsl:otherwise>
218             <xsl:value-of select="$nav.text.other.page"/>
219           </xsl:otherwise>
220         </xsl:choose>
221       </xsl:otherwise>
222     </xsl:choose>
223   </xsl:variable>
224
225   <xsl:variable name="following-icon">
226     <xsl:value-of select="$relpath"/>
227     <xsl:value-of select="$nav.icon.path"/>
228     <xsl:value-of select="$nav.icon.style"/>
229     <xsl:text>/current/pointer</xsl:text>
230     <xsl:value-of select="$nav.icon.extension"/>
231   </xsl:variable>
232
233   <xsl:variable name="following-text">
234     <xsl:value-of select="$nav.text.pointer"/>
235   </xsl:variable>
236
237   <xsl:variable name="revisionflag-icon">
238     <xsl:value-of select="$relpath"/>
239     <xsl:value-of select="$nav.icon.path"/>
240     <xsl:value-of select="$nav.icon.style"/>
241     <xsl:text>/</xsl:text>
242     <xsl:value-of select="$revisionflag"/>
243     <xsl:value-of select="$nav.icon.extension"/>
244   </xsl:variable>
245
246   <xsl:variable name="revisionflag-text">
247     <xsl:choose>
248       <xsl:when test="$revisionflag = 'changed'">
249         <xsl:value-of select="$nav.text.revisionflag.changed"/>
250       </xsl:when>
251       <xsl:when test="$revisionflag = 'added'">
252         <xsl:value-of select="$nav.text.revisionflag.added"/>
253       </xsl:when>
254       <xsl:when test="$revisionflag = 'deleted'">
255         <xsl:value-of select="$nav.text.revisionflag.deleted"/>
256       </xsl:when>
257       <xsl:otherwise>
258         <xsl:value-of select="$nav.text.revisionflag.off"/>
259       </xsl:otherwise>
260     </xsl:choose>
261   </xsl:variable>
262
263   <span>
264     <xsl:if test="$toclevel = 2">
265       <xsl:attribute name="class">
266         <xsl:text>toplevel</xsl:text>
267       </xsl:attribute>
268     </xsl:if>
269
270     <xsl:if test="$toclevel &gt; 2">
271       <xsl:attribute name="class">
272         <xsl:text>shrink</xsl:text>
273         <xsl:value-of select="$toclevel - 2"/>
274       </xsl:attribute>
275     </xsl:if>
276
277     <xsl:call-template name="insert.spacers">
278       <xsl:with-param name="count" select="$toclevel - 1"/>
279       <xsl:with-param name="relpath" select="$relpath"/>
280     </xsl:call-template>
281
282     <xsl:choose>
283       <xsl:when test="$nav.graphics != 0">
284         <xsl:call-template name="link.to.page">
285           <xsl:with-param name="href" select="@href"/>
286           <xsl:with-param name="page" select="$target"/>
287           <xsl:with-param name="relpath" select="$relpath"/>
288           <xsl:with-param name="linktext">
289             <img src="{$preceding-icon}" alt="{$preceding-text}" border="0"/>
290           </xsl:with-param>
291         </xsl:call-template>
292       </xsl:when>
293       <xsl:otherwise>
294         <xsl:value-of select="$preceding-text"/>
295       </xsl:otherwise>
296     </xsl:choose>
297
298     <xsl:choose>
299       <xsl:when test="$pageid = @id">
300         <span class="curpage">
301           <xsl:choose>
302             <xsl:when test="titleabbrev">
303               <xsl:apply-templates select="titleabbrev"/>
304             </xsl:when>
305             <xsl:otherwise>
306               <xsl:apply-templates select="title"/>
307             </xsl:otherwise>
308           </xsl:choose>
309
310           <xsl:if test="$nav.revisionflag != '0' and $revisionflag">
311             <xsl:value-of select="$nav.text.spacer"/>
312             <xsl:choose>
313               <xsl:when test="$nav.graphics = '1'">
314                 <img src="{$revisionflag-icon}" alt="{$revisionflag-text}" align="bottom"/>
315               </xsl:when>
316               <xsl:otherwise>
317                 <xsl:text>(</xsl:text>
318                 <xsl:value-of select="$revisionflag-text"/>
319                 <xsl:text>)</xsl:text>
320               </xsl:otherwise>
321             </xsl:choose>
322           </xsl:if>
323
324           <xsl:if test="$nav.pointer != '0'">
325             <xsl:value-of select="$nav.text.spacer"/>
326             <xsl:choose>
327               <xsl:when test="$nav.graphics = '1'">
328                 <img src="{$following-icon}" alt="{$following-text}"/>
329               </xsl:when>
330               <xsl:otherwise>
331                 <xsl:value-of select="$following-text"/>
332               </xsl:otherwise>
333             </xsl:choose>
334           </xsl:if>
335         </span>
336         <br/>
337       </xsl:when>
338       <xsl:otherwise>
339         <span>
340           <xsl:choose>
341             <xsl:when test="$isdescendant='0'">
342               <xsl:choose>
343                 <xsl:when test="$isancestor='1'">
344                   <xsl:attribute name="class">ancestor</xsl:attribute>
345                 </xsl:when>
346                 <xsl:otherwise>
347                   <xsl:attribute name="class">otherpage</xsl:attribute>
348                 </xsl:otherwise>
349               </xsl:choose>
350             </xsl:when>
351             <xsl:otherwise>
352               <!-- IS a descendant of curpage -->
353               <xsl:attribute name="class">descendant</xsl:attribute>
354             </xsl:otherwise>
355           </xsl:choose>
356
357           <xsl:call-template name="link.to.page">
358             <xsl:with-param name="href" select="@href"/>
359             <xsl:with-param name="page" select="$target"/>
360             <xsl:with-param name="relpath" select="$relpath"/>
361             <xsl:with-param name="linktext">
362               <xsl:choose>
363                 <xsl:when test="titleabbrev">
364                   <xsl:apply-templates select="titleabbrev"/>
365                 </xsl:when>
366                 <xsl:otherwise>
367                   <xsl:apply-templates select="title"/>
368                 </xsl:otherwise>
369               </xsl:choose>
370             </xsl:with-param>
371           </xsl:call-template>
372
373           <xsl:if test="$nav.revisionflag != '0' and $revisionflag">
374             <xsl:value-of select="$nav.text.spacer"/>
375             <xsl:choose>
376               <xsl:when test="$nav.graphics = '1'">
377                 <img src="{$revisionflag-icon}" alt="{$revisionflag-text}"/>
378               </xsl:when>
379               <xsl:otherwise>
380                 <xsl:text>(</xsl:text>
381                 <xsl:value-of select="$revisionflag-text"/>
382                 <xsl:text>)</xsl:text>
383               </xsl:otherwise>
384             </xsl:choose>
385           </xsl:if>
386
387         </span>
388         <br/>
389       </xsl:otherwise>
390     </xsl:choose>
391   </span>
392
393   <xsl:if test="$is.open != 0">
394     <xsl:apply-templates select="tocentry">
395       <xsl:with-param name="pageid" select="$pageid"/>
396       <xsl:with-param name="relpath" select="$relpath"/>
397     </xsl:apply-templates>
398   </xsl:if>
399 </xsl:template>
400
401 <xsl:template name="insert.spacers">
402   <xsl:param name="count" select="0"/>
403   <xsl:param name="relpath"/>
404   <xsl:if test="$count>0">
405     <xsl:choose>
406       <xsl:when test="$nav.graphics != 0">
407         <img src="{$relpath}{$toc.spacer.image}" alt="{$toc.spacer.text}"/>
408       </xsl:when>
409       <xsl:otherwise>
410         <xsl:value-of select="$toc.spacer.text"/>
411       </xsl:otherwise>
412     </xsl:choose>
413     <xsl:call-template name="insert.spacers">
414       <xsl:with-param name="count" select="$count - 1"/>
415       <xsl:with-param name="relpath" select="$relpath"/>
416     </xsl:call-template>
417   </xsl:if>
418 </xsl:template>
419
420 <xsl:template match="toc|tocentry|notoc" mode="toc-rel-path">
421   <xsl:call-template name="toc-rel-path"/>
422 </xsl:template>
423
424 <xsl:template name="toc-rel-path">
425   <xsl:param name="pageid" select="@id"/>
426   <xsl:variable name="entry" select="$autolayout//*[@id=$pageid]"/>
427   <xsl:variable name="filename" select="concat($entry/@dir,$entry/@filename)"/>
428
429   <xsl:variable name="slash-count">
430     <xsl:call-template name="toc-directory-depth">
431       <xsl:with-param name="filename" select="$filename"/>
432     </xsl:call-template>
433   </xsl:variable>
434
435   <xsl:variable name="depth">
436     <xsl:choose>
437       <xsl:when test="starts-with($filename, '/')">
438         <xsl:value-of select="$slash-count - 1"/>
439       </xsl:when>
440       <xsl:otherwise>
441         <xsl:value-of select="$slash-count"/>
442       </xsl:otherwise>
443     </xsl:choose>
444   </xsl:variable>
445
446 <!--
447   <xsl:message>
448     <xsl:value-of select="$filename"/>
449     <xsl:text> depth=</xsl:text>
450     <xsl:value-of select="$depth"/>
451   </xsl:message>
452 -->
453
454   <xsl:if test="$depth > 0">
455     <xsl:call-template name="copy-string">
456       <xsl:with-param name="string">../</xsl:with-param>
457       <xsl:with-param name="count" select="$depth"/>
458     </xsl:call-template>
459   </xsl:if>
460 </xsl:template>
461
462 <xsl:template name="toc-directory-depth">
463   <xsl:param name="filename"></xsl:param>
464   <xsl:param name="count" select="0"/>
465
466   <xsl:choose>
467     <xsl:when test='contains($filename,"/")'>
468       <xsl:call-template name="toc-directory-depth">
469         <xsl:with-param name="filename"
470                         select="substring-after($filename,'/')"/>
471         <xsl:with-param name="count" select="$count + 1"/>
472       </xsl:call-template>
473     </xsl:when>
474     <xsl:otherwise>
475       <xsl:value-of select="$count"/>
476     </xsl:otherwise>
477   </xsl:choose>
478 </xsl:template>
479
480 </xsl:stylesheet>