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