Project

General

Profile

1
<?xml version='1.0'?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4
                xmlns:stbl="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Table"
5
                xmlns:xtbl="xalan://com.nwalsh.xalan.Table"
6
                xmlns:lxslt="http://xml.apache.org/xslt"
7
                xmlns:ptbl="http://nwalsh.com/xslt/ext/xsltproc/python/Table"
8
                exclude-result-prefixes="doc stbl xtbl lxslt ptbl"
9
                version='1.0'>
10

    
11
<xsl:include href="../common/table.xsl"/>
12

    
13
<!-- ********************************************************************
14
     $Id: table.xsl 8421 2009-05-04 07:49:49Z bobstayton $
15
     ********************************************************************
16

    
17
     This file is part of the XSL DocBook Stylesheet distribution.
18
     See ../README or http://docbook.sf.net/release/xsl/current/ for
19
     copyright and other information.
20

    
21
     ******************************************************************** -->
22

    
23
<lxslt:component prefix="xtbl"
24
                 functions="adjustColumnWidths"/>
25

    
26
<xsl:template name="empty.table.cell">
27
  <xsl:param name="colnum" select="0"/>
28

    
29
  <xsl:variable name="rowsep">
30
    <xsl:choose>
31
      <!-- If this is the last row, rowsep never applies. -->
32
      <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row
33
                          or ancestor-or-self::thead/following-sibling::tbody
34
                          or ancestor-or-self::tbody/preceding-sibling::tfoot)">
35
        <xsl:value-of select="0"/>
36
      </xsl:when>
37
      <xsl:otherwise>
38
        <xsl:call-template name="inherited.table.attribute">
39
          <xsl:with-param name="entry" select="NOT-AN-ELEMENT-NAME"/>
40
          <xsl:with-param name="row" select="ancestor-or-self::row[1]"/>
41
          <xsl:with-param name="colnum" select="$colnum"/>
42
          <xsl:with-param name="attribute" select="'rowsep'"/>
43
        </xsl:call-template>
44
      </xsl:otherwise>
45
    </xsl:choose>
46
  </xsl:variable>
47

    
48
  <xsl:variable name="colsep">
49
    <xsl:choose>
50
      <!-- If this is the last column, colsep never applies. -->
51
      <xsl:when test="number($colnum) &gt;= ancestor::tgroup/@cols">0</xsl:when>
52
      <xsl:otherwise>
53
        <xsl:call-template name="inherited.table.attribute">
54
          <xsl:with-param name="entry" select="NOT-AN-ELEMENT-NAME"/>
55
          <xsl:with-param name="row" select="ancestor-or-self::row[1]"/>
56
          <xsl:with-param name="colnum" select="$colnum"/>
57
          <xsl:with-param name="attribute" select="'colsep'"/>
58
        </xsl:call-template>
59
      </xsl:otherwise>
60
    </xsl:choose>
61
  </xsl:variable>
62

    
63
  <td class="auto-generated">
64
    <xsl:if test="$table.borders.with.css != 0">
65
      <xsl:attribute name="style">
66
        <xsl:if test="$colsep &gt; 0">
67
          <xsl:call-template name="border">
68
            <xsl:with-param name="side" select="'right'"/>
69
          </xsl:call-template>
70
        </xsl:if>
71
        <xsl:if test="$rowsep &gt; 0">
72
          <xsl:call-template name="border">
73
            <xsl:with-param name="side" select="'bottom'"/>
74
          </xsl:call-template>
75
        </xsl:if>
76
      </xsl:attribute>
77
    </xsl:if>
78
    <xsl:text>&#160;</xsl:text>
79
  </td>
80
</xsl:template>
81

    
82
<!-- ==================================================================== -->
83

    
84
<xsl:template name="border">
85
  <xsl:param name="side" select="'left'"/>
86
  <xsl:param name="padding" select="0"/>
87
  <xsl:param name="style" select="$table.cell.border.style"/>
88
  <xsl:param name="color" select="$table.cell.border.color"/>
89
  <xsl:param name="thickness" select="$table.cell.border.thickness"/>
90

    
91
  <!-- Note: Some browsers (mozilla) require at least a width and style. -->
92

    
93
  <xsl:choose>
94
    <xsl:when test="($thickness != ''
95
                     and $style != ''
96
                     and $color != '')
97
                    or ($thickness != ''
98
                        and $style != '')
99
                    or ($thickness != '')">
100
      <!-- use the compound property if we can: -->
101
      <!-- it saves space and probably works more reliably -->
102
      <xsl:text>border-</xsl:text>
103
      <xsl:value-of select="$side"/>
104
      <xsl:text>: </xsl:text>
105
      <xsl:value-of select="$thickness"/>
106
      <xsl:text> </xsl:text>
107
      <xsl:value-of select="$style"/>
108
      <xsl:text> </xsl:text>
109
      <xsl:value-of select="$color"/>
110
      <xsl:text>; </xsl:text>
111
    </xsl:when>
112
    <xsl:otherwise>
113
      <!-- we need to specify the styles individually -->
114
      <xsl:if test="$thickness != ''">
115
        <xsl:text>border-</xsl:text>
116
        <xsl:value-of select="$side"/>
117
        <xsl:text>-width: </xsl:text>
118
        <xsl:value-of select="$thickness"/>
119
        <xsl:text>; </xsl:text>
120
      </xsl:if>
121

    
122
      <xsl:if test="$style != ''">
123
        <xsl:text>border-</xsl:text>
124
        <xsl:value-of select="$side"/>
125
        <xsl:text>-style: </xsl:text>
126
        <xsl:value-of select="$style"/>
127
        <xsl:text>; </xsl:text>
128
      </xsl:if>
129

    
130
      <xsl:if test="$color != ''">
131
        <xsl:text>border-</xsl:text>
132
        <xsl:value-of select="$side"/>
133
        <xsl:text>-color: </xsl:text>
134
        <xsl:value-of select="$color"/>
135
        <xsl:text>; </xsl:text>
136
      </xsl:if>
137
    </xsl:otherwise>
138
  </xsl:choose>
139
</xsl:template>
140

    
141
<!-- ==================================================================== -->
142

    
143
<xsl:template match="tgroup" name="tgroup">
144
  <xsl:if test="not(@cols) or @cols = '' or string(number(@cols)) = 'NaN'">
145
    <xsl:message terminate="yes">
146
      <xsl:text>Error: CALS tables must specify the number of columns.</xsl:text>
147
    </xsl:message>
148
  </xsl:if>
149

    
150
  <xsl:variable name="summary">
151
    <xsl:call-template name="pi.dbhtml_table-summary"/>
152
  </xsl:variable>
153

    
154
  <xsl:variable name="cellspacing">
155
    <xsl:call-template name="pi.dbhtml_cellspacing"/>
156
  </xsl:variable>
157

    
158
  <xsl:variable name="cellpadding">
159
    <xsl:call-template name="pi.dbhtml_cellpadding"/>
160
  </xsl:variable>
161

    
162
  <table>
163
    <xsl:choose>
164
      <!-- If there's a textobject/phrase for the table summary, use it -->
165
      <xsl:when test="../textobject/phrase">
166
        <xsl:attribute name="summary">
167
          <xsl:value-of select="../textobject/phrase"/>
168
        </xsl:attribute>
169
      </xsl:when>
170

    
171
      <!-- If there's a <?dbhtml table-summary="foo"?> PI, use it for
172
           the HTML table summary attribute -->
173
      <xsl:when test="$summary != ''">
174
        <xsl:attribute name="summary">
175
          <xsl:value-of select="$summary"/>
176
        </xsl:attribute>
177
      </xsl:when>
178

    
179
      <!-- Otherwise, if there's a title, use that -->
180
      <xsl:when test="../title">
181
        <xsl:attribute name="summary">
182
          <!-- This screws up on inline markup and footnotes, oh well... -->
183
          <xsl:value-of select="string(../title)"/>
184
        </xsl:attribute>
185
      </xsl:when>
186

    
187
      <!-- Otherwise, forget the whole idea -->
188
      <xsl:otherwise><!-- nevermind --></xsl:otherwise>
189
    </xsl:choose>
190

    
191
    <xsl:if test="$cellspacing != '' or $html.cellspacing != ''">
192
      <xsl:attribute name="cellspacing">
193
        <xsl:choose>
194
          <xsl:when test="$cellspacing != ''">
195
            <xsl:value-of select="$cellspacing"/>
196
          </xsl:when>
197
          <xsl:otherwise>
198
            <xsl:value-of select="$html.cellspacing"/>
199
          </xsl:otherwise>
200
        </xsl:choose>
201
      </xsl:attribute>
202
    </xsl:if>
203

    
204
    <xsl:if test="$cellpadding != '' or $html.cellpadding != ''">
205
      <xsl:attribute name="cellpadding">
206
        <xsl:choose>
207
          <xsl:when test="$cellpadding != ''">
208
            <xsl:value-of select="$cellpadding"/>
209
          </xsl:when>
210
          <xsl:otherwise>
211
            <xsl:value-of select="$html.cellpadding"/>
212
          </xsl:otherwise>
213
        </xsl:choose>
214
      </xsl:attribute>
215
    </xsl:if>
216

    
217
    <xsl:if test="../@pgwide=1 or local-name(.) = 'entrytbl'">
218
      <xsl:attribute name="width">100%</xsl:attribute>
219
    </xsl:if>
220

    
221
    <xsl:choose>
222
      <xsl:when test="$table.borders.with.css != 0">
223
        <xsl:choose>
224
          <xsl:when test="../@frame='all' or (not(../@frame) and $default.table.frame='all')">
225
            <xsl:attribute name="style">
226
              <xsl:text>border-collapse: collapse;</xsl:text>
227
              <xsl:call-template name="border">
228
                <xsl:with-param name="side" select="'top'"/>
229
                <xsl:with-param name="style" select="$table.frame.border.style"/>
230
                <xsl:with-param name="color" select="$table.frame.border.color"/>
231
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
232
              </xsl:call-template>
233
              <xsl:call-template name="border">
234
                <xsl:with-param name="side" select="'bottom'"/>
235
                <xsl:with-param name="style" select="$table.frame.border.style"/>
236
                <xsl:with-param name="color" select="$table.frame.border.color"/>
237
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
238
              </xsl:call-template>
239
              <xsl:call-template name="border">
240
                <xsl:with-param name="side" select="'left'"/>
241
                <xsl:with-param name="style" select="$table.frame.border.style"/>
242
                <xsl:with-param name="color" select="$table.frame.border.color"/>
243
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
244
              </xsl:call-template>
245
              <xsl:call-template name="border">
246
                <xsl:with-param name="side" select="'right'"/>
247
                <xsl:with-param name="style" select="$table.frame.border.style"/>
248
                <xsl:with-param name="color" select="$table.frame.border.color"/>
249
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
250
              </xsl:call-template>
251
            </xsl:attribute>
252
          </xsl:when>
253
          <xsl:when test="../@frame='topbot' or (not(../@frame) and $default.table.frame='topbot')">
254
            <xsl:attribute name="style">
255
              <xsl:text>border-collapse: collapse;</xsl:text>
256
              <xsl:call-template name="border">
257
                <xsl:with-param name="side" select="'top'"/>
258
                <xsl:with-param name="style" select="$table.frame.border.style"/>
259
                <xsl:with-param name="color" select="$table.frame.border.color"/>
260
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
261
              </xsl:call-template>
262
              <xsl:call-template name="border">
263
                <xsl:with-param name="side" select="'bottom'"/>
264
                <xsl:with-param name="style" select="$table.frame.border.style"/>
265
                <xsl:with-param name="color" select="$table.frame.border.color"/>
266
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
267
              </xsl:call-template>
268
            </xsl:attribute>
269
          </xsl:when>
270
          <xsl:when test="../@frame='top' or (not(../@frame) and $default.table.frame='top')">
271
            <xsl:attribute name="style">
272
              <xsl:text>border-collapse: collapse;</xsl:text>
273
              <xsl:call-template name="border">
274
                <xsl:with-param name="side" select="'top'"/>
275
                <xsl:with-param name="style" select="$table.frame.border.style"/>
276
                <xsl:with-param name="color" select="$table.frame.border.color"/>
277
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
278
              </xsl:call-template>
279
            </xsl:attribute>
280
          </xsl:when>
281
          <xsl:when test="../@frame='bottom' or (not(../@frame) and $default.table.frame='bottom')">
282
            <xsl:attribute name="style">
283
              <xsl:text>border-collapse: collapse;</xsl:text>
284
              <xsl:call-template name="border">
285
                <xsl:with-param name="side" select="'bottom'"/>
286
                <xsl:with-param name="style" select="$table.frame.border.style"/>
287
                <xsl:with-param name="color" select="$table.frame.border.color"/>
288
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
289
              </xsl:call-template>
290
            </xsl:attribute>
291
          </xsl:when>
292
          <xsl:when test="../@frame='sides' or (not(../@frame) and $default.table.frame='sides')">
293
            <xsl:attribute name="style">
294
              <xsl:text>border-collapse: collapse;</xsl:text>
295
              <xsl:call-template name="border">
296
                <xsl:with-param name="side" select="'left'"/>
297
                <xsl:with-param name="style" select="$table.frame.border.style"/>
298
                <xsl:with-param name="color" select="$table.frame.border.color"/>
299
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
300
              </xsl:call-template>
301
              <xsl:call-template name="border">
302
                <xsl:with-param name="side" select="'right'"/>
303
                <xsl:with-param name="style" select="$table.frame.border.style"/>
304
                <xsl:with-param name="color" select="$table.frame.border.color"/>
305
                <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
306
              </xsl:call-template>
307
            </xsl:attribute>
308
          </xsl:when>
309
          <xsl:when test="../@frame='none'">
310
            <xsl:attribute name="style">
311
              <xsl:text>border: none;</xsl:text>
312
            </xsl:attribute>
313
          </xsl:when>
314
          <xsl:otherwise>
315
            <xsl:attribute name="style">
316
              <xsl:text>border-collapse: collapse;</xsl:text>
317
            </xsl:attribute>
318
          </xsl:otherwise>
319
        </xsl:choose>
320

    
321
      </xsl:when>
322
      <xsl:when test="../@frame='none' or (not(../@frame) and $default.table.frame='none') or local-name(.) = 'entrytbl'">
323
        <xsl:attribute name="border">0</xsl:attribute>
324
      </xsl:when>
325
      <xsl:otherwise>
326
        <xsl:attribute name="border">1</xsl:attribute>
327
      </xsl:otherwise>
328
    </xsl:choose>
329

    
330
    <xsl:variable name="colgroup">
331
      <colgroup>
332
        <xsl:call-template name="generate.colgroup">
333
          <xsl:with-param name="cols" select="@cols"/>
334
        </xsl:call-template>
335
      </colgroup>
336
    </xsl:variable>
337

    
338
    <xsl:variable name="explicit.table.width">
339
      <xsl:call-template name="pi.dbhtml_table-width">
340
        <xsl:with-param name="node" select=".."/>
341
      </xsl:call-template>
342
    </xsl:variable>
343

    
344
    <xsl:variable name="table.width">
345
      <xsl:choose>
346
        <xsl:when test="$explicit.table.width != ''">
347
          <xsl:value-of select="$explicit.table.width"/>
348
        </xsl:when>
349
        <xsl:when test="$default.table.width = ''">
350
          <xsl:text>100%</xsl:text>
351
        </xsl:when>
352
        <xsl:otherwise>
353
          <xsl:value-of select="$default.table.width"/>
354
        </xsl:otherwise>
355
      </xsl:choose>
356
    </xsl:variable>
357

    
358
    <xsl:if test="$default.table.width != ''
359
                  or $explicit.table.width != ''">
360
      <xsl:attribute name="width">
361
        <xsl:choose>
362
          <xsl:when test="contains($table.width, '%')">
363
            <xsl:value-of select="$table.width"/>
364
          </xsl:when>
365
          <xsl:when test="$use.extensions != 0
366
                          and $tablecolumns.extension != 0">
367
            <xsl:choose>
368
              <xsl:when test="function-available('stbl:convertLength')">
369
                <xsl:value-of select="stbl:convertLength($table.width)"/>
370
              </xsl:when>
371
              <xsl:when test="function-available('xtbl:convertLength')">
372
                <xsl:value-of select="xtbl:convertLength($table.width)"/>
373
              </xsl:when>
374
              <xsl:otherwise>
375
                <xsl:message terminate="yes">
376
                  <xsl:text>No convertLength function available.</xsl:text>
377
                </xsl:message>
378
              </xsl:otherwise>
379
            </xsl:choose>
380
          </xsl:when>
381
          <xsl:otherwise>
382
            <xsl:value-of select="$table.width"/>
383
          </xsl:otherwise>
384
        </xsl:choose>
385
      </xsl:attribute>
386
    </xsl:if>
387

    
388
    <xsl:choose>
389
      <xsl:when test="$use.extensions != 0
390
                      and $tablecolumns.extension != 0">
391
        <xsl:choose>
392
          <xsl:when test="function-available('stbl:adjustColumnWidths')">
393
            <xsl:copy-of select="stbl:adjustColumnWidths($colgroup)"/>
394
          </xsl:when>
395
          <xsl:when test="function-available('xtbl:adjustColumnWidths')">
396
            <xsl:copy-of select="xtbl:adjustColumnWidths($colgroup)"/>
397
          </xsl:when>
398
          <xsl:when test="function-available('ptbl:adjustColumnWidths')">
399
            <xsl:copy-of select="ptbl:adjustColumnWidths($colgroup)"/>
400
          </xsl:when>
401
          <xsl:otherwise>
402
            <xsl:message terminate="yes">
403
              <xsl:text>No adjustColumnWidths function available.</xsl:text>
404
            </xsl:message>
405
          </xsl:otherwise>
406
        </xsl:choose>
407
      </xsl:when>
408
      <xsl:otherwise>
409
        <xsl:copy-of select="$colgroup"/>
410
      </xsl:otherwise>
411
    </xsl:choose>
412

    
413
    <xsl:apply-templates select="thead"/>
414
    <xsl:apply-templates select="tfoot"/>
415
    <xsl:apply-templates select="tbody"/>
416

    
417
    <xsl:if test=".//footnote|../title//footnote">
418
      <tbody class="footnotes">
419
        <tr>
420
          <td colspan="{@cols}">
421
            <xsl:apply-templates select=".//footnote|../title//footnote" mode="table.footnote.mode"/>
422
          </td>
423
        </tr>
424
      </tbody>
425
    </xsl:if>
426
  </table>
427
</xsl:template>
428

    
429
<xsl:template match="tgroup/processing-instruction('dbhtml')">
430
  <xsl:variable name="summary">
431
    <xsl:call-template name="pi.dbhtml_table-summary"/>
432
  </xsl:variable>
433

    
434
  <!-- Suppress the table-summary PI -->
435
  <xsl:if test="$summary = ''">
436
    <xsl:processing-instruction name="dbhtml">
437
      <xsl:value-of select="."/>
438
    </xsl:processing-instruction>
439
  </xsl:if>
440
</xsl:template>
441

    
442
<xsl:template match="colspec"></xsl:template>
443

    
444
<xsl:template match="spanspec"></xsl:template>
445

    
446
<xsl:template match="thead|tfoot">
447
  <xsl:element name="{local-name(.)}">
448
    <xsl:if test="@align">
449
      <xsl:attribute name="align">
450
        <xsl:value-of select="@align"/>
451
      </xsl:attribute>
452
    </xsl:if>
453
    <xsl:if test="@char">
454
      <xsl:attribute name="char">
455
        <xsl:value-of select="@char"/>
456
      </xsl:attribute>
457
    </xsl:if>
458
    <xsl:if test="@charoff">
459
      <xsl:attribute name="charoff">
460
        <xsl:value-of select="@charoff"/>
461
      </xsl:attribute>
462
    </xsl:if>
463
    <xsl:if test="@valign">
464
      <xsl:attribute name="valign">
465
        <xsl:value-of select="@valign"/>
466
      </xsl:attribute>
467
    </xsl:if>
468

    
469
    <xsl:apply-templates select="row[1]">
470
      <xsl:with-param name="spans">
471
        <xsl:call-template name="blank.spans">
472
          <xsl:with-param name="cols" select="../@cols"/>
473
        </xsl:call-template>
474
      </xsl:with-param>
475
    </xsl:apply-templates>
476

    
477
  </xsl:element>
478
</xsl:template>
479

    
480
<xsl:template match="tbody">
481
  <tbody>
482
    <xsl:if test="@align">
483
      <xsl:attribute name="align">
484
        <xsl:value-of select="@align"/>
485
      </xsl:attribute>
486
    </xsl:if>
487
    <xsl:if test="@char">
488
      <xsl:attribute name="char">
489
        <xsl:value-of select="@char"/>
490
      </xsl:attribute>
491
    </xsl:if>
492
    <xsl:if test="@charoff">
493
      <xsl:attribute name="charoff">
494
        <xsl:value-of select="@charoff"/>
495
      </xsl:attribute>
496
    </xsl:if>
497
    <xsl:if test="@valign">
498
      <xsl:attribute name="valign">
499
        <xsl:value-of select="@valign"/>
500
      </xsl:attribute>
501
    </xsl:if>
502

    
503
    <xsl:apply-templates select="row[1]">
504
      <xsl:with-param name="spans">
505
        <xsl:call-template name="blank.spans">
506
          <xsl:with-param name="cols" select="../@cols"/>
507
        </xsl:call-template>
508
      </xsl:with-param>
509
    </xsl:apply-templates>
510

    
511
  </tbody>
512
</xsl:template>
513

    
514
<xsl:template match="row">
515
  <xsl:param name="spans"/>
516

    
517
  <xsl:choose>
518
    <xsl:when test="contains($spans, '0')">
519
      <xsl:call-template name="normal-row">
520
        <xsl:with-param name="spans" select="$spans"/>
521
      </xsl:call-template>
522
    </xsl:when>
523
    <xsl:otherwise>
524
      <!--
525
      <xsl:message>
526
        <xsl:text>Ignoring row: </xsl:text>
527
        <xsl:value-of select="$spans"/>
528
        <xsl:text> = </xsl:text>
529
        <xsl:call-template name="consume-row">
530
          <xsl:with-param name="spans" select="$spans"/>
531
        </xsl:call-template>
532
      </xsl:message>
533
      -->
534

    
535
      <xsl:if test="normalize-space(.//text()) != ''">
536
        <xsl:message>Warning: overlapped row contains content!</xsl:message>
537
      </xsl:if>
538

    
539
      <tr><xsl:comment> This row intentionally left blank </xsl:comment></tr>
540

    
541
      <xsl:apply-templates select="following-sibling::row[1]">
542
        <xsl:with-param name="spans">
543
          <xsl:call-template name="consume-row">
544
            <xsl:with-param name="spans" select="$spans"/>
545
          </xsl:call-template>
546
        </xsl:with-param>
547
      </xsl:apply-templates>
548
    </xsl:otherwise>
549
  </xsl:choose>
550
</xsl:template>
551

    
552
<xsl:template name="normal-row">
553
  <xsl:param name="spans"/>
554

    
555
  <xsl:variable name="row-height">
556
    <xsl:if test="processing-instruction('dbhtml')">
557
      <xsl:call-template name="pi.dbhtml_row-height"/>
558
    </xsl:if>
559
  </xsl:variable>
560

    
561
  <xsl:variable name="bgcolor">
562
    <xsl:if test="processing-instruction('dbhtml')">
563
      <xsl:call-template name="pi.dbhtml_bgcolor"/>
564
    </xsl:if>
565
  </xsl:variable>
566

    
567
  <xsl:variable name="class">
568
    <xsl:if test="processing-instruction('dbhtml')">
569
      <xsl:call-template name="pi.dbhtml_class"/>
570
    </xsl:if>
571
  </xsl:variable>
572

    
573
  <tr>
574
    <xsl:call-template name="tr.attributes">
575
      <xsl:with-param name="rownum">
576
        <xsl:number from="tgroup" count="row"/>
577
      </xsl:with-param>
578
    </xsl:call-template>
579

    
580
    <xsl:if test="$row-height != ''">
581
      <xsl:attribute name="height">
582
        <xsl:value-of select="$row-height"/>
583
      </xsl:attribute>
584
    </xsl:if>
585

    
586
    <xsl:if test="$bgcolor != ''">
587
      <xsl:attribute name="bgcolor">
588
        <xsl:value-of select="$bgcolor"/>
589
      </xsl:attribute>
590
    </xsl:if>
591

    
592
    <xsl:if test="$class != ''">
593
      <xsl:attribute name="class">
594
        <xsl:value-of select="$class"/>
595
      </xsl:attribute>
596
    </xsl:if>
597

    
598
    <xsl:if test="$table.borders.with.css != 0">
599
      <xsl:if test="@rowsep = 1 and following-sibling::row">
600
        <xsl:attribute name="style">
601
          <xsl:call-template name="border">
602
            <xsl:with-param name="side" select="'bottom'"/>
603
          </xsl:call-template>
604
        </xsl:attribute>
605
      </xsl:if>
606
    </xsl:if>
607

    
608
    <xsl:if test="@align">
609
      <xsl:attribute name="align">
610
        <xsl:value-of select="@align"/>
611
      </xsl:attribute>
612
    </xsl:if>
613
    <xsl:if test="@char">
614
      <xsl:attribute name="char">
615
        <xsl:value-of select="@char"/>
616
      </xsl:attribute>
617
    </xsl:if>
618
    <xsl:if test="@charoff">
619
      <xsl:attribute name="charoff">
620
        <xsl:value-of select="@charoff"/>
621
      </xsl:attribute>
622
    </xsl:if>
623
    <xsl:if test="@valign">
624
      <xsl:attribute name="valign">
625
        <xsl:value-of select="@valign"/>
626
      </xsl:attribute>
627
    </xsl:if>
628

    
629
    <xsl:apply-templates select="(entry|entrytbl)[1]">
630
      <xsl:with-param name="spans" select="$spans"/>
631
    </xsl:apply-templates>
632
  </tr>
633

    
634
  <xsl:if test="following-sibling::row">
635
    <xsl:variable name="nextspans">
636
      <xsl:apply-templates select="(entry|entrytbl)[1]" mode="span">
637
        <xsl:with-param name="spans" select="$spans"/>
638
      </xsl:apply-templates>
639
    </xsl:variable>
640

    
641
    <xsl:apply-templates select="following-sibling::row[1]">
642
      <xsl:with-param name="spans" select="$nextspans"/>
643
    </xsl:apply-templates>
644
  </xsl:if>
645
</xsl:template>
646

    
647
<xsl:template match="entry|entrytbl" name="entry">
648
  <xsl:param name="col">
649
    <xsl:choose>
650
      <xsl:when test="@revisionflag">
651
        <xsl:number from="row"/>
652
      </xsl:when>
653
      <xsl:otherwise>1</xsl:otherwise>
654
    </xsl:choose>
655
  </xsl:param>
656

    
657
  <xsl:param name="spans"/>
658

    
659
  <xsl:variable name="cellgi">
660
    <xsl:choose>
661
      <xsl:when test="ancestor::thead">th</xsl:when>
662
      <xsl:when test="ancestor::tfoot">th</xsl:when>
663
      <xsl:otherwise>td</xsl:otherwise>
664
    </xsl:choose>
665
  </xsl:variable>
666

    
667
  <xsl:variable name="empty.cell" select="count(node()) = 0"/>
668

    
669
  <xsl:variable name="named.colnum">
670
    <xsl:call-template name="entry.colnum"/>
671
  </xsl:variable>
672

    
673
  <xsl:variable name="entry.colnum">
674
    <xsl:choose>
675
      <xsl:when test="$named.colnum &gt; 0">
676
        <xsl:value-of select="$named.colnum"/>
677
      </xsl:when>
678
      <xsl:otherwise>
679
        <xsl:value-of select="$col"/>
680
      </xsl:otherwise>
681
    </xsl:choose>
682
  </xsl:variable>
683

    
684
  <xsl:variable name="entry.colspan">
685
    <xsl:choose>
686
      <xsl:when test="@spanname or @namest">
687
        <xsl:call-template name="calculate.colspan"/>
688
      </xsl:when>
689
      <xsl:otherwise>1</xsl:otherwise>
690
    </xsl:choose>
691
  </xsl:variable>
692

    
693
  <xsl:variable name="following.spans">
694
    <xsl:call-template name="calculate.following.spans">
695
      <xsl:with-param name="colspan" select="$entry.colspan"/>
696
      <xsl:with-param name="spans" select="$spans"/>
697
    </xsl:call-template>
698
  </xsl:variable>
699

    
700
  <xsl:variable name="rowsep">
701
    <xsl:choose>
702
      <!-- If this is the last row, rowsep never applies. -->
703
      <xsl:when test="ancestor::entrytbl
704
                      and not (ancestor-or-self::row[1]/following-sibling::row)
705
                      and not (ancestor::thead)">
706
        <xsl:value-of select="0"/>
707
      </xsl:when>
708
      <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row
709
                          or ancestor-or-self::thead/following-sibling::tbody
710
                          or ancestor-or-self::tbody/preceding-sibling::tfoot)">
711
        <xsl:value-of select="0"/>
712
      </xsl:when>
713
      <xsl:when test="@morerows and not(@morerows &lt; 
714
                 count(ancestor-or-self::row[1]/following-sibling::row))">
715
        <xsl:value-of select="0"/>
716
      </xsl:when>
717
      <xsl:otherwise>
718
        <xsl:call-template name="inherited.table.attribute">
719
          <xsl:with-param name="entry" select="."/>
720
          <xsl:with-param name="colnum" select="$entry.colnum"/>
721
          <xsl:with-param name="attribute" select="'rowsep'"/>
722
        </xsl:call-template>
723
      </xsl:otherwise>
724
    </xsl:choose>
725
  </xsl:variable>
726

    
727
  <xsl:variable name="colsep">
728
    <xsl:choose>
729
      <!-- If this is the last column, colsep never applies. -->
730
      <xsl:when test="$following.spans = ''">0</xsl:when>
731
      <xsl:otherwise>
732
        <xsl:call-template name="inherited.table.attribute">
733
          <xsl:with-param name="entry" select="."/>
734
          <xsl:with-param name="colnum" select="$entry.colnum"/>
735
          <xsl:with-param name="attribute" select="'colsep'"/>
736
        </xsl:call-template>
737
      </xsl:otherwise>
738
    </xsl:choose>
739
  </xsl:variable>
740

    
741
  <xsl:variable name="valign">
742
    <xsl:call-template name="inherited.table.attribute">
743
      <xsl:with-param name="entry" select="."/>
744
      <xsl:with-param name="colnum" select="$entry.colnum"/>
745
      <xsl:with-param name="attribute" select="'valign'"/>
746
    </xsl:call-template>
747
  </xsl:variable>
748

    
749
  <xsl:variable name="align">
750
    <xsl:call-template name="inherited.table.attribute">
751
      <xsl:with-param name="entry" select="."/>
752
      <xsl:with-param name="colnum" select="$entry.colnum"/>
753
      <xsl:with-param name="attribute" select="'align'"/>
754
    </xsl:call-template>
755
  </xsl:variable>
756

    
757
  <xsl:variable name="char">
758
    <xsl:call-template name="inherited.table.attribute">
759
      <xsl:with-param name="entry" select="."/>
760
      <xsl:with-param name="colnum" select="$entry.colnum"/>
761
      <xsl:with-param name="attribute" select="'char'"/>
762
    </xsl:call-template>
763
  </xsl:variable>
764

    
765
  <xsl:variable name="charoff">
766
    <xsl:call-template name="inherited.table.attribute">
767
      <xsl:with-param name="entry" select="."/>
768
      <xsl:with-param name="colnum" select="$entry.colnum"/>
769
      <xsl:with-param name="attribute" select="'charoff'"/>
770
    </xsl:call-template>
771
  </xsl:variable>
772

    
773
  <xsl:choose>
774
    <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
775
      <xsl:call-template name="entry">
776
        <xsl:with-param name="col" select="$col+1"/>
777
        <xsl:with-param name="spans" select="substring-after($spans,':')"/>
778
      </xsl:call-template>
779
    </xsl:when>
780

    
781
    <xsl:when test="number($entry.colnum) &gt; $col">
782
      <xsl:call-template name="empty.table.cell"/>
783
      <xsl:call-template name="entry">
784
        <xsl:with-param name="col" select="$col+1"/>
785
        <xsl:with-param name="spans" select="substring-after($spans,':')"/>
786
      </xsl:call-template>
787
    </xsl:when>
788

    
789
    <xsl:otherwise>
790
      <xsl:variable name="bgcolor">
791
        <xsl:if test="processing-instruction('dbhtml')">
792
          <xsl:call-template name="pi.dbhtml_bgcolor"/>
793
        </xsl:if>
794
      </xsl:variable>
795

    
796
      <xsl:element name="{$cellgi}">
797
        <xsl:if test="$bgcolor != ''">
798
          <xsl:attribute name="bgcolor">
799
            <xsl:value-of select="$bgcolor"/>
800
          </xsl:attribute>
801
        </xsl:if>
802

    
803
        <xsl:call-template name="locale.html.attributes"/>
804
        <xsl:if test="$entry.propagates.style != 0 and @role">
805
          <xsl:apply-templates select="." mode="class.attribute">
806
            <xsl:with-param name="class" select="@role"/>
807
          </xsl:apply-templates>
808
        </xsl:if>
809

    
810
        <xsl:if test="$show.revisionflag and @revisionflag">
811
          <xsl:attribute name="class">
812
            <xsl:value-of select="@revisionflag"/>
813
          </xsl:attribute>
814
        </xsl:if>
815

    
816
        <xsl:if test="$table.borders.with.css != 0">
817
          <xsl:attribute name="style">
818
            <xsl:if test="$colsep &gt; 0">
819
              <xsl:call-template name="border">
820
                <xsl:with-param name="side" select="'right'"/>
821
              </xsl:call-template>
822
            </xsl:if>
823
            <xsl:if test="$rowsep &gt; 0">
824
              <xsl:call-template name="border">
825
                <xsl:with-param name="side" select="'bottom'"/>
826
              </xsl:call-template>
827
            </xsl:if>
828
          </xsl:attribute>
829
        </xsl:if>
830

    
831
        <xsl:if test="@morerows &gt; 0">
832
          <xsl:attribute name="rowspan">
833
            <xsl:value-of select="1+@morerows"/>
834
          </xsl:attribute>
835
        </xsl:if>
836

    
837
        <xsl:if test="$entry.colspan &gt; 1">
838
          <xsl:attribute name="colspan">
839
            <xsl:value-of select="$entry.colspan"/>
840
          </xsl:attribute>
841
        </xsl:if>
842

    
843
        <xsl:if test="$align != ''">
844
          <xsl:attribute name="align">
845
            <xsl:value-of select="$align"/>
846
          </xsl:attribute>
847
        </xsl:if>
848

    
849
        <xsl:if test="$valign != ''">
850
          <xsl:attribute name="valign">
851
            <xsl:value-of select="$valign"/>
852
          </xsl:attribute>
853
        </xsl:if>
854

    
855
        <xsl:if test="$char != ''">
856
          <xsl:attribute name="char">
857
            <xsl:value-of select="$char"/>
858
          </xsl:attribute>
859
        </xsl:if>
860

    
861
        <xsl:if test="$charoff != ''">
862
          <xsl:attribute name="charoff">
863
            <xsl:value-of select="$charoff"/>
864
          </xsl:attribute>
865
        </xsl:if>
866

    
867
        <xsl:if test="not(preceding-sibling::*) and 
868
                    (ancestor::row[1]/@id or ancestor::row[1]/@xml:id)">
869
          <xsl:call-template name="anchor">
870
            <xsl:with-param name="node" select="ancestor::row[1]"/>
871
          </xsl:call-template>
872
        </xsl:if>
873

    
874
        <xsl:call-template name="anchor"/>
875

    
876
        <xsl:choose>
877
          <xsl:when test="$empty.cell">
878
            <xsl:text>&#160;</xsl:text>
879
          </xsl:when>
880
          <xsl:when test="self::entrytbl">
881
            <xsl:call-template name="tgroup"/>
882
          </xsl:when>
883
          <xsl:otherwise>
884
            <xsl:apply-templates/>
885
          </xsl:otherwise>
886
        </xsl:choose>
887
      </xsl:element>
888

    
889
      <xsl:choose>
890
        <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
891
          <xsl:apply-templates select="(following-sibling::entry
892
                                       |following-sibling::entrytbl)[1]">
893
            <xsl:with-param name="col" select="$col+$entry.colspan"/>
894
            <xsl:with-param name="spans" select="$following.spans"/>
895
          </xsl:apply-templates>
896
        </xsl:when>
897
        <xsl:otherwise>
898
          <xsl:call-template name="finaltd">
899
            <xsl:with-param name="spans" select="$following.spans"/>
900
            <xsl:with-param name="col" select="$col+$entry.colspan"/>
901
          </xsl:call-template>
902
        </xsl:otherwise>
903
      </xsl:choose>
904
    </xsl:otherwise>
905
  </xsl:choose>
906
</xsl:template>
907

    
908
<xsl:template match="entry|entrytbl" name="sentry" mode="span">
909
  <xsl:param name="col" select="1"/>
910
  <xsl:param name="spans"/>
911

    
912
  <xsl:variable name="entry.colnum">
913
    <xsl:call-template name="entry.colnum"/>
914
  </xsl:variable>
915

    
916
  <xsl:variable name="entry.colspan">
917
    <xsl:choose>
918
      <xsl:when test="@spanname or @namest">
919
        <xsl:call-template name="calculate.colspan"/>
920
      </xsl:when>
921
      <xsl:otherwise>1</xsl:otherwise>
922
    </xsl:choose>
923
  </xsl:variable>
924

    
925
  <xsl:variable name="following.spans">
926
    <xsl:call-template name="calculate.following.spans">
927
      <xsl:with-param name="colspan" select="$entry.colspan"/>
928
      <xsl:with-param name="spans" select="$spans"/>
929
    </xsl:call-template>
930
  </xsl:variable>
931

    
932
  <xsl:choose>
933
    <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
934
      <xsl:value-of select="substring-before($spans,':')-1"/>
935
      <xsl:text>:</xsl:text>
936
      <xsl:call-template name="sentry">
937
        <xsl:with-param name="col" select="$col+1"/>
938
        <xsl:with-param name="spans" select="substring-after($spans,':')"/>
939
      </xsl:call-template>
940
    </xsl:when>
941

    
942
    <xsl:when test="number($entry.colnum) &gt; $col">
943
      <xsl:text>0:</xsl:text>
944
      <xsl:call-template name="sentry">
945
        <xsl:with-param name="col" select="$col + 1"/>
946
        <xsl:with-param name="spans" select="substring-after($spans,':')"/>
947
      </xsl:call-template>
948
    </xsl:when>
949

    
950
    <xsl:otherwise>
951
      <xsl:call-template name="copy-string">
952
        <xsl:with-param name="count" select="$entry.colspan"/>
953
        <xsl:with-param name="string">
954
          <xsl:choose>
955
            <xsl:when test="@morerows">
956
              <xsl:value-of select="@morerows"/>
957
            </xsl:when>
958
            <xsl:otherwise>0</xsl:otherwise>
959
          </xsl:choose>
960
          <xsl:text>:</xsl:text>
961
        </xsl:with-param>
962
      </xsl:call-template>
963

    
964
      <xsl:choose>
965
        <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
966
          <xsl:apply-templates select="(following-sibling::entry
967
                                        |following-sibling::entrytbl)[1]"
968
                               mode="span">
969
            <xsl:with-param name="col" select="$col+$entry.colspan"/>
970
            <xsl:with-param name="spans" select="$following.spans"/>
971
          </xsl:apply-templates>
972
        </xsl:when>
973
        <xsl:otherwise>
974
          <xsl:call-template name="sfinaltd">
975
            <xsl:with-param name="spans" select="$following.spans"/>
976
          </xsl:call-template>
977
        </xsl:otherwise>
978
      </xsl:choose>
979
    </xsl:otherwise>
980
  </xsl:choose>
981
</xsl:template>
982

    
983
<xsl:template name="generate.colgroup">
984
  <xsl:param name="cols" select="1"/>
985
  <xsl:param name="count" select="1"/>
986
  <xsl:choose>
987
    <xsl:when test="$count &gt; $cols"></xsl:when>
988
    <xsl:otherwise>
989
      <xsl:call-template name="generate.col">
990
        <xsl:with-param name="countcol" select="$count"/>
991
      </xsl:call-template>
992
      <xsl:call-template name="generate.colgroup">
993
        <xsl:with-param name="cols" select="$cols"/>
994
        <xsl:with-param name="count" select="$count+1"/>
995
      </xsl:call-template>
996
    </xsl:otherwise>
997
  </xsl:choose>
998
</xsl:template>
999

    
1000
<xsl:template name="generate.col">
1001
  <xsl:param name="countcol">1</xsl:param>
1002
  <xsl:param name="colspecs" select="./colspec"/>
1003
  <xsl:param name="count">1</xsl:param>
1004
  <xsl:param name="colnum">1</xsl:param>
1005

    
1006
  <xsl:choose>
1007
    <xsl:when test="$count>count($colspecs)">
1008
      <col/>
1009
    </xsl:when>
1010
    <xsl:otherwise>
1011
      <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1012
      <xsl:variable name="colspec.colnum">
1013
        <xsl:choose>
1014
          <xsl:when test="$colspec/@colnum">
1015
            <xsl:value-of select="$colspec/@colnum"/>
1016
          </xsl:when>
1017
          <xsl:otherwise>
1018
            <xsl:value-of select="$colnum"/>
1019
          </xsl:otherwise>
1020
        </xsl:choose>
1021
      </xsl:variable>
1022

    
1023
      <xsl:choose>
1024
        <xsl:when test="$colspec.colnum=$countcol">
1025
          <col>
1026
            <xsl:choose>
1027
              <xsl:when test="$colspec/@colwidth
1028
                            and $use.extensions != 0
1029
                            and $tablecolumns.extension != 0">
1030
                <xsl:attribute name="width">
1031
                  <xsl:choose>
1032
                    <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1033
                      <xsl:value-of select="'1*'"/>
1034
                    </xsl:when>
1035
                    <xsl:otherwise>
1036
                      <xsl:value-of select="$colspec/@colwidth"/>
1037
                    </xsl:otherwise>
1038
                  </xsl:choose>
1039
                </xsl:attribute>
1040
              </xsl:when>
1041
              <!-- pass through to HTML if no * in colspecs -->
1042
              <xsl:when test="$colspec/@colwidth and
1043
                             not($colspec/parent::*/colspec/@colwidth[contains(.,'*')])">
1044
                <xsl:attribute name="width">
1045
                  <xsl:choose>
1046
                    <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1047
                      <xsl:value-of select="'1*'"/>
1048
                    </xsl:when>
1049
                    <xsl:otherwise>
1050
                      <xsl:value-of select="$colspec/@colwidth"/>
1051
                    </xsl:otherwise>
1052
                  </xsl:choose>
1053
                </xsl:attribute>
1054
              </xsl:when>
1055
            </xsl:choose>
1056

    
1057
            <xsl:choose>
1058
              <xsl:when test="$colspec/@align">
1059
                <xsl:attribute name="align">
1060
                  <xsl:value-of select="$colspec/@align"/>
1061
                </xsl:attribute>
1062
              </xsl:when>
1063
              <!-- Suggested by Pavel ZAMPACH <zampach@nemcb.cz> -->
1064
              <xsl:when test="$colspecs/ancestor::tgroup/@align">
1065
                <xsl:attribute name="align">
1066
                  <xsl:value-of select="$colspecs/ancestor::tgroup/@align"/>
1067
                </xsl:attribute>
1068
              </xsl:when>
1069
            </xsl:choose>
1070

    
1071
            <xsl:if test="$colspec/@char">
1072
              <xsl:attribute name="char">
1073
                <xsl:value-of select="$colspec/@char"/>
1074
              </xsl:attribute>
1075
            </xsl:if>
1076
            <xsl:if test="$colspec/@charoff">
1077
              <xsl:attribute name="charoff">
1078
                <xsl:value-of select="$colspec/@charoff"/>
1079
              </xsl:attribute>
1080
            </xsl:if>
1081
          </col>
1082
        </xsl:when>
1083
        <xsl:otherwise>
1084
          <xsl:call-template name="generate.col">
1085
            <xsl:with-param name="countcol" select="$countcol"/>
1086
            <xsl:with-param name="colspecs" select="$colspecs"/>
1087
            <xsl:with-param name="count" select="$count+1"/>
1088
            <xsl:with-param name="colnum">
1089
              <xsl:choose>
1090
                <xsl:when test="$colspec/@colnum">
1091
                  <xsl:value-of select="$colspec/@colnum + 1"/>
1092
                </xsl:when>
1093
                <xsl:otherwise>
1094
                  <xsl:value-of select="$colnum + 1"/>
1095
                </xsl:otherwise>
1096
              </xsl:choose>
1097
            </xsl:with-param>
1098
           </xsl:call-template>
1099
        </xsl:otherwise>
1100
      </xsl:choose>
1101
    </xsl:otherwise>
1102
  </xsl:choose>
1103
</xsl:template>
1104

    
1105
<xsl:template name="colspec.colwidth">
1106
  <!-- when this macro is called, the current context must be an entry -->
1107
  <xsl:param name="colname"></xsl:param>
1108
  <!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
1109
  <xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
1110
  <xsl:param name="count">1</xsl:param>
1111
  <xsl:choose>
1112
    <xsl:when test="$count>count($colspecs)"></xsl:when>
1113
    <xsl:otherwise>
1114
      <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1115
      <xsl:choose>
1116
        <xsl:when test="$colspec/@colname=$colname">
1117
          <xsl:value-of select="$colspec/@colwidth"/>
1118
        </xsl:when>
1119
        <xsl:otherwise>
1120
          <xsl:call-template name="colspec.colwidth">
1121
            <xsl:with-param name="colname" select="$colname"/>
1122
            <xsl:with-param name="colspecs" select="$colspecs"/>
1123
            <xsl:with-param name="count" select="$count+1"/>
1124
          </xsl:call-template>
1125
        </xsl:otherwise>
1126
      </xsl:choose>
1127
    </xsl:otherwise>
1128
  </xsl:choose>
1129
</xsl:template>
1130

    
1131
<!-- ====================================================================== -->
1132

    
1133
<xsl:template name="tr.attributes">
1134
  <xsl:param name="row" select="."/>
1135
  <xsl:param name="rownum" select="0"/>
1136

    
1137
  <!-- by default, do nothing. But you might want to say:
1138

    
1139
  <xsl:if test="$rownum mod 2 = 0">
1140
    <xsl:attribute name="class">oddrow</xsl:attribute>
1141
  </xsl:if>
1142

    
1143
  -->
1144
</xsl:template>
1145

    
1146
</xsl:stylesheet>
1147

    
(33-33/39)