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