~ubuntu-branches/ubuntu/precise/dblatex/precise

« back to all changes in this revision

Viewing changes to xsl/htmltbl.xsl

  • Committer: Package Import Robot
  • Author(s): Andreas Hoenen
  • Date: 2011-07-09 15:20:37 UTC
  • mfrom: (0.8.1) (0.6.2) (8.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: package-import@ubuntu.com-20110709152037-8ao9l07dmgyjn6vn
* New upstram release
* New upstream release fixes the following open Debian BTS issues:
  + Don't crash on XeTeX backend compilation of spanish documents with an
    <appendix> element.  Thanks to W. Martin Borgert for reporting.
    Closes: #629110
* Remove patches that have been integrated upstream:
  + 20_filename_replaceable.patch (#623590)
* Take over actualized copyright period of upstream COPYRIGHT to
  debian/copyright.
* Replace python build helper dh_pysupport with dh_python2.
* In draft mode set draft watermark for XeTeX backend, too.  Thanks to W.
  Martin Borgert for reporting and for the patch.  Closes: #629514

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version='1.0' encoding="utf-8" ?>
 
2
 
 
3
<xsl:stylesheet
 
4
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
5
    xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
 
6
    xmlns:exsl="http://exslt.org/common"
 
7
    exclude-result-prefixes="doc exsl" version='1.0'>
 
8
 
 
9
<xsl:param name="default.table.rules">none</xsl:param>
 
10
 
 
11
 
 
12
 
 
13
<xsl:template match="table|informaltable" mode="htmlTable">
 
14
  <xsl:param name="tabletype">tabular</xsl:param>
 
15
  <xsl:param name="tablewidth">\linewidth-2\tabcolsep</xsl:param>
 
16
  <xsl:param name="tableframe">all</xsl:param>
 
17
 
 
18
  <xsl:variable name="numcols">
 
19
    <xsl:call-template name="widest-html-row">
 
20
      <xsl:with-param name="rows" select=".//tr"/>
 
21
    </xsl:call-template>
 
22
  </xsl:variable>
 
23
 
 
24
  <!-- Get the specified table width -->
 
25
  <xsl:variable name="table.width">
 
26
    <xsl:call-template name="table.width">
 
27
      <xsl:with-param name="fullwidth" select="$tablewidth"/>
 
28
    </xsl:call-template>
 
29
  </xsl:variable>
 
30
 
 
31
  <!-- Find the table width -->
 
32
  <xsl:variable name="width">
 
33
    <xsl:choose>
 
34
      <xsl:when test="not(contains($table.width,'auto'))">
 
35
        <xsl:value-of select="$table.width"/>
 
36
      </xsl:when>
 
37
      <xsl:otherwise>
 
38
        <xsl:call-template name="table.width">
 
39
          <xsl:with-param name="fullwidth" select="$tablewidth"/>
 
40
          <xsl:with-param name="exclude" select="'auto'"/>
 
41
        </xsl:call-template>
 
42
      </xsl:otherwise>
 
43
    </xsl:choose>
 
44
  </xsl:variable>
 
45
 
 
46
  <!-- Now the frame style -->
 
47
  <xsl:variable name="frame">
 
48
    <xsl:choose>
 
49
      <xsl:when test="@frame">
 
50
        <xsl:call-template name="cals.frame">
 
51
          <xsl:with-param name="frame" select="@frame"/>
 
52
        </xsl:call-template>
 
53
      </xsl:when>
 
54
      <xsl:otherwise><xsl:value-of select="$tableframe"/></xsl:otherwise>
 
55
    </xsl:choose>
 
56
  </xsl:variable>
 
57
 
 
58
  <xsl:variable name="colspec">
 
59
    <xsl:apply-templates select="(colgroup|col)[1]"
 
60
                         mode="make.colspec">
 
61
      <xsl:with-param name="colnum" select="1"/>
 
62
      <xsl:with-param name="colmax" select="$numcols"/>
 
63
    </xsl:apply-templates>
 
64
  </xsl:variable>
 
65
 
 
66
  <!-- Build the <row>s from the <tr>s -->
 
67
  <xsl:variable name="rows-head" select="tr[child::th]"/>
 
68
  <xsl:variable name="rows-body" select="tr[not(child::th)]"/>
 
69
 
 
70
  <xsl:variable name="rows">
 
71
    <!-- First the header -->
 
72
    <xsl:choose>
 
73
    <xsl:when test="thead">
 
74
      <xsl:apply-templates select="thead" mode="htmlTable">
 
75
        <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
 
76
      </xsl:apply-templates>
 
77
    </xsl:when>
 
78
    <xsl:otherwise>
 
79
      <xsl:apply-templates select="$rows-head[1]" mode="htmlTable">
 
80
        <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
 
81
        <xsl:with-param name="rownum" select="1"/>
 
82
        <xsl:with-param name="context" select="'thead'"/>
 
83
      </xsl:apply-templates>
 
84
    </xsl:otherwise>
 
85
    </xsl:choose>
 
86
 
 
87
    <!-- Then the body -->
 
88
    <xsl:choose>
 
89
    <xsl:when test="tbody">
 
90
      <xsl:apply-templates select="tbody" mode="htmlTable">
 
91
        <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
 
92
      </xsl:apply-templates>
 
93
    </xsl:when>
 
94
    <xsl:otherwise>
 
95
      <xsl:apply-templates select="$rows-body[1]" mode="htmlTable">
 
96
        <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
 
97
        <xsl:with-param name="rownum" select="count($rows-head) +
 
98
                                              count(thead/*) + 1"/>
 
99
      </xsl:apply-templates>
 
100
    </xsl:otherwise>
 
101
    </xsl:choose>
 
102
    <xsl:apply-templates select="tfoot/tr[1]" mode="htmlTable">
 
103
      <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
 
104
      <xsl:with-param name="rownum" select="count(.//tr[not(parent::tfoot)])+1"/>
 
105
    </xsl:apply-templates>
 
106
  </xsl:variable>
 
107
 
 
108
  <!-- Complete the colspecs @width from the fully expended <row>s -->
 
109
  <xsl:variable name="colspec2">
 
110
    <xsl:call-template name="build.colwidth">
 
111
      <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
 
112
      <xsl:with-param name="rows" select="exsl:node-set($rows)"/>
 
113
    </xsl:call-template>
 
114
  </xsl:variable>
 
115
 
 
116
  <!-- TIP: to check the built RTF elements, uncomment and call testtbl.xsl 
 
117
  <xsl:copy-of select="exsl:node-set($colspec2)"/>
 
118
  <xsl:copy-of select="exsl:node-set($rows)"/>
 
119
  -->
 
120
 
 
121
  <xsl:variable name="t.rows" select="exsl:node-set($rows)"/>
 
122
 
 
123
  <xsl:text>\begingroup%&#10;</xsl:text>
 
124
 
 
125
  <!-- Set cellpadding -->
 
126
  <xsl:if test="@cellpadding">
 
127
    <xsl:text>\setlength{\tabcolsep}{</xsl:text>
 
128
    <xsl:value-of select="@cellpadding"/>
 
129
    <xsl:text>}%&#10;</xsl:text>
 
130
  </xsl:if>
 
131
 
 
132
  <xsl:text>\setlength{\tablewidth}{</xsl:text>
 
133
  <xsl:value-of select="$width"/>
 
134
  <xsl:text>}%&#10;</xsl:text>
 
135
 
 
136
  <xsl:if test="$tabletype != 'tabularx'">
 
137
    <xsl:call-template name="tbl.sizes">
 
138
      <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
 
139
      <xsl:with-param name="width" select="$width"/>
 
140
    </xsl:call-template>
 
141
  </xsl:if>
 
142
 
 
143
  <xsl:if test="$tabletype = 'tabularx'">
 
144
    <xsl:call-template name="tbl.valign.x">
 
145
      <xsl:with-param name="valign" select="@valign"/>
 
146
    </xsl:call-template>
 
147
  </xsl:if>
 
148
  
 
149
  <!-- Translate the table to latex -->
 
150
 
 
151
  <!-- Start the table declaration -->
 
152
  <xsl:call-template name="tbl.begin">
 
153
    <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
 
154
    <xsl:with-param name="tabletype" select="$tabletype"/>
 
155
    <xsl:with-param name="width" select="$width"/>
 
156
  </xsl:call-template>
 
157
 
 
158
  <!-- Need a top line? -->
 
159
  <xsl:if test="$frame = 'all' or $frame = 'top' or $frame = 'topbot'">
 
160
    <xsl:text>\hline</xsl:text>
 
161
  </xsl:if>
 
162
  <xsl:text>&#10;</xsl:text>
 
163
 
 
164
  <!-- First, the head rows -->
 
165
  <xsl:variable name="headrows">
 
166
    <xsl:apply-templates select="$t.rows/*[@type='thead']"
 
167
                         mode="htmlTable">
 
168
      <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
 
169
      <xsl:with-param name="context" select="'thead'"/>
 
170
      <xsl:with-param name="frame" select="$frame"/>
 
171
    </xsl:apply-templates>
 
172
  </xsl:variable>
 
173
 
 
174
  <xsl:apply-templates select="." mode="newtbl.endhead">
 
175
    <xsl:with-param name="tabletype" select="$tabletype"/>
 
176
    <xsl:with-param name="headrows" select="$headrows"/>
 
177
  </xsl:apply-templates>
 
178
 
 
179
  <!-- Then, the body rows -->
 
180
  <xsl:apply-templates select="$t.rows/*[@type!='thead']"
 
181
                       mode="htmlTable">
 
182
    <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
 
183
    <xsl:with-param name="context" select="'tbody'"/>
 
184
    <xsl:with-param name="frame" select="$frame"/>
 
185
  </xsl:apply-templates>
 
186
 
 
187
  <!-- Need a bottom line? -->
 
188
  <xsl:if test="$frame = 'all' or $frame = 'bottom' or $frame = 'topbot'">
 
189
    <xsl:text>\hline</xsl:text>
 
190
  </xsl:if>
 
191
  <xsl:text>&#10;</xsl:text>
 
192
  
 
193
  <xsl:text>\end{</xsl:text>
 
194
  <xsl:value-of select="$tabletype"/>
 
195
  <xsl:text>}\endgroup%&#10;</xsl:text>
 
196
 
 
197
</xsl:template>
 
198
 
 
199
 
 
200
<!-- Build the latex row from the <row> element -->
 
201
<xsl:template match="row" mode="htmlTable">
 
202
  <xsl:param name="colspec"/>
 
203
  <xsl:param name="context"/>
 
204
  <xsl:param name="frame"/>
 
205
 
 
206
  <xsl:apply-templates mode="newtbl">
 
207
    <xsl:with-param name="colspec" select="$colspec"/>
 
208
    <xsl:with-param name="context" select="$context"/>
 
209
    <xsl:with-param name="frame" select="$frame"/>
 
210
    <xsl:with-param name="rownum" select="@rownum"/>
 
211
  </xsl:apply-templates>
 
212
 
 
213
  <!-- End this row -->
 
214
  <xsl:text>\tabularnewline&#10;</xsl:text>
 
215
  
 
216
  <!-- Now process rowseps only if not the last row -->
 
217
  <xsl:if test="@rowsep=1">
 
218
    <xsl:choose>
 
219
    <xsl:when test="$newtbl.use.hhline='1'">
 
220
      <xsl:call-template name="hhline.build">
 
221
        <xsl:with-param name="entries" select="."/>
 
222
        <xsl:with-param name="rownum" select="@rownum"/>
 
223
      </xsl:call-template>
 
224
    </xsl:when>
 
225
    <xsl:otherwise>
 
226
      <xsl:call-template name="clines.build">
 
227
        <xsl:with-param name="entries" select="."/>
 
228
        <xsl:with-param name="rownum" select="@rownum"/>
 
229
      </xsl:call-template>
 
230
    </xsl:otherwise>
 
231
    </xsl:choose>
 
232
  </xsl:if>
 
233
</xsl:template>
 
234
 
 
235
 
 
236
<xsl:template match="thead" mode="htmlTable">
 
237
  <xsl:param name="colspec"/>
 
238
  <xsl:apply-templates select="tr[1]" mode="htmlTable">
 
239
    <xsl:with-param name="colspec" select="$colspec"/>
 
240
    <xsl:with-param name="rownum" select="1"/>
 
241
  </xsl:apply-templates>
 
242
</xsl:template>
 
243
 
 
244
 
 
245
<xsl:template match="tbody" mode="htmlTable">
 
246
  <xsl:param name="colspec"/>
 
247
  <xsl:apply-templates select="tr[1]" mode="htmlTable">
 
248
    <xsl:with-param name="colspec" select="$colspec"/>
 
249
    <xsl:with-param name="rownum"
 
250
                    select="count(preceding-sibling::*[self::tbody or
 
251
                                                       self::thead]/*)+1"/>
 
252
  </xsl:apply-templates>
 
253
</xsl:template>
 
254
 
 
255
 
 
256
<!-- Build an intermediate <row> element from a <tr> only if the row
 
257
     has the required 'context'
 
258
  -->
 
259
<xsl:template match="tr" mode="htmlTable">
 
260
  <xsl:param name="rownum"/>
 
261
  <xsl:param name="colspec"/>
 
262
  <xsl:param name="oldentries"/>
 
263
  <xsl:param name="context"/>
 
264
 
 
265
  <xsl:variable name="type">
 
266
    <xsl:choose>
 
267
    <xsl:when test="parent::thead">thead</xsl:when>
 
268
    <xsl:when test="parent::tbody">tbody</xsl:when>
 
269
    <xsl:when test="parent::tfoot">tfoot</xsl:when>
 
270
    <!-- 'tr' contain 'th' and is not in a t* group -->
 
271
    <xsl:when test="th">thead</xsl:when>
 
272
    <xsl:otherwise>tbody</xsl:otherwise>
 
273
    </xsl:choose>
 
274
  </xsl:variable>
 
275
 
 
276
  <xsl:if test="$context='' or $type=$context">
 
277
    <xsl:variable name="entries">
 
278
      <xsl:apply-templates select="(td|th)[1]" mode="htmlTable">
 
279
        <xsl:with-param name="colspec" select="$colspec"/>
 
280
        <xsl:with-param name="rownum" select="$rownum"/>
 
281
        <xsl:with-param name="colnum" select="1"/>
 
282
        <xsl:with-param name="entries" select="exsl:node-set($oldentries)"/>
 
283
      </xsl:apply-templates>
 
284
    </xsl:variable>
 
285
 
 
286
    <row type='{$type}' rownum='{$rownum}'>
 
287
      <xsl:call-template name="html.table.row.rules"/>
 
288
      <xsl:copy-of select="$entries"/>
 
289
    </row>
 
290
 
 
291
    <xsl:apply-templates select="following-sibling::tr[1]" mode="htmlTable">
 
292
      <xsl:with-param name="colspec" select="$colspec"/>
 
293
      <xsl:with-param name="rownum" select="$rownum + 1"/>
 
294
      <xsl:with-param name="oldentries" select="$entries"/>
 
295
      <xsl:with-param name="context" select="$context"/>
 
296
    </xsl:apply-templates>
 
297
  </xsl:if>
 
298
 
 
299
</xsl:template>
 
300
 
 
301
<!-- ==================================================================== -->
 
302
 
 
303
<!-- This template writes rowsep equivalant for html tables -->
 
304
<xsl:template name="html.table.row.rules">
 
305
  <xsl:variable name="border" 
 
306
                select="(ancestor::table |
 
307
                         ancestor::informaltable)[last()]/@border"/>
 
308
  <xsl:variable name="table.rules"
 
309
                select="(ancestor::table |
 
310
                         ancestor::informaltable)[last()]/@rules"/>
 
311
 
 
312
  <xsl:variable name="rules">
 
313
    <xsl:choose>
 
314
      <xsl:when test="$table.rules != ''">
 
315
        <xsl:value-of select="$table.rules"/>
 
316
      </xsl:when>
 
317
      <xsl:when test="$border != '' and number($border) != 0">
 
318
        <xsl:value-of select="'all'"/>
 
319
      </xsl:when>
 
320
      <xsl:when test="$border != '' and number($border) = 0">
 
321
        <xsl:value-of select="'none'"/>
 
322
      </xsl:when>
 
323
      <xsl:when test="$default.table.rules != ''">
 
324
        <xsl:value-of select="$default.table.rules"/>
 
325
      </xsl:when>
 
326
    </xsl:choose>
 
327
  </xsl:variable>
 
328
 
 
329
  <xsl:choose>
 
330
 
 
331
    <xsl:when test="$rules = 'none'">
 
332
      <xsl:attribute name="rowsep">0</xsl:attribute>
 
333
    </xsl:when>
 
334
 
 
335
    <xsl:when test="$rules = 'cols'">
 
336
      <xsl:attribute name="rowsep">0</xsl:attribute>
 
337
    </xsl:when>
 
338
 
 
339
    <!-- If not the last row, add border below -->
 
340
    <xsl:when test="$rules = 'rows' or $rules = 'all'">
 
341
      <xsl:variable name="rowborder">
 
342
        <xsl:choose>
 
343
          <!-- If in thead and tbody has rows, add border -->
 
344
          <xsl:when test="parent::thead/
 
345
                          following-sibling::tbody/tr">1</xsl:when>
 
346
          <!-- If in tbody and tfoot has rows, add border -->
 
347
          <xsl:when test="parent::tbody/
 
348
                          following-sibling::tfoot/tr">1</xsl:when>
 
349
          <!-- If in thead and table has body rows, add border -->
 
350
          <xsl:when test="parent::thead/
 
351
                          following-sibling::tr">1</xsl:when>
 
352
          <xsl:when test="parent::tbody/
 
353
                          preceding-sibling::tfoot/tr">1</xsl:when>
 
354
          <xsl:when test="preceding-sibling::tfoot/tr">1</xsl:when>
 
355
          <!-- If following rows, but not rowspan reaches last row -->
 
356
          <xsl:when test="following-sibling::tr and
 
357
             not(@rowspan = count(following-sibling::tr) + 1)">1</xsl:when>
 
358
          <xsl:otherwise>0</xsl:otherwise>
 
359
        </xsl:choose>
 
360
      </xsl:variable>
 
361
 
 
362
      <xsl:if test="$rowborder = 1">
 
363
        <xsl:attribute name="rowsep">1</xsl:attribute>
 
364
      </xsl:if>
 
365
    </xsl:when>
 
366
 
 
367
    <!-- rules only between 'thead' and 'tbody', or 'tbody' and 'tfoot' -->
 
368
    <xsl:when test="$rules = 'groups' and parent::thead 
 
369
                    and not(following-sibling::tr)">
 
370
      <xsl:attribute name="rowsep">1</xsl:attribute>
 
371
    </xsl:when>
 
372
    <xsl:when test="$rules = 'groups' and parent::tfoot 
 
373
                    and not(preceding-sibling::tr)">
 
374
      <xsl:attribute name="rowsep">1</xsl:attribute>
 
375
    </xsl:when>
 
376
  </xsl:choose>
 
377
</xsl:template>
 
378
 
 
379
<xsl:template name="html.table.column.rules">
 
380
  <xsl:param name="colnum"/>
 
381
  <xsl:param name="colmax"/>
 
382
 
 
383
  <xsl:variable name="border" 
 
384
                select="(ancestor::table |
 
385
                         ancestor::informaltable)[last()]/@border"/>
 
386
  <xsl:variable name="table.rules"
 
387
                select="(ancestor::table |
 
388
                         ancestor::informaltable)[last()]/@rules"/>
 
389
 
 
390
  <xsl:variable name="rules">
 
391
    <xsl:choose>
 
392
      <xsl:when test="$table.rules != ''">
 
393
        <xsl:value-of select="$table.rules"/>
 
394
      </xsl:when>
 
395
      <xsl:when test="$border != '' and number($border) != 0">
 
396
        <xsl:value-of select="'all'"/>
 
397
      </xsl:when>
 
398
      <xsl:when test="$border != '' and number($border) = 0">
 
399
        <xsl:value-of select="'none'"/>
 
400
      </xsl:when>
 
401
      <xsl:when test="$default.table.rules != ''">
 
402
        <xsl:value-of select="$default.table.rules"/>
 
403
      </xsl:when>
 
404
    </xsl:choose>
 
405
  </xsl:variable>
 
406
 
 
407
  <xsl:choose>
 
408
    <xsl:when test="$rules = 'none'">
 
409
      <xsl:attribute name="colsep">0</xsl:attribute>
 
410
    </xsl:when>
 
411
    <xsl:when test="$rules = 'rows'">
 
412
      <xsl:attribute name="colsep">0</xsl:attribute>
 
413
    </xsl:when>
 
414
    <xsl:when test="$rules = 'groups'">
 
415
      <xsl:attribute name="colsep">0</xsl:attribute>
 
416
    </xsl:when>
 
417
    <!-- If not the last column, add border after -->
 
418
    <xsl:when test="($rules = 'cols' or $rules = 'all') and
 
419
                    ($colnum &lt; $colmax)">
 
420
      <xsl:attribute name="colsep">1</xsl:attribute>
 
421
    </xsl:when>
 
422
  </xsl:choose>
 
423
</xsl:template>
 
424
 
 
425
<!-- ==================================================================== -->
 
426
 
 
427
<xsl:template match="td|th" mode="htmlTable">
 
428
  <xsl:param name="rownum"/>
 
429
  <xsl:param name="colnum"/>
 
430
  <xsl:param name="colspec"/>
 
431
  <xsl:param name="entries"/>
 
432
 
 
433
  <xsl:variable name="cols" select="count($colspec/*)"/>
 
434
 
 
435
  <xsl:if test="$colnum &lt;= $cols">
 
436
 
 
437
    <xsl:variable name="entry"
 
438
                  select="$entries/*[self::entry or self::entrytbl]
 
439
                                    [@colstart=$colnum and
 
440
                                     @rowend &gt;= $rownum]"/>
 
441
 
 
442
    <!-- Do we have an existing entry element from a previous row that -->
 
443
    <!-- should be copied into this row? -->
 
444
    <xsl:choose><xsl:when test="$entry">
 
445
      <!-- Just copy this entry then -->
 
446
      <xsl:copy-of select="$entry"/>
 
447
 
 
448
      <!-- Process the next column using this current entry -->
 
449
      <xsl:apply-templates mode="htmlTable" select=".">
 
450
        <xsl:with-param name="colnum" 
 
451
                        select="$entries/entry[@colstart=$colnum]/@colend + 1"/>
 
452
        <xsl:with-param name="rownum" select="$rownum"/>
 
453
        <xsl:with-param name="colspec" select="$colspec"/>
 
454
        <xsl:with-param name="entries" select="$entries"/>
 
455
      </xsl:apply-templates>
 
456
    </xsl:when><xsl:otherwise>
 
457
 
 
458
      <xsl:variable name="colstart" select="$colnum"/>
 
459
 
 
460
      <xsl:variable name="colend">
 
461
        <xsl:choose>
 
462
        <xsl:when test="@colspan">
 
463
          <xsl:value-of select="@colspan + $colnum -1"/>
 
464
        </xsl:when>
 
465
        <xsl:otherwise>
 
466
          <xsl:value-of select="$colnum"/>
 
467
        </xsl:otherwise>
 
468
        </xsl:choose>
 
469
      </xsl:variable>
 
470
 
 
471
      <xsl:variable name="rowend">
 
472
        <xsl:choose>
 
473
        <xsl:when test="@rowspan">
 
474
          <xsl:value-of select="@rowspan + $rownum -1"/>
 
475
        </xsl:when>
 
476
        <xsl:otherwise>
 
477
          <xsl:value-of select="$rownum"/>
 
478
        </xsl:otherwise>
 
479
        </xsl:choose>
 
480
      </xsl:variable>
 
481
 
 
482
      <xsl:variable name="rowcolor" select="parent::tr/@bgcolor"/>
 
483
 
 
484
      <xsl:variable name="col" select="$colspec/colspec[@colnum=$colstart]"/>
 
485
 
 
486
      <xsl:variable name="bgcolor">
 
487
        <xsl:choose>
 
488
          <xsl:when test="$rowcolor != ''">
 
489
            <xsl:value-of select="$rowcolor"/>
 
490
          </xsl:when>
 
491
          <xsl:when test="$col/@bgcolor">
 
492
            <xsl:value-of select="$col/@bgcolor"/>
 
493
          </xsl:when>
 
494
          <xsl:when test="ancestor::*[@bgcolor]">
 
495
            <xsl:value-of select="ancestor::*[@bgcolor][last()]/@bgcolor"/>
 
496
          </xsl:when>
 
497
        </xsl:choose>
 
498
      </xsl:variable>
 
499
 
 
500
      <xsl:variable name="valign">
 
501
        <xsl:choose>
 
502
          <xsl:when test="../@valign">
 
503
            <xsl:value-of select="../@valign"/>
 
504
          </xsl:when>
 
505
          <xsl:when test="$col/@valign">
 
506
            <xsl:value-of select="$col/@valign"/>
 
507
          </xsl:when>
 
508
          <xsl:when test="ancestor::*[@valign]">
 
509
            <xsl:value-of select="ancestor::*[@valign][last()]/@valign"/>
 
510
          </xsl:when>
 
511
        </xsl:choose>
 
512
      </xsl:variable>
 
513
 
 
514
      <xsl:variable name="align">
 
515
        <xsl:choose>
 
516
          <xsl:when test="../@align">
 
517
            <xsl:value-of select="../@align"/>
 
518
          </xsl:when>
 
519
          <xsl:when test="$col/@align">
 
520
            <xsl:value-of select="$col/@align"/>
 
521
          </xsl:when>
 
522
          <xsl:when test="ancestor::*[@align]">
 
523
            <xsl:value-of select="ancestor::*[@align][last()]/@align"/>
 
524
          </xsl:when>
 
525
        </xsl:choose>
 
526
      </xsl:variable>
 
527
 
 
528
      <entry>
 
529
        <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
 
530
        <xsl:attribute name="colstart">
 
531
          <xsl:value-of select="$colstart"/>
 
532
        </xsl:attribute>
 
533
        <xsl:attribute name="colend">
 
534
          <xsl:value-of select="$colend"/>
 
535
        </xsl:attribute>
 
536
        <xsl:attribute name="rowstart">
 
537
          <xsl:value-of select="$rownum"/>
 
538
        </xsl:attribute>
 
539
        <xsl:attribute name="rowend">
 
540
          <xsl:value-of select="$rowend"/>
 
541
        </xsl:attribute>
 
542
        <xsl:if test="$rowend &gt; $rownum">
 
543
          <xsl:attribute name="morerows">
 
544
            <xsl:value-of select="$rowend - $rownum"/>
 
545
          </xsl:attribute>
 
546
        </xsl:if>
 
547
        <xsl:if test="$col/@colsep = 1">
 
548
          <xsl:attribute name="colsep">
 
549
            <xsl:value-of select="1"/>
 
550
          </xsl:attribute>
 
551
        </xsl:if>
 
552
        <xsl:if test="not(@bgcolor) and $bgcolor != ''">
 
553
          <xsl:attribute name="bgcolor">
 
554
            <xsl:value-of select="$bgcolor"/>
 
555
          </xsl:attribute>
 
556
        </xsl:if>
 
557
        <xsl:if test="not(@valign) and $valign != ''">
 
558
          <xsl:attribute name="valign">
 
559
            <xsl:value-of select="$valign"/>
 
560
          </xsl:attribute>
 
561
        </xsl:if>
 
562
        <xsl:if test="not(@align) and $align != ''">
 
563
          <xsl:attribute name="align">
 
564
            <xsl:value-of select="$align"/>
 
565
          </xsl:attribute>
 
566
        </xsl:if>
 
567
        <xsl:element name="output">
 
568
          <xsl:apply-templates select="." mode="output"/>
 
569
        </xsl:element>
 
570
      </entry>
 
571
 
 
572
      <xsl:choose>
 
573
      <xsl:when test="following-sibling::*[self::td or self::th]">
 
574
 
 
575
        <xsl:apply-templates
 
576
              select="following-sibling::*[self::td or self::th][1]"
 
577
              mode="htmlTable">
 
578
          <xsl:with-param name="colspec" select="$colspec"/>
 
579
          <xsl:with-param name="rownum" select="$rownum"/>
 
580
          <xsl:with-param name="colnum" select="$colend + 1"/>
 
581
          <xsl:with-param name="entries" select="$entries"/>
 
582
        </xsl:apply-templates>
 
583
 
 
584
      </xsl:when>
 
585
      <xsl:when test="$colend &lt; $cols">
 
586
        <!-- Create more blank entries to pad the row -->
 
587
        <xsl:call-template name="tbl.blankentry">
 
588
          <xsl:with-param name="colnum" select="$colend + 1"/>
 
589
          <xsl:with-param name="colend" select="$cols"/>
 
590
          <xsl:with-param name="colspec" select="$colspec"/>
 
591
          <xsl:with-param name="rownum" select="$rownum"/>
 
592
          <xsl:with-param name="entries" select="$entries"/>
 
593
          <xsl:with-param name="rowcolor" select="$rowcolor"/>
 
594
        </xsl:call-template>
 
595
 
 
596
      </xsl:when>
 
597
      </xsl:choose>
 
598
    </xsl:otherwise></xsl:choose>
 
599
  </xsl:if>
 
600
</xsl:template>
 
601
 
 
602
<!-- ==================================================================== -->
 
603
 
 
604
<xsl:template match="tr" mode="span">
 
605
  <xsl:param name="currow"/>
 
606
  <xsl:variable name="tr.pos" select="position()"/>
 
607
  <xsl:variable name="spantds" select="td[@rowspan][$tr.pos + @rowspan &gt; 
 
608
                                                    $currow]"/>
 
609
  <xsl:if test="$spantds">
 
610
    <span rownum="{$currow}" p="{$tr.pos}">
 
611
      <xsl:attribute name="value">
 
612
        <xsl:value-of
 
613
        select="sum($spantds/@colspan)+count($spantds[not(@colspan)])"/>
 
614
      </xsl:attribute>
 
615
    </span>
 
616
  </xsl:if>
 
617
</xsl:template>
 
618
 
 
619
 
 
620
<xsl:template name="widest-html-row">
 
621
  <xsl:param name="rows" select="''"/>
 
622
  <xsl:param name="count" select="0"/>
 
623
  <xsl:param name="currow" select="1"/>
 
624
  <xsl:variable name="row" select="$rows[position()=$currow]"/>
 
625
  <xsl:choose>
 
626
    <xsl:when test="not($row)">
 
627
      <xsl:value-of select="$count"/>
 
628
    </xsl:when>
 
629
    <xsl:otherwise>
 
630
      <xsl:variable name="count1" select="count($row/*[not(@colspan)])"/>
 
631
      <xsl:variable name="count2" select="sum($row/*/@colspan)"/>
 
632
      <xsl:variable name="countn" select="$count1 + $count2"/>
 
633
 
 
634
      <!-- retrieve the previous <td>s that contain a @rowspan
 
635
           that span over the current row -->
 
636
      <xsl:variable name="spantds">
 
637
        <xsl:apply-templates
 
638
             select="$rows[position() &lt; $currow]"
 
639
             mode="span">
 
640
          <xsl:with-param name="currow" select="$currow"/>
 
641
        </xsl:apply-templates>
 
642
      </xsl:variable>
 
643
 
 
644
      <!-- get the additional columns implied by the upward spanning <td> -->
 
645
      <xsl:variable name="addcols"
 
646
                    select="sum(exsl:node-set($spantds)/*/@value)"/>
 
647
 
 
648
      <!-- TIP: uncomment to debug the column count algorithm
 
649
      <foo> <xsl:copy-of select="$spantds"/> </foo>
 
650
 
 
651
      <xsl:message>
 
652
        <xsl:text>p=</xsl:text><xsl:value-of select="$currow"/>
 
653
        <xsl:text> c=</xsl:text><xsl:value-of select="$count"/>
 
654
        <xsl:text> s=</xsl:text><xsl:value-of select="$addcols"/>
 
655
      </xsl:message>
 
656
      -->
 
657
 
 
658
      <xsl:choose>
 
659
        <xsl:when test="$count &gt; ($countn + $addcols)">
 
660
          <xsl:call-template name="widest-html-row">
 
661
            <xsl:with-param name="rows" select="$rows"/>
 
662
            <xsl:with-param name="count" select="$count"/>
 
663
            <xsl:with-param name="currow" select="$currow + 1"/>
 
664
          </xsl:call-template>
 
665
        </xsl:when>
 
666
        <xsl:otherwise>
 
667
          <xsl:call-template name="widest-html-row">
 
668
            <xsl:with-param name="rows" select="$rows"/>
 
669
            <xsl:with-param name="count" select="$countn + $addcols"/>
 
670
            <xsl:with-param name="currow" select="$currow + 1"/>
 
671
          </xsl:call-template>
 
672
        </xsl:otherwise>
 
673
      </xsl:choose>
 
674
    </xsl:otherwise>
 
675
  </xsl:choose>
 
676
</xsl:template>
 
677
 
 
678
<!-- ==================================================================== -->
 
679
 
 
680
<xsl:template name="build.colwidth">
 
681
  <xsl:param name="colspec"/>
 
682
  <xsl:param name="rows"/>
 
683
 
 
684
  <xsl:for-each select="$colspec/*">
 
685
    <xsl:variable name="pos" select="position()"/>
 
686
    <xsl:variable name="colentries"
 
687
                  select="$rows/row/entry[@colstart &lt;= $pos and
 
688
                                          @colend &gt;= $pos][@width]"/>
 
689
 
 
690
    <xsl:variable name="pct">
 
691
      <xsl:call-template name="max.percent">
 
692
        <xsl:with-param name="entries" select="$colentries"/>
 
693
        <xsl:with-param name="maxpct">
 
694
          <xsl:choose>
 
695
          <xsl:when test="substring(@width,string-length(@width))='%'">
 
696
            <xsl:value-of select="number(substring-before(@width, '%'))"/>
 
697
          </xsl:when>
 
698
          <xsl:otherwise>
 
699
            <xsl:value-of select="0"/>
 
700
          </xsl:otherwise>
 
701
          </xsl:choose>
 
702
        </xsl:with-param>
 
703
      </xsl:call-template>
 
704
    </xsl:variable>
 
705
    <xsl:variable name="fixed">
 
706
      <xsl:call-template name="max.value">
 
707
        <xsl:with-param name="entries" select="$colentries"/>
 
708
        <xsl:with-param name="maxval">
 
709
          <xsl:choose>
 
710
          <xsl:when test="string(number(@width))!='NaN'">
 
711
            <xsl:value-of select="number(@width)"/>
 
712
          </xsl:when>
 
713
          <xsl:otherwise>
 
714
            <xsl:value-of select="0"/>
 
715
          </xsl:otherwise>
 
716
          </xsl:choose>
 
717
        </xsl:with-param>
 
718
      </xsl:call-template>
 
719
    </xsl:variable>
 
720
    <xsl:variable name="star">
 
721
      <xsl:choose>
 
722
      <xsl:when test="substring(@width,string-length(@width))='*'">
 
723
        <xsl:value-of select="number(substring-before(@width, '*'))"/>
 
724
      </xsl:when>
 
725
      <xsl:otherwise>
 
726
        <!-- '0*' is allowed and meaningfull, so use a negative number to
 
727
             signify a missing star -->
 
728
        <xsl:value-of select="-1"/>
 
729
      </xsl:otherwise>
 
730
      </xsl:choose>
 
731
    </xsl:variable>
 
732
 
 
733
    <!--
 
734
    <xsl:message>
 
735
      <xsl:value-of select="$pos"/>
 
736
      <xsl:text>, </xsl:text>
 
737
      <xsl:value-of select="count($colentries)"/>
 
738
      <xsl:text> pct=</xsl:text><xsl:value-of select="$pct"/>
 
739
      <xsl:text> val=</xsl:text><xsl:value-of select="$fixed"/>
 
740
      <xsl:text> star=</xsl:text><xsl:value-of select="$star"/>
 
741
    </xsl:message>
 
742
    -->
 
743
 
 
744
    <xsl:copy>
 
745
      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
 
746
 
 
747
      <!-- Now, make precedences between the found width types -->
 
748
      <xsl:choose>
 
749
      <!-- the special form "0*" means to use the column's content width -->
 
750
      <xsl:when test="$star = 0">
 
751
        <xsl:attribute name="autowidth">1</xsl:attribute>
 
752
        <!-- set a star to reserve some default space for the column -->
 
753
        <xsl:attribute name="colwidth">
 
754
          <xsl:text>\newtblstarfactor</xsl:text>
 
755
        </xsl:attribute>
 
756
        <xsl:attribute name="star">
 
757
          <xsl:value-of select="1"/>
 
758
        </xsl:attribute>
 
759
      </xsl:when>
 
760
      <xsl:when test="$star &gt; 0">
 
761
        <xsl:attribute name="colwidth">
 
762
          <xsl:value-of select="$star"/>
 
763
          <xsl:text>\newtblstarfactor</xsl:text>
 
764
        </xsl:attribute>
 
765
        <xsl:attribute name="star">
 
766
          <xsl:value-of select="$star"/>
 
767
        </xsl:attribute>
 
768
      </xsl:when>
 
769
      <xsl:when test="$pct &gt; 0">
 
770
        <xsl:variable name="width">
 
771
          <xsl:value-of select="$pct div 100"/>
 
772
          <xsl:text>\tablewidth</xsl:text>
 
773
        </xsl:variable>
 
774
        <xsl:attribute name="fixedwidth">
 
775
          <xsl:value-of select="$width"/>
 
776
        </xsl:attribute>
 
777
        <xsl:attribute name="colwidth">
 
778
          <xsl:value-of select="$width"/>
 
779
        </xsl:attribute>
 
780
      </xsl:when>
 
781
      <xsl:when test="$fixed &gt; 0">
 
782
        <!-- the width is expressed in 'px' bus is seen as 'pt' for tex -->
 
783
        <xsl:variable name="width">
 
784
          <xsl:value-of select="$fixed"/>
 
785
          <xsl:text>pt</xsl:text>
 
786
        </xsl:variable>
 
787
        <xsl:attribute name="fixedwidth">
 
788
          <xsl:value-of select="$width"/>
 
789
        </xsl:attribute>
 
790
        <xsl:attribute name="colwidth">
 
791
          <xsl:value-of select="$width"/>
 
792
        </xsl:attribute>
 
793
      </xsl:when>
 
794
      <xsl:otherwise>
 
795
        <!-- no width specified: equivalent to a '*' -->
 
796
        <xsl:attribute name="colwidth">
 
797
          <xsl:text>\newtblstarfactor</xsl:text>
 
798
        </xsl:attribute>
 
799
        <xsl:attribute name="star">1</xsl:attribute>
 
800
      </xsl:otherwise>
 
801
      </xsl:choose>
 
802
    </xsl:copy>
 
803
  </xsl:for-each>
 
804
</xsl:template>
 
805
 
 
806
 
 
807
<!-- Find the maximum width expressed in percentage in column entries -->
 
808
<xsl:template name="max.percent">
 
809
  <xsl:param name="entries"/>
 
810
  <xsl:param name="maxpct" select="0"/>
 
811
 
 
812
  <xsl:choose>
 
813
  <xsl:when test="$entries">
 
814
    <xsl:variable name="width" select="$entries[1]/@width"/>
 
815
 
 
816
    <xsl:variable name="newpct">
 
817
      <xsl:choose>
 
818
      <xsl:when test="substring($width,string-length($width))='%'">
 
819
        <xsl:variable name="pct" select="number(substring-before($width, '%'))"/>
 
820
        <xsl:choose>
 
821
        <xsl:when test="$pct &gt; $maxpct">
 
822
          <xsl:value-of select="$pct"/>
 
823
        </xsl:when>
 
824
        <xsl:otherwise>
 
825
          <xsl:value-of select="$maxpct"/>
 
826
        </xsl:otherwise>
 
827
        </xsl:choose>
 
828
      </xsl:when>
 
829
      <xsl:otherwise>
 
830
        <xsl:value-of select="$maxpct"/>
 
831
      </xsl:otherwise>
 
832
      </xsl:choose>
 
833
    </xsl:variable>
 
834
    <xsl:call-template name="max.percent">
 
835
      <xsl:with-param name="maxpct" select="$newpct"/>
 
836
      <xsl:with-param name="entries" select="$entries[position() &gt; 1]"/>
 
837
    </xsl:call-template>
 
838
  </xsl:when>
 
839
  <xsl:otherwise>
 
840
    <xsl:value-of select="$maxpct"/>
 
841
  </xsl:otherwise>
 
842
  </xsl:choose>
 
843
</xsl:template>
 
844
 
 
845
<!-- Find the maximum width expressed in numbers in column entries -->
 
846
<xsl:template name="max.value">
 
847
  <xsl:param name="entries"/>
 
848
  <xsl:param name="maxval" select="0"/>
 
849
 
 
850
  <xsl:choose>
 
851
  <xsl:when test="$entries">
 
852
    <xsl:variable name="width" select="$entries[1]/@width"/>
 
853
 
 
854
    <xsl:variable name="newval">
 
855
      <xsl:choose>
 
856
      <xsl:when test="string(number($width))!='NaN'">
 
857
        <xsl:variable name="val" select="number($width)"/>
 
858
        <xsl:choose>
 
859
        <xsl:when test="$val &gt; $maxval">
 
860
          <xsl:value-of select="$val"/>
 
861
        </xsl:when>
 
862
        <xsl:otherwise>
 
863
          <xsl:value-of select="$maxval"/>
 
864
        </xsl:otherwise>
 
865
        </xsl:choose>
 
866
      </xsl:when>
 
867
      <xsl:otherwise>
 
868
        <xsl:value-of select="$maxval"/>
 
869
      </xsl:otherwise>
 
870
      </xsl:choose>
 
871
    </xsl:variable>
 
872
    <xsl:call-template name="max.value">
 
873
      <xsl:with-param name="maxval" select="$newval"/>
 
874
      <xsl:with-param name="entries" select="$entries[position() &gt; 1]"/>
 
875
    </xsl:call-template>
 
876
  </xsl:when>
 
877
  <xsl:otherwise>
 
878
    <xsl:value-of select="$maxval"/>
 
879
  </xsl:otherwise>
 
880
  </xsl:choose>
 
881
</xsl:template>
 
882
 
 
883
<!-- ==================================================================== -->
 
884
 
 
885
<!-- Build the equivalent <colspec>s elements from <colgroup>s and <col>s
 
886
     and use default colspec for undefined <col>s in order to have a colspec
 
887
     per actual column.
 
888
-->
 
889
 
 
890
<xsl:template match="colgroup" mode="make.colspec">
 
891
  <xsl:param name="done" select="0"/>
 
892
  <xsl:param name="colnum"/>
 
893
  <xsl:param name="colmax"/>
 
894
 
 
895
  <xsl:choose>
 
896
  <xsl:when test="col">
 
897
    <!-- the spec are handled by <col>s -->
 
898
    <xsl:apply-templates select="col[1]" mode="make.colspec">
 
899
      <xsl:with-param name="colnum" select="$colnum"/>
 
900
      <xsl:with-param name="colmax" select="$colmax"/>
 
901
    </xsl:apply-templates>
 
902
  </xsl:when>
 
903
  <xsl:otherwise>
 
904
 
 
905
    <xsl:variable name="span">
 
906
      <xsl:choose>
 
907
        <xsl:when test="@span">
 
908
          <xsl:value-of select="@span"/>
 
909
        </xsl:when>
 
910
        <xsl:otherwise>
 
911
          <xsl:value-of select="1"/>
 
912
        </xsl:otherwise>
 
913
      </xsl:choose>
 
914
    </xsl:variable>
 
915
 
 
916
    <xsl:choose>
 
917
    <xsl:when test="$done &lt; $span">
 
918
      <!-- bgcolor specified via a PI -->
 
919
      <xsl:variable name="bgcolor">
 
920
        <xsl:if test="processing-instruction('dblatex')">
 
921
          <xsl:call-template name="pi-attribute">
 
922
            <xsl:with-param name="pis"
 
923
                            select="processing-instruction('dblatex')"/>
 
924
            <xsl:with-param name="attribute" select="'bgcolor'"/>
 
925
          </xsl:call-template>
 
926
        </xsl:if>
 
927
      </xsl:variable>
 
928
 
 
929
      <colspec>
 
930
        <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
 
931
        <xsl:attribute name="colnum">
 
932
          <xsl:value-of select="$colnum"/>
 
933
        </xsl:attribute>
 
934
        <xsl:if test="$bgcolor != ''">
 
935
          <xsl:attribute name="bgcolor"><xsl:value-of select="$bgcolor"/>
 
936
          </xsl:attribute>
 
937
        </xsl:if>
 
938
        <xsl:call-template name="html.table.column.rules">
 
939
          <xsl:with-param name="colnum" select="$colnum"/>
 
940
          <xsl:with-param name="colmax" select="$colmax"/>
 
941
        </xsl:call-template>
 
942
      </colspec>
 
943
 
 
944
      <xsl:apply-templates select="." mode="make.colspec">
 
945
        <xsl:with-param name="done" select="$done + 1"/>
 
946
        <xsl:with-param name="colnum" select="$colnum + 1"/>
 
947
        <xsl:with-param name="colmax" select="$colmax"/>
 
948
      </xsl:apply-templates>
 
949
    </xsl:when>
 
950
    <xsl:when test="following-sibling::*[self::colgroup or self::col]">
 
951
      <xsl:apply-templates select="following-sibling::*[self::colgroup or
 
952
                                                        self::col][1]"
 
953
                           mode="make.colspec">
 
954
        <xsl:with-param name="colnum" select="$colnum"/>
 
955
        <xsl:with-param name="colmax" select="$colmax"/>
 
956
      </xsl:apply-templates>
 
957
    </xsl:when>
 
958
    <!-- build empty default <colspec>s for missing columns -->
 
959
    <xsl:when test="$colnum &lt;= $colmax">
 
960
      <colspec>
 
961
        <xsl:attribute name="colnum">
 
962
          <xsl:value-of select="$colnum"/>
 
963
        </xsl:attribute>
 
964
        <xsl:call-template name="html.table.column.rules">
 
965
          <xsl:with-param name="colnum" select="$colnum"/>
 
966
          <xsl:with-param name="colmax" select="$colmax"/>
 
967
        </xsl:call-template>
 
968
      </colspec>
 
969
 
 
970
      <xsl:apply-templates select="." mode="make.colspec">
 
971
        <xsl:with-param name="colnum" select="$colnum + 1"/>
 
972
        <xsl:with-param name="colmax" select="$colmax"/>
 
973
        <xsl:with-param name="done" select="$colmax"/>
 
974
      </xsl:apply-templates>
 
975
    </xsl:when>
 
976
    </xsl:choose>
 
977
  </xsl:otherwise>
 
978
  </xsl:choose>
 
979
</xsl:template>
 
980
 
 
981
<xsl:template match="col" mode="make.colspec">
 
982
  <xsl:param name="done" select="0"/>
 
983
  <xsl:param name="colnum"/>
 
984
  <xsl:param name="colmax"/>
 
985
 
 
986
  <!--
 
987
  <xsl:message>
 
988
    <xsl:text>p=</xsl:text>
 
989
    <xsl:value-of select="local-name()"/>
 
990
    <xsl:text> </xsl:text>
 
991
    <xsl:value-of select="generate-id()"/>
 
992
    <xsl:text> r=</xsl:text>
 
993
    <xsl:value-of select="$colnum"/>
 
994
  </xsl:message>
 
995
  -->
 
996
 
 
997
  <xsl:variable name="span">
 
998
    <xsl:choose>
 
999
      <xsl:when test="@span">
 
1000
        <xsl:value-of select="@span"/>
 
1001
      </xsl:when>
 
1002
      <xsl:otherwise>
 
1003
        <xsl:value-of select="1"/>
 
1004
      </xsl:otherwise>
 
1005
    </xsl:choose>
 
1006
  </xsl:variable>
 
1007
 
 
1008
  <xsl:choose>
 
1009
  <!-- clone the same <colspec> span times -->
 
1010
  <xsl:when test="$done &lt; $span">
 
1011
    <!-- bgcolor specified via a PI or a colgroup parent PI -->
 
1012
    <xsl:variable name="bgcolor">
 
1013
      <xsl:choose>
 
1014
      <xsl:when test="processing-instruction('dblatex')">
 
1015
        <xsl:call-template name="pi-attribute">
 
1016
          <xsl:with-param name="pis"
 
1017
                          select="processing-instruction('dblatex')"/>
 
1018
          <xsl:with-param name="attribute" select="'bgcolor'"/>
 
1019
        </xsl:call-template>
 
1020
      </xsl:when>
 
1021
      <xsl:when test="../processing-instruction('dblatex')">
 
1022
        <xsl:call-template name="pi-attribute">
 
1023
          <xsl:with-param name="pis"
 
1024
                          select="../processing-instruction('dblatex')"/>
 
1025
          <xsl:with-param name="attribute" select="'bgcolor'"/>
 
1026
        </xsl:call-template>
 
1027
      </xsl:when>
 
1028
      </xsl:choose>
 
1029
    </xsl:variable>
 
1030
 
 
1031
    <colspec>
 
1032
      <xsl:for-each select="parent::colgroup/@*"><xsl:copy/></xsl:for-each>
 
1033
      <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
 
1034
      <xsl:attribute name="colnum">
 
1035
        <xsl:value-of select="$colnum"/>
 
1036
      </xsl:attribute>
 
1037
      <xsl:if test="$bgcolor != ''">
 
1038
        <xsl:attribute name="bgcolor"><xsl:value-of select="$bgcolor"/>
 
1039
        </xsl:attribute>
 
1040
      </xsl:if>
 
1041
      <xsl:call-template name="html.table.column.rules">
 
1042
        <xsl:with-param name="colnum" select="$colnum"/>
 
1043
        <xsl:with-param name="colmax" select="$colmax"/>
 
1044
      </xsl:call-template>
 
1045
    </colspec>
 
1046
 
 
1047
    <xsl:apply-templates select="." mode="make.colspec">
 
1048
      <xsl:with-param name="done" select="$done + 1"/>
 
1049
      <xsl:with-param name="colnum" select="$colnum + 1"/>
 
1050
      <xsl:with-param name="colmax" select="$colmax"/>
 
1051
    </xsl:apply-templates>
 
1052
  </xsl:when>
 
1053
  <!-- process the next following <col*> -->
 
1054
  <xsl:when test="following-sibling::*[self::colgroup or self::col]">
 
1055
    <xsl:apply-templates
 
1056
        select="following-sibling::*[self::col or self::colgroup][1]"
 
1057
        mode="make.colspec">
 
1058
      <xsl:with-param name="colnum" select="$colnum"/>
 
1059
      <xsl:with-param name="colmax" select="$colmax"/>
 
1060
    </xsl:apply-templates>
 
1061
  </xsl:when>
 
1062
  <!-- if <col> is a <colgroup> child, process the next <col*> at the parent
 
1063
       level -->
 
1064
  <xsl:when test="parent::colgroup[following-sibling::*[self::colgroup or
 
1065
                                                        self::col]]">
 
1066
    <xsl:apply-templates select="parent::colgroup/
 
1067
                                 following-sibling::*[self::col or
 
1068
                                                      self::colgroup][1]"
 
1069
                         mode="make.colspec">
 
1070
      <xsl:with-param name="colnum" select="$colnum"/>
 
1071
      <xsl:with-param name="colmax" select="$colmax"/>
 
1072
    </xsl:apply-templates>
 
1073
  </xsl:when>
 
1074
  <!-- build empty default <colspec>s for missing columns -->
 
1075
  <xsl:when test="$colnum &lt;= $colmax">
 
1076
    <colspec>
 
1077
      <xsl:attribute name="colnum">
 
1078
        <xsl:value-of select="$colnum"/>
 
1079
      </xsl:attribute>
 
1080
      <xsl:call-template name="html.table.column.rules">
 
1081
        <xsl:with-param name="colnum" select="$colnum"/>
 
1082
        <xsl:with-param name="colmax" select="$colmax"/>
 
1083
      </xsl:call-template>
 
1084
    </colspec>
 
1085
 
 
1086
    <xsl:apply-templates select="." mode="make.colspec">
 
1087
      <xsl:with-param name="colnum" select="$colnum + 1"/>
 
1088
      <xsl:with-param name="colmax" select="$colmax"/>
 
1089
      <xsl:with-param name="done" select="$colmax"/>
 
1090
    </xsl:apply-templates>
 
1091
  </xsl:when>
 
1092
  </xsl:choose>
 
1093
</xsl:template>
 
1094
 
 
1095
</xsl:stylesheet>