Imported Upstream version 1.77.1
[platform/upstream/docbook-xsl.git] / xhtml / table.xsl
1 <?xml version="1.0" encoding="ASCII"?>
2 <!--This file was created automatically by html2xhtml-->
3 <!--from the HTML stylesheets.-->
4 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:doc="http://nwalsh.com/xsl/documentation/1.0" xmlns:stbl="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Table" xmlns:xtbl="xalan://com.nwalsh.xalan.Table" xmlns:lxslt="http://xml.apache.org/xslt" xmlns:ptbl="http://nwalsh.com/xslt/ext/xsltproc/python/Table" xmlns="http://www.w3.org/1999/xhtml" exclude-result-prefixes="doc stbl xtbl lxslt ptbl" version="1.0">
5
6 <xsl:include href="../common/table.xsl"/>
7
8 <!-- ********************************************************************
9      $Id: table.xsl 9297 2012-04-22 03:56:16Z bobstayton $
10      ********************************************************************
11
12      This file is part of the XSL DocBook Stylesheet distribution.
13      See ../README or http://docbook.sf.net/release/xsl/current/ for
14      copyright and other information.
15
16      ******************************************************************** -->
17
18 <lxslt:component prefix="xtbl" functions="adjustColumnWidths"/>
19
20 <xsl:template name="empty.table.cell">
21   <xsl:param name="colnum" select="0"/>
22
23   <xsl:variable name="rowsep">
24     <xsl:choose>
25       <!-- If this is the last row, rowsep never applies. -->
26       <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row                           or ancestor-or-self::thead/following-sibling::tbody                           or ancestor-or-self::tbody/preceding-sibling::tfoot)">
27         <xsl:value-of select="0"/>
28       </xsl:when>
29       <xsl:otherwise>
30         <xsl:call-template name="inherited.table.attribute">
31           <xsl:with-param name="entry" select="NOT-AN-ELEMENT-NAME"/>
32           <xsl:with-param name="row" select="ancestor-or-self::row[1]"/>
33           <xsl:with-param name="colnum" select="$colnum"/>
34           <xsl:with-param name="attribute" select="'rowsep'"/>
35         </xsl:call-template>
36       </xsl:otherwise>
37     </xsl:choose>
38   </xsl:variable>
39
40   <xsl:variable name="colsep">
41     <xsl:choose>
42       <!-- If this is the last column, colsep never applies. -->
43       <xsl:when test="number($colnum) &gt;= ancestor::tgroup/@cols">0</xsl:when>
44       <xsl:otherwise>
45         <xsl:call-template name="inherited.table.attribute">
46           <xsl:with-param name="entry" select="NOT-AN-ELEMENT-NAME"/>
47           <xsl:with-param name="row" select="ancestor-or-self::row[1]"/>
48           <xsl:with-param name="colnum" select="$colnum"/>
49           <xsl:with-param name="attribute" select="'colsep'"/>
50         </xsl:call-template>
51       </xsl:otherwise>
52     </xsl:choose>
53   </xsl:variable>
54
55   <td class="auto-generated">
56     <xsl:if test="$table.borders.with.css != 0">
57       <xsl:attribute name="style">
58         <xsl:if test="$colsep &gt; 0">
59           <xsl:call-template name="border">
60             <xsl:with-param name="side" select="'right'"/>
61           </xsl:call-template>
62         </xsl:if>
63         <xsl:if test="$rowsep &gt; 0">
64           <xsl:call-template name="border">
65             <xsl:with-param name="side" select="'bottom'"/>
66           </xsl:call-template>
67         </xsl:if>
68       </xsl:attribute>
69     </xsl:if>
70     <xsl:text>&#160;</xsl:text>
71   </td>
72 </xsl:template>
73
74 <!-- ==================================================================== -->
75
76 <xsl:template name="border">
77   <xsl:param name="side" select="'left'"/>
78   <xsl:param name="padding" select="0"/>
79   <xsl:param name="style" select="$table.cell.border.style"/>
80   <xsl:param name="color" select="$table.cell.border.color"/>
81   <xsl:param name="thickness" select="$table.cell.border.thickness"/>
82
83   <!-- Note: Some browsers (mozilla) require at least a width and style. -->
84
85   <xsl:choose>
86     <xsl:when test="($thickness != ''                      and $style != ''                      and $color != '')                     or ($thickness != ''                         and $style != '')                     or ($thickness != '')">
87       <!-- use the compound property if we can: -->
88       <!-- it saves space and probably works more reliably -->
89       <xsl:text>border-</xsl:text>
90       <xsl:value-of select="$side"/>
91       <xsl:text>: </xsl:text>
92       <xsl:value-of select="$thickness"/>
93       <xsl:text> </xsl:text>
94       <xsl:value-of select="$style"/>
95       <xsl:text> </xsl:text>
96       <xsl:value-of select="$color"/>
97       <xsl:text>; </xsl:text>
98     </xsl:when>
99     <xsl:otherwise>
100       <!-- we need to specify the styles individually -->
101       <xsl:if test="$thickness != ''">
102         <xsl:text>border-</xsl:text>
103         <xsl:value-of select="$side"/>
104         <xsl:text>-width: </xsl:text>
105         <xsl:value-of select="$thickness"/>
106         <xsl:text>; </xsl:text>
107       </xsl:if>
108
109       <xsl:if test="$style != ''">
110         <xsl:text>border-</xsl:text>
111         <xsl:value-of select="$side"/>
112         <xsl:text>-style: </xsl:text>
113         <xsl:value-of select="$style"/>
114         <xsl:text>; </xsl:text>
115       </xsl:if>
116
117       <xsl:if test="$color != ''">
118         <xsl:text>border-</xsl:text>
119         <xsl:value-of select="$side"/>
120         <xsl:text>-color: </xsl:text>
121         <xsl:value-of select="$color"/>
122         <xsl:text>; </xsl:text>
123       </xsl:if>
124     </xsl:otherwise>
125   </xsl:choose>
126 </xsl:template>
127
128 <!-- ==================================================================== -->
129
130 <xsl:template match="tgroup" name="tgroup">
131   <xsl:if test="not(@cols) or @cols = '' or string(number(@cols)) = 'NaN'">
132     <xsl:message terminate="yes">
133       <xsl:text>Error: CALS tables must specify the number of columns.</xsl:text>
134     </xsl:message>
135   </xsl:if>
136
137   <xsl:variable name="summary">
138     <xsl:call-template name="pi.dbhtml_table-summary"/>
139   </xsl:variable>
140
141   <xsl:variable name="cellspacing">
142     <xsl:call-template name="pi.dbhtml_cellspacing"/>
143   </xsl:variable>
144
145   <xsl:variable name="cellpadding">
146     <xsl:call-template name="pi.dbhtml_cellpadding"/>
147   </xsl:variable>
148
149   <table>
150     <xsl:choose>
151       <!-- If there's a textobject/phrase for the table summary, use it -->
152       <xsl:when test="../textobject/phrase">
153         <xsl:attribute name="summary">
154           <xsl:value-of select="../textobject/phrase"/>
155         </xsl:attribute>
156       </xsl:when>
157
158       <!-- If there's a <?dbhtml table-summary="foo"?> PI, use it for
159            the HTML table summary attribute -->
160       <xsl:when test="$summary != ''">
161         <xsl:attribute name="summary">
162           <xsl:value-of select="$summary"/>
163         </xsl:attribute>
164       </xsl:when>
165
166       <!-- Otherwise, if there's a title, use that -->
167       <xsl:when test="../title">
168         <xsl:attribute name="summary">
169           <!-- This screws up on inline markup and footnotes, oh well... -->
170           <xsl:value-of select="string(../title)"/>
171         </xsl:attribute>
172       </xsl:when>
173
174       <!-- Otherwise, forget the whole idea -->
175       <xsl:otherwise><!-- nevermind --></xsl:otherwise>
176     </xsl:choose>
177
178     <xsl:if test="$cellspacing != '' or $html.cellspacing != ''">
179       <xsl:attribute name="cellspacing">
180         <xsl:choose>
181           <xsl:when test="$cellspacing != ''">
182             <xsl:value-of select="$cellspacing"/>
183           </xsl:when>
184           <xsl:otherwise>
185             <xsl:value-of select="$html.cellspacing"/>
186           </xsl:otherwise>
187         </xsl:choose>
188       </xsl:attribute>
189     </xsl:if>
190
191     <xsl:if test="$cellpadding != '' or $html.cellpadding != ''">
192       <xsl:attribute name="cellpadding">
193         <xsl:choose>
194           <xsl:when test="$cellpadding != ''">
195             <xsl:value-of select="$cellpadding"/>
196           </xsl:when>
197           <xsl:otherwise>
198             <xsl:value-of select="$html.cellpadding"/>
199           </xsl:otherwise>
200         </xsl:choose>
201       </xsl:attribute>
202     </xsl:if>
203
204     <xsl:if test="../@pgwide=1 or local-name(.) = 'entrytbl'">
205       <xsl:attribute name="width">100%</xsl:attribute>
206     </xsl:if>
207
208     <xsl:choose>
209       <xsl:when test="$table.borders.with.css != 0">
210         <xsl:choose>
211           <xsl:when test="../@frame='all' or (not(../@frame) and $default.table.frame='all')">
212             <xsl:attribute name="style">
213               <xsl:text>border-collapse: collapse;</xsl:text>
214               <xsl:call-template name="border">
215                 <xsl:with-param name="side" select="'top'"/>
216                 <xsl:with-param name="style" select="$table.frame.border.style"/>
217                 <xsl:with-param name="color" select="$table.frame.border.color"/>
218                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
219               </xsl:call-template>
220               <xsl:call-template name="border">
221                 <xsl:with-param name="side" select="'bottom'"/>
222                 <xsl:with-param name="style" select="$table.frame.border.style"/>
223                 <xsl:with-param name="color" select="$table.frame.border.color"/>
224                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
225               </xsl:call-template>
226               <xsl:call-template name="border">
227                 <xsl:with-param name="side" select="'left'"/>
228                 <xsl:with-param name="style" select="$table.frame.border.style"/>
229                 <xsl:with-param name="color" select="$table.frame.border.color"/>
230                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
231               </xsl:call-template>
232               <xsl:call-template name="border">
233                 <xsl:with-param name="side" select="'right'"/>
234                 <xsl:with-param name="style" select="$table.frame.border.style"/>
235                 <xsl:with-param name="color" select="$table.frame.border.color"/>
236                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
237               </xsl:call-template>
238             </xsl:attribute>
239           </xsl:when>
240           <xsl:when test="../@frame='topbot' or (not(../@frame) and $default.table.frame='topbot')">
241             <xsl:attribute name="style">
242               <xsl:text>border-collapse: collapse;</xsl:text>
243               <xsl:call-template name="border">
244                 <xsl:with-param name="side" select="'top'"/>
245                 <xsl:with-param name="style" select="$table.frame.border.style"/>
246                 <xsl:with-param name="color" select="$table.frame.border.color"/>
247                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
248               </xsl:call-template>
249               <xsl:call-template name="border">
250                 <xsl:with-param name="side" select="'bottom'"/>
251                 <xsl:with-param name="style" select="$table.frame.border.style"/>
252                 <xsl:with-param name="color" select="$table.frame.border.color"/>
253                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
254               </xsl:call-template>
255             </xsl:attribute>
256           </xsl:when>
257           <xsl:when test="../@frame='top' or (not(../@frame) and $default.table.frame='top')">
258             <xsl:attribute name="style">
259               <xsl:text>border-collapse: collapse;</xsl:text>
260               <xsl:call-template name="border">
261                 <xsl:with-param name="side" select="'top'"/>
262                 <xsl:with-param name="style" select="$table.frame.border.style"/>
263                 <xsl:with-param name="color" select="$table.frame.border.color"/>
264                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
265               </xsl:call-template>
266             </xsl:attribute>
267           </xsl:when>
268           <xsl:when test="../@frame='bottom' or (not(../@frame) and $default.table.frame='bottom')">
269             <xsl:attribute name="style">
270               <xsl:text>border-collapse: collapse;</xsl:text>
271               <xsl:call-template name="border">
272                 <xsl:with-param name="side" select="'bottom'"/>
273                 <xsl:with-param name="style" select="$table.frame.border.style"/>
274                 <xsl:with-param name="color" select="$table.frame.border.color"/>
275                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
276               </xsl:call-template>
277             </xsl:attribute>
278           </xsl:when>
279           <xsl:when test="../@frame='sides' or (not(../@frame) and $default.table.frame='sides')">
280             <xsl:attribute name="style">
281               <xsl:text>border-collapse: collapse;</xsl:text>
282               <xsl:call-template name="border">
283                 <xsl:with-param name="side" select="'left'"/>
284                 <xsl:with-param name="style" select="$table.frame.border.style"/>
285                 <xsl:with-param name="color" select="$table.frame.border.color"/>
286                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
287               </xsl:call-template>
288               <xsl:call-template name="border">
289                 <xsl:with-param name="side" select="'right'"/>
290                 <xsl:with-param name="style" select="$table.frame.border.style"/>
291                 <xsl:with-param name="color" select="$table.frame.border.color"/>
292                 <xsl:with-param name="thickness" select="$table.frame.border.thickness"/>
293               </xsl:call-template>
294             </xsl:attribute>
295           </xsl:when>
296           <xsl:when test="../@frame='none'">
297             <xsl:attribute name="style">
298               <xsl:text>border: none;</xsl:text>
299             </xsl:attribute>
300           </xsl:when>
301           <xsl:otherwise>
302             <xsl:attribute name="style">
303               <xsl:text>border-collapse: collapse;</xsl:text>
304             </xsl:attribute>
305           </xsl:otherwise>
306         </xsl:choose>
307
308       </xsl:when>
309       <xsl:when test="../@frame='none' or (not(../@frame) and $default.table.frame='none') or local-name(.) = 'entrytbl'">
310         <xsl:attribute name="border">0</xsl:attribute>
311       </xsl:when>
312       <xsl:otherwise>
313         <xsl:attribute name="border">1</xsl:attribute>
314       </xsl:otherwise>
315     </xsl:choose>
316
317     <xsl:variable name="colgroup">
318       <colgroup>
319         <xsl:call-template name="generate.colgroup">
320           <xsl:with-param name="cols" select="@cols"/>
321         </xsl:call-template>
322       </colgroup>
323     </xsl:variable>
324
325     <xsl:variable name="explicit.table.width">
326       <xsl:call-template name="pi.dbhtml_table-width">
327         <xsl:with-param name="node" select=".."/>
328       </xsl:call-template>
329     </xsl:variable>
330
331     <xsl:variable name="table.width">
332       <xsl:choose>
333         <xsl:when test="$explicit.table.width != ''">
334           <xsl:value-of select="$explicit.table.width"/>
335         </xsl:when>
336         <xsl:when test="$default.table.width = ''">
337           <xsl:text>100%</xsl:text>
338         </xsl:when>
339         <xsl:otherwise>
340           <xsl:value-of select="$default.table.width"/>
341         </xsl:otherwise>
342       </xsl:choose>
343     </xsl:variable>
344
345     <xsl:if test="$default.table.width != ''                   or $explicit.table.width != ''">
346       <xsl:attribute name="width">
347         <xsl:choose>
348           <xsl:when test="contains($table.width, '%')">
349             <xsl:value-of select="$table.width"/>
350           </xsl:when>
351           <xsl:when test="$use.extensions != 0                           and $tablecolumns.extension != 0">
352             <xsl:choose>
353               <xsl:when test="function-available('stbl:convertLength')">
354                 <xsl:value-of select="stbl:convertLength($table.width)"/>
355               </xsl:when>
356               <xsl:when test="function-available('xtbl:convertLength')">
357                 <xsl:value-of select="xtbl:convertLength($table.width)"/>
358               </xsl:when>
359               <xsl:otherwise>
360                 <xsl:message terminate="yes">
361                   <xsl:text>No convertLength function available.</xsl:text>
362                 </xsl:message>
363               </xsl:otherwise>
364             </xsl:choose>
365           </xsl:when>
366           <xsl:otherwise>
367             <xsl:value-of select="$table.width"/>
368           </xsl:otherwise>
369         </xsl:choose>
370       </xsl:attribute>
371     </xsl:if>
372
373     <xsl:choose>
374       <xsl:when test="$use.extensions != 0                       and $tablecolumns.extension != 0">
375         <xsl:choose>
376           <xsl:when test="function-available('stbl:adjustColumnWidths')">
377             <xsl:copy-of select="stbl:adjustColumnWidths($colgroup)"/>
378           </xsl:when>
379           <xsl:when test="function-available('xtbl:adjustColumnWidths')">
380             <xsl:copy-of select="xtbl:adjustColumnWidths($colgroup)"/>
381           </xsl:when>
382           <xsl:when test="function-available('ptbl:adjustColumnWidths')">
383             <xsl:copy-of select="ptbl:adjustColumnWidths($colgroup)"/>
384           </xsl:when>
385           <xsl:otherwise>
386             <xsl:message terminate="yes">
387               <xsl:text>No adjustColumnWidths function available.</xsl:text>
388             </xsl:message>
389           </xsl:otherwise>
390         </xsl:choose>
391       </xsl:when>
392       <xsl:otherwise>
393         <xsl:copy-of select="$colgroup"/>
394       </xsl:otherwise>
395     </xsl:choose>
396
397     <xsl:apply-templates select="thead"/>
398     <xsl:apply-templates select="tfoot"/>
399     <xsl:apply-templates select="tbody"/>
400
401     <xsl:if test=".//footnote|../title//footnote">
402       <tbody class="footnotes">
403         <tr>
404           <td colspan="{@cols}">
405             <xsl:apply-templates select=".//footnote|../title//footnote" mode="table.footnote.mode"/>
406           </td>
407         </tr>
408       </tbody>
409     </xsl:if>
410   </table>
411 </xsl:template>
412
413 <xsl:template match="tgroup/processing-instruction('dbhtml')">
414   <xsl:variable name="summary">
415     <xsl:call-template name="pi.dbhtml_table-summary"/>
416   </xsl:variable>
417
418   <!-- Suppress the table-summary PI -->
419   <xsl:if test="$summary = ''">
420     <xsl:processing-instruction name="dbhtml">
421       <xsl:value-of select="."/>
422     </xsl:processing-instruction>
423   </xsl:if>
424 </xsl:template>
425
426 <xsl:template match="colspec"/>
427
428 <xsl:template match="spanspec"/>
429
430 <xsl:template match="thead|tfoot">
431   <xsl:element name="{local-name(.)}" namespace="http://www.w3.org/1999/xhtml">
432     <xsl:if test="@align">
433       <xsl:attribute name="align">
434         <xsl:value-of select="@align"/>
435       </xsl:attribute>
436     </xsl:if>
437     <xsl:if test="@char">
438       <xsl:attribute name="char">
439         <xsl:value-of select="@char"/>
440       </xsl:attribute>
441     </xsl:if>
442     <xsl:if test="@charoff">
443       <xsl:attribute name="charoff">
444         <xsl:value-of select="@charoff"/>
445       </xsl:attribute>
446     </xsl:if>
447     <xsl:if test="@valign">
448       <xsl:attribute name="valign">
449         <xsl:value-of select="@valign"/>
450       </xsl:attribute>
451     </xsl:if>
452
453     <xsl:choose>
454       <!-- recurse on rows only if @morerows is present -->
455       <xsl:when test="row/entry/@morerows|row/entrytbl/@morerows">
456         <xsl:apply-templates select="row[1]">
457           <xsl:with-param name="spans">
458             <xsl:call-template name="blank.spans">
459               <xsl:with-param name="cols" select="../@cols"/>
460             </xsl:call-template>
461           </xsl:with-param>
462           <xsl:with-param name="browserows" select="'recurse'"/>
463         </xsl:apply-templates>
464       </xsl:when>
465       <xsl:otherwise>
466         <xsl:apply-templates select="row">
467           <xsl:with-param name="spans">
468             <xsl:call-template name="blank.spans">
469               <xsl:with-param name="cols" select="../@cols"/>
470             </xsl:call-template>
471           </xsl:with-param>
472           <xsl:with-param name="browserows" select="'loop'"/>
473         </xsl:apply-templates>
474       </xsl:otherwise>
475     </xsl:choose>
476
477   </xsl:element>
478 </xsl:template>
479
480 <xsl:template match="tbody">
481   <tbody>
482     <xsl:if test="@align">
483       <xsl:attribute name="align">
484         <xsl:value-of select="@align"/>
485       </xsl:attribute>
486     </xsl:if>
487     <xsl:if test="@char">
488       <xsl:attribute name="char">
489         <xsl:value-of select="@char"/>
490       </xsl:attribute>
491     </xsl:if>
492     <xsl:if test="@charoff">
493       <xsl:attribute name="charoff">
494         <xsl:value-of select="@charoff"/>
495       </xsl:attribute>
496     </xsl:if>
497     <xsl:if test="@valign">
498       <xsl:attribute name="valign">
499         <xsl:value-of select="@valign"/>
500       </xsl:attribute>
501     </xsl:if>
502
503     <xsl:choose>
504       <xsl:when test="row/entry/@morerows|row/entrytbl/@morerows">
505         <xsl:apply-templates select="row[1]">
506           <xsl:with-param name="spans">
507             <xsl:call-template name="blank.spans">
508               <xsl:with-param name="cols" select="../@cols"/>
509             </xsl:call-template>
510           </xsl:with-param>
511           <xsl:with-param name="browserows" select="'recurse'"/>
512         </xsl:apply-templates>
513       </xsl:when>
514       <xsl:otherwise>
515         <xsl:apply-templates select="row">
516           <xsl:with-param name="spans">
517             <xsl:call-template name="blank.spans">
518               <xsl:with-param name="cols" select="../@cols"/>
519             </xsl:call-template>
520           </xsl:with-param>
521           <xsl:with-param name="browserows" select="'loop'"/>
522         </xsl:apply-templates>
523       </xsl:otherwise>
524     </xsl:choose>
525
526   </tbody>
527 </xsl:template>
528
529 <xsl:template match="row">
530   <xsl:param name="spans"/>
531   <xsl:param name="browserows"/>
532
533   <xsl:choose>
534     <xsl:when test="contains($spans, '0')">
535       <xsl:call-template name="normal-row">
536         <xsl:with-param name="spans" select="$spans"/>
537         <xsl:with-param name="browserows" select="$browserows"/>
538       </xsl:call-template>
539     </xsl:when>
540     <xsl:otherwise>
541       <!--
542       <xsl:message>
543         <xsl:text>Ignoring row: </xsl:text>
544         <xsl:value-of select="$spans"/>
545         <xsl:text> = </xsl:text>
546         <xsl:call-template name="consume-row">
547           <xsl:with-param name="spans" select="$spans"/>
548         </xsl:call-template>
549       </xsl:message>
550       -->
551
552       <xsl:if test="normalize-space(.//text()) != ''">
553         <xsl:message>Warning: overlapped row contains content!</xsl:message>
554       </xsl:if>
555
556       <tr><xsl:comment> This row intentionally left blank </xsl:comment></tr>
557
558       <xsl:if test="$browserows = 'recurse'">
559         <xsl:apply-templates select="following-sibling::row[1]">
560           <xsl:with-param name="spans">
561             <xsl:call-template name="consume-row">
562               <xsl:with-param name="spans" select="$spans"/>
563             </xsl:call-template>
564           </xsl:with-param>
565           <xsl:with-param name="browserows" select="$browserows"/>
566         </xsl:apply-templates>
567       </xsl:if>
568     </xsl:otherwise>
569   </xsl:choose>
570 </xsl:template>
571
572 <xsl:template name="normal-row">
573   <xsl:param name="spans"/>
574   <xsl:param name="browserows"/>
575
576   <xsl:variable name="row-height">
577     <xsl:if test="processing-instruction('dbhtml')">
578       <xsl:call-template name="pi.dbhtml_row-height"/>
579     </xsl:if>
580   </xsl:variable>
581
582   <xsl:variable name="bgcolor">
583     <xsl:if test="processing-instruction('dbhtml')">
584       <xsl:call-template name="pi.dbhtml_bgcolor"/>
585     </xsl:if>
586   </xsl:variable>
587
588   <xsl:variable name="class">
589     <xsl:if test="processing-instruction('dbhtml')">
590       <xsl:call-template name="pi.dbhtml_class"/>
591     </xsl:if>
592   </xsl:variable>
593
594   <tr>
595     <xsl:call-template name="id.attribute"/>
596     <xsl:call-template name="tr.attributes">
597       <xsl:with-param name="rownum">
598         <xsl:number from="tgroup" count="row"/>
599       </xsl:with-param>
600     </xsl:call-template>
601
602     <xsl:if test="$row-height != ''">
603       <xsl:attribute name="height">
604         <xsl:value-of select="$row-height"/>
605       </xsl:attribute>
606     </xsl:if>
607
608     <xsl:if test="$bgcolor != ''">
609       <xsl:attribute name="bgcolor">
610         <xsl:value-of select="$bgcolor"/>
611       </xsl:attribute>
612     </xsl:if>
613
614     <xsl:if test="$class != ''">
615       <xsl:attribute name="class">
616         <xsl:value-of select="$class"/>
617       </xsl:attribute>
618     </xsl:if>
619
620     <xsl:if test="$table.borders.with.css != 0">
621       <xsl:if test="@rowsep = 1 and following-sibling::row">
622         <xsl:attribute name="style">
623           <xsl:call-template name="border">
624             <xsl:with-param name="side" select="'bottom'"/>
625           </xsl:call-template>
626         </xsl:attribute>
627       </xsl:if>
628     </xsl:if>
629
630     <xsl:if test="@align">
631       <xsl:attribute name="align">
632         <xsl:value-of select="@align"/>
633       </xsl:attribute>
634     </xsl:if>
635     <xsl:if test="@char">
636       <xsl:attribute name="char">
637         <xsl:value-of select="@char"/>
638       </xsl:attribute>
639     </xsl:if>
640     <xsl:if test="@charoff">
641       <xsl:attribute name="charoff">
642         <xsl:value-of select="@charoff"/>
643       </xsl:attribute>
644     </xsl:if>
645     <xsl:if test="@valign">
646       <xsl:attribute name="valign">
647         <xsl:value-of select="@valign"/>
648       </xsl:attribute>
649     </xsl:if>
650
651     <xsl:apply-templates select="(entry|entrytbl)[1]">
652       <xsl:with-param name="spans" select="$spans"/>
653     </xsl:apply-templates>
654   </tr>
655
656   <xsl:if test="$browserows = 'recurse'">
657     <xsl:if test="following-sibling::row">
658       <xsl:variable name="nextspans">
659         <xsl:apply-templates select="(entry|entrytbl)[1]" mode="span">
660           <xsl:with-param name="spans" select="$spans"/>
661         </xsl:apply-templates>
662       </xsl:variable>
663   
664       <xsl:apply-templates select="following-sibling::row[1]">
665         <xsl:with-param name="spans" select="$nextspans"/>
666         <xsl:with-param name="browserows" select="$browserows"/>
667       </xsl:apply-templates>
668     </xsl:if>
669   </xsl:if>
670 </xsl:template>
671
672 <xsl:template match="entry|entrytbl" name="entry">
673   <xsl:param name="col">
674     <xsl:choose>
675       <xsl:when test="@revisionflag">
676         <xsl:number from="row"/>
677       </xsl:when>
678       <xsl:otherwise>1</xsl:otherwise>
679     </xsl:choose>
680   </xsl:param>
681
682   <xsl:param name="spans"/>
683
684   <xsl:variable name="cellgi">
685     <xsl:choose>
686       <xsl:when test="ancestor::thead">th</xsl:when>
687       <xsl:when test="ancestor::tfoot">th</xsl:when>
688       <xsl:when test="ancestor::tbody and                        (ancestor::table[@rowheader = 'firstcol'] or                       ancestor::informaltable[@rowheader = 'firstcol']) and                       ancestor-or-self::entry[1][count(preceding-sibling::entry) = 0]">
689         <xsl:text>th</xsl:text>
690       </xsl:when>
691       <xsl:otherwise>td</xsl:otherwise>
692     </xsl:choose>
693   </xsl:variable>
694
695   <xsl:variable name="empty.cell" select="count(node()) = 0"/>
696
697   <xsl:variable name="named.colnum">
698     <xsl:call-template name="entry.colnum"/>
699   </xsl:variable>
700
701   <xsl:variable name="entry.colnum">
702     <xsl:choose>
703       <xsl:when test="$named.colnum &gt; 0">
704         <xsl:value-of select="$named.colnum"/>
705       </xsl:when>
706       <xsl:otherwise>
707         <xsl:value-of select="$col"/>
708       </xsl:otherwise>
709     </xsl:choose>
710   </xsl:variable>
711
712   <xsl:variable name="entry.colspan">
713     <xsl:choose>
714       <xsl:when test="@spanname or @namest">
715         <xsl:call-template name="calculate.colspan"/>
716       </xsl:when>
717       <xsl:otherwise>1</xsl:otherwise>
718     </xsl:choose>
719   </xsl:variable>
720
721   <xsl:variable name="following.spans">
722     <xsl:call-template name="calculate.following.spans">
723       <xsl:with-param name="colspan" select="$entry.colspan"/>
724       <xsl:with-param name="spans" select="$spans"/>
725     </xsl:call-template>
726   </xsl:variable>
727
728   <xsl:variable name="rowsep">
729     <xsl:choose>
730       <!-- If this is the last row, rowsep never applies. -->
731       <xsl:when test="ancestor::entrytbl                       and not (ancestor-or-self::row[1]/following-sibling::row)                       and not (ancestor::thead)">
732         <xsl:value-of select="0"/>
733       </xsl:when>
734       <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row                           or ancestor-or-self::thead/following-sibling::tbody                           or ancestor-or-self::tbody/preceding-sibling::tfoot)">
735         <xsl:value-of select="0"/>
736       </xsl:when>
737       <xsl:when test="@morerows and not(@morerows &lt;                   count(ancestor-or-self::row[1]/following-sibling::row))">
738         <xsl:value-of select="0"/>
739       </xsl:when>
740       <xsl:otherwise>
741         <xsl:call-template name="inherited.table.attribute">
742           <xsl:with-param name="entry" select="."/>
743           <xsl:with-param name="colnum" select="$entry.colnum"/>
744           <xsl:with-param name="attribute" select="'rowsep'"/>
745         </xsl:call-template>
746       </xsl:otherwise>
747     </xsl:choose>
748   </xsl:variable>
749
750   <xsl:variable name="colsep">
751     <xsl:choose>
752       <!-- If this is the last column, colsep never applies. -->
753       <xsl:when test="$following.spans = ''">0</xsl:when>
754       <xsl:otherwise>
755         <xsl:call-template name="inherited.table.attribute">
756           <xsl:with-param name="entry" select="."/>
757           <xsl:with-param name="colnum" select="$entry.colnum"/>
758           <xsl:with-param name="attribute" select="'colsep'"/>
759         </xsl:call-template>
760       </xsl:otherwise>
761     </xsl:choose>
762   </xsl:variable>
763
764   <xsl:variable name="valign">
765     <xsl:call-template name="inherited.table.attribute">
766       <xsl:with-param name="entry" select="."/>
767       <xsl:with-param name="colnum" select="$entry.colnum"/>
768       <xsl:with-param name="attribute" select="'valign'"/>
769     </xsl:call-template>
770   </xsl:variable>
771
772   <xsl:variable name="align">
773     <xsl:call-template name="inherited.table.attribute">
774       <xsl:with-param name="entry" select="."/>
775       <xsl:with-param name="colnum" select="$entry.colnum"/>
776       <xsl:with-param name="attribute" select="'align'"/>
777     </xsl:call-template>
778   </xsl:variable>
779
780   <xsl:variable name="char">
781     <xsl:call-template name="inherited.table.attribute">
782       <xsl:with-param name="entry" select="."/>
783       <xsl:with-param name="colnum" select="$entry.colnum"/>
784       <xsl:with-param name="attribute" select="'char'"/>
785     </xsl:call-template>
786   </xsl:variable>
787
788   <xsl:variable name="charoff">
789     <xsl:call-template name="inherited.table.attribute">
790       <xsl:with-param name="entry" select="."/>
791       <xsl:with-param name="colnum" select="$entry.colnum"/>
792       <xsl:with-param name="attribute" select="'charoff'"/>
793     </xsl:call-template>
794   </xsl:variable>
795
796   <xsl:choose>
797     <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
798       <xsl:call-template name="entry">
799         <xsl:with-param name="col" select="$col+1"/>
800         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
801       </xsl:call-template>
802     </xsl:when>
803
804     <xsl:when test="number($entry.colnum) &gt; $col">
805       <xsl:call-template name="empty.table.cell"/>
806       <xsl:call-template name="entry">
807         <xsl:with-param name="col" select="$col+1"/>
808         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
809       </xsl:call-template>
810     </xsl:when>
811
812     <xsl:otherwise>
813       <xsl:variable name="bgcolor">
814         <xsl:if test="processing-instruction('dbhtml')">
815           <xsl:call-template name="pi.dbhtml_bgcolor"/>
816         </xsl:if>
817       </xsl:variable>
818
819       <xsl:element name="{$cellgi}" namespace="http://www.w3.org/1999/xhtml">
820         <xsl:call-template name="id.attribute"/>
821         <xsl:if test="$bgcolor != ''">
822           <xsl:attribute name="bgcolor">
823             <xsl:value-of select="$bgcolor"/>
824           </xsl:attribute>
825         </xsl:if>
826
827         <xsl:call-template name="locale.html.attributes"/>
828         <xsl:choose>
829           <xsl:when test="$entry.propagates.style != 0 and @role">
830             <xsl:apply-templates select="." mode="class.attribute">
831               <xsl:with-param name="class" select="@role"/>
832             </xsl:apply-templates>
833           </xsl:when>
834           <xsl:otherwise>
835             <xsl:apply-templates select="." mode="class.attribute">
836               <xsl:with-param name="class" select="''"/>
837             </xsl:apply-templates>
838           </xsl:otherwise>
839         </xsl:choose>
840
841         <xsl:if test="$show.revisionflag and @revisionflag">
842           <xsl:attribute name="class">
843             <xsl:value-of select="@revisionflag"/>
844           </xsl:attribute>
845         </xsl:if>
846
847         <xsl:if test="$table.borders.with.css != 0">
848           <xsl:attribute name="style">
849             <xsl:if test="$colsep &gt; 0">
850               <xsl:call-template name="border">
851                 <xsl:with-param name="side" select="'right'"/>
852               </xsl:call-template>
853             </xsl:if>
854             <xsl:if test="$rowsep &gt; 0">
855               <xsl:call-template name="border">
856                 <xsl:with-param name="side" select="'bottom'"/>
857               </xsl:call-template>
858             </xsl:if>
859           </xsl:attribute>
860         </xsl:if>
861
862         <xsl:if test="@morerows &gt; 0">
863           <xsl:attribute name="rowspan">
864             <xsl:value-of select="1+@morerows"/>
865           </xsl:attribute>
866         </xsl:if>
867
868         <xsl:if test="$entry.colspan &gt; 1">
869           <xsl:attribute name="colspan">
870             <xsl:value-of select="$entry.colspan"/>
871           </xsl:attribute>
872         </xsl:if>
873
874         <xsl:if test="$align != ''">
875           <xsl:attribute name="align">
876             <xsl:value-of select="$align"/>
877           </xsl:attribute>
878         </xsl:if>
879
880         <xsl:if test="$valign != ''">
881           <xsl:attribute name="valign">
882             <xsl:value-of select="$valign"/>
883           </xsl:attribute>
884         </xsl:if>
885
886         <xsl:if test="$char != ''">
887           <xsl:attribute name="char">
888             <xsl:value-of select="$char"/>
889           </xsl:attribute>
890         </xsl:if>
891
892         <xsl:if test="$charoff != ''">
893           <xsl:attribute name="charoff">
894             <xsl:value-of select="$charoff"/>
895           </xsl:attribute>
896         </xsl:if>
897
898         <xsl:if test="not(preceding-sibling::*) and                      (ancestor::row[1]/@id or ancestor::row[1]/@xml:id)">
899           <xsl:call-template name="anchor">
900             <xsl:with-param name="node" select="ancestor::row[1]"/>
901           </xsl:call-template>
902         </xsl:if>
903
904         <xsl:call-template name="anchor"/>
905
906         <xsl:choose>
907           <xsl:when test="$empty.cell">
908             <xsl:text>&#160;</xsl:text>
909           </xsl:when>
910           <xsl:when test="self::entrytbl">
911             <xsl:call-template name="tgroup"/>
912           </xsl:when>
913           <xsl:otherwise>
914             <xsl:apply-templates/>
915           </xsl:otherwise>
916         </xsl:choose>
917       </xsl:element>
918
919       <xsl:choose>
920         <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
921           <xsl:apply-templates select="(following-sibling::entry                                        |following-sibling::entrytbl)[1]">
922             <xsl:with-param name="col" select="$col+$entry.colspan"/>
923             <xsl:with-param name="spans" select="$following.spans"/>
924           </xsl:apply-templates>
925         </xsl:when>
926         <xsl:otherwise>
927           <xsl:call-template name="finaltd">
928             <xsl:with-param name="spans" select="$following.spans"/>
929             <xsl:with-param name="col" select="$col+$entry.colspan"/>
930           </xsl:call-template>
931         </xsl:otherwise>
932       </xsl:choose>
933     </xsl:otherwise>
934   </xsl:choose>
935 </xsl:template>
936
937 <xsl:template match="entry|entrytbl" name="sentry" mode="span">
938   <xsl:param name="col" select="1"/>
939   <xsl:param name="spans"/>
940
941   <xsl:variable name="entry.colnum">
942     <xsl:call-template name="entry.colnum"/>
943   </xsl:variable>
944
945   <xsl:variable name="entry.colspan">
946     <xsl:choose>
947       <xsl:when test="@spanname or @namest">
948         <xsl:call-template name="calculate.colspan"/>
949       </xsl:when>
950       <xsl:otherwise>1</xsl:otherwise>
951     </xsl:choose>
952   </xsl:variable>
953
954   <xsl:variable name="following.spans">
955     <xsl:call-template name="calculate.following.spans">
956       <xsl:with-param name="colspan" select="$entry.colspan"/>
957       <xsl:with-param name="spans" select="$spans"/>
958     </xsl:call-template>
959   </xsl:variable>
960
961   <xsl:choose>
962     <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
963       <xsl:value-of select="substring-before($spans,':')-1"/>
964       <xsl:text>:</xsl:text>
965       <xsl:call-template name="sentry">
966         <xsl:with-param name="col" select="$col+1"/>
967         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
968       </xsl:call-template>
969     </xsl:when>
970
971     <xsl:when test="number($entry.colnum) &gt; $col">
972       <xsl:text>0:</xsl:text>
973       <xsl:call-template name="sentry">
974         <xsl:with-param name="col" select="$col + 1"/>
975         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
976       </xsl:call-template>
977     </xsl:when>
978
979     <xsl:otherwise>
980       <xsl:call-template name="copy-string">
981         <xsl:with-param name="count" select="$entry.colspan"/>
982         <xsl:with-param name="string">
983           <xsl:choose>
984             <xsl:when test="@morerows">
985               <xsl:value-of select="@morerows"/>
986             </xsl:when>
987             <xsl:otherwise>0</xsl:otherwise>
988           </xsl:choose>
989           <xsl:text>:</xsl:text>
990         </xsl:with-param>
991       </xsl:call-template>
992
993       <xsl:choose>
994         <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
995           <xsl:apply-templates select="(following-sibling::entry                                         |following-sibling::entrytbl)[1]" mode="span">
996             <xsl:with-param name="col" select="$col+$entry.colspan"/>
997             <xsl:with-param name="spans" select="$following.spans"/>
998           </xsl:apply-templates>
999         </xsl:when>
1000         <xsl:otherwise>
1001           <xsl:call-template name="sfinaltd">
1002             <xsl:with-param name="spans" select="$following.spans"/>
1003           </xsl:call-template>
1004         </xsl:otherwise>
1005       </xsl:choose>
1006     </xsl:otherwise>
1007   </xsl:choose>
1008 </xsl:template>
1009
1010 <xsl:template name="generate.colgroup">
1011   <xsl:param name="cols" select="1"/>
1012   <xsl:param name="count" select="1"/>
1013   <xsl:choose>
1014     <xsl:when test="$count &gt; $cols"/>
1015     <xsl:otherwise>
1016       <xsl:call-template name="generate.col">
1017         <xsl:with-param name="countcol" select="$count"/>
1018       </xsl:call-template>
1019       <xsl:call-template name="generate.colgroup">
1020         <xsl:with-param name="cols" select="$cols"/>
1021         <xsl:with-param name="count" select="$count+1"/>
1022       </xsl:call-template>
1023     </xsl:otherwise>
1024   </xsl:choose>
1025 </xsl:template>
1026
1027 <xsl:template name="generate.col">
1028   <xsl:param name="countcol">1</xsl:param>
1029   <xsl:param name="colspecs" select="./colspec"/>
1030   <xsl:param name="count">1</xsl:param>
1031   <xsl:param name="colnum">1</xsl:param>
1032
1033   <xsl:choose>
1034     <xsl:when test="$count&gt;count($colspecs)">
1035       <col/>
1036     </xsl:when>
1037     <xsl:otherwise>
1038       <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1039       <xsl:variable name="colspec.colnum">
1040         <xsl:choose>
1041           <xsl:when test="$colspec/@colnum">
1042             <xsl:value-of select="$colspec/@colnum"/>
1043           </xsl:when>
1044           <xsl:otherwise>
1045             <xsl:value-of select="$colnum"/>
1046           </xsl:otherwise>
1047         </xsl:choose>
1048       </xsl:variable>
1049
1050       <xsl:choose>
1051         <xsl:when test="$colspec.colnum=$countcol">
1052           <col>
1053             <xsl:choose>
1054               <xsl:when test="$colspec/@colwidth                             and $use.extensions != 0                             and $tablecolumns.extension != 0">
1055                 <xsl:attribute name="width">
1056                   <xsl:choose>
1057                     <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1058                       <xsl:value-of select="'1*'"/>
1059                     </xsl:when>
1060                     <xsl:otherwise>
1061                       <xsl:value-of select="$colspec/@colwidth"/>
1062                     </xsl:otherwise>
1063                   </xsl:choose>
1064                 </xsl:attribute>
1065               </xsl:when>
1066               <!-- pass through to HTML if no * in colspecs -->
1067               <xsl:when test="$colspec/@colwidth and                              not($colspec/parent::*/colspec/@colwidth[contains(.,'*')])">
1068                 <xsl:attribute name="width">
1069                   <xsl:choose>
1070                     <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1071                       <xsl:value-of select="'1*'"/>
1072                     </xsl:when>
1073                     <xsl:otherwise>
1074                       <xsl:value-of select="$colspec/@colwidth"/>
1075                     </xsl:otherwise>
1076                   </xsl:choose>
1077                 </xsl:attribute>
1078               </xsl:when>
1079             </xsl:choose>
1080
1081             <xsl:choose>
1082               <xsl:when test="$colspec/@align">
1083                 <xsl:attribute name="align">
1084                   <xsl:value-of select="$colspec/@align"/>
1085                 </xsl:attribute>
1086               </xsl:when>
1087               <!-- Suggested by Pavel ZAMPACH <zampach@nemcb.cz> -->
1088               <xsl:when test="$colspecs/ancestor::tgroup/@align">
1089                 <xsl:attribute name="align">
1090                   <xsl:value-of select="$colspecs/ancestor::tgroup/@align"/>
1091                 </xsl:attribute>
1092               </xsl:when>
1093             </xsl:choose>
1094
1095             <xsl:if test="$colspec/@char">
1096               <xsl:attribute name="char">
1097                 <xsl:value-of select="$colspec/@char"/>
1098               </xsl:attribute>
1099             </xsl:if>
1100             
1101             <xsl:if test="$colspec/@charoff">
1102               <xsl:attribute name="charoff">
1103                 <xsl:value-of select="$colspec/@charoff"/>
1104               </xsl:attribute>
1105             </xsl:if>
1106
1107             <xsl:if test="$colspec/@colname">
1108               <xsl:attribute name="class">
1109                 <xsl:value-of select="$colspec/@colname"/>
1110               </xsl:attribute>
1111             </xsl:if>
1112           </col>
1113         </xsl:when>
1114         <xsl:otherwise>
1115           <xsl:call-template name="generate.col">
1116             <xsl:with-param name="countcol" select="$countcol"/>
1117             <xsl:with-param name="colspecs" select="$colspecs"/>
1118             <xsl:with-param name="count" select="$count+1"/>
1119             <xsl:with-param name="colnum">
1120               <xsl:choose>
1121                 <xsl:when test="$colspec/@colnum">
1122                   <xsl:value-of select="$colspec/@colnum + 1"/>
1123                 </xsl:when>
1124                 <xsl:otherwise>
1125                   <xsl:value-of select="$colnum + 1"/>
1126                 </xsl:otherwise>
1127               </xsl:choose>
1128             </xsl:with-param>
1129            </xsl:call-template>
1130         </xsl:otherwise>
1131       </xsl:choose>
1132     </xsl:otherwise>
1133   </xsl:choose>
1134 </xsl:template>
1135
1136 <xsl:template name="colspec.colwidth">
1137   <!-- when this macro is called, the current context must be an entry -->
1138   <xsl:param name="colname"/>
1139   <!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
1140   <xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
1141   <xsl:param name="count">1</xsl:param>
1142   <xsl:choose>
1143     <xsl:when test="$count&gt;count($colspecs)"/>
1144     <xsl:otherwise>
1145       <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1146       <xsl:choose>
1147         <xsl:when test="$colspec/@colname=$colname">
1148           <xsl:value-of select="$colspec/@colwidth"/>
1149         </xsl:when>
1150         <xsl:otherwise>
1151           <xsl:call-template name="colspec.colwidth">
1152             <xsl:with-param name="colname" select="$colname"/>
1153             <xsl:with-param name="colspecs" select="$colspecs"/>
1154             <xsl:with-param name="count" select="$count+1"/>
1155           </xsl:call-template>
1156         </xsl:otherwise>
1157       </xsl:choose>
1158     </xsl:otherwise>
1159   </xsl:choose>
1160 </xsl:template>
1161
1162 <!-- ====================================================================== -->
1163
1164 <xsl:template name="tr.attributes">
1165   <xsl:param name="row" select="."/>
1166   <xsl:param name="rownum" select="0"/>
1167
1168   <!-- by default, do nothing. But you might want to say:
1169
1170   <xsl:if test="$rownum mod 2 = 0">
1171     <xsl:attribute name="class">oddrow</xsl:attribute>
1172   </xsl:if>
1173
1174   -->
1175 </xsl:template>
1176
1177 </xsl:stylesheet>