]> git.stg.codes - stg.git/blob - doc/xslt/html/table.xsl
Fix accessing array element above array bounds in rsconf
[stg.git] / doc / xslt / html / table.xsl
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 8813 2010-08-09 21:18:23Z 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:choose>
470       <!-- recurse on rows only if @morerows is present -->
471       <xsl:when test="row/entry/@morerows|row/entrytbl/@morerows">
472         <xsl:apply-templates select="row[1]">
473           <xsl:with-param name="spans">
474             <xsl:call-template name="blank.spans">
475               <xsl:with-param name="cols" select="../@cols"/>
476             </xsl:call-template>
477           </xsl:with-param>
478           <xsl:with-param name="browserows" select="'recurse'"/>
479         </xsl:apply-templates>
480       </xsl:when>
481       <xsl:otherwise>
482         <xsl:apply-templates select="row">
483           <xsl:with-param name="spans">
484             <xsl:call-template name="blank.spans">
485               <xsl:with-param name="cols" select="../@cols"/>
486             </xsl:call-template>
487           </xsl:with-param>
488           <xsl:with-param name="browserows" select="'loop'" />
489         </xsl:apply-templates>
490       </xsl:otherwise>
491     </xsl:choose>
492
493   </xsl:element>
494 </xsl:template>
495
496 <xsl:template match="tbody">
497   <tbody>
498     <xsl:if test="@align">
499       <xsl:attribute name="align">
500         <xsl:value-of select="@align"/>
501       </xsl:attribute>
502     </xsl:if>
503     <xsl:if test="@char">
504       <xsl:attribute name="char">
505         <xsl:value-of select="@char"/>
506       </xsl:attribute>
507     </xsl:if>
508     <xsl:if test="@charoff">
509       <xsl:attribute name="charoff">
510         <xsl:value-of select="@charoff"/>
511       </xsl:attribute>
512     </xsl:if>
513     <xsl:if test="@valign">
514       <xsl:attribute name="valign">
515         <xsl:value-of select="@valign"/>
516       </xsl:attribute>
517     </xsl:if>
518
519     <xsl:choose>
520       <xsl:when test="row/entry/@morerows|row/entrytbl/@morerows">
521         <xsl:apply-templates select="row[1]">
522           <xsl:with-param name="spans">
523             <xsl:call-template name="blank.spans">
524               <xsl:with-param name="cols" select="../@cols"/>
525             </xsl:call-template>
526           </xsl:with-param>
527           <xsl:with-param name="browserows" select="'recurse'"/>
528         </xsl:apply-templates>
529       </xsl:when>
530       <xsl:otherwise>
531         <xsl:apply-templates select="row">
532           <xsl:with-param name="spans">
533             <xsl:call-template name="blank.spans">
534               <xsl:with-param name="cols" select="../@cols"/>
535             </xsl:call-template>
536           </xsl:with-param>
537           <xsl:with-param name="browserows" select="'loop'" />
538         </xsl:apply-templates>
539       </xsl:otherwise>
540     </xsl:choose>
541
542   </tbody>
543 </xsl:template>
544
545 <xsl:template match="row">
546   <xsl:param name="spans"/>
547   <xsl:param name="browserows"/>
548
549   <xsl:choose>
550     <xsl:when test="contains($spans, '0')">
551       <xsl:call-template name="normal-row">
552         <xsl:with-param name="spans" select="$spans"/>
553         <xsl:with-param name="browserows" select="$browserows"/>
554       </xsl:call-template>
555     </xsl:when>
556     <xsl:otherwise>
557       <!--
558       <xsl:message>
559         <xsl:text>Ignoring row: </xsl:text>
560         <xsl:value-of select="$spans"/>
561         <xsl:text> = </xsl:text>
562         <xsl:call-template name="consume-row">
563           <xsl:with-param name="spans" select="$spans"/>
564         </xsl:call-template>
565       </xsl:message>
566       -->
567
568       <xsl:if test="normalize-space(.//text()) != ''">
569         <xsl:message>Warning: overlapped row contains content!</xsl:message>
570       </xsl:if>
571
572       <tr><xsl:comment> This row intentionally left blank </xsl:comment></tr>
573
574       <xsl:if test="$browserows = 'recurse'">
575         <xsl:apply-templates select="following-sibling::row[1]">
576           <xsl:with-param name="spans">
577             <xsl:call-template name="consume-row">
578               <xsl:with-param name="spans" select="$spans"/>
579             </xsl:call-template>
580           </xsl:with-param>
581           <xsl:with-param name="browserows" select="$browserows"/>
582         </xsl:apply-templates>
583       </xsl:if>
584     </xsl:otherwise>
585   </xsl:choose>
586 </xsl:template>
587
588 <xsl:template name="normal-row">
589   <xsl:param name="spans"/>
590   <xsl:param name="browserows"/>
591
592   <xsl:variable name="row-height">
593     <xsl:if test="processing-instruction('dbhtml')">
594       <xsl:call-template name="pi.dbhtml_row-height"/>
595     </xsl:if>
596   </xsl:variable>
597
598   <xsl:variable name="bgcolor">
599     <xsl:if test="processing-instruction('dbhtml')">
600       <xsl:call-template name="pi.dbhtml_bgcolor"/>
601     </xsl:if>
602   </xsl:variable>
603
604   <xsl:variable name="class">
605     <xsl:if test="processing-instruction('dbhtml')">
606       <xsl:call-template name="pi.dbhtml_class"/>
607     </xsl:if>
608   </xsl:variable>
609
610   <tr>
611     <xsl:call-template name="tr.attributes">
612       <xsl:with-param name="rownum">
613         <xsl:number from="tgroup" count="row"/>
614       </xsl:with-param>
615     </xsl:call-template>
616
617     <xsl:if test="$row-height != ''">
618       <xsl:attribute name="height">
619         <xsl:value-of select="$row-height"/>
620       </xsl:attribute>
621     </xsl:if>
622
623     <xsl:if test="$bgcolor != ''">
624       <xsl:attribute name="bgcolor">
625         <xsl:value-of select="$bgcolor"/>
626       </xsl:attribute>
627     </xsl:if>
628
629     <xsl:if test="$class != ''">
630       <xsl:attribute name="class">
631         <xsl:value-of select="$class"/>
632       </xsl:attribute>
633     </xsl:if>
634
635     <xsl:if test="$table.borders.with.css != 0">
636       <xsl:if test="@rowsep = 1 and following-sibling::row">
637         <xsl:attribute name="style">
638           <xsl:call-template name="border">
639             <xsl:with-param name="side" select="'bottom'"/>
640           </xsl:call-template>
641         </xsl:attribute>
642       </xsl:if>
643     </xsl:if>
644
645     <xsl:if test="@align">
646       <xsl:attribute name="align">
647         <xsl:value-of select="@align"/>
648       </xsl:attribute>
649     </xsl:if>
650     <xsl:if test="@char">
651       <xsl:attribute name="char">
652         <xsl:value-of select="@char"/>
653       </xsl:attribute>
654     </xsl:if>
655     <xsl:if test="@charoff">
656       <xsl:attribute name="charoff">
657         <xsl:value-of select="@charoff"/>
658       </xsl:attribute>
659     </xsl:if>
660     <xsl:if test="@valign">
661       <xsl:attribute name="valign">
662         <xsl:value-of select="@valign"/>
663       </xsl:attribute>
664     </xsl:if>
665
666     <xsl:apply-templates select="(entry|entrytbl)[1]">
667       <xsl:with-param name="spans" select="$spans"/>
668     </xsl:apply-templates>
669   </tr>
670
671   <xsl:if test="$browserows = 'recurse'">
672     <xsl:if test="following-sibling::row">
673       <xsl:variable name="nextspans">
674         <xsl:apply-templates select="(entry|entrytbl)[1]" mode="span">
675           <xsl:with-param name="spans" select="$spans"/>
676         </xsl:apply-templates>
677       </xsl:variable>
678   
679       <xsl:apply-templates select="following-sibling::row[1]">
680         <xsl:with-param name="spans" select="$nextspans"/>
681         <xsl:with-param name="browserows" select="$browserows"/>
682       </xsl:apply-templates>
683     </xsl:if>
684   </xsl:if>
685 </xsl:template>
686
687 <xsl:template match="entry|entrytbl" name="entry">
688   <xsl:param name="col">
689     <xsl:choose>
690       <xsl:when test="@revisionflag">
691         <xsl:number from="row"/>
692       </xsl:when>
693       <xsl:otherwise>1</xsl:otherwise>
694     </xsl:choose>
695   </xsl:param>
696
697   <xsl:param name="spans"/>
698
699   <xsl:variable name="cellgi">
700     <xsl:choose>
701       <xsl:when test="ancestor::thead">th</xsl:when>
702       <xsl:when test="ancestor::tfoot">th</xsl:when>
703       <xsl:when test="ancestor::tbody and 
704                       (ancestor::table[@rowheader = 'firstcol'] or
705                       ancestor::informaltable[@rowheader = 'firstcol']) and
706                       ancestor-or-self::entry[1][count(preceding-sibling::entry) = 0]">
707         <xsl:text>th</xsl:text>
708       </xsl:when>
709       <xsl:otherwise>td</xsl:otherwise>
710     </xsl:choose>
711   </xsl:variable>
712
713   <xsl:variable name="empty.cell" select="count(node()) = 0"/>
714
715   <xsl:variable name="named.colnum">
716     <xsl:call-template name="entry.colnum"/>
717   </xsl:variable>
718
719   <xsl:variable name="entry.colnum">
720     <xsl:choose>
721       <xsl:when test="$named.colnum &gt; 0">
722         <xsl:value-of select="$named.colnum"/>
723       </xsl:when>
724       <xsl:otherwise>
725         <xsl:value-of select="$col"/>
726       </xsl:otherwise>
727     </xsl:choose>
728   </xsl:variable>
729
730   <xsl:variable name="entry.colspan">
731     <xsl:choose>
732       <xsl:when test="@spanname or @namest">
733         <xsl:call-template name="calculate.colspan"/>
734       </xsl:when>
735       <xsl:otherwise>1</xsl:otherwise>
736     </xsl:choose>
737   </xsl:variable>
738
739   <xsl:variable name="following.spans">
740     <xsl:call-template name="calculate.following.spans">
741       <xsl:with-param name="colspan" select="$entry.colspan"/>
742       <xsl:with-param name="spans" select="$spans"/>
743     </xsl:call-template>
744   </xsl:variable>
745
746   <xsl:variable name="rowsep">
747     <xsl:choose>
748       <!-- If this is the last row, rowsep never applies. -->
749       <xsl:when test="ancestor::entrytbl
750                       and not (ancestor-or-self::row[1]/following-sibling::row)
751                       and not (ancestor::thead)">
752         <xsl:value-of select="0"/>
753       </xsl:when>
754       <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row
755                           or ancestor-or-self::thead/following-sibling::tbody
756                           or ancestor-or-self::tbody/preceding-sibling::tfoot)">
757         <xsl:value-of select="0"/>
758       </xsl:when>
759       <xsl:when test="@morerows and not(@morerows &lt; 
760                  count(ancestor-or-self::row[1]/following-sibling::row))">
761         <xsl:value-of select="0"/>
762       </xsl:when>
763       <xsl:otherwise>
764         <xsl:call-template name="inherited.table.attribute">
765           <xsl:with-param name="entry" select="."/>
766           <xsl:with-param name="colnum" select="$entry.colnum"/>
767           <xsl:with-param name="attribute" select="'rowsep'"/>
768         </xsl:call-template>
769       </xsl:otherwise>
770     </xsl:choose>
771   </xsl:variable>
772
773   <xsl:variable name="colsep">
774     <xsl:choose>
775       <!-- If this is the last column, colsep never applies. -->
776       <xsl:when test="$following.spans = ''">0</xsl:when>
777       <xsl:otherwise>
778         <xsl:call-template name="inherited.table.attribute">
779           <xsl:with-param name="entry" select="."/>
780           <xsl:with-param name="colnum" select="$entry.colnum"/>
781           <xsl:with-param name="attribute" select="'colsep'"/>
782         </xsl:call-template>
783       </xsl:otherwise>
784     </xsl:choose>
785   </xsl:variable>
786
787   <xsl:variable name="valign">
788     <xsl:call-template name="inherited.table.attribute">
789       <xsl:with-param name="entry" select="."/>
790       <xsl:with-param name="colnum" select="$entry.colnum"/>
791       <xsl:with-param name="attribute" select="'valign'"/>
792     </xsl:call-template>
793   </xsl:variable>
794
795   <xsl:variable name="align">
796     <xsl:call-template name="inherited.table.attribute">
797       <xsl:with-param name="entry" select="."/>
798       <xsl:with-param name="colnum" select="$entry.colnum"/>
799       <xsl:with-param name="attribute" select="'align'"/>
800     </xsl:call-template>
801   </xsl:variable>
802
803   <xsl:variable name="char">
804     <xsl:call-template name="inherited.table.attribute">
805       <xsl:with-param name="entry" select="."/>
806       <xsl:with-param name="colnum" select="$entry.colnum"/>
807       <xsl:with-param name="attribute" select="'char'"/>
808     </xsl:call-template>
809   </xsl:variable>
810
811   <xsl:variable name="charoff">
812     <xsl:call-template name="inherited.table.attribute">
813       <xsl:with-param name="entry" select="."/>
814       <xsl:with-param name="colnum" select="$entry.colnum"/>
815       <xsl:with-param name="attribute" select="'charoff'"/>
816     </xsl:call-template>
817   </xsl:variable>
818
819   <xsl:choose>
820     <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
821       <xsl:call-template name="entry">
822         <xsl:with-param name="col" select="$col+1"/>
823         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
824       </xsl:call-template>
825     </xsl:when>
826
827     <xsl:when test="number($entry.colnum) &gt; $col">
828       <xsl:call-template name="empty.table.cell"/>
829       <xsl:call-template name="entry">
830         <xsl:with-param name="col" select="$col+1"/>
831         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
832       </xsl:call-template>
833     </xsl:when>
834
835     <xsl:otherwise>
836       <xsl:variable name="bgcolor">
837         <xsl:if test="processing-instruction('dbhtml')">
838           <xsl:call-template name="pi.dbhtml_bgcolor"/>
839         </xsl:if>
840       </xsl:variable>
841
842       <xsl:element name="{$cellgi}">
843         <xsl:if test="$bgcolor != ''">
844           <xsl:attribute name="bgcolor">
845             <xsl:value-of select="$bgcolor"/>
846           </xsl:attribute>
847         </xsl:if>
848
849         <xsl:call-template name="locale.html.attributes"/>
850         <xsl:if test="$entry.propagates.style != 0 and @role">
851           <xsl:apply-templates select="." mode="class.attribute">
852             <xsl:with-param name="class" select="@role"/>
853           </xsl:apply-templates>
854         </xsl:if>
855
856         <xsl:if test="$show.revisionflag and @revisionflag">
857           <xsl:attribute name="class">
858             <xsl:value-of select="@revisionflag"/>
859           </xsl:attribute>
860         </xsl:if>
861
862         <xsl:if test="$table.borders.with.css != 0">
863           <xsl:attribute name="style">
864             <xsl:if test="$colsep &gt; 0">
865               <xsl:call-template name="border">
866                 <xsl:with-param name="side" select="'right'"/>
867               </xsl:call-template>
868             </xsl:if>
869             <xsl:if test="$rowsep &gt; 0">
870               <xsl:call-template name="border">
871                 <xsl:with-param name="side" select="'bottom'"/>
872               </xsl:call-template>
873             </xsl:if>
874           </xsl:attribute>
875         </xsl:if>
876
877         <xsl:if test="@morerows &gt; 0">
878           <xsl:attribute name="rowspan">
879             <xsl:value-of select="1+@morerows"/>
880           </xsl:attribute>
881         </xsl:if>
882
883         <xsl:if test="$entry.colspan &gt; 1">
884           <xsl:attribute name="colspan">
885             <xsl:value-of select="$entry.colspan"/>
886           </xsl:attribute>
887         </xsl:if>
888
889         <xsl:if test="$align != ''">
890           <xsl:attribute name="align">
891             <xsl:value-of select="$align"/>
892           </xsl:attribute>
893         </xsl:if>
894
895         <xsl:if test="$valign != ''">
896           <xsl:attribute name="valign">
897             <xsl:value-of select="$valign"/>
898           </xsl:attribute>
899         </xsl:if>
900
901         <xsl:if test="$char != ''">
902           <xsl:attribute name="char">
903             <xsl:value-of select="$char"/>
904           </xsl:attribute>
905         </xsl:if>
906
907         <xsl:if test="$charoff != ''">
908           <xsl:attribute name="charoff">
909             <xsl:value-of select="$charoff"/>
910           </xsl:attribute>
911         </xsl:if>
912
913         <xsl:if test="not(preceding-sibling::*) and 
914                     (ancestor::row[1]/@id or ancestor::row[1]/@xml:id)">
915           <xsl:call-template name="anchor">
916             <xsl:with-param name="node" select="ancestor::row[1]"/>
917           </xsl:call-template>
918         </xsl:if>
919
920         <xsl:call-template name="anchor"/>
921
922         <xsl:choose>
923           <xsl:when test="$empty.cell">
924             <xsl:text>&#160;</xsl:text>
925           </xsl:when>
926           <xsl:when test="self::entrytbl">
927             <xsl:call-template name="tgroup"/>
928           </xsl:when>
929           <xsl:otherwise>
930             <xsl:apply-templates/>
931           </xsl:otherwise>
932         </xsl:choose>
933       </xsl:element>
934
935       <xsl:choose>
936         <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
937           <xsl:apply-templates select="(following-sibling::entry
938                                        |following-sibling::entrytbl)[1]">
939             <xsl:with-param name="col" select="$col+$entry.colspan"/>
940             <xsl:with-param name="spans" select="$following.spans"/>
941           </xsl:apply-templates>
942         </xsl:when>
943         <xsl:otherwise>
944           <xsl:call-template name="finaltd">
945             <xsl:with-param name="spans" select="$following.spans"/>
946             <xsl:with-param name="col" select="$col+$entry.colspan"/>
947           </xsl:call-template>
948         </xsl:otherwise>
949       </xsl:choose>
950     </xsl:otherwise>
951   </xsl:choose>
952 </xsl:template>
953
954 <xsl:template match="entry|entrytbl" name="sentry" mode="span">
955   <xsl:param name="col" select="1"/>
956   <xsl:param name="spans"/>
957
958   <xsl:variable name="entry.colnum">
959     <xsl:call-template name="entry.colnum"/>
960   </xsl:variable>
961
962   <xsl:variable name="entry.colspan">
963     <xsl:choose>
964       <xsl:when test="@spanname or @namest">
965         <xsl:call-template name="calculate.colspan"/>
966       </xsl:when>
967       <xsl:otherwise>1</xsl:otherwise>
968     </xsl:choose>
969   </xsl:variable>
970
971   <xsl:variable name="following.spans">
972     <xsl:call-template name="calculate.following.spans">
973       <xsl:with-param name="colspan" select="$entry.colspan"/>
974       <xsl:with-param name="spans" select="$spans"/>
975     </xsl:call-template>
976   </xsl:variable>
977
978   <xsl:choose>
979     <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
980       <xsl:value-of select="substring-before($spans,':')-1"/>
981       <xsl:text>:</xsl:text>
982       <xsl:call-template name="sentry">
983         <xsl:with-param name="col" select="$col+1"/>
984         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
985       </xsl:call-template>
986     </xsl:when>
987
988     <xsl:when test="number($entry.colnum) &gt; $col">
989       <xsl:text>0:</xsl:text>
990       <xsl:call-template name="sentry">
991         <xsl:with-param name="col" select="$col + 1"/>
992         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
993       </xsl:call-template>
994     </xsl:when>
995
996     <xsl:otherwise>
997       <xsl:call-template name="copy-string">
998         <xsl:with-param name="count" select="$entry.colspan"/>
999         <xsl:with-param name="string">
1000           <xsl:choose>
1001             <xsl:when test="@morerows">
1002               <xsl:value-of select="@morerows"/>
1003             </xsl:when>
1004             <xsl:otherwise>0</xsl:otherwise>
1005           </xsl:choose>
1006           <xsl:text>:</xsl:text>
1007         </xsl:with-param>
1008       </xsl:call-template>
1009
1010       <xsl:choose>
1011         <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
1012           <xsl:apply-templates select="(following-sibling::entry
1013                                         |following-sibling::entrytbl)[1]"
1014                                mode="span">
1015             <xsl:with-param name="col" select="$col+$entry.colspan"/>
1016             <xsl:with-param name="spans" select="$following.spans"/>
1017           </xsl:apply-templates>
1018         </xsl:when>
1019         <xsl:otherwise>
1020           <xsl:call-template name="sfinaltd">
1021             <xsl:with-param name="spans" select="$following.spans"/>
1022           </xsl:call-template>
1023         </xsl:otherwise>
1024       </xsl:choose>
1025     </xsl:otherwise>
1026   </xsl:choose>
1027 </xsl:template>
1028
1029 <xsl:template name="generate.colgroup">
1030   <xsl:param name="cols" select="1"/>
1031   <xsl:param name="count" select="1"/>
1032   <xsl:choose>
1033     <xsl:when test="$count &gt; $cols"></xsl:when>
1034     <xsl:otherwise>
1035       <xsl:call-template name="generate.col">
1036         <xsl:with-param name="countcol" select="$count"/>
1037       </xsl:call-template>
1038       <xsl:call-template name="generate.colgroup">
1039         <xsl:with-param name="cols" select="$cols"/>
1040         <xsl:with-param name="count" select="$count+1"/>
1041       </xsl:call-template>
1042     </xsl:otherwise>
1043   </xsl:choose>
1044 </xsl:template>
1045
1046 <xsl:template name="generate.col">
1047   <xsl:param name="countcol">1</xsl:param>
1048   <xsl:param name="colspecs" select="./colspec"/>
1049   <xsl:param name="count">1</xsl:param>
1050   <xsl:param name="colnum">1</xsl:param>
1051
1052   <xsl:choose>
1053     <xsl:when test="$count>count($colspecs)">
1054       <col/>
1055     </xsl:when>
1056     <xsl:otherwise>
1057       <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1058       <xsl:variable name="colspec.colnum">
1059         <xsl:choose>
1060           <xsl:when test="$colspec/@colnum">
1061             <xsl:value-of select="$colspec/@colnum"/>
1062           </xsl:when>
1063           <xsl:otherwise>
1064             <xsl:value-of select="$colnum"/>
1065           </xsl:otherwise>
1066         </xsl:choose>
1067       </xsl:variable>
1068
1069       <xsl:choose>
1070         <xsl:when test="$colspec.colnum=$countcol">
1071           <col>
1072             <xsl:choose>
1073               <xsl:when test="$colspec/@colwidth
1074                             and $use.extensions != 0
1075                             and $tablecolumns.extension != 0">
1076                 <xsl:attribute name="width">
1077                   <xsl:choose>
1078                     <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1079                       <xsl:value-of select="'1*'"/>
1080                     </xsl:when>
1081                     <xsl:otherwise>
1082                       <xsl:value-of select="$colspec/@colwidth"/>
1083                     </xsl:otherwise>
1084                   </xsl:choose>
1085                 </xsl:attribute>
1086               </xsl:when>
1087               <!-- pass through to HTML if no * in colspecs -->
1088               <xsl:when test="$colspec/@colwidth and
1089                              not($colspec/parent::*/colspec/@colwidth[contains(.,'*')])">
1090                 <xsl:attribute name="width">
1091                   <xsl:choose>
1092                     <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1093                       <xsl:value-of select="'1*'"/>
1094                     </xsl:when>
1095                     <xsl:otherwise>
1096                       <xsl:value-of select="$colspec/@colwidth"/>
1097                     </xsl:otherwise>
1098                   </xsl:choose>
1099                 </xsl:attribute>
1100               </xsl:when>
1101             </xsl:choose>
1102
1103             <xsl:choose>
1104               <xsl:when test="$colspec/@align">
1105                 <xsl:attribute name="align">
1106                   <xsl:value-of select="$colspec/@align"/>
1107                 </xsl:attribute>
1108               </xsl:when>
1109               <!-- Suggested by Pavel ZAMPACH <zampach@nemcb.cz> -->
1110               <xsl:when test="$colspecs/ancestor::tgroup/@align">
1111                 <xsl:attribute name="align">
1112                   <xsl:value-of select="$colspecs/ancestor::tgroup/@align"/>
1113                 </xsl:attribute>
1114               </xsl:when>
1115             </xsl:choose>
1116
1117             <xsl:if test="$colspec/@char">
1118               <xsl:attribute name="char">
1119                 <xsl:value-of select="$colspec/@char"/>
1120               </xsl:attribute>
1121             </xsl:if>
1122             
1123             <xsl:if test="$colspec/@charoff">
1124               <xsl:attribute name="charoff">
1125                 <xsl:value-of select="$colspec/@charoff"/>
1126               </xsl:attribute>
1127             </xsl:if>
1128
1129             <xsl:if test="$colspec/@colname">
1130               <xsl:attribute name="class">
1131                 <xsl:value-of select="$colspec/@colname"/>
1132               </xsl:attribute>
1133             </xsl:if>
1134           </col>
1135         </xsl:when>
1136         <xsl:otherwise>
1137           <xsl:call-template name="generate.col">
1138             <xsl:with-param name="countcol" select="$countcol"/>
1139             <xsl:with-param name="colspecs" select="$colspecs"/>
1140             <xsl:with-param name="count" select="$count+1"/>
1141             <xsl:with-param name="colnum">
1142               <xsl:choose>
1143                 <xsl:when test="$colspec/@colnum">
1144                   <xsl:value-of select="$colspec/@colnum + 1"/>
1145                 </xsl:when>
1146                 <xsl:otherwise>
1147                   <xsl:value-of select="$colnum + 1"/>
1148                 </xsl:otherwise>
1149               </xsl:choose>
1150             </xsl:with-param>
1151            </xsl:call-template>
1152         </xsl:otherwise>
1153       </xsl:choose>
1154     </xsl:otherwise>
1155   </xsl:choose>
1156 </xsl:template>
1157
1158 <xsl:template name="colspec.colwidth">
1159   <!-- when this macro is called, the current context must be an entry -->
1160   <xsl:param name="colname"></xsl:param>
1161   <!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
1162   <xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
1163   <xsl:param name="count">1</xsl:param>
1164   <xsl:choose>
1165     <xsl:when test="$count>count($colspecs)"></xsl:when>
1166     <xsl:otherwise>
1167       <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1168       <xsl:choose>
1169         <xsl:when test="$colspec/@colname=$colname">
1170           <xsl:value-of select="$colspec/@colwidth"/>
1171         </xsl:when>
1172         <xsl:otherwise>
1173           <xsl:call-template name="colspec.colwidth">
1174             <xsl:with-param name="colname" select="$colname"/>
1175             <xsl:with-param name="colspecs" select="$colspecs"/>
1176             <xsl:with-param name="count" select="$count+1"/>
1177           </xsl:call-template>
1178         </xsl:otherwise>
1179       </xsl:choose>
1180     </xsl:otherwise>
1181   </xsl:choose>
1182 </xsl:template>
1183
1184 <!-- ====================================================================== -->
1185
1186 <xsl:template name="tr.attributes">
1187   <xsl:param name="row" select="."/>
1188   <xsl:param name="rownum" select="0"/>
1189
1190   <!-- by default, do nothing. But you might want to say:
1191
1192   <xsl:if test="$rownum mod 2 = 0">
1193     <xsl:attribute name="class">oddrow</xsl:attribute>
1194   </xsl:if>
1195
1196   -->
1197 </xsl:template>
1198
1199 </xsl:stylesheet>
1200