1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:str="http://exslt.org/strings"
xmlns:exslt="http://exslt.org/common"
extension-element-prefixes="str exslt xsl"
exclude-result-prefixes="str exslt xsl"
xmlns="http://www.w3.org/1999/xhtml">
<xsl:import href="xsl/str.tokenize.function.xsl"/>
<xsl:import href="xsl/lang.highlight.c.xsl"/>
<xsl:import href="xsl/lang.highlight.ebuild.xsl"/>
<xsl:import href="xsl/lang.highlight.make.xsl"/>
<xsl:import href="xsl/lang.highlight.m4.xsl"/>
<xsl:import href="xsl/lang.highlight.sgml.xsl"/>
<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" indent="yes"/>
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="chapter">
<h1><xsl:apply-templates select="title"/></h1>
<xsl:apply-templates select="(body|section)"/>
</xsl:template>
<xsl:template match="section">
<div class="section">
<xsl:variable name="anchor">
<xsl:call-template name="convert-to-anchor">
<xsl:with-param name="data" select="title"/>
</xsl:call-template>
</xsl:variable>
<h2><a name="{$anchor}"><xsl:apply-templates select="title"/></a></h2>
<xsl:apply-templates select="(body|subsection)"/>
</div>
</xsl:template>
<xsl:template match="subsection">
<div class="section">
<xsl:variable name="anchor">
<xsl:call-template name="convert-to-anchor">
<xsl:with-param name="data" select="title"/>
</xsl:call-template>
</xsl:variable>
<h3><a name="{$anchor}"><xsl:apply-templates select="title"/></a></h3>
<xsl:apply-templates select="(body|subsubsection)"/>
<!-- If you need, change here to add more nesting levels -->
</div>
</xsl:template>
<xsl:template match="subsubsection">
<div class="section">
<xsl:variable name="anchor">
<xsl:call-template name="convert-to-anchor">
<xsl:with-param name="data" select="title"/>
</xsl:call-template>
</xsl:variable>
<h4><a name="{$anchor}"><xsl:apply-templates select="title"/></a></h4>
<xsl:apply-templates select="(body)"/>
<!-- If you need, change here to add more nesting levels -->
</div>
</xsl:template>
<xsl:template match="body">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p">
<p>
<xsl:apply-templates/>
</p>
</xsl:template>
<xsl:template match="pre">
<pre><xsl:apply-templates/></pre>
</xsl:template>
<!-- Tables -->
<!-- From the Gentoo GuideXML Stylesheet -->
<xsl:template match="table">
<table><xsl:apply-templates/></table>
</xsl:template>
<xsl:template match="tr">
<tr><xsl:apply-templates/></tr>
</xsl:template>
<xsl:template match="tcolumn">
<col width="{@width}"/>
</xsl:template>
<!-- Table Item -->
<xsl:template match="ti">
<td class="devbook">
<xsl:if test="@colspan">
<xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute>
</xsl:if>
<xsl:if test="@rowspan">
<xsl:attribute name="rowspan"><xsl:value-of select="@rowspan"/></xsl:attribute>
</xsl:if>
<xsl:apply-templates/>
</td>
</xsl:template>
<!-- Table Heading -->
<xsl:template match="th">
<td class="devbook">
<xsl:if test="@colspan">
<xsl:attribute name="colspan"><xsl:value-of select="@colspan"/></xsl:attribute>
<!-- Center only when item spans several columns as
centering all <th> might disrupt some pages.
We might want to use a plain html <th> tag later.
Tip: to center a single-cell title, use <th colspan="1">
-->
<xsl:attribute name="style">text-align:center</xsl:attribute>
</xsl:if>
<xsl:if test="@rowspan">
<xsl:attribute name="rowspan"><xsl:value-of select="@rowspan"/></xsl:attribute>
</xsl:if>
<b>
<xsl:apply-templates/>
</b>
</td>
</xsl:template>
<!-- End Table Jojo -->
<!-- FIXME: Handle lang=... -->
<xsl:template match="codesample">
<xsl:variable name="ctype"><xsl:if test="@lang = 'ebuild'">Constant</xsl:if></xsl:variable>
<xsl:variable name="numbering" select="@numbering"/>
<xsl:variable name="lang" select="@lang"/>
<pre><span class="{$ctype}">
<xsl:for-each select="str:tokenize_plasmaroo(., $newline)">
<xsl:choose>
<xsl:when test=". = $newline">
<xsl:if test="position() != 1"><xsl:value-of select='$newline'/></xsl:if>
<xsl:if test="$numbering = 'lines' and position() != last()-1">
<span style="float: left;"><xsl:number format="01"/>:<xsl:text> </xsl:text></span>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$lang = 'ebuild'">
<xsl:call-template name="lang.highlight.ebuild.tokenate">
<xsl:with-param name="data" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lang = 'make'">
<xsl:call-template name="lang.highlight.make.tokenate">
<xsl:with-param name="data" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lang = 'm4'">
<xsl:call-template name="lang.highlight.m4.tokenate">
<xsl:with-param name="data" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lang = 'sgml'">
<xsl:call-template name="lang.highlight.sgml.tokenate">
<xsl:with-param name="data" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lang = 'c'">
<xsl:call-template name="lang.highlight.c.tokenate">
<xsl:with-param name="data" select="."/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:message>Error: Unknown language type (<xsl:value-of select="$lang"/>)</xsl:message>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</span></pre>
</xsl:template>
<xsl:template match="figure">
<div class="figure">
<div class="image"><img alt="{@short}" src="{@link}"/></div>
<p class="caption"><xsl:value-of select="."/></p>
</div>
</xsl:template>
<!-- Lists -->
<xsl:template match="li">
<li><xsl:apply-templates/></li>
</xsl:template>
<xsl:template match="ol">
<ol><xsl:apply-templates/></ol>
</xsl:template>
<xsl:template match="ul">
<ul><xsl:apply-templates/></ul>
</xsl:template>
<!-- Definition Lists -->
<xsl:template match="dl">
<dl><xsl:apply-templates/></dl>
</xsl:template>
<xsl:template match="dt">
<dt><xsl:apply-templates/></dt>
</xsl:template>
<xsl:template match="dd">
<dd>
<xsl:for-each select="p">
<xsl:choose>
<xsl:when test="count(../p) = 1"><xsl:apply-templates/></xsl:when>
<xsl:when test="position() = 1"><p class="first"><xsl:apply-templates/></p></xsl:when>
<xsl:when test="position() = last()"><p class="last"><xsl:apply-templates/></p></xsl:when>
<xsl:otherwise><p><xsl:apply-templates/></p></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</dd>
</xsl:template>
<xsl:template match="important">
<div class="important">
<p class="first admonition-title">Important</p>
<p class="last"><xsl:apply-templates/></p>
</div>
</xsl:template>
<xsl:template match="note">
<div class="note">
<p class="first admonition-title">Note</p>
<p class="last"><xsl:apply-templates/></p>
</div>
</xsl:template>
<xsl:template match="todo">
<div class="todo">
<p class="first admonition-title">Todo</p>
<p class="last"><xsl:apply-templates/></p>
</div>
</xsl:template>
<xsl:template match="warning">
<div class="warning">
<p class="first admonition-title">Warning</p>
<p class="last"><xsl:apply-templates/></p>
</div>
</xsl:template>
<xsl:template match="b">
<b><xsl:apply-templates/></b>
</xsl:template>
<xsl:template match="d">
—
</xsl:template>
<xsl:template match="e">
<i><xsl:apply-templates/></i>
</xsl:template>
<xsl:template match="c">
<code class="docutils literal"><span class="pre"><xsl:apply-templates/></span></code>
</xsl:template>
<xsl:template name="convert-to-anchor">
<xsl:param name="data"/>
<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz--</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ<xsl:text> </xsl:text>,</xsl:variable>
<xsl:value-of select="translate($data,$ucletters,$lcletters)"/>
</xsl:template>
<xsl:template match="uri">
<xsl:choose>
<xsl:when test="starts-with(@link, '::')">
<!-- Ideally we would work out how many levels to nest down to save a few bytes but
going down to root level works just as well (and is faster). -->
<xsl:variable name="relative_path_depth" select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , ''))"/>
<xsl:variable name="relative_path_depth_recursion">
<xsl:call-template name="str:repeatString">
<xsl:with-param name="count" select="$relative_path_depth"/>
<xsl:with-param name="append">../</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains(@link, '##')">
<a href="{concat($relative_path_depth_recursion, substring-after(substring-before(@link, '##'), '::'), '/index.html#', substring-after(@link, '##'))}"><xsl:value-of select="."/></a>
</xsl:when>
<xsl:when test="contains(@link, '#')">
<xsl:variable name="anchor">
<xsl:call-template name="convert-to-anchor">
<xsl:with-param name="data" select="substring-after(@link, '#')"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="slash">
<xsl:if test="substring(substring-before(@link, '#'), string-length(substring-before(@link, '#'))) != '/'">/</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test=". != ''">
<a href="{concat($relative_path_depth_recursion, substring-after(substring-before(@link, '#'), '::'), $slash, 'index.html#', $anchor)}"><xsl:value-of select="."/></a>
</xsl:when>
<xsl:otherwise>
<a href="{concat($relative_path_depth_recursion, substring-after(substring-before(@link, '#'), '::'), $slash, 'index.html#', $anchor)}"><xsl:value-of select="substring-after(@link, '#')"/></a>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="slash">
<xsl:if test="substring(@link, string-length(@link)) != '/'">/</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test=". != ''">
<a href="{concat($relative_path_depth_recursion, substring-after(@link, '::'), $slash, 'index.html')}"><xsl:value-of select="."/></a>
</xsl:when>
<xsl:otherwise>
<a href="{concat($relative_path_depth_recursion, substring-after(@link, '::'), $slash, 'index.html')}"><xsl:value-of select="document(concat(/guide/@self, $relative_path_depth_recursion, substring-after(@link, '::'), '/text.xml'))/guide/chapter[1]/title"/></a>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<a href="{@link}"><xsl:value-of select="."/></a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- TOC Tree -->
<xsl:template match="contentsTree" name="contentsTree">
<xsl:param name="depth" select="0"/>
<xsl:param name="maxdepth">
<xsl:choose>
<xsl:when test="@maxdepth"><xsl:value-of select="@maxdepth"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="path">
<xsl:choose>
<xsl:when test="@root"><xsl:value-of select="@root"/></xsl:when>
<xsl:otherwise><xsl:value-of select="/guide/@self"/></xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="path_rel">
<xsl:if test="$depth = 0 and $path = '' and /guide/@self != ''">
<xsl:call-template name="str:repeatString">
<xsl:with-param name="count" select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , ''))"/>
<xsl:with-param name="append">../</xsl:with-param>
</xsl:call-template>
</xsl:if>
</xsl:param>
<xsl:param name="extraction" select="@extraction"/>
<xsl:param name="extraction_counting"/>
<xsl:variable name="doc_self" select="concat($path, 'text.xml')"/>
<xsl:if test="count(document($doc_self)/guide/include) > 0 and ($depth < $maxdepth or $maxdepth = '0')">
<xsl:choose>
<xsl:when test="$extraction_counting = 1">
<xsl:for-each select="document($doc_self)/guide/include">
<count value="{count(document(concat($path, @href, 'text.xml'))//*[name()=$extraction])}" path="{concat($path, @href)}">
<xsl:call-template name="contentsTree">
<xsl:with-param name="depth" select="$depth + 1"/>
<xsl:with-param name="maxdepth" select="$maxdepth"/>
<xsl:with-param name="path" select="concat($path, @href)"/>
<xsl:with-param name="path_rel" select="concat($path_rel, @href)"/>
<xsl:with-param name="extraction" select="$extraction"/>
<xsl:with-param name="extraction_counting" select="1"/>
</xsl:call-template>
</count>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<ul>
<xsl:for-each select="document($doc_self)/guide/include">
<xsl:variable name="extraction_counter_node">
<xsl:call-template name="contentsTree">
<xsl:with-param name="depth" select="$depth + 1"/>
<xsl:with-param name="maxdepth" select="$maxdepth"/>
<xsl:with-param name="path" select="concat($path, @href)"/>
<xsl:with-param name="path_rel" select="concat($path_rel, @href)"/>
<xsl:with-param name="extraction" select="$extraction"/>
<xsl:with-param name="extraction_counting" select="1"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="extraction_counter" select="count(exslt:node-set($extraction_counter_node)//*[@value != 0]) + count(document(concat($path, @href, 'text.xml'))//*[name()=$extraction])"/>
<xsl:if test="string($extraction) = '' or $extraction_counter > 0">
<li>
<a class="reference" href="{concat($path_rel, @href, 'index.html')}"><xsl:value-of select="document(concat($path, @href, 'text.xml'))/guide/chapter[1]/title"/></a>
<xsl:if test="$extraction != ''">
<ul>
<xsl:for-each select="document(concat($path, @href, 'text.xml'))//*[name()=$extraction]">
<xsl:variable name="extraction_id" select="position()"/>
<li><xsl:apply-templates select="(//*[name()=$extraction])[position()=$extraction_id]"/><br/></li>
</xsl:for-each>
</ul>
</xsl:if>
<xsl:call-template name="contentsTree">
<xsl:with-param name="depth" select="$depth + 1"/>
<xsl:with-param name="maxdepth" select="$maxdepth"/>
<xsl:with-param name="path" select="concat($path, @href)"/>
<xsl:with-param name="path_rel" select="concat($path_rel, @href)"/>
<xsl:with-param name="extraction" select="$extraction"/>
</xsl:call-template>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
<xsl:template match="/">
<html lang="en-GB" xml:lang="en-GB" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Gentoo Development Guide: <xsl:value-of select="/guide/chapter[1]/title"/></title>
<xsl:variable name="relative_path_depth" select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , ''))"/>
<xsl:variable name="relative_path_depth_recursion">
<xsl:call-template name="str:repeatString">
<xsl:with-param name="count" select="$relative_path_depth"/>
<xsl:with-param name="append">../</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<link rel="stylesheet" href="{$relative_path_depth_recursion}devmanual.css" type="text/css" />
</head>
<body>
<div class="main">
<h1>Gentoo Development Guide</h1>
<div class="navtop" style="text-align: center;">
<table style="border-top: 1px dashed #330066; margin-left: auto; margin-right: auto;
width: 100%;">
<col width="33%" />
<col width="34%" />
<col width="33%" />
<tr>
<td style="text-align: center; border-right: 1px dashed #330066;">← <xsl:call-template name="findPrevious"/></td>
<td style="text-align: center;">↑ <xsl:call-template name="findParent"/> ↑</td>
<td style="text-align: center; border-left: 1px dashed #330066;"><xsl:call-template name="findNext"/> →</td>
</tr>
</table>
</div>
<div class="document">
<xsl:apply-templates/>
</div>
<div class="navbottom" style="text-align: center;">
<table style="border-top: 1px dashed #330066; margin-left: auto; margin-right: auto;
width: 100%;">
<col width="33%" />
<col width="34%" />
<col width="33%" />
<tr>
<td style="text-align: center; border-right: 1px dashed #330066;">← <xsl:call-template name="findPrevious"/></td>
<td style="text-align: center;">↑ <xsl:call-template name="findParent"/> ↑</td>
<td style="text-align: center; border-left: 1px dashed #330066;"><xsl:call-template name="findNext"/> →</td>
</tr>
</table>
</div>
</div>
<div class="footer">
<p>
<a href="http://validator.w3.org/check/referer"><img src="/icons/icon_mini-xhtml.png" alt="Valid XHTML 1.0" /></a>
<a href="http://jigsaw.w3.org/css-validator/check/referer"><img src="/icons/icon_mini-css.png" alt="Valid CSS" /></a>
<a href="http://www.gentoo.org/"><img src="/icons/icon_mini-gentoo.png" alt="Powered by Gentoo" /></a>
<a href="http://creativecommons.org/licenses/by-sa/2.0/"><img src="/icons/icon_mini-creativecommons.png" alt="Creative Commons License" /></a>
<img src="/icons/icon_mini-xml.png" alt="XML Powered!"/>
<br />
<br />
The text of this document is distributed under the <a href="http://creativecommons.org/licenses/by-sa/2.0/">Creative Commons Attribution-ShareAlike 2.0 License</a>.
</p>
</div>
</body>
</html>
</xsl:template>
<xsl:template name="str:repeatString">
<xsl:param name="string"/>
<xsl:param name="count"/>
<xsl:param name="append"/>
<xsl:choose>
<xsl:when test="$count != 0">
<xsl:call-template name="str:repeatString">
<xsl:with-param name="string" select="concat($string, $append)"/>
<xsl:with-param name="count" select="$count - 1"/>
<xsl:with-param name="append" select="$append"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="findNext">
<xsl:param name="self" select="/guide/@self"/>
<xsl:choose>
<!-- To find the "next" node:
* See if this node includes any subnodes... if it does, that is
our next node
* Look at our parent and see if it includes any nodes after us, if
it does use it.
* Repeat recursively, going down parents if needed.
* End at the root item if needed.
-->
<xsl:when test="count(/guide/include) > 0">
<xsl:variable name="doc" select="/guide/include[1]/@href"/>
<a href="{concat($doc, 'index.html')}"><xsl:value-of select="document(concat(/guide/@self, $doc, 'text.xml'))/guide/chapter[1]/title"/></a>
</xsl:when>
<xsl:otherwise>
<!-- This document's path -->
<xsl:variable name="doc_self" select="concat($self, 'text.xml')"/>
<!-- Turn the absolute path into a relative path so we can find ourselves in
the parent -->
<xsl:variable name="path_self" select="concat(str:tokenize($self, '/')[last()], '/')"/>
<xsl:variable name="index_self" select="count(document(concat($self, '../text.xml'))/guide/include[@href=$path_self]/preceding-sibling::*)+1"/>
<!-- Go down a parent, lookup the item after us... -->
<xsl:variable name="parentItem_lookup" select="document(concat($self, '../text.xml'))/guide/include[$index_self]/@href"/>
<xsl:variable name="parentItem_next" select="concat(document(concat($self, '../text.xml'))/guide/@self, $parentItem_lookup)"/>
<xsl:choose>
<!-- If we have an item after us, or we are at the root node (termination condition) we need to
not recurse any further... -->
<xsl:when test="$parentItem_lookup != '' or document(concat($self, '../text.xml'))/guide/@root">
<xsl:variable name="parentItem_actual">
<xsl:choose>
<xsl:when test="$parentItem_next = ''"></xsl:when>
<xsl:otherwise><xsl:value-of select="$parentItem_next"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- This is where we do a little trickery. To count how many levels we need to go down,
we count how far up we currently are (remember that the absolute link we get is relative to /...) and
hence we can build a relative link... -->
<xsl:variable name="relative_path" select="$parentItem_actual"/>
<xsl:variable name="relative_path_depth" select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , ''))"/>
<xsl:variable name="relative_path_depth_recursion">
<xsl:call-template name="str:repeatString">
<xsl:with-param name="count" select="$relative_path_depth"/>
<xsl:with-param name="append">../</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<a href="{concat($relative_path_depth_recursion, $relative_path, 'index.html')}"><xsl:value-of select="document(concat($parentItem_actual, 'text.xml'))/guide/chapter[1]/title"/></a>
</xsl:when>
<xsl:otherwise>
<!-- We need to recurse downwards; so we need to strip off a directory element off our absolute path to feed
into the next iteration... -->
<xsl:variable name="relative_path_depth" select="string-length($self)-string-length(translate($self, '/' , ''))"/>
<xsl:variable name="relative_path_fixed">
<xsl:for-each select="str:tokenize_plasmaroo($self, '/')[position() < (($relative_path_depth - 1)*2 + 1)]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:call-template name="findNext">
<xsl:with-param name="self" select="$relative_path_fixed"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="getLastNode">
<!-- This function recurses forward down nodes stopping at the very last include... -->
<xsl:param name="root"/>
<xsl:param name="path"/>
<xsl:variable name="include" select="document(concat($root, $path))/guide/include[last()]/@href"/>
<xsl:choose>
<xsl:when test="$include">
<xsl:call-template name="getLastNode">
<xsl:with-param name="root" select="$root"/>
<xsl:with-param name="path" select="concat(substring-before($path, 'text.xml'), $include, 'text.xml')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$path"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="findPrevious">
<xsl:choose>
<!-- To find the "previous" node:
* Go down to our parent
* See if there are any nodes before us
* If we have a valid node that is before us
* Fully recurse up the node to get the last extremity
* Otherwise list the parent -->
<xsl:when test="/guide/@root">
<a href="#"><xsl:value-of select="/guide/chapter[1]/title"/></a>
</xsl:when>
<xsl:otherwise>
<!-- This document's path -->
<xsl:variable name="doc_self" select="concat(/guide/@self, 'text.xml')"/>
<!-- Turn the absolute path we have into a relative path so we can find ourselves in the
parent -->
<!-- FIXME: Bombproof the doc_self so it still works if it's missing a '/' on the end -->
<xsl:variable name="path_self" select="concat(str:tokenize(/guide/@self, '/')[last()], '/')"/>
<xsl:variable name="index_self" select="count(document(concat(/guide/@self, '../text.xml'))/guide/include[@href=$path_self]/preceding-sibling::*)-1"/>
<xsl:choose>
<xsl:when test="$index_self > 0">
<!-- Relative path of the parent -->
<xsl:variable name="parentItem_path" select="document(concat(/guide/@self, '../text.xml'))/guide/@self"/>
<!-- Previous item in the parent -->
<xsl:variable name="parentItem_next" select="document(concat(/guide/@self, '../text.xml'))/guide/include[$index_self]/@href"/>
<xsl:variable name="myItem_path">
<xsl:call-template name="getLastNode">
<xsl:with-param name="root" select="$parentItem_path"/>
<xsl:with-param name="path" select="concat($parentItem_next, 'text.xml')"/>
</xsl:call-template>
</xsl:variable>
<!-- Make a relative <a> link; we need an absolute reference for the XSLT processor though... -->
<a href="{concat('../', substring-before($myItem_path, 'text.xml'), 'index.html')}"><xsl:value-of select="document(concat($parentItem_path, $myItem_path))/guide/chapter[1]/title"/></a>
</xsl:when>
<xsl:otherwise>
<a href="../index.html"><xsl:value-of select="document(concat(/guide/@self, '../text.xml'))/guide/chapter[1]/title"/></a>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="findParent">
<xsl:choose>
<xsl:when test="not(/guide/@root)">
<a href="../index.html"><xsl:value-of select="document(concat(/guide/@self, '../text.xml'))/guide/chapter[1]/title"/></a>
</xsl:when>
<xsl:otherwise>
<a href="#"><xsl:value-of select="/guide/chapter[1]/title"/></a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="author">
<dt><xsl:value-of select="@name"/><xsl:if test="@email != ''"> <<a href="mailto:{@email}"><xsl:value-of select="@email"/></a>></xsl:if></dt>
<dd><xsl:apply-templates/></dd>
</xsl:template>
<xsl:template match="authors">
<dl>
<xsl:apply-templates select="author"/>
</dl>
</xsl:template>
</xsl:stylesheet>
|