~ubuntu-branches/debian/jessie/gnucash-docs/jessie

« back to all changes in this revision

Viewing changes to xsl/1.45/html/chunk-experimental.xsl

  • Committer: Bazaar Package Importer
  • Author(s): James A. Treacy
  • Date: 2004-04-20 00:19:06 UTC
  • Revision ID: james.westby@ubuntu.com-20040420001906-40kllkvvkxlxr9u7
Tags: upstream-1.8.4
ImportĀ upstreamĀ versionĀ 1.8.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
2
                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
 
3
                version="1.0"
 
4
                exclude-result-prefixes="doc">
 
5
 
 
6
<xsl:param name="html.ext" select="'.html'"/>
 
7
<doc:param name="html.ext" xmlns="">
 
8
<refpurpose>Extension for chunked files</refpurpose>
 
9
<refdescription>
 
10
<para>The extension identified by <parameter>html.ext</parameter> will
 
11
be used as the filename extension for chunks created by this stylesheet.
 
12
</para>
 
13
</refdescription>
 
14
</doc:param>
 
15
 
 
16
<xsl:param name="root.filename" select="'index'"/>
 
17
<doc:param name="root.filename" xmlns="">
 
18
<refpurpose>Filename for the root chunk</refpurpose>
 
19
<refdescription>
 
20
<para>The <parameter>root.filename</parameter> is the base filename for
 
21
the chunk created for the root of each document processed.
 
22
</para>
 
23
</refdescription>
 
24
</doc:param>
 
25
 
 
26
<xsl:param name="base.dir" select="''"/>
 
27
<doc:param name="base.dir" xmlns="">
 
28
<refpurpose>Output directory for chunks</refpurpose>
 
29
<refdescription>
 
30
<para>If specified, the <literal>base.dir</literal> identifies
 
31
the output directory for chunks. (If not specified, the output directory
 
32
is system dependent.)</para>
 
33
</refdescription>
 
34
</doc:param>
 
35
 
 
36
<xsl:param name="chunk.sections" select="'1'"/>
 
37
<doc:param name="chunk.sections" xmlns="">
 
38
<refpurpose>Create chunks for top-level sections in components?</refpurpose>
 
39
<refdescription>
 
40
<para>If non-zero, chunks will be created for top-level
 
41
<sgmltag>sect1</sgmltag> and <sgmltag>section</sgmltag> elements in
 
42
each component.
 
43
</para>
 
44
</refdescription>
 
45
</doc:param>
 
46
 
 
47
<xsl:param name="chunk.first.sections" select="'0'"/>
 
48
<doc:param name="chunk.first.sections" xmlns="">
 
49
<refpurpose>Create a chunk for the first top-level section in each component?</refpurpose>
 
50
<refdescription>
 
51
<para>If non-zero, a chunk will be created for the first top-level
 
52
<sgmltag>sect1</sgmltag> or <sgmltag>section</sgmltag> elements in
 
53
each component. Otherwise, that section will be part of the chunk for
 
54
its parent.
 
55
</para>
 
56
</refdescription>
 
57
</doc:param>
 
58
 
 
59
<xsl:param name="chunk.datafile" select="'.chunks'"/>
 
60
<doc:param name="chunk.datafile" xmlns="">
 
61
<refpurpose>Name of the temporary file used to hold chunking data</refpurpose>
 
62
<refdescription>
 
63
<para>Chunking is now a two-step process. The
 
64
<parameter>chunk.datafile</parameter> is the name of the file used to
 
65
hold the chunking data.
 
66
</para>
 
67
</refdescription>
 
68
</doc:param>
 
69
 
 
70
<!-- ==================================================================== -->
 
71
<!-- What's a chunk?
 
72
 
 
73
     appendix
 
74
     article
 
75
     bibliography  in article or book
 
76
     book
 
77
     chapter
 
78
     colophon
 
79
     glossary      in article or book
 
80
     index         in article or book
 
81
     part
 
82
     preface
 
83
     refentry
 
84
     reference
 
85
     sect1         if position()>1
 
86
     section       if position()>1 && parent != section
 
87
     set
 
88
     setindex
 
89
                                                                          -->
 
90
<!-- ==================================================================== -->
 
91
 
 
92
<xsl:template name="chunk">
 
93
  <xsl:param name="node" select="."/>
 
94
  <!-- returns 1 if $node is a chunk -->
 
95
 
 
96
  <xsl:variable name="id">
 
97
    <xsl:choose>
 
98
      <xsl:when test="$node/@id">
 
99
        <xsl:value-of select="$node/@id"/>
 
100
      </xsl:when>
 
101
      <xsl:otherwise>
 
102
        <xsl:value-of select="generate-id($node)"/>
 
103
      </xsl:otherwise>
 
104
    </xsl:choose>
 
105
  </xsl:variable>
 
106
 
 
107
  <xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
 
108
 
 
109
  <xsl:choose>
 
110
    <xsl:when test="$chunks/chunks/chunk[@id=$id]">1</xsl:when>
 
111
    <xsl:otherwise>0</xsl:otherwise>
 
112
  </xsl:choose>
 
113
</xsl:template>
 
114
 
 
115
<!-- ==================================================================== -->
 
116
 
 
117
<xsl:template match="*" mode="chunk-filename">
 
118
  <!-- returns the filename of a chunk -->
 
119
 
 
120
  <xsl:variable name="id">
 
121
    <xsl:choose>
 
122
      <xsl:when test="@id">
 
123
        <xsl:value-of select="@id"/>
 
124
      </xsl:when>
 
125
      <xsl:otherwise>
 
126
        <xsl:value-of select="generate-id(.)"/>
 
127
      </xsl:otherwise>
 
128
    </xsl:choose>
 
129
  </xsl:variable>
 
130
 
 
131
  <xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
 
132
  <xsl:variable name="chunk" select="$chunks/chunks/chunk[@id=$id]"/>
 
133
 
 
134
  <xsl:choose>
 
135
    <xsl:when test="$chunk">
 
136
      <xsl:value-of select="$chunk/@filename"/>
 
137
    </xsl:when>
 
138
    <xsl:otherwise>
 
139
      <xsl:apply-templates select="parent::*" mode="chunk-filename"/>
 
140
    </xsl:otherwise>
 
141
  </xsl:choose>
 
142
</xsl:template>
 
143
 
 
144
<!-- ==================================================================== -->
 
145
 
 
146
<xsl:template name="href.target">
 
147
  <xsl:param name="object" select="."/>
 
148
  <xsl:variable name="ischunk">
 
149
    <xsl:call-template name="chunk">
 
150
      <xsl:with-param name="node" select="$object"/>
 
151
    </xsl:call-template>
 
152
  </xsl:variable>
 
153
 
 
154
  <xsl:apply-templates mode="chunk-filename" select="$object"/>
 
155
 
 
156
  <xsl:if test="$ischunk='0'">
 
157
    <xsl:text>#</xsl:text>
 
158
    <xsl:call-template name="object.id">
 
159
      <xsl:with-param name="object" select="$object"/>
 
160
    </xsl:call-template>
 
161
  </xsl:if>
 
162
</xsl:template>
 
163
 
 
164
<!-- ==================================================================== -->
 
165
 
 
166
<xsl:template name="html.head">
 
167
  <xsl:param name="prev" select="/foo"/>
 
168
  <xsl:param name="next" select="/foo"/>
 
169
  <xsl:variable name="home" select="/*[1]"/>
 
170
  <xsl:variable name="up" select="parent::*"/>
 
171
 
 
172
  <head>
 
173
    <xsl:call-template name="head.content"/>
 
174
    <xsl:call-template name="user.head.content"/>
 
175
 
 
176
    <xsl:if test="$home">
 
177
      <link rel="home">
 
178
        <xsl:attribute name="href">
 
179
          <xsl:call-template name="href.target">
 
180
            <xsl:with-param name="object" select="$home"/>
 
181
          </xsl:call-template>
 
182
        </xsl:attribute>
 
183
        <xsl:attribute name="title">
 
184
          <xsl:apply-templates select="$home"
 
185
                               mode="object.title.markup.textonly"/>
 
186
        </xsl:attribute>
 
187
      </link>
 
188
    </xsl:if>
 
189
 
 
190
    <xsl:if test="$up">
 
191
      <link rel="up">
 
192
        <xsl:attribute name="href">
 
193
          <xsl:call-template name="href.target">
 
194
            <xsl:with-param name="object" select="$up"/>
 
195
          </xsl:call-template>
 
196
        </xsl:attribute>
 
197
        <xsl:attribute name="title">
 
198
          <xsl:apply-templates select="$up" mode="object.title.markup.textonly"/>
 
199
        </xsl:attribute>
 
200
      </link>
 
201
    </xsl:if>
 
202
 
 
203
    <xsl:if test="$prev">
 
204
      <link rel="previous">
 
205
        <xsl:attribute name="href">
 
206
          <xsl:call-template name="href.target">
 
207
            <xsl:with-param name="object" select="$prev"/>
 
208
          </xsl:call-template>
 
209
        </xsl:attribute>
 
210
        <xsl:attribute name="title">
 
211
          <xsl:apply-templates select="$prev" mode="object.title.markup.textonly"/>
 
212
        </xsl:attribute>
 
213
      </link>
 
214
    </xsl:if>
 
215
 
 
216
    <xsl:if test="$next">
 
217
      <link rel="next">
 
218
        <xsl:attribute name="href">
 
219
          <xsl:call-template name="href.target">
 
220
            <xsl:with-param name="object" select="$next"/>
 
221
          </xsl:call-template>
 
222
        </xsl:attribute>
 
223
        <xsl:attribute name="title">
 
224
          <xsl:apply-templates select="$next" mode="object.title.markup.textonly"/>
 
225
        </xsl:attribute>
 
226
      </link>
 
227
    </xsl:if>
 
228
  </head>
 
229
</xsl:template>
 
230
 
 
231
<!-- ==================================================================== -->
 
232
 
 
233
<xsl:template name="header.navigation">
 
234
  <xsl:param name="prev" select="/foo"/>
 
235
  <xsl:param name="next" select="/foo"/>
 
236
  <xsl:variable name="home" select="/*[1]"/>
 
237
  <xsl:variable name="up" select="parent::*"/>
 
238
 
 
239
  <xsl:if test="$suppress.navigation = '0'">
 
240
    <div class="navheader">
 
241
      <table width="100%" summary="Navigation header">
 
242
        <tr>
 
243
          <th colspan="3" align="center">
 
244
            <xsl:apply-templates select="." mode="object.title.markup"/>
 
245
          </th>
 
246
        </tr>
 
247
        <tr>
 
248
          <td width="20%" align="left">
 
249
            <xsl:if test="count($prev)>0">
 
250
              <a accesskey="p">
 
251
                <xsl:attribute name="href">
 
252
                  <xsl:call-template name="href.target">
 
253
                    <xsl:with-param name="object" select="$prev"/>
 
254
                  </xsl:call-template>
 
255
                </xsl:attribute>
 
256
                <xsl:call-template name="gentext">
 
257
                  <xsl:with-param name="key">nav-prev</xsl:with-param>
 
258
                </xsl:call-template>
 
259
              </a>
 
260
            </xsl:if>
 
261
            <xsl:text>&#160;</xsl:text>
 
262
          </td>
 
263
          <th width="60%" align="center">
 
264
            <xsl:choose>
 
265
              <xsl:when test="count($up) > 0 and $up != $home">
 
266
                <xsl:apply-templates select="$up" mode="object.title.markup"/>
 
267
              </xsl:when>
 
268
              <xsl:otherwise>&#160;</xsl:otherwise>
 
269
            </xsl:choose>
 
270
          </th>
 
271
          <td width="20%" align="right">
 
272
            <xsl:text>&#160;</xsl:text>
 
273
            <xsl:if test="count($next)>0">
 
274
              <a accesskey="n">
 
275
                <xsl:attribute name="href">
 
276
                  <xsl:call-template name="href.target">
 
277
                    <xsl:with-param name="object" select="$next"/>
 
278
                  </xsl:call-template>
 
279
                </xsl:attribute>
 
280
                <xsl:call-template name="gentext">
 
281
                  <xsl:with-param name="key">nav-next</xsl:with-param>
 
282
                </xsl:call-template>
 
283
              </a>
 
284
            </xsl:if>
 
285
          </td>
 
286
        </tr>
 
287
      </table>
 
288
      <hr/>
 
289
    </div>
 
290
  </xsl:if>
 
291
</xsl:template>
 
292
 
 
293
<!-- ==================================================================== -->
 
294
 
 
295
<xsl:template name="footer.navigation">
 
296
  <xsl:param name="prev" select="/foo"/>
 
297
  <xsl:param name="next" select="/foo"/>
 
298
  <xsl:variable name="home" select="/*[1]"/>
 
299
  <xsl:variable name="up" select="parent::*"/>
 
300
 
 
301
  <xsl:if test="$suppress.navigation = '0'">
 
302
    <div class="navfooter">
 
303
      <hr/>
 
304
      <table width="100%" summary="Navigation footer">
 
305
        <tr>
 
306
          <td width="40%" align="left">
 
307
            <xsl:if test="count($prev)>0">
 
308
              <a accesskey="p">
 
309
                <xsl:attribute name="href">
 
310
                  <xsl:call-template name="href.target">
 
311
                    <xsl:with-param name="object" select="$prev"/>
 
312
                  </xsl:call-template>
 
313
                </xsl:attribute>
 
314
                <xsl:call-template name="gentext">
 
315
                  <xsl:with-param name="key">nav-prev</xsl:with-param>
 
316
                </xsl:call-template>
 
317
              </a>
 
318
            </xsl:if>
 
319
            <xsl:text>&#160;</xsl:text>
 
320
          </td>
 
321
          <td width="20%" align="center">
 
322
            <xsl:choose>
 
323
              <xsl:when test="$home != .">
 
324
                <a accesskey="h">
 
325
                  <xsl:attribute name="href">
 
326
                    <xsl:call-template name="href.target">
 
327
                      <xsl:with-param name="object" select="$home"/>
 
328
                    </xsl:call-template>
 
329
                  </xsl:attribute>
 
330
                  <xsl:call-template name="gentext">
 
331
                    <xsl:with-param name="key">nav-home</xsl:with-param>
 
332
                  </xsl:call-template>
 
333
                </a>
 
334
              </xsl:when>
 
335
              <xsl:otherwise>&#160;</xsl:otherwise>
 
336
            </xsl:choose>
 
337
          </td>
 
338
          <td width="40%" align="right">
 
339
            <xsl:text>&#160;</xsl:text>
 
340
            <xsl:if test="count($next)>0">
 
341
              <a accesskey="n">
 
342
                <xsl:attribute name="href">
 
343
                  <xsl:call-template name="href.target">
 
344
                    <xsl:with-param name="object" select="$next"/>
 
345
                  </xsl:call-template>
 
346
                </xsl:attribute>
 
347
                <xsl:call-template name="gentext">
 
348
                  <xsl:with-param name="key">nav-next</xsl:with-param>
 
349
                </xsl:call-template>
 
350
              </a>
 
351
            </xsl:if>
 
352
          </td>
 
353
        </tr>
 
354
 
 
355
        <tr>
 
356
          <td width="40%" align="left">
 
357
            <xsl:apply-templates select="$prev" mode="object.title.markup"/>
 
358
            <xsl:text>&#160;</xsl:text>
 
359
          </td>
 
360
          <td width="20%" align="center">
 
361
            <xsl:choose>
 
362
              <xsl:when test="count($up)>0">
 
363
                <a accesskey="u">
 
364
                  <xsl:attribute name="href">
 
365
                    <xsl:call-template name="href.target">
 
366
                      <xsl:with-param name="object" select="$up"/>
 
367
                    </xsl:call-template>
 
368
                  </xsl:attribute>
 
369
                  <xsl:call-template name="gentext">
 
370
                    <xsl:with-param name="key">nav-up</xsl:with-param>
 
371
                  </xsl:call-template>
 
372
                </a>
 
373
              </xsl:when>
 
374
              <xsl:otherwise>&#160;</xsl:otherwise>
 
375
            </xsl:choose>
 
376
          </td>
 
377
          <td width="40%" align="right">
 
378
            <xsl:text>&#160;</xsl:text>
 
379
            <xsl:apply-templates select="$next" mode="object.title.markup"/>
 
380
          </td>
 
381
        </tr>
 
382
      </table>
 
383
    </div>
 
384
  </xsl:if>
 
385
</xsl:template>
 
386
 
 
387
<!-- ==================================================================== -->
 
388
 
 
389
<xsl:template match="processing-instruction('dbhtml')">
 
390
  <!-- nop -->
 
391
</xsl:template>
 
392
 
 
393
<!-- ==================================================================== -->
 
394
 
 
395
<xsl:template name="process-chunk">
 
396
  <xsl:variable name="id">
 
397
    <xsl:choose>
 
398
      <xsl:when test="@id">
 
399
        <xsl:value-of select="@id"/>
 
400
      </xsl:when>
 
401
      <xsl:otherwise>
 
402
        <xsl:value-of select="generate-id(.)"/>
 
403
      </xsl:otherwise>
 
404
    </xsl:choose>
 
405
  </xsl:variable>
 
406
 
 
407
  <xsl:variable name="chunks" select="document($chunk.datafile,.)"/>
 
408
 
 
409
  <xsl:variable name="chunk" select="$chunks/chunks/chunk[@id=$id]"/>
 
410
  <xsl:variable name="prev-id"
 
411
                select="$chunk/preceding-sibling::chunk[1]/@id"/>
 
412
  <xsl:variable name="next-id"
 
413
                select="$chunk/following-sibling::chunk[1]/@id"/>
 
414
 
 
415
  <xsl:variable name="prev" select="id($prev-id)"/>
 
416
  <xsl:variable name="next" select="id($next-id)"/>
 
417
 
 
418
  <xsl:variable name="ischunk">
 
419
    <xsl:call-template name="chunk"/>
 
420
  </xsl:variable>
 
421
 
 
422
  <xsl:variable name="chunkfn">
 
423
    <xsl:if test="$ischunk='1'">
 
424
      <xsl:apply-templates mode="chunk-filename" select="."/>
 
425
    </xsl:if>
 
426
  </xsl:variable>
 
427
 
 
428
  <xsl:if test="$ischunk='0'">
 
429
    <xsl:message>
 
430
      <xsl:text>Error </xsl:text>
 
431
      <xsl:value-of select="name(.)"/>
 
432
      <xsl:text> is not a chunk!</xsl:text>
 
433
    </xsl:message>
 
434
  </xsl:if>
 
435
 
 
436
  <xsl:variable name="filename">
 
437
    <xsl:call-template name="make-relative-filename">
 
438
      <xsl:with-param name="base.dir" select="$base.dir"/>
 
439
      <xsl:with-param name="base.name" select="$chunkfn"/>
 
440
    </xsl:call-template>
 
441
  </xsl:variable>
 
442
 
 
443
  <xsl:call-template name="write.chunk">
 
444
    <xsl:with-param name="filename" select="$filename"/>
 
445
    <xsl:with-param name="content">
 
446
      <xsl:call-template name="chunk-element-content">
 
447
        <xsl:with-param name="prev" select="$prev"/>
 
448
        <xsl:with-param name="next" select="$next"/>
 
449
      </xsl:call-template>
 
450
    </xsl:with-param>
 
451
  </xsl:call-template>
 
452
</xsl:template>
 
453
 
 
454
<xsl:template name="chunk-element-content">
 
455
  <xsl:param name="prev"></xsl:param>
 
456
  <xsl:param name="next"></xsl:param>
 
457
 
 
458
  <html>
 
459
    <xsl:call-template name="html.head">
 
460
      <xsl:with-param name="prev" select="$prev"/>
 
461
      <xsl:with-param name="next" select="$next"/>
 
462
    </xsl:call-template>
 
463
 
 
464
    <body>
 
465
      <xsl:call-template name="body.attributes"/>
 
466
      <xsl:call-template name="user.header.navigation"/>
 
467
 
 
468
      <xsl:call-template name="header.navigation">
 
469
        <xsl:with-param name="prev" select="$prev"/>
 
470
        <xsl:with-param name="next" select="$next"/>
 
471
      </xsl:call-template>
 
472
 
 
473
      <xsl:call-template name="user.header.content"/>
 
474
 
 
475
      <xsl:apply-imports/>
 
476
 
 
477
      <xsl:call-template name="user.footer.content"/>
 
478
 
 
479
      <xsl:call-template name="footer.navigation">
 
480
        <xsl:with-param name="prev" select="$prev"/>
 
481
        <xsl:with-param name="next" select="$next"/>
 
482
      </xsl:call-template>
 
483
 
 
484
      <xsl:call-template name="user.footer.navigation"/>
 
485
    </body>
 
486
  </html>
 
487
</xsl:template>
 
488
 
 
489
<!-- ==================================================================== -->
 
490
 
 
491
<xsl:template match="set">
 
492
  <xsl:call-template name="process-chunk"/>
 
493
</xsl:template>
 
494
 
 
495
<xsl:template match="book">
 
496
  <xsl:call-template name="process-chunk"/>
 
497
</xsl:template>
 
498
 
 
499
<xsl:template match="book/appendix">
 
500
  <xsl:call-template name="process-chunk"/>
 
501
</xsl:template>
 
502
 
 
503
<xsl:template match="book/glossary">
 
504
  <xsl:call-template name="process-chunk"/>
 
505
</xsl:template>
 
506
 
 
507
<xsl:template match="book/bibliography">
 
508
  <xsl:call-template name="process-chunk"/>
 
509
</xsl:template>
 
510
 
 
511
<xsl:template match="preface|chapter">
 
512
  <xsl:call-template name="process-chunk"/>
 
513
</xsl:template>
 
514
 
 
515
<xsl:template match="part|reference">
 
516
  <xsl:call-template name="process-chunk"/>
 
517
</xsl:template>
 
518
 
 
519
<xsl:template match="refentry">
 
520
  <xsl:call-template name="process-chunk"/>
 
521
</xsl:template>
 
522
 
 
523
<xsl:template match="colophon">
 
524
  <xsl:call-template name="process-chunk"/>
 
525
</xsl:template>
 
526
 
 
527
<xsl:template match="article">
 
528
  <xsl:call-template name="process-chunk"/>
 
529
</xsl:template>
 
530
 
 
531
<xsl:template match="article/appendix">
 
532
  <xsl:call-template name="process-chunk"/>
 
533
</xsl:template>
 
534
 
 
535
<xsl:template match="article/glossary">
 
536
  <xsl:call-template name="process-chunk"/>
 
537
</xsl:template>
 
538
 
 
539
<xsl:template match="article/bibliography">
 
540
  <xsl:call-template name="process-chunk"/>
 
541
</xsl:template>
 
542
 
 
543
<xsl:template match="sect1
 
544
                     |/section
 
545
                     |section[local-name(parent::*) != 'section']">
 
546
  <xsl:choose>
 
547
    <xsl:when test=". = /section">
 
548
      <xsl:call-template name="process-chunk"/>
 
549
    </xsl:when>
 
550
    <xsl:when test="$chunk.sections = 0">
 
551
      <xsl:apply-imports/>
 
552
    </xsl:when>
 
553
    <xsl:when test="ancestor::partintro">
 
554
      <xsl:apply-imports/>
 
555
    </xsl:when>
 
556
    <xsl:when test="$chunk.first.sections = 0">
 
557
      <xsl:choose>
 
558
        <xsl:when test="count(preceding-sibling::section) &gt; 0
 
559
                        or count(preceding-sibling::sect1) &gt; 0">
 
560
          <xsl:call-template name="process-chunk"/>
 
561
        </xsl:when>
 
562
        <xsl:otherwise>
 
563
          <xsl:apply-imports/>
 
564
        </xsl:otherwise>
 
565
      </xsl:choose>
 
566
    </xsl:when>
 
567
    <xsl:otherwise>
 
568
      <xsl:call-template name="process-chunk"/>
 
569
    </xsl:otherwise>
 
570
  </xsl:choose>
 
571
</xsl:template>
 
572
 
 
573
<xsl:template match="setindex
 
574
                     |book/index
 
575
                     |article/index">
 
576
  <!-- some implementations use completely empty index tags to indicate -->
 
577
  <!-- where an automatically generated index should be inserted. so -->
 
578
  <!-- if the index is completely empty, skip it. -->
 
579
  <xsl:if test="count(*)>0 or $generate.index != '0'">
 
580
    <xsl:call-template name="process-chunk"/>
 
581
  </xsl:if>
 
582
</xsl:template>
 
583
 
 
584
<!-- ==================================================================== -->
 
585
 
 
586
<xsl:template match="/">
 
587
  <xsl:choose>
 
588
    <xsl:when test="$rootid != ''">
 
589
      <xsl:choose>
 
590
        <xsl:when test="count(id($rootid)) = 0">
 
591
          <xsl:message terminate="yes">
 
592
            <xsl:text>ID '</xsl:text>
 
593
            <xsl:value-of select="$rootid"/>
 
594
            <xsl:text>' not found in document.</xsl:text>
 
595
          </xsl:message>
 
596
        </xsl:when>
 
597
        <xsl:otherwise>
 
598
          <xsl:apply-templates select="id($rootid)"/>
 
599
        </xsl:otherwise>
 
600
      </xsl:choose>
 
601
    </xsl:when>
 
602
    <xsl:otherwise>
 
603
      <xsl:apply-templates select="/" mode="process.root"/>
 
604
    </xsl:otherwise>
 
605
  </xsl:choose>
 
606
</xsl:template>
 
607
 
 
608
<xsl:template match="*" mode="process.root">
 
609
  <xsl:apply-templates select="."/>
 
610
</xsl:template>
 
611
 
 
612
<!-- ==================================================================== -->
 
613
 
 
614
<xsl:template name="in.other.chunk">
 
615
  <xsl:param name="chunk" select="."/>
 
616
  <xsl:param name="node" select="."/>
 
617
 
 
618
  <xsl:variable name="is.chunk">
 
619
    <xsl:call-template name="chunk">
 
620
      <xsl:with-param name="node" select="$node"/>
 
621
    </xsl:call-template>
 
622
  </xsl:variable>
 
623
 
 
624
<!--
 
625
  <xsl:message>
 
626
    <xsl:text>in.other.chunk: </xsl:text>
 
627
    <xsl:value-of select="name($chunk)"/>
 
628
    <xsl:text> </xsl:text>
 
629
    <xsl:value-of select="name($node)"/>
 
630
    <xsl:text> </xsl:text>
 
631
    <xsl:value-of select="$chunk = $node"/>
 
632
    <xsl:text> </xsl:text>
 
633
    <xsl:value-of select="$is.chunk"/>
 
634
  </xsl:message>
 
635
-->
 
636
 
 
637
  <xsl:choose>
 
638
    <xsl:when test="$chunk = $node">0</xsl:when>
 
639
    <xsl:when test="$is.chunk = 1">1</xsl:when>
 
640
    <xsl:when test="count($node) = 0">0</xsl:when>
 
641
    <xsl:otherwise>
 
642
      <xsl:call-template name="in.other.chunk">
 
643
        <xsl:with-param name="chunk" select="$chunk"/>
 
644
        <xsl:with-param name="node" select="$node/parent::*"/>
 
645
      </xsl:call-template>
 
646
    </xsl:otherwise>
 
647
  </xsl:choose>
 
648
</xsl:template>
 
649
 
 
650
<xsl:template name="count.footnotes.in.this.chunk">
 
651
  <xsl:param name="node" select="."/>
 
652
  <xsl:param name="footnotes" select="$node//footnote"/>
 
653
  <xsl:param name="count" select="0"/>
 
654
 
 
655
<!--
 
656
  <xsl:message>
 
657
    <xsl:text>count.footnotes.in.this.chunk: </xsl:text>
 
658
    <xsl:value-of select="name($node)"/>
 
659
  </xsl:message>
 
660
-->
 
661
 
 
662
  <xsl:variable name="in.other.chunk">
 
663
    <xsl:call-template name="in.other.chunk">
 
664
      <xsl:with-param name="chunk" select="$node"/>
 
665
      <xsl:with-param name="node" select="$footnotes[1]"/>
 
666
    </xsl:call-template>
 
667
  </xsl:variable>
 
668
 
 
669
  <xsl:choose>
 
670
    <xsl:when test="count($footnotes) = 0">
 
671
      <xsl:value-of select="$count"/>
 
672
    </xsl:when>
 
673
    <xsl:otherwise>
 
674
      <xsl:choose>
 
675
        <xsl:when test="$in.other.chunk != 0">
 
676
          <xsl:call-template name="count.footnotes.in.this.chunk">
 
677
            <xsl:with-param name="node" select="$node"/>
 
678
            <xsl:with-param name="footnotes"
 
679
                            select="$footnotes[position() &gt; 1]"/>
 
680
            <xsl:with-param name="count" select="$count"/>
 
681
          </xsl:call-template>
 
682
        </xsl:when>
 
683
        <xsl:when test="$footnotes[1]/ancestor::table
 
684
                        |$footnotes[1]/ancestor::informaltable">
 
685
          <xsl:call-template name="count.footnotes.in.this.chunk">
 
686
            <xsl:with-param name="node" select="$node"/>
 
687
            <xsl:with-param name="footnotes"
 
688
                            select="$footnotes[position() &gt; 1]"/>
 
689
            <xsl:with-param name="count" select="$count"/>
 
690
          </xsl:call-template>
 
691
        </xsl:when>
 
692
        <xsl:otherwise>
 
693
          <xsl:call-template name="count.footnotes.in.this.chunk">
 
694
            <xsl:with-param name="node" select="$node"/>
 
695
            <xsl:with-param name="footnotes"
 
696
                            select="$footnotes[position() &gt; 1]"/>
 
697
            <xsl:with-param name="count" select="$count + 1"/>
 
698
          </xsl:call-template>
 
699
        </xsl:otherwise>
 
700
      </xsl:choose>
 
701
    </xsl:otherwise>
 
702
  </xsl:choose>
 
703
</xsl:template>
 
704
 
 
705
<xsl:template name="process.footnotes.in.this.chunk">
 
706
  <xsl:param name="node" select="."/>
 
707
  <xsl:param name="footnotes" select="$node//footnote"/>
 
708
 
 
709
<!--
 
710
  <xsl:message>process.footnotes.in.this.chunk</xsl:message>
 
711
-->
 
712
 
 
713
  <xsl:variable name="in.other.chunk">
 
714
    <xsl:call-template name="in.other.chunk">
 
715
      <xsl:with-param name="chunk" select="$node"/>
 
716
      <xsl:with-param name="node" select="$footnotes[1]"/>
 
717
    </xsl:call-template>
 
718
  </xsl:variable>
 
719
 
 
720
  <xsl:choose>
 
721
    <xsl:when test="count($footnotes) = 0">
 
722
      <!-- nop -->
 
723
    </xsl:when>
 
724
    <xsl:otherwise>
 
725
      <xsl:choose>
 
726
        <xsl:when test="$in.other.chunk != 0">
 
727
          <xsl:call-template name="process.footnotes.in.this.chunk">
 
728
            <xsl:with-param name="node" select="$node"/>
 
729
            <xsl:with-param name="footnotes"
 
730
                            select="$footnotes[position() &gt; 1]"/>
 
731
          </xsl:call-template>
 
732
        </xsl:when>
 
733
        <xsl:when test="$footnotes[1]/ancestor::table
 
734
                        |$footnotes[1]/ancestor::informaltable">
 
735
          <xsl:call-template name="process.footnotes.in.this.chunk">
 
736
            <xsl:with-param name="node" select="$node"/>
 
737
            <xsl:with-param name="footnotes"
 
738
                            select="$footnotes[position() &gt; 1]"/>
 
739
          </xsl:call-template>
 
740
        </xsl:when>
 
741
        <xsl:otherwise>
 
742
          <xsl:apply-templates select="$footnotes[1]"
 
743
                               mode="process.footnote.mode"/>
 
744
          <xsl:call-template name="process.footnotes.in.this.chunk">
 
745
            <xsl:with-param name="node" select="$node"/>
 
746
            <xsl:with-param name="footnotes"
 
747
                            select="$footnotes[position() &gt; 1]"/>
 
748
          </xsl:call-template>
 
749
        </xsl:otherwise>
 
750
      </xsl:choose>
 
751
    </xsl:otherwise>
 
752
  </xsl:choose>
 
753
</xsl:template>
 
754
 
 
755
<xsl:template name="process.footnotes">
 
756
  <xsl:variable name="footnotes" select=".//footnote"/>
 
757
  <xsl:variable name="fcount">
 
758
    <xsl:call-template name="count.footnotes.in.this.chunk">
 
759
      <xsl:with-param name="node" select="."/>
 
760
      <xsl:with-param name="footnotes" select="$footnotes"/>
 
761
    </xsl:call-template>
 
762
  </xsl:variable>
 
763
 
 
764
<!--
 
765
  <xsl:message>
 
766
    <xsl:value-of select="name(.)"/>
 
767
    <xsl:text> fcount: </xsl:text>
 
768
    <xsl:value-of select="$fcount"/>
 
769
  </xsl:message>
 
770
-->
 
771
 
 
772
  <!-- Only bother to do this if there's at least one non-table footnote -->
 
773
  <xsl:if test="$fcount &gt; 0">
 
774
    <div class="footnotes">
 
775
      <br/>
 
776
      <hr width="100" align="left"/>
 
777
      <xsl:call-template name="process.footnotes.in.this.chunk">
 
778
        <xsl:with-param name="node" select="."/>
 
779
        <xsl:with-param name="footnotes" select="$footnotes"/>
 
780
      </xsl:call-template>
 
781
    </div>
 
782
  </xsl:if>
 
783
</xsl:template>
 
784
 
 
785
<xsl:template name="process.chunk.footnotes">
 
786
  <xsl:variable name="is.chunk">
 
787
    <xsl:call-template name="chunk"/>
 
788
  </xsl:variable>
 
789
  <xsl:if test="$is.chunk = 1">
 
790
    <xsl:call-template name="process.footnotes"/>
 
791
  </xsl:if>
 
792
</xsl:template>
 
793
 
 
794
<!-- ==================================================================== -->
 
795
 
 
796
</xsl:stylesheet>