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