]> git.stg.codes - stg.git/blob - doc/xslt/xhtml/table.xsl
Infer DST from the current locale for mktime.
[stg.git] / doc / xslt / 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 8813 2010-08-09 21:18:23Z 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="tr.attributes">
596       <xsl:with-param name="rownum">
597         <xsl:number from="tgroup" count="row"/>
598       </xsl:with-param>
599     </xsl:call-template>
600
601     <xsl:if test="$row-height != ''">
602       <xsl:attribute name="height">
603         <xsl:value-of select="$row-height"/>
604       </xsl:attribute>
605     </xsl:if>
606
607     <xsl:if test="$bgcolor != ''">
608       <xsl:attribute name="bgcolor">
609         <xsl:value-of select="$bgcolor"/>
610       </xsl:attribute>
611     </xsl:if>
612
613     <xsl:if test="$class != ''">
614       <xsl:attribute name="class">
615         <xsl:value-of select="$class"/>
616       </xsl:attribute>
617     </xsl:if>
618
619     <xsl:if test="$table.borders.with.css != 0">
620       <xsl:if test="@rowsep = 1 and following-sibling::row">
621         <xsl:attribute name="style">
622           <xsl:call-template name="border">
623             <xsl:with-param name="side" select="'bottom'"/>
624           </xsl:call-template>
625         </xsl:attribute>
626       </xsl:if>
627     </xsl:if>
628
629     <xsl:if test="@align">
630       <xsl:attribute name="align">
631         <xsl:value-of select="@align"/>
632       </xsl:attribute>
633     </xsl:if>
634     <xsl:if test="@char">
635       <xsl:attribute name="char">
636         <xsl:value-of select="@char"/>
637       </xsl:attribute>
638     </xsl:if>
639     <xsl:if test="@charoff">
640       <xsl:attribute name="charoff">
641         <xsl:value-of select="@charoff"/>
642       </xsl:attribute>
643     </xsl:if>
644     <xsl:if test="@valign">
645       <xsl:attribute name="valign">
646         <xsl:value-of select="@valign"/>
647       </xsl:attribute>
648     </xsl:if>
649
650     <xsl:apply-templates select="(entry|entrytbl)[1]">
651       <xsl:with-param name="spans" select="$spans"/>
652     </xsl:apply-templates>
653   </tr>
654
655   <xsl:if test="$browserows = 'recurse'">
656     <xsl:if test="following-sibling::row">
657       <xsl:variable name="nextspans">
658         <xsl:apply-templates select="(entry|entrytbl)[1]" mode="span">
659           <xsl:with-param name="spans" select="$spans"/>
660         </xsl:apply-templates>
661       </xsl:variable>
662   
663       <xsl:apply-templates select="following-sibling::row[1]">
664         <xsl:with-param name="spans" select="$nextspans"/>
665         <xsl:with-param name="browserows" select="$browserows"/>
666       </xsl:apply-templates>
667     </xsl:if>
668   </xsl:if>
669 </xsl:template>
670
671 <xsl:template match="entry|entrytbl" name="entry">
672   <xsl:param name="col">
673     <xsl:choose>
674       <xsl:when test="@revisionflag">
675         <xsl:number from="row"/>
676       </xsl:when>
677       <xsl:otherwise>1</xsl:otherwise>
678     </xsl:choose>
679   </xsl:param>
680
681   <xsl:param name="spans"/>
682
683   <xsl:variable name="cellgi">
684     <xsl:choose>
685       <xsl:when test="ancestor::thead">th</xsl:when>
686       <xsl:when test="ancestor::tfoot">th</xsl:when>
687       <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]">
688         <xsl:text>th</xsl:text>
689       </xsl:when>
690       <xsl:otherwise>td</xsl:otherwise>
691     </xsl:choose>
692   </xsl:variable>
693
694   <xsl:variable name="empty.cell" select="count(node()) = 0"/>
695
696   <xsl:variable name="named.colnum">
697     <xsl:call-template name="entry.colnum"/>
698   </xsl:variable>
699
700   <xsl:variable name="entry.colnum">
701     <xsl:choose>
702       <xsl:when test="$named.colnum &gt; 0">
703         <xsl:value-of select="$named.colnum"/>
704       </xsl:when>
705       <xsl:otherwise>
706         <xsl:value-of select="$col"/>
707       </xsl:otherwise>
708     </xsl:choose>
709   </xsl:variable>
710
711   <xsl:variable name="entry.colspan">
712     <xsl:choose>
713       <xsl:when test="@spanname or @namest">
714         <xsl:call-template name="calculate.colspan"/>
715       </xsl:when>
716       <xsl:otherwise>1</xsl:otherwise>
717     </xsl:choose>
718   </xsl:variable>
719
720   <xsl:variable name="following.spans">
721     <xsl:call-template name="calculate.following.spans">
722       <xsl:with-param name="colspan" select="$entry.colspan"/>
723       <xsl:with-param name="spans" select="$spans"/>
724     </xsl:call-template>
725   </xsl:variable>
726
727   <xsl:variable name="rowsep">
728     <xsl:choose>
729       <!-- If this is the last row, rowsep never applies. -->
730       <xsl:when test="ancestor::entrytbl                       and not (ancestor-or-self::row[1]/following-sibling::row)                       and not (ancestor::thead)">
731         <xsl:value-of select="0"/>
732       </xsl:when>
733       <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)">
734         <xsl:value-of select="0"/>
735       </xsl:when>
736       <xsl:when test="@morerows and not(@morerows &lt;                   count(ancestor-or-self::row[1]/following-sibling::row))">
737         <xsl:value-of select="0"/>
738       </xsl:when>
739       <xsl:otherwise>
740         <xsl:call-template name="inherited.table.attribute">
741           <xsl:with-param name="entry" select="."/>
742           <xsl:with-param name="colnum" select="$entry.colnum"/>
743           <xsl:with-param name="attribute" select="'rowsep'"/>
744         </xsl:call-template>
745       </xsl:otherwise>
746     </xsl:choose>
747   </xsl:variable>
748
749   <xsl:variable name="colsep">
750     <xsl:choose>
751       <!-- If this is the last column, colsep never applies. -->
752       <xsl:when test="$following.spans = ''">0</xsl:when>
753       <xsl:otherwise>
754         <xsl:call-template name="inherited.table.attribute">
755           <xsl:with-param name="entry" select="."/>
756           <xsl:with-param name="colnum" select="$entry.colnum"/>
757           <xsl:with-param name="attribute" select="'colsep'"/>
758         </xsl:call-template>
759       </xsl:otherwise>
760     </xsl:choose>
761   </xsl:variable>
762
763   <xsl:variable name="valign">
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="'valign'"/>
768     </xsl:call-template>
769   </xsl:variable>
770
771   <xsl:variable name="align">
772     <xsl:call-template name="inherited.table.attribute">
773       <xsl:with-param name="entry" select="."/>
774       <xsl:with-param name="colnum" select="$entry.colnum"/>
775       <xsl:with-param name="attribute" select="'align'"/>
776     </xsl:call-template>
777   </xsl:variable>
778
779   <xsl:variable name="char">
780     <xsl:call-template name="inherited.table.attribute">
781       <xsl:with-param name="entry" select="."/>
782       <xsl:with-param name="colnum" select="$entry.colnum"/>
783       <xsl:with-param name="attribute" select="'char'"/>
784     </xsl:call-template>
785   </xsl:variable>
786
787   <xsl:variable name="charoff">
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="'charoff'"/>
792     </xsl:call-template>
793   </xsl:variable>
794
795   <xsl:choose>
796     <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
797       <xsl:call-template name="entry">
798         <xsl:with-param name="col" select="$col+1"/>
799         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
800       </xsl:call-template>
801     </xsl:when>
802
803     <xsl:when test="number($entry.colnum) &gt; $col">
804       <xsl:call-template name="empty.table.cell"/>
805       <xsl:call-template name="entry">
806         <xsl:with-param name="col" select="$col+1"/>
807         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
808       </xsl:call-template>
809     </xsl:when>
810
811     <xsl:otherwise>
812       <xsl:variable name="bgcolor">
813         <xsl:if test="processing-instruction('dbhtml')">
814           <xsl:call-template name="pi.dbhtml_bgcolor"/>
815         </xsl:if>
816       </xsl:variable>
817
818       <xsl:element name="{$cellgi}" namespace="http://www.w3.org/1999/xhtml">
819         <xsl:if test="$bgcolor != ''">
820           <xsl:attribute name="bgcolor">
821             <xsl:value-of select="$bgcolor"/>
822           </xsl:attribute>
823         </xsl:if>
824
825         <xsl:call-template name="locale.html.attributes"/>
826         <xsl:if test="$entry.propagates.style != 0 and @role">
827           <xsl:apply-templates select="." mode="class.attribute">
828             <xsl:with-param name="class" select="@role"/>
829           </xsl:apply-templates>
830         </xsl:if>
831
832         <xsl:if test="$show.revisionflag and @revisionflag">
833           <xsl:attribute name="class">
834             <xsl:value-of select="@revisionflag"/>
835           </xsl:attribute>
836         </xsl:if>
837
838         <xsl:if test="$table.borders.with.css != 0">
839           <xsl:attribute name="style">
840             <xsl:if test="$colsep &gt; 0">
841               <xsl:call-template name="border">
842                 <xsl:with-param name="side" select="'right'"/>
843               </xsl:call-template>
844             </xsl:if>
845             <xsl:if test="$rowsep &gt; 0">
846               <xsl:call-template name="border">
847                 <xsl:with-param name="side" select="'bottom'"/>
848               </xsl:call-template>
849             </xsl:if>
850           </xsl:attribute>
851         </xsl:if>
852
853         <xsl:if test="@morerows &gt; 0">
854           <xsl:attribute name="rowspan">
855             <xsl:value-of select="1+@morerows"/>
856           </xsl:attribute>
857         </xsl:if>
858
859         <xsl:if test="$entry.colspan &gt; 1">
860           <xsl:attribute name="colspan">
861             <xsl:value-of select="$entry.colspan"/>
862           </xsl:attribute>
863         </xsl:if>
864
865         <xsl:if test="$align != ''">
866           <xsl:attribute name="align">
867             <xsl:value-of select="$align"/>
868           </xsl:attribute>
869         </xsl:if>
870
871         <xsl:if test="$valign != ''">
872           <xsl:attribute name="valign">
873             <xsl:value-of select="$valign"/>
874           </xsl:attribute>
875         </xsl:if>
876
877         <xsl:if test="$char != ''">
878           <xsl:attribute name="char">
879             <xsl:value-of select="$char"/>
880           </xsl:attribute>
881         </xsl:if>
882
883         <xsl:if test="$charoff != ''">
884           <xsl:attribute name="charoff">
885             <xsl:value-of select="$charoff"/>
886           </xsl:attribute>
887         </xsl:if>
888
889         <xsl:if test="not(preceding-sibling::*) and                      (ancestor::row[1]/@id or ancestor::row[1]/@xml:id)">
890           <xsl:call-template name="anchor">
891             <xsl:with-param name="node" select="ancestor::row[1]"/>
892           </xsl:call-template>
893         </xsl:if>
894
895         <xsl:call-template name="anchor"/>
896
897         <xsl:choose>
898           <xsl:when test="$empty.cell">
899             <xsl:text>&#160;</xsl:text>
900           </xsl:when>
901           <xsl:when test="self::entrytbl">
902             <xsl:call-template name="tgroup"/>
903           </xsl:when>
904           <xsl:otherwise>
905             <xsl:apply-templates/>
906           </xsl:otherwise>
907         </xsl:choose>
908       </xsl:element>
909
910       <xsl:choose>
911         <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
912           <xsl:apply-templates select="(following-sibling::entry                                        |following-sibling::entrytbl)[1]">
913             <xsl:with-param name="col" select="$col+$entry.colspan"/>
914             <xsl:with-param name="spans" select="$following.spans"/>
915           </xsl:apply-templates>
916         </xsl:when>
917         <xsl:otherwise>
918           <xsl:call-template name="finaltd">
919             <xsl:with-param name="spans" select="$following.spans"/>
920             <xsl:with-param name="col" select="$col+$entry.colspan"/>
921           </xsl:call-template>
922         </xsl:otherwise>
923       </xsl:choose>
924     </xsl:otherwise>
925   </xsl:choose>
926 </xsl:template>
927
928 <xsl:template match="entry|entrytbl" name="sentry" mode="span">
929   <xsl:param name="col" select="1"/>
930   <xsl:param name="spans"/>
931
932   <xsl:variable name="entry.colnum">
933     <xsl:call-template name="entry.colnum"/>
934   </xsl:variable>
935
936   <xsl:variable name="entry.colspan">
937     <xsl:choose>
938       <xsl:when test="@spanname or @namest">
939         <xsl:call-template name="calculate.colspan"/>
940       </xsl:when>
941       <xsl:otherwise>1</xsl:otherwise>
942     </xsl:choose>
943   </xsl:variable>
944
945   <xsl:variable name="following.spans">
946     <xsl:call-template name="calculate.following.spans">
947       <xsl:with-param name="colspan" select="$entry.colspan"/>
948       <xsl:with-param name="spans" select="$spans"/>
949     </xsl:call-template>
950   </xsl:variable>
951
952   <xsl:choose>
953     <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
954       <xsl:value-of select="substring-before($spans,':')-1"/>
955       <xsl:text>:</xsl:text>
956       <xsl:call-template name="sentry">
957         <xsl:with-param name="col" select="$col+1"/>
958         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
959       </xsl:call-template>
960     </xsl:when>
961
962     <xsl:when test="number($entry.colnum) &gt; $col">
963       <xsl:text>0:</xsl:text>
964       <xsl:call-template name="sentry">
965         <xsl:with-param name="col" select="$col + 1"/>
966         <xsl:with-param name="spans" select="substring-after($spans,':')"/>
967       </xsl:call-template>
968     </xsl:when>
969
970     <xsl:otherwise>
971       <xsl:call-template name="copy-string">
972         <xsl:with-param name="count" select="$entry.colspan"/>
973         <xsl:with-param name="string">
974           <xsl:choose>
975             <xsl:when test="@morerows">
976               <xsl:value-of select="@morerows"/>
977             </xsl:when>
978             <xsl:otherwise>0</xsl:otherwise>
979           </xsl:choose>
980           <xsl:text>:</xsl:text>
981         </xsl:with-param>
982       </xsl:call-template>
983
984       <xsl:choose>
985         <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
986           <xsl:apply-templates select="(following-sibling::entry                                         |following-sibling::entrytbl)[1]" mode="span">
987             <xsl:with-param name="col" select="$col+$entry.colspan"/>
988             <xsl:with-param name="spans" select="$following.spans"/>
989           </xsl:apply-templates>
990         </xsl:when>
991         <xsl:otherwise>
992           <xsl:call-template name="sfinaltd">
993             <xsl:with-param name="spans" select="$following.spans"/>
994           </xsl:call-template>
995         </xsl:otherwise>
996       </xsl:choose>
997     </xsl:otherwise>
998   </xsl:choose>
999 </xsl:template>
1000
1001 <xsl:template name="generate.colgroup">
1002   <xsl:param name="cols" select="1"/>
1003   <xsl:param name="count" select="1"/>
1004   <xsl:choose>
1005     <xsl:when test="$count &gt; $cols"/>
1006     <xsl:otherwise>
1007       <xsl:call-template name="generate.col">
1008         <xsl:with-param name="countcol" select="$count"/>
1009       </xsl:call-template>
1010       <xsl:call-template name="generate.colgroup">
1011         <xsl:with-param name="cols" select="$cols"/>
1012         <xsl:with-param name="count" select="$count+1"/>
1013       </xsl:call-template>
1014     </xsl:otherwise>
1015   </xsl:choose>
1016 </xsl:template>
1017
1018 <xsl:template name="generate.col">
1019   <xsl:param name="countcol">1</xsl:param>
1020   <xsl:param name="colspecs" select="./colspec"/>
1021   <xsl:param name="count">1</xsl:param>
1022   <xsl:param name="colnum">1</xsl:param>
1023
1024   <xsl:choose>
1025     <xsl:when test="$count&gt;count($colspecs)">
1026       <col/>
1027     </xsl:when>
1028     <xsl:otherwise>
1029       <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1030       <xsl:variable name="colspec.colnum">
1031         <xsl:choose>
1032           <xsl:when test="$colspec/@colnum">
1033             <xsl:value-of select="$colspec/@colnum"/>
1034           </xsl:when>
1035           <xsl:otherwise>
1036             <xsl:value-of select="$colnum"/>
1037           </xsl:otherwise>
1038         </xsl:choose>
1039       </xsl:variable>
1040
1041       <xsl:choose>
1042         <xsl:when test="$colspec.colnum=$countcol">
1043           <col>
1044             <xsl:choose>
1045               <xsl:when test="$colspec/@colwidth                             and $use.extensions != 0                             and $tablecolumns.extension != 0">
1046                 <xsl:attribute name="width">
1047                   <xsl:choose>
1048                     <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1049                       <xsl:value-of select="'1*'"/>
1050                     </xsl:when>
1051                     <xsl:otherwise>
1052                       <xsl:value-of select="$colspec/@colwidth"/>
1053                     </xsl:otherwise>
1054                   </xsl:choose>
1055                 </xsl:attribute>
1056               </xsl:when>
1057               <!-- pass through to HTML if no * in colspecs -->
1058               <xsl:when test="$colspec/@colwidth and                              not($colspec/parent::*/colspec/@colwidth[contains(.,'*')])">
1059                 <xsl:attribute name="width">
1060                   <xsl:choose>
1061                     <xsl:when test="normalize-space($colspec/@colwidth) = '*'">
1062                       <xsl:value-of select="'1*'"/>
1063                     </xsl:when>
1064                     <xsl:otherwise>
1065                       <xsl:value-of select="$colspec/@colwidth"/>
1066                     </xsl:otherwise>
1067                   </xsl:choose>
1068                 </xsl:attribute>
1069               </xsl:when>
1070             </xsl:choose>
1071
1072             <xsl:choose>
1073               <xsl:when test="$colspec/@align">
1074                 <xsl:attribute name="align">
1075                   <xsl:value-of select="$colspec/@align"/>
1076                 </xsl:attribute>
1077               </xsl:when>
1078               <!-- Suggested by Pavel ZAMPACH <zampach@nemcb.cz> -->
1079               <xsl:when test="$colspecs/ancestor::tgroup/@align">
1080                 <xsl:attribute name="align">
1081                   <xsl:value-of select="$colspecs/ancestor::tgroup/@align"/>
1082                 </xsl:attribute>
1083               </xsl:when>
1084             </xsl:choose>
1085
1086             <xsl:if test="$colspec/@char">
1087               <xsl:attribute name="char">
1088                 <xsl:value-of select="$colspec/@char"/>
1089               </xsl:attribute>
1090             </xsl:if>
1091             
1092             <xsl:if test="$colspec/@charoff">
1093               <xsl:attribute name="charoff">
1094                 <xsl:value-of select="$colspec/@charoff"/>
1095               </xsl:attribute>
1096             </xsl:if>
1097
1098             <xsl:if test="$colspec/@colname">
1099               <xsl:attribute name="class">
1100                 <xsl:value-of select="$colspec/@colname"/>
1101               </xsl:attribute>
1102             </xsl:if>
1103           </col>
1104         </xsl:when>
1105         <xsl:otherwise>
1106           <xsl:call-template name="generate.col">
1107             <xsl:with-param name="countcol" select="$countcol"/>
1108             <xsl:with-param name="colspecs" select="$colspecs"/>
1109             <xsl:with-param name="count" select="$count+1"/>
1110             <xsl:with-param name="colnum">
1111               <xsl:choose>
1112                 <xsl:when test="$colspec/@colnum">
1113                   <xsl:value-of select="$colspec/@colnum + 1"/>
1114                 </xsl:when>
1115                 <xsl:otherwise>
1116                   <xsl:value-of select="$colnum + 1"/>
1117                 </xsl:otherwise>
1118               </xsl:choose>
1119             </xsl:with-param>
1120            </xsl:call-template>
1121         </xsl:otherwise>
1122       </xsl:choose>
1123     </xsl:otherwise>
1124   </xsl:choose>
1125 </xsl:template>
1126
1127 <xsl:template name="colspec.colwidth">
1128   <!-- when this macro is called, the current context must be an entry -->
1129   <xsl:param name="colname"/>
1130   <!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
1131   <xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
1132   <xsl:param name="count">1</xsl:param>
1133   <xsl:choose>
1134     <xsl:when test="$count&gt;count($colspecs)"/>
1135     <xsl:otherwise>
1136       <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1137       <xsl:choose>
1138         <xsl:when test="$colspec/@colname=$colname">
1139           <xsl:value-of select="$colspec/@colwidth"/>
1140         </xsl:when>
1141         <xsl:otherwise>
1142           <xsl:call-template name="colspec.colwidth">
1143             <xsl:with-param name="colname" select="$colname"/>
1144             <xsl:with-param name="colspecs" select="$colspecs"/>
1145             <xsl:with-param name="count" select="$count+1"/>
1146           </xsl:call-template>
1147         </xsl:otherwise>
1148       </xsl:choose>
1149     </xsl:otherwise>
1150   </xsl:choose>
1151 </xsl:template>
1152
1153 <!-- ====================================================================== -->
1154
1155 <xsl:template name="tr.attributes">
1156   <xsl:param name="row" select="."/>
1157   <xsl:param name="rownum" select="0"/>
1158
1159   <!-- by default, do nothing. But you might want to say:
1160
1161   <xsl:if test="$rownum mod 2 = 0">
1162     <xsl:attribute name="class">oddrow</xsl:attribute>
1163   </xsl:if>
1164
1165   -->
1166 </xsl:template>
1167
1168 </xsl:stylesheet>