]> git.stg.codes - stg.git/blob - doc/xslt/website/toc.xsl
Don't build projects in debug mode.
[stg.git] / doc / xslt / website / toc.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="max.toc.width" select="7"/>
8
9 <xsl:template match="toc/title|tocentry/title|titleabbrev">
10   <xsl:apply-templates/>
11 </xsl:template>
12
13 <xsl:template match="toc">
14   <xsl:param name="pageid" select="@id"/>
15
16   <xsl:variable name="relpath">
17     <xsl:call-template name="toc-rel-path">
18       <xsl:with-param name="pageid" select="$pageid"/>
19     </xsl:call-template>
20   </xsl:variable>
21
22   <xsl:variable name="homebanner"
23                 select="/autolayout/config[@param='homebanner'][1]"/>
24
25   <xsl:variable name="banner"
26                 select="/autolayout/config[@param='banner'][1]"/>
27
28   <xsl:variable name="homebannertext"
29                 select="/autolayout/config[@param='homebannertext'][1]"/>
30
31   <xsl:variable name="bannertext"
32                 select="/autolayout/config[@param='bannertext'][1]"/>
33
34   <xsl:choose>
35     <xsl:when test="$pageid = @id">
36       <xsl:choose>
37         <xsl:when test="$homebanner">
38           <img border="0">
39             <xsl:attribute name="src">
40               <xsl:value-of select="$relpath"/>
41               <xsl:value-of select="$homebanner/@value"/>
42             </xsl:attribute>
43             <xsl:attribute name="alt">
44               <xsl:value-of select="$homebanner/@altval"/>
45             </xsl:attribute>
46           </img>
47           <xsl:value-of select="$currentpage.marker"/>
48         </xsl:when>
49         <xsl:when test="$homebannertext">
50           <xsl:value-of select="$homebannertext/@value"/>
51           <xsl:value-of select="$currentpage.marker"/>
52         </xsl:when>
53         <xsl:otherwise>
54           <xsl:call-template name="gentext.nav.home"/>
55           <xsl:value-of select="$currentpage.marker"/>
56         </xsl:otherwise>
57       </xsl:choose>
58     </xsl:when>
59     <xsl:otherwise>
60       <a href="{$relpath}{@dir}{$filename-prefix}{@filename}">
61         <xsl:choose>
62           <xsl:when test="$banner">
63             <img border="0">
64               <xsl:attribute name="src">
65                 <xsl:value-of select="$relpath"/>
66                 <xsl:value-of select="$banner/@value"/>
67               </xsl:attribute>
68               <xsl:attribute name="alt">
69                 <xsl:value-of select="$banner/@altval"/>
70               </xsl:attribute>
71             </img>
72           </xsl:when>
73           <xsl:when test="$bannertext">
74             <xsl:value-of select="$bannertext/@value"/>
75           </xsl:when>
76           <xsl:otherwise>
77             <xsl:call-template name="gentext.nav.home"/>
78           </xsl:otherwise>
79         </xsl:choose>
80       </a>
81     </xsl:otherwise>
82   </xsl:choose>
83
84   <xsl:text> | </xsl:text>
85
86   <xsl:call-template name="process-children">
87     <xsl:with-param name="pageid" select="$pageid"/>
88     <xsl:with-param name="relpath" select="$relpath"/>
89   </xsl:call-template>
90 </xsl:template>
91
92 <xsl:template match="tocentry">
93   <xsl:param name="pageid" select="@id"/>
94   <xsl:param name="relpath" select="''"/>
95
96   <xsl:if test="preceding-sibling::tocentry">
97     <xsl:text> | </xsl:text>
98   </xsl:if>
99
100   <xsl:choose>
101     <xsl:when test="$pageid = @id">
102       <xsl:choose>
103         <xsl:when test="titleabbrev">
104           <xsl:apply-templates select="titleabbrev"/>
105         </xsl:when>
106         <xsl:otherwise>
107           <xsl:apply-templates select="title"/>
108         </xsl:otherwise>
109       </xsl:choose>
110       <xsl:value-of select="$currentpage.marker"/>
111     </xsl:when>
112     <xsl:otherwise>
113       <a>
114         <xsl:attribute name="href">
115           <xsl:choose>
116             <xsl:when test="@href">
117               <xsl:value-of select="@href"/>
118             </xsl:when>
119             <xsl:otherwise>
120               <xsl:value-of select="$relpath"/>
121               <xsl:value-of select="@dir"/>
122               <xsl:value-of select="$filename-prefix"/>
123               <xsl:value-of select="@filename"/>
124             </xsl:otherwise>
125           </xsl:choose>
126         </xsl:attribute>
127         <xsl:choose>
128           <xsl:when test="titleabbrev">
129             <xsl:apply-templates select="titleabbrev"/>
130           </xsl:when>
131           <xsl:otherwise>
132             <xsl:apply-templates select="title"/>
133           </xsl:otherwise>
134         </xsl:choose>
135       </a>
136     </xsl:otherwise>
137   </xsl:choose>
138 </xsl:template>
139
140 <xsl:template match="toc|tocentry|notoc" mode="toc-rel-path">
141   <xsl:call-template name="toc-rel-path"/>
142 </xsl:template>
143
144 <xsl:template name="toc-rel-path">
145   <xsl:param name="pageid" select="@id"/>
146   <xsl:variable name="entry" select="$autolayout//*[@id=$pageid]"/>
147   <xsl:variable name="filename" select="concat($entry/@dir,$entry/@filename)"/>
148
149   <xsl:variable name="depth">
150     <xsl:call-template name="toc-directory-depth">
151       <xsl:with-param name="filename" select="$filename"/>
152     </xsl:call-template>
153   </xsl:variable>
154
155   <xsl:if test="$depth > 0">
156     <xsl:call-template name="copy-string">
157       <xsl:with-param name="string">../</xsl:with-param>
158       <xsl:with-param name="count" select="$depth"/>
159     </xsl:call-template>
160   </xsl:if>
161 </xsl:template>
162
163 <xsl:template name="toc-directory-depth">
164   <xsl:param name="filename"></xsl:param>
165   <xsl:param name="count" select="0"/>
166
167   <xsl:choose>
168     <xsl:when test='contains($filename,"/")'>
169       <xsl:call-template name="toc-directory-depth">
170         <xsl:with-param name="filename"
171                         select="substring-after($filename,'/')"/>
172         <xsl:with-param name="count" select="$count + 1"/>
173       </xsl:call-template>
174     </xsl:when>
175     <xsl:otherwise>
176       <xsl:value-of select="$count"/>
177     </xsl:otherwise>
178   </xsl:choose>
179 </xsl:template>
180
181 <xsl:template name="process-children">
182   <xsl:param name="pageid" select="@id"/>
183   <xsl:param name="relpath" select="''"/>
184
185   <xsl:choose>
186     <xsl:when test="tocentry[descendant-or-self::*[@id=$pageid]]">
187       <xsl:call-template name="process-tocentry-children">
188         <xsl:with-param name="pageid" select="$pageid"/>
189         <xsl:with-param name="relpath" select="$relpath"/>
190       </xsl:call-template>
191     </xsl:when>
192     <xsl:otherwise>
193       <xsl:call-template name="process-toc-children">
194         <xsl:with-param name="pageid" select="$pageid"/>
195         <xsl:with-param name="relpath" select="$relpath"/>
196       </xsl:call-template>
197     </xsl:otherwise>
198   </xsl:choose>
199 </xsl:template>
200
201 <xsl:template name="process-tocentry-children">
202   <xsl:param name="pageid" select="@id"/>
203   <xsl:param name="relpath" select="''"/>
204
205   <xsl:choose>
206     <xsl:when test="count(tocentry) &gt; $max.toc.width">
207       <xsl:variable name="cur"
208                     select="tocentry[descendant-or-self::*[@id=$pageid]]"/>
209
210       <xsl:variable name="half" select="$max.toc.width div 2"/>
211
212       <xsl:variable name="all-nodes"
213                     select="$cur/preceding-sibling::tocentry[position() &lt; $half]
214                             | $cur
215                             | $cur/following-sibling::tocentry"/>
216
217       <xsl:variable name="nodes"
218                     select="$all-nodes[position() &lt; $max.toc.width]"/>
219
220       <xsl:if test="count($cur/preceding-sibling::tocentry) &gt; $half">
221         <xsl:text>...</xsl:text>
222       </xsl:if>
223       <xsl:apply-templates select="$nodes">
224         <xsl:with-param name="pageid" select="$pageid"/>
225         <xsl:with-param name="relpath" select="$relpath"/>
226       </xsl:apply-templates>
227       <xsl:if test="count($all-nodes) &gt; $max.toc.width">
228         <xsl:text> | ...</xsl:text>
229       </xsl:if>
230     </xsl:when>
231     <xsl:otherwise>
232       <xsl:apply-templates select="tocentry">
233         <xsl:with-param name="pageid" select="$pageid"/>
234         <xsl:with-param name="relpath" select="$relpath"/>
235       </xsl:apply-templates>
236     </xsl:otherwise>
237   </xsl:choose>
238
239   <br/>
240
241   <!-- if the current page isn't in this list, keep digging... -->
242   <xsl:if test="not(tocentry[$pageid=@id])">
243     <xsl:for-each select="tocentry">
244       <xsl:if test="descendant::*[@id=$pageid]">
245         <xsl:call-template name="process-children">
246           <xsl:with-param name="pageid" select="$pageid"/>
247           <xsl:with-param name="relpath" select="$relpath"/>
248         </xsl:call-template>
249       </xsl:if>
250     </xsl:for-each>
251   </xsl:if>
252 </xsl:template>
253
254 <xsl:template name="process-toc-children">
255   <xsl:param name="pageid" select="@id"/>
256   <xsl:param name="relpath" select="''"/>
257
258   <xsl:choose>
259     <xsl:when test="count(tocentry) &gt; $max.toc.width">
260       <xsl:variable name="half" select="$max.toc.width div 2"/>
261
262       <xsl:variable name="all-nodes" select="tocentry"/>
263       <xsl:variable name="nodes"
264                     select="$all-nodes[position() &lt; $max.toc.width]"/>
265
266       <xsl:apply-templates select="$nodes">
267         <xsl:with-param name="pageid" select="$pageid"/>
268         <xsl:with-param name="relpath" select="$relpath"/>
269       </xsl:apply-templates>
270
271       <xsl:if test="count($all-nodes) &gt; $max.toc.width">
272         <xsl:text> | ...</xsl:text>
273       </xsl:if>
274     </xsl:when>
275     <xsl:otherwise>
276       <xsl:apply-templates select="tocentry">
277         <xsl:with-param name="pageid" select="$pageid"/>
278         <xsl:with-param name="relpath" select="$relpath"/>
279       </xsl:apply-templates>
280     </xsl:otherwise>
281   </xsl:choose>
282
283   <br/>
284 </xsl:template>
285
286 </xsl:stylesheet>