summaryrefslogtreecommitdiff
blob: 491070b459a02e7a94bc8bbb45b3398095faf1be (plain)
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
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:dyn="http://exslt.org/dynamic"
                xmlns:func="http://exslt.org/functions"
                xmlns:exslt="http://exslt.org/common"
                extension-element-prefixes="exslt func dyn">

<!-- Define global variables; if a user has
     already defined those, this is a NOP -->
<xsl:param name="part">0</xsl:param>
<xsl:param name="chap">0</xsl:param>
<xsl:param name="full">0</xsl:param>

<!-- A book -->
<xsl:template match="/book">
  <!-- If chap = 0, show an index -->
  <xsl:choose>
    <xsl:when test="$part != 0">
      <xsl:apply-templates select="part" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:call-template name="doclayout"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<!-- <sections>, i.e. when user tries to access a book file directly -->
<xsl:template match="/sections">
  <xsl:call-template name="doclayout"/>
</xsl:template>

<!-- Content of /book -->
<xsl:template name="bookcontent">
  <xsl:call-template name="menubar" />
  <h1><xsl:value-of select="title" /></h1>
  <xsl:if test="$style = 'printable'">
    <xsl:apply-templates select="author" />
    <br/>
    <i><xsl:call-template name="contentdate"/></i>
    <xsl:variable name="outdated">
      <xsl:call-template name="outdated-translation"/>
    </xsl:variable>
    <xsl:if test="string-length($outdated) &gt; 1">
      <br/><i><xsl:copy-of select="$outdated"/></i>
    </xsl:if>
  </xsl:if>
  <p><xsl:value-of select="func:gettext('Content')"/>:</p>
  <ul>
    <xsl:for-each select="part">
      <xsl:variable name="curpart" select="position()" />
      <li>
        <xsl:choose>
          <xsl:when test="$full = 0">
            <xsl:choose>
              <xsl:when test="$style != 'printable'">
                <b><a href="?part={$curpart}"><xsl:value-of select="title" /></a></b>
              </xsl:when>
              <xsl:otherwise>
                <b><a href="?part={$curpart}&amp;style=printable"><xsl:value-of select="title" /></a></b>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <b><a href="#book_part{$curpart}"><xsl:value-of select="title" /></a></b>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="abstract">
          <br />
          <xsl:value-of select="abstract" />
        </xsl:if>
        <ol>
          <xsl:for-each select="chapter">
            <xsl:variable name="curchap" select="position()" />
            <li>
              <xsl:choose>
                <xsl:when test="$full = 0">
                  <xsl:choose>
                    <xsl:when test="$style != 'printable'">
                      <b><a href="?part={$curpart}&amp;chap={$curchap}"><xsl:value-of select="title" /></a></b>
                    </xsl:when>
                    <xsl:otherwise>
                      <b><a href="?part={$curpart}&amp;chap={$curchap}&amp;style=printable"><xsl:value-of select="title" /></a></b>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                  <b><a href="#book_part{$curpart}_chap{$curchap}"><xsl:value-of select="title" /></a></b>
                </xsl:otherwise>
              </xsl:choose>
              <xsl:choose>
                <xsl:when test="abstract">
                  <br/>
                  <xsl:value-of select="abstract" />
                </xsl:when>
                <xsl:otherwise>
                  <br/>
                  <xsl:value-of select="document(include/@href)/*[1]/abstract" />
                </xsl:otherwise>
              </xsl:choose>
            </li>
          </xsl:for-each>
        </ol>
      </li>
    </xsl:for-each>
  </ul>
  <xsl:call-template name="menubar" />

  <xsl:if test="$full =1">
    <xsl:apply-templates select="part" />
  </xsl:if>
  
  <xsl:apply-templates select="/book/license" />
</xsl:template>

<!-- Part inside a book -->
<xsl:template match="/book/part">
  <xsl:if test="(($chap != 0) and ($part = position())) or ($full = 1)">
    <xsl:variable name="pos" select="position()"/>
    <xsl:if test="$full = 1">
      <a name="book_part{$pos}"/>
      <h2><xsl:number level="multiple" format="A. " value="$pos"/><xsl:value-of select="title" /></h2>
    </xsl:if>
    <xsl:apply-templates select="chapter">
      <xsl:with-param name="partnum" select="$pos"/>
    </xsl:apply-templates>
  </xsl:if>
  <xsl:if test="($chap = 0) and ($part = position())">
    <xsl:call-template name="doclayout" />
  </xsl:if>
</xsl:template>

<!-- Content of /book/part -->
<xsl:template name="bookpartcontent">
  <xsl:call-template name="menubar" />
  <xsl:if test="@id">
    <a name="{@id}"/>
  </xsl:if>
  <h1><xsl:number level="multiple" format="1. " value="position()"/><xsl:value-of select="title" /></h1>
  <xsl:if test="abstract">
    <p><xsl:value-of select="abstract" /></p>
  </xsl:if>
  <p><xsl:value-of select="func:gettext('Content')"/>:</p>
  <ol>
    <xsl:for-each select="chapter">
      <xsl:variable name="curpos" select="position()" />
      <xsl:if test="title">
        <li>
          <b><a href="?part={$part}&amp;chap={$curpos}"><xsl:value-of select="title" /></a></b>
          <xsl:choose>
            <xsl:when test="abstract">
              <br/>
              <xsl:value-of select="abstract" />
            </xsl:when>
            <xsl:otherwise>
              <br/>
              <xsl:value-of select="document(include/@href)/*[1]/abstract" />
            </xsl:otherwise>
          </xsl:choose>
        </li>
      </xsl:if>
    </xsl:for-each>
  </ol>
  
  <xsl:call-template name="menubar" />
  <xsl:apply-templates select="/book/license" />
</xsl:template>

<!-- Menu bar -->
<xsl:template name="menubar">
  <xsl:variable name="prevpart" select="number($part) - 1" />
  <xsl:variable name="prevchap" select="number($chap) - 1" />
  <xsl:variable name="nextpart" select="number($part) + 1" />
  <xsl:variable name="nextchap" select="number($chap) + 1" />
  <xsl:if test="($style != 'printable') and ($full = 0)">
    <hr />
    <p>
      <!-- Previous Parts -->
      <xsl:choose>
        <xsl:when test="number($prevpart) &lt; 1">
          [ &lt;&lt; ]
        </xsl:when>
        <xsl:otherwise>
          [ <a href="{concat($link, '?part=', $prevpart)}">&lt;&lt;</a> ]
        </xsl:otherwise>
      </xsl:choose>
      <!-- Previous Chapter -->
      <xsl:choose>
        <xsl:when test="number($prevchap) &lt; 1">
          [ &lt; ]
        </xsl:when>
        <xsl:otherwise>
          [ <a href="{concat($link, '?part=', $part, '&amp;chap=', $prevchap)}">&lt;</a> ]
        </xsl:otherwise>
      </xsl:choose>
      <!-- Content -->
      [ <a href="{$link}"><xsl:value-of select="func:gettext('Home')"/></a> ]
      <!-- Next Chapter -->
      <xsl:if test="name() = 'book'">
        [ <a href="{concat($link, '?part=1')}">&gt;</a> ]
      </xsl:if>
      <xsl:if test="name() = 'part'">
        [ <a href="{concat($link, '?part=', $part, '&amp;chap=1')}">&gt;</a> ]
      </xsl:if>
      <xsl:if test="name() = 'chapter'">
        <xsl:choose>
          <xsl:when test="last() = position()">
            [ &gt; ]
          </xsl:when>
          <xsl:otherwise>
            [ <a href="{concat($link, '?part=', $part, '&amp;chap=', $nextchap)}">&gt;</a> ]
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
      <!-- Next Part -->
      <xsl:if test="name() = 'book'">
        [ <a href="{concat($link, '?part=', $nextpart)}">&gt;&gt;</a> ]
      </xsl:if>
      <xsl:if test="name() = 'part'">
        <xsl:choose>
          <xsl:when test="number($part) = last()">
            [ &gt;&gt; ]
          </xsl:when>
          <xsl:otherwise>
            [ <a href="{concat($link, '?part=', $nextpart)}">&gt;&gt;</a> ]
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
      <xsl:if test="name() = 'chapter'">
        <xsl:choose>
          <xsl:when test="count(/book/part) = number($part)">
            [ &gt;&gt; ] 
          </xsl:when>
          <xsl:otherwise>
            [ <a href="{concat($link, '?part=', $nextpart)}">&gt;&gt;</a> ]
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </p>
    <hr />
  </xsl:if>
</xsl:template>


<!-- Chapter inside a part -->
<xsl:template match="/book/part/chapter">
  <xsl:param name="partnum"/>
  <xsl:variable name="pos" select="position()"/>
  <xsl:if test="($chap = position()) and ($full = 0)">
    <xsl:call-template name="doclayout">
      <xsl:with-param name="partnum" select="$partnum"/>
      <xsl:with-param name="chapnum" select="$pos"/>
    </xsl:call-template>
  </xsl:if>
  <xsl:if test="$full = 1">
    <xsl:call-template name="bookpartchaptercontent">
      <xsl:with-param name="partnum" select="$partnum"/>
      <xsl:with-param name="chapnum" select="$pos"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

<!-- Content of /book/part/chapter -->
<xsl:template name="bookpartchaptercontent">
  <xsl:param name="partnum"/>
  <xsl:param name="chapnum"/>
  <xsl:call-template name="menubar" />
  <xsl:if test="@id">
    <a name="{@id}"/>
  </xsl:if>

  <xsl:if test="$debug='1'">
    <xsl:text disable-output-escaping="yes">&lt;div style="border-left:4px solid #AAA; margin-top:4px; padding-left:4px;"&gt;</xsl:text>
    <div style="color:white;background:#AAA;font-weight:bold;padding:4px;margin-left:-4px;"><xsl:value-of select="include/@href"/></div>
  </xsl:if>

  <xsl:if test="$full = 1">
    <a name="book_part{$partnum}_chap{$chapnum}"/>
    <h3><xsl:number level="multiple" format="1. " value="position()"/><xsl:value-of select="title" /></h3>
  </xsl:if>
  <xsl:if test="$full = 0">
    <h1><xsl:number level="multiple" format="1. " value="position()"/><xsl:value-of select="title" /></h1>
  </xsl:if>
  <xsl:variable name="doc" select="include/@href"/>
  <xsl:variable name="FILE" select="document($doc)" />
  <xsl:if test="$full = 0">
    <!-- Chapter content only when rendering a single page -->
    <xsl:if test="count(exslt:node-set($doc-struct)//chapter)&gt;1">
      <b><xsl:value-of select="func:gettext('Content')"/>: </b>
      <ul>
        <xsl:for-each select="exslt:node-set($doc-struct)//chapter">
          <li><a href="#doc_chap{position()}" class="altlink"><xsl:value-of select="@title" /></a></li>
        </xsl:for-each>
      </ul>
    </xsl:if>
  </xsl:if>

  <xsl:choose>
    <xsl:when test="$full = 1">
      <xsl:apply-templates select="$FILE/sections/section[not(@test) or dyn:evaluate(@test)]">
        <xsl:with-param name="chapnum" select="$chapnum"/>
        <xsl:with-param name="partnum" select="$partnum"/>
      </xsl:apply-templates>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="$FILE/sections/section[not(@test) or dyn:evaluate(@test)]">
        <xsl:with-param name="chapnum" select="$chapnum"/>
        <xsl:with-param name="partnum" select="$partnum"/>
      </xsl:apply-templates>
    </xsl:otherwise>
  </xsl:choose>

  <xsl:if test="$debug='1'">
    <xsl:text disable-output-escaping="yes">&lt;/div&gt;</xsl:text>
  </xsl:if>
  
  <xsl:call-template name="menubar" />

  <xsl:if test="$full = 0">
    <xsl:apply-templates select="/book/license" />
  </xsl:if>
</xsl:template>

</xsl:stylesheet>