source: clfs-sysroot/BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/fo/table.xsl @ a18aefd

Last change on this file since a18aefd was a18aefd, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added lfs-xsl stylesheets.

  • Property mode set to 100644
File size: 54.0 KB
Line 
1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4                xmlns:fo="http://www.w3.org/1999/XSL/Format"
5                xmlns:rx="http://www.renderx.com/XSL/Extensions"
6                xmlns:stbl="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.Table"
7                xmlns:xtbl="com.nwalsh.xalan.Table"
8                xmlns:lxslt="http://xml.apache.org/xslt"
9                xmlns:ptbl="http://nwalsh.com/xslt/ext/xsltproc/python/Table"
10                exclude-result-prefixes="doc stbl xtbl lxslt ptbl"
11                version='1.0'>
12
13<xsl:include href="../common/table.xsl"/>
14
15<!-- ********************************************************************
16     $Id$
17     ********************************************************************
18
19     This file is part of the XSL DocBook Stylesheet distribution.
20     See ../README or http://docbook.sf.net/release/xsl/current/ for
21     copyright and other information.
22
23     ******************************************************************** -->
24
25<doc:reference xmlns="" xml:id="table-templates">
26  <?dbhtml dir="fo"?>
27  <info>
28    <title>Formatting Object Table Reference</title>
29    <releaseinfo role="meta">
30      $Id$
31    </releaseinfo>
32  </info>
33  <partintro xml:id="partintro">
34    <title>Introduction</title>
35    <para>This is technical reference documentation for the FO
36      table-processing templates in the DocBook XSL Stylesheets.</para>
37    <para>This is not intended to be user documentation.  It is
38      provided for developers writing customization layers for the
39      stylesheets.</para>
40  </partintro>
41</doc:reference>
42
43<!-- ==================================================================== -->
44
45<lxslt:component prefix="xtbl"
46                 functions="adjustColumnWidths"/>
47
48<!-- ==================================================================== -->
49
50<xsl:template name="make.table.content">
51  <xsl:choose>
52    <xsl:when test="tgroup|mediaobject|graphic">
53      <xsl:call-template name="calsTable"/>
54    </xsl:when>
55    <xsl:otherwise>
56      <xsl:apply-templates select="." mode="htmlTable"/>
57    </xsl:otherwise>
58  </xsl:choose>
59</xsl:template>
60
61<!-- ==================================================================== -->
62
63<xsl:template name="calsTable">
64
65  <xsl:variable name="keep.together">
66    <xsl:call-template name="pi.dbfo_keep-together"/>
67  </xsl:variable>
68
69  <xsl:for-each select="tgroup">
70
71    <fo:table xsl:use-attribute-sets="table.table.properties">
72      <xsl:if test="$keep.together != ''">
73        <xsl:attribute name="keep-together.within-column">
74          <xsl:value-of select="$keep.together"/>
75        </xsl:attribute>
76      </xsl:if>
77      <xsl:call-template name="table.frame"/>
78      <xsl:if test="following-sibling::tgroup">
79        <xsl:attribute name="border-bottom-width">0pt</xsl:attribute>
80        <xsl:attribute name="border-bottom-style">none</xsl:attribute>
81        <xsl:attribute name="padding-bottom">0pt</xsl:attribute>
82        <xsl:attribute name="margin-bottom">0pt</xsl:attribute>
83        <xsl:attribute name="space-after">0pt</xsl:attribute>
84        <xsl:attribute name="space-after.minimum">0pt</xsl:attribute>
85        <xsl:attribute name="space-after.optimum">0pt</xsl:attribute>
86        <xsl:attribute name="space-after.maximum">0pt</xsl:attribute>
87      </xsl:if>
88      <xsl:if test="preceding-sibling::tgroup">
89        <xsl:attribute name="border-top-width">0pt</xsl:attribute>
90        <xsl:attribute name="border-top-style">none</xsl:attribute>
91        <xsl:attribute name="padding-top">0pt</xsl:attribute>
92        <xsl:attribute name="margin-top">0pt</xsl:attribute>
93        <xsl:attribute name="space-before">0pt</xsl:attribute>
94        <xsl:attribute name="space-before.minimum">0pt</xsl:attribute>
95        <xsl:attribute name="space-before.optimum">0pt</xsl:attribute>
96        <xsl:attribute name="space-before.maximum">0pt</xsl:attribute>
97      </xsl:if>
98      <xsl:apply-templates select="."/>
99    </fo:table>
100  </xsl:for-each>
101</xsl:template>
102
103<!-- ==================================================================== -->
104
105<!-- Placeholder template enables wrapping a fo:table in
106     another table for purposes of layout or applying
107     extensions such as XEP table-omit-initial-header to
108     create "continued" titles on page breaks. -->
109<xsl:template name="table.layout">
110  <xsl:param name="table.content" select="NOTANODE"/>
111
112  <xsl:copy-of select="$table.content"/>
113</xsl:template>
114
115<xsl:template name="table.block">
116  <xsl:param name="table.layout" select="NOTANODE"/>
117
118  <xsl:variable name="id">
119    <xsl:call-template name="object.id"/>
120  </xsl:variable>
121
122  <xsl:variable name="param.placement"
123                select="substring-after(normalize-space(
124                   $formal.title.placement), concat(local-name(.), ' '))"/>
125
126  <xsl:variable name="placement">
127    <xsl:choose>
128      <xsl:when test="contains($param.placement, ' ')">
129        <xsl:value-of select="substring-before($param.placement, ' ')"/>
130      </xsl:when>
131      <xsl:when test="$param.placement = ''">before</xsl:when>
132      <xsl:otherwise>
133        <xsl:value-of select="$param.placement"/>
134      </xsl:otherwise>
135    </xsl:choose>
136  </xsl:variable>
137
138  <xsl:choose>
139    <xsl:when test="self::table">
140      <fo:block id="{$id}"
141                xsl:use-attribute-sets="table.properties">
142        <xsl:if test="$placement = 'before'">
143          <xsl:call-template name="formal.object.heading">
144            <xsl:with-param name="placement" select="$placement"/>
145          </xsl:call-template>
146        </xsl:if>
147        <xsl:copy-of select="$table.layout"/>
148        <xsl:call-template name="table.footnote.block"/>
149        <xsl:if test="$placement != 'before'">
150          <xsl:call-template name="formal.object.heading">
151            <xsl:with-param name="placement" select="$placement"/>
152          </xsl:call-template>
153        </xsl:if>
154      </fo:block>
155    </xsl:when>
156    <xsl:otherwise>
157      <fo:block id="{$id}"
158                xsl:use-attribute-sets="informaltable.properties">
159        <xsl:copy-of select="$table.layout"/>
160        <xsl:call-template name="table.footnote.block"/>
161      </fo:block>
162    </xsl:otherwise>
163  </xsl:choose>
164
165
166</xsl:template>
167
168<!-- Output a table's footnotes in a block -->
169<xsl:template name="table.footnote.block">
170  <xsl:if test=".//footnote">
171    <fo:block keep-with-previous.within-column="always">
172      <xsl:apply-templates select=".//footnote" mode="table.footnote.mode"/>
173    </fo:block>
174  </xsl:if>
175</xsl:template>
176
177<!-- ==================================================================== -->
178
179<xsl:template name="table.container">
180  <xsl:param name="table.block"/>
181  <xsl:choose>
182    <xsl:when test="@orient='land' and
183                    $fop.extensions = 0 and
184                    $passivetex.extensions = 0" >
185      <fo:block-container reference-orientation="90"
186            padding="6pt"
187            xsl:use-attribute-sets="list.block.spacing">
188        <xsl:attribute name="width">
189          <xsl:call-template name="table.width"/>
190        </xsl:attribute>
191        <fo:block start-indent="0pt" end-indent="0pt">
192          <xsl:copy-of select="$table.block"/>
193        </fo:block>
194      </fo:block-container>
195    </xsl:when>
196    <xsl:when test="@pgwide = 1">
197      <fo:block xsl:use-attribute-sets="pgwide.properties">
198        <xsl:copy-of select="$table.block"/>
199      </fo:block>
200    </xsl:when>
201    <xsl:otherwise>
202      <xsl:copy-of select="$table.block"/>
203    </xsl:otherwise>
204  </xsl:choose>
205</xsl:template>
206
207<!-- ==================================================================== -->
208
209<xsl:template name="empty.table.cell">
210  <xsl:param name="colnum" select="0"/>
211
212  <xsl:variable name="rowsep">
213    <xsl:choose>
214      <!-- If this is the last row, rowsep never applies. -->
215      <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row
216                          or ancestor-or-self::thead/following-sibling::tbody
217                          or ancestor-or-self::tbody/preceding-sibling::tfoot)">
218        <xsl:value-of select="0"/>
219      </xsl:when>
220      <xsl:otherwise>
221        <xsl:call-template name="inherited.table.attribute">
222          <xsl:with-param name="entry" select="NOT-AN-ELEMENT-NAME"/>
223          <xsl:with-param name="row" select="ancestor-or-self::row[1]"/>
224          <xsl:with-param name="colnum" select="$colnum"/>
225          <xsl:with-param name="attribute" select="'rowsep'"/>
226        </xsl:call-template>
227      </xsl:otherwise>
228    </xsl:choose>
229  </xsl:variable>
230
231  <xsl:variable name="colsep">
232    <xsl:choose>
233      <!-- If this is the last column, colsep never applies. -->
234      <xsl:when test="number($colnum) &gt;= ancestor::tgroup/@cols">0</xsl:when>
235      <xsl:otherwise>
236        <xsl:call-template name="inherited.table.attribute">
237          <xsl:with-param name="entry" select="NOT-AN-ELEMENT-NAME"/>
238          <xsl:with-param name="row" select="ancestor-or-self::row[1]"/>
239          <xsl:with-param name="colnum" select="$colnum"/>
240          <xsl:with-param name="attribute" select="'colsep'"/>
241        </xsl:call-template>
242      </xsl:otherwise>
243    </xsl:choose>
244  </xsl:variable>
245
246  <fo:table-cell text-align="center"
247                 display-align="center"
248                 xsl:use-attribute-sets="table.cell.padding">
249    <xsl:if test="$xep.extensions != 0">
250      <!-- Suggested by RenderX to workaround a bug in their implementation -->
251      <xsl:attribute name="keep-together.within-column">always</xsl:attribute>
252    </xsl:if>
253    <xsl:if test="$rowsep &gt; 0">
254      <xsl:call-template name="border">
255        <xsl:with-param name="side" select="'bottom'"/>
256      </xsl:call-template>
257    </xsl:if>
258
259    <xsl:if test="$colsep &gt; 0 and number($colnum) &lt; ancestor::tgroup/@cols">
260      <xsl:call-template name="border">
261        <xsl:with-param name="side" select="'right'"/>
262      </xsl:call-template>
263    </xsl:if>
264
265    <!-- fo:table-cell should not be empty -->
266    <fo:block/>
267  </fo:table-cell>
268</xsl:template>
269
270<!-- ==================================================================== -->
271<xsl:template name="table.frame">
272  <xsl:variable name="frame">
273    <xsl:choose>
274      <xsl:when test="../@frame">
275        <xsl:value-of select="../@frame"/>
276      </xsl:when>
277      <xsl:when test="$default.table.frame != ''">
278        <xsl:value-of select="$default.table.frame"/>
279      </xsl:when>
280      <xsl:otherwise>all</xsl:otherwise>
281    </xsl:choose>
282  </xsl:variable>
283
284  <xsl:choose>
285    <xsl:when test="$frame='all'">
286      <xsl:attribute name="border-left-style">
287        <xsl:value-of select="$table.frame.border.style"/>
288      </xsl:attribute>
289      <xsl:attribute name="border-right-style">
290        <xsl:value-of select="$table.frame.border.style"/>
291      </xsl:attribute>
292      <xsl:attribute name="border-top-style">
293        <xsl:value-of select="$table.frame.border.style"/>
294      </xsl:attribute>
295      <xsl:attribute name="border-bottom-style">
296        <xsl:value-of select="$table.frame.border.style"/>
297      </xsl:attribute>
298      <xsl:attribute name="border-left-width">
299        <xsl:value-of select="$table.frame.border.thickness"/>
300      </xsl:attribute>
301      <xsl:attribute name="border-right-width">
302        <xsl:value-of select="$table.frame.border.thickness"/>
303      </xsl:attribute>
304      <xsl:attribute name="border-top-width">
305        <xsl:value-of select="$table.frame.border.thickness"/>
306      </xsl:attribute>
307      <xsl:attribute name="border-bottom-width">
308        <xsl:value-of select="$table.frame.border.thickness"/>
309      </xsl:attribute>
310      <xsl:attribute name="border-left-color">
311        <xsl:value-of select="$table.frame.border.color"/>
312      </xsl:attribute>
313      <xsl:attribute name="border-right-color">
314        <xsl:value-of select="$table.frame.border.color"/>
315      </xsl:attribute>
316      <xsl:attribute name="border-top-color">
317        <xsl:value-of select="$table.frame.border.color"/>
318      </xsl:attribute>
319      <xsl:attribute name="border-bottom-color">
320        <xsl:value-of select="$table.frame.border.color"/>
321      </xsl:attribute>
322    </xsl:when>
323    <xsl:when test="$frame='bottom'">
324      <xsl:attribute name="border-left-style">none</xsl:attribute>
325      <xsl:attribute name="border-right-style">none</xsl:attribute>
326      <xsl:attribute name="border-top-style">none</xsl:attribute>
327      <xsl:attribute name="border-bottom-style">
328        <xsl:value-of select="$table.frame.border.style"/>
329      </xsl:attribute>
330      <xsl:attribute name="border-bottom-width">
331        <xsl:value-of select="$table.frame.border.thickness"/>
332      </xsl:attribute>
333      <xsl:attribute name="border-bottom-color">
334        <xsl:value-of select="$table.frame.border.color"/>
335      </xsl:attribute>
336    </xsl:when>
337    <xsl:when test="$frame='sides'">
338      <xsl:attribute name="border-left-style">
339        <xsl:value-of select="$table.frame.border.style"/>
340      </xsl:attribute>
341      <xsl:attribute name="border-right-style">
342        <xsl:value-of select="$table.frame.border.style"/>
343      </xsl:attribute>
344      <xsl:attribute name="border-top-style">none</xsl:attribute>
345      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
346      <xsl:attribute name="border-left-width">
347        <xsl:value-of select="$table.frame.border.thickness"/>
348      </xsl:attribute>
349      <xsl:attribute name="border-right-width">
350        <xsl:value-of select="$table.frame.border.thickness"/>
351      </xsl:attribute>
352      <xsl:attribute name="border-left-color">
353        <xsl:value-of select="$table.frame.border.color"/>
354      </xsl:attribute>
355      <xsl:attribute name="border-right-color">
356        <xsl:value-of select="$table.frame.border.color"/>
357      </xsl:attribute>
358    </xsl:when>
359    <xsl:when test="$frame='top'">
360      <xsl:attribute name="border-left-style">none</xsl:attribute>
361      <xsl:attribute name="border-right-style">none</xsl:attribute>
362      <xsl:attribute name="border-top-style">
363        <xsl:value-of select="$table.frame.border.style"/>
364      </xsl:attribute>
365      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
366      <xsl:attribute name="border-top-width">
367        <xsl:value-of select="$table.frame.border.thickness"/>
368      </xsl:attribute>
369      <xsl:attribute name="border-top-color">
370        <xsl:value-of select="$table.frame.border.color"/>
371      </xsl:attribute>
372    </xsl:when>
373    <xsl:when test="$frame='topbot'">
374      <xsl:attribute name="border-left-style">none</xsl:attribute>
375      <xsl:attribute name="border-right-style">none</xsl:attribute>
376      <xsl:attribute name="border-top-style">
377        <xsl:value-of select="$table.frame.border.style"/>
378      </xsl:attribute>
379      <xsl:attribute name="border-bottom-style">
380        <xsl:value-of select="$table.frame.border.style"/>
381      </xsl:attribute>
382      <xsl:attribute name="border-top-width">
383        <xsl:value-of select="$table.frame.border.thickness"/>
384      </xsl:attribute>
385      <xsl:attribute name="border-bottom-width">
386        <xsl:value-of select="$table.frame.border.thickness"/>
387      </xsl:attribute>
388      <xsl:attribute name="border-top-color">
389        <xsl:value-of select="$table.frame.border.color"/>
390      </xsl:attribute>
391      <xsl:attribute name="border-bottom-color">
392        <xsl:value-of select="$table.frame.border.color"/>
393      </xsl:attribute>
394    </xsl:when>
395    <xsl:when test="$frame='none'">
396      <xsl:attribute name="border-left-style">none</xsl:attribute>
397      <xsl:attribute name="border-right-style">none</xsl:attribute>
398      <xsl:attribute name="border-top-style">none</xsl:attribute>
399      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
400    </xsl:when>
401    <xsl:otherwise>
402      <xsl:message>
403        <xsl:text>Impossible frame on table: </xsl:text>
404        <xsl:value-of select="$frame"/>
405      </xsl:message>
406      <xsl:attribute name="border-left-style">none</xsl:attribute>
407      <xsl:attribute name="border-right-style">none</xsl:attribute>
408      <xsl:attribute name="border-top-style">none</xsl:attribute>
409      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
410    </xsl:otherwise>
411  </xsl:choose>
412</xsl:template>
413
414<!-- ==================================================================== -->
415
416<xsl:template name="border">
417  <xsl:param name="side" select="'left'"/>
418
419  <xsl:attribute name="border-{$side}-width">
420    <xsl:value-of select="$table.cell.border.thickness"/>
421  </xsl:attribute>
422  <xsl:attribute name="border-{$side}-style">
423    <xsl:value-of select="$table.cell.border.style"/>
424  </xsl:attribute>
425  <xsl:attribute name="border-{$side}-color">
426    <xsl:value-of select="$table.cell.border.color"/>
427  </xsl:attribute>
428</xsl:template>
429
430<!-- ==================================================================== -->
431
432<xsl:template match="tgroup" name="tgroup">
433  <xsl:if test="not(@cols) or @cols = '' or string(number(@cols)) = 'NaN'">
434    <xsl:message terminate="yes">
435      <xsl:text>Error: CALS tables must specify the number of columns.</xsl:text>
436    </xsl:message>
437  </xsl:if>
438
439  <xsl:variable name="table.width">
440    <xsl:call-template name="table.width"/>
441  </xsl:variable>
442
443  <xsl:variable name="colspecs">
444    <xsl:choose>
445      <xsl:when test="$use.extensions != 0
446                      and $tablecolumns.extension != 0">
447        <xsl:call-template name="generate.colgroup.raw">
448          <xsl:with-param name="cols" select="@cols"/>
449        </xsl:call-template>
450      </xsl:when>
451      <xsl:otherwise>
452        <xsl:call-template name="generate.colgroup">
453          <xsl:with-param name="cols" select="@cols"/>
454        </xsl:call-template>
455      </xsl:otherwise>
456    </xsl:choose>
457  </xsl:variable>
458
459  <xsl:variable name="prop-columns"
460                select=".//colspec[contains(@colwidth, '*')]"/>
461  <xsl:if test="count($prop-columns) != 0 or
462                $fop.extensions != 0 or
463                $fop1.extensions != 0 or
464                $passivetex.extensions != 0">
465    <xsl:attribute name="table-layout">fixed</xsl:attribute>
466  </xsl:if>
467
468  <xsl:if test="count(preceding-sibling::tgroup) = 0">
469    <!-- If this is the first tgroup, output the width attribute for the -->
470    <!-- surrounding fo:table. (If this isn't the first tgroup, trying   -->
471    <!-- to output the attribute will cause an error.)                   -->
472    <xsl:attribute name="width">
473      <xsl:value-of select="$table.width"/>
474    </xsl:attribute>
475  </xsl:if>
476
477  <xsl:choose>
478    <xsl:when test="$use.extensions != 0
479                    and $tablecolumns.extension != 0">
480      <xsl:choose>
481        <xsl:when test="function-available('stbl:adjustColumnWidths')">
482          <xsl:copy-of select="stbl:adjustColumnWidths($colspecs)"/>
483        </xsl:when>
484        <xsl:when test="function-available('xtbl:adjustColumnWidths')">
485          <xsl:copy-of select="xtbl:adjustColumnWidths($colspecs)"/>
486        </xsl:when>
487        <xsl:when test="function-available('ptbl:adjustColumnWidths')">
488          <xsl:copy-of select="ptbl:adjustColumnWidths($colspecs)"/>
489        </xsl:when>
490        <xsl:otherwise>
491          <xsl:message terminate="yes">
492            <xsl:text>No adjustColumnWidths function available.</xsl:text>
493          </xsl:message>
494        </xsl:otherwise>
495      </xsl:choose>
496    </xsl:when>
497    <xsl:otherwise>
498      <xsl:copy-of select="$colspecs"/>
499    </xsl:otherwise>
500  </xsl:choose>
501
502  <xsl:apply-templates select="thead"/>
503  <xsl:apply-templates select="tfoot"/>
504  <xsl:apply-templates select="tbody"/>
505</xsl:template>
506
507<xsl:template match="colspec"></xsl:template>
508
509<xsl:template name="table.width">
510
511  <xsl:variable name="numcols">
512    <xsl:call-template name="widest-html-row">
513      <xsl:with-param name="rows" select=".//tr"/>
514    </xsl:call-template>
515  </xsl:variable>
516
517  <xsl:variable name="explicit.table.width">
518    <xsl:choose>
519      <xsl:when test="self::entrytbl">
520        <xsl:call-template name="pi.dbfo_table-width"/>
521      </xsl:when>
522      <xsl:when test="self::table or self::informaltable">
523        <xsl:call-template name="pi.dbfo_table-width"/>
524      </xsl:when>
525      <xsl:otherwise>
526        <!-- * no dbfo@table-width PI as a child of this table, so check -->
527        <!-- * the parent of this table to see if the table has any -->
528        <!-- * sibling dbfo@table-width PIs (FIXME: 2007-07 MikeSmith: we -->
529        <!-- * should really instead be checking here just to see if the -->
530        <!-- * first preceding sibling of this table is a -->
531        <!-- * dbfo@table-width PI) -->
532        <xsl:call-template name="pi.dbfo_table-width">
533          <xsl:with-param name="node" select=".."/>
534        </xsl:call-template>
535      </xsl:otherwise>
536    </xsl:choose>
537  </xsl:variable>
538
539  <xsl:variable name="column.sum">
540    <xsl:choose>
541      <!-- CALS table -->
542      <xsl:when test="@cols">
543        <xsl:if test="count(colspec) = @cols">
544          <xsl:for-each select="colspec">
545            <xsl:if test="position() != 1">
546              <xsl:text> + </xsl:text>
547            </xsl:if>
548            <xsl:choose>
549              <xsl:when test="not(@colwidth)">NOWIDTH</xsl:when>
550              <xsl:when test="contains(@colwidth, '*')">NOWIDTH</xsl:when>
551              <xsl:otherwise>
552                <xsl:value-of select="@colwidth"/>
553              </xsl:otherwise>
554            </xsl:choose>
555          </xsl:for-each>
556        </xsl:if>
557      </xsl:when>
558      <xsl:otherwise>
559        <!-- HTML table -->
560        <xsl:if test="count(col|colgroup/col) = $numcols">
561          <xsl:for-each select="col|colgroup/col">
562            <xsl:if test="position() != 1">
563              <xsl:text> + </xsl:text>
564            </xsl:if>
565            <xsl:choose>
566              <xsl:when test="not(@width)">NOWIDTH</xsl:when>
567              <xsl:when test="contains(@width, '%')">NOWIDTH</xsl:when>
568              <xsl:otherwise>
569                <xsl:value-of select="@width"/>
570              </xsl:otherwise>
571            </xsl:choose>
572          </xsl:for-each>
573        </xsl:if>
574      </xsl:otherwise>
575    </xsl:choose>
576  </xsl:variable>
577
578  <xsl:variable name="column.sum.width">
579    <xsl:if test="not(contains($column.sum, 'NOWIDTH'))">
580      <xsl:value-of select="$column.sum"/>
581    </xsl:if>
582  </xsl:variable>
583
584  <xsl:variable name="prop-columns"
585                select=".//colspec[contains(@colwidth, '*')]"/>
586
587  <xsl:variable name="table.width">
588    <xsl:choose>
589      <xsl:when test="$explicit.table.width != ''">
590        <xsl:value-of select="$explicit.table.width"/>
591      </xsl:when>
592      <xsl:when test="$column.sum.width != ''">
593        <xsl:value-of select="$column.sum.width"/>
594      </xsl:when>
595      <xsl:when test="$default.table.width = ''">
596        <xsl:choose>
597          <!-- These processors don't support table-layout="auto" -->
598          <xsl:when test="$fop.extensions != 0 or
599                          $fop1.extensions != 0 or
600                          $passivetex.extensions != 0">
601            <xsl:text>100%</xsl:text>
602          </xsl:when>
603          <!-- Proportional columns imply 100% width -->
604          <xsl:when test="count($prop-columns) != 0">
605            <xsl:text>100%</xsl:text>
606          </xsl:when>
607          <xsl:otherwise>
608            <xsl:text>auto</xsl:text>
609          </xsl:otherwise>
610        </xsl:choose>
611      </xsl:when>
612      <xsl:otherwise>
613        <xsl:value-of select="$default.table.width"/>
614      </xsl:otherwise>
615    </xsl:choose>
616  </xsl:variable>
617  <xsl:value-of select="$table.width"/>
618
619</xsl:template>
620
621<xsl:template match="spanspec"></xsl:template>
622
623<xsl:template match="thead">
624  <xsl:variable name="tgroup" select="parent::*"/>
625
626  <fo:table-header start-indent="0pt" end-indent="0pt">
627    <xsl:apply-templates select="row[1]">
628      <xsl:with-param name="spans">
629        <xsl:call-template name="blank.spans">
630          <xsl:with-param name="cols" select="../@cols"/>
631        </xsl:call-template>
632      </xsl:with-param>
633    </xsl:apply-templates>
634  </fo:table-header>
635</xsl:template>
636
637<xsl:template match="tfoot">
638  <xsl:variable name="tgroup" select="parent::*"/>
639
640  <fo:table-footer start-indent="0pt" end-indent="0pt">
641    <xsl:apply-templates select="row[1]">
642      <xsl:with-param name="spans">
643        <xsl:call-template name="blank.spans">
644          <xsl:with-param name="cols" select="../@cols"/>
645        </xsl:call-template>
646      </xsl:with-param>
647    </xsl:apply-templates>
648
649  </fo:table-footer>
650</xsl:template>
651
652<xsl:template match="tbody">
653  <xsl:variable name="tgroup" select="parent::*"/>
654
655  <fo:table-body start-indent="0pt" end-indent="0pt">
656    <xsl:apply-templates select="row[1]">
657      <xsl:with-param name="spans">
658        <xsl:call-template name="blank.spans">
659          <xsl:with-param name="cols" select="../@cols"/>
660        </xsl:call-template>
661      </xsl:with-param>
662    </xsl:apply-templates>
663  </fo:table-body>
664</xsl:template>
665
666<xsl:template match="row">
667  <xsl:param name="spans"/>
668
669  <xsl:choose>
670    <xsl:when test="contains($spans, '0')">
671      <xsl:call-template name="normal-row">
672        <xsl:with-param name="spans" select="$spans"/>
673      </xsl:call-template>
674    </xsl:when>
675    <xsl:otherwise>
676      <!--
677      <xsl:message>
678        <xsl:text>Ignoring row: </xsl:text>
679        <xsl:value-of select="$spans"/>
680        <xsl:text> = </xsl:text>
681        <xsl:call-template name="consume-row">
682          <xsl:with-param name="spans" select="$spans"/>
683        </xsl:call-template>
684      </xsl:message>
685      -->
686
687      <xsl:if test="normalize-space(.//text()) != ''">
688        <xsl:message>Warning: overlapped row contains content!</xsl:message>
689      </xsl:if>
690
691      <fo:table-row>
692        <xsl:comment> This row intentionally left blank </xsl:comment>
693        <fo:table-cell><fo:block/></fo:table-cell>
694      </fo:table-row>
695
696      <xsl:apply-templates select="following-sibling::row[1]">
697        <xsl:with-param name="spans">
698          <xsl:call-template name="consume-row">
699            <xsl:with-param name="spans" select="$spans"/>
700          </xsl:call-template>
701        </xsl:with-param>
702      </xsl:apply-templates>
703    </xsl:otherwise>
704  </xsl:choose>
705</xsl:template>
706
707<xsl:template name="normal-row">
708  <xsl:param name="spans"/>
709
710  <fo:table-row>
711    <xsl:call-template name="table.row.properties"/>
712    <xsl:call-template name="anchor"/>
713
714    <xsl:apply-templates select="(entry|entrytbl)[1]">
715      <xsl:with-param name="spans" select="$spans"/>
716    </xsl:apply-templates>
717  </fo:table-row>
718
719  <xsl:if test="following-sibling::row">
720    <xsl:variable name="nextspans">
721      <xsl:apply-templates select="(entry|entrytbl)[1]" mode="span">
722        <xsl:with-param name="spans" select="$spans"/>
723      </xsl:apply-templates>
724    </xsl:variable>
725
726    <xsl:apply-templates select="following-sibling::row[1]">
727      <xsl:with-param name="spans" select="$nextspans"/>
728    </xsl:apply-templates>
729  </xsl:if>
730</xsl:template>
731
732<!-- customize this template to add row properties -->
733<xsl:template name="table.row.properties">
734  <xsl:variable name="bgcolor">
735    <xsl:call-template name="pi.dbfo_bgcolor"/>
736  </xsl:variable>
737  <xsl:if test="$bgcolor != ''">
738    <xsl:attribute name="background-color">
739      <xsl:value-of select="$bgcolor"/>
740    </xsl:attribute>
741  </xsl:if>
742
743  <!-- Keep header row with next row -->
744  <xsl:if test="ancestor::thead">
745    <xsl:attribute name="keep-with-next.within-column">always</xsl:attribute>
746  </xsl:if>
747
748</xsl:template>
749
750<xsl:template match="entry|entrytbl" name="entry">
751  <xsl:param name="col" select="1"/>
752  <xsl:param name="spans"/>
753
754  <xsl:variable name="row" select="parent::row"/>
755  <xsl:variable name="group" select="$row/parent::*[1]"/>
756  <xsl:variable name="frame" select="ancestor::tgroup/parent::*/@frame"/>
757
758  <xsl:variable name="empty.cell" select="count(node()) = 0"/>
759
760  <xsl:variable name="named.colnum">
761    <xsl:call-template name="entry.colnum"/>
762  </xsl:variable>
763
764  <xsl:variable name="entry.colnum">
765    <xsl:choose>
766      <xsl:when test="$named.colnum &gt; 0">
767        <xsl:value-of select="$named.colnum"/>
768      </xsl:when>
769      <xsl:otherwise>
770        <xsl:value-of select="$col"/>
771      </xsl:otherwise>
772    </xsl:choose>
773  </xsl:variable>
774
775  <xsl:variable name="entry.colspan">
776    <xsl:choose>
777      <xsl:when test="@spanname or @namest">
778        <xsl:call-template name="calculate.colspan"/>
779      </xsl:when>
780      <xsl:otherwise>1</xsl:otherwise>
781    </xsl:choose>
782  </xsl:variable>
783
784  <xsl:variable name="following.spans">
785    <xsl:call-template name="calculate.following.spans">
786      <xsl:with-param name="colspan" select="$entry.colspan"/>
787      <xsl:with-param name="spans" select="$spans"/>
788    </xsl:call-template>
789  </xsl:variable>
790
791  <xsl:variable name="rowsep">
792    <xsl:choose>
793      <!-- If this is the last row, rowsep never applies. -->
794      <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row
795                          or ancestor-or-self::thead/following-sibling::tbody
796                          or ancestor-or-self::tbody/preceding-sibling::tfoot)">
797        <xsl:value-of select="0"/>
798      </xsl:when>
799      <!-- Check for morerows too -->
800      <xsl:when test="(@morerows and count(ancestor-or-self::row[1]/
801                       following-sibling::row) = @morerows )
802                      and not (ancestor-or-self::thead/following-sibling::tbody
803                       or ancestor-or-self::tbody/preceding-sibling::tfoot)">
804        <xsl:value-of select="0"/>
805      </xsl:when>
806      <xsl:otherwise>
807        <xsl:call-template name="inherited.table.attribute">
808          <xsl:with-param name="entry" select="."/>
809          <xsl:with-param name="colnum" select="$entry.colnum"/>
810          <xsl:with-param name="attribute" select="'rowsep'"/>
811        </xsl:call-template>
812      </xsl:otherwise>
813    </xsl:choose>
814  </xsl:variable>
815
816<!--
817  <xsl:message><xsl:value-of select="."/>: <xsl:value-of select="$rowsep"/></xsl:message>
818-->
819
820  <xsl:variable name="colsep">
821    <xsl:choose>
822      <!-- If this is the last column, colsep never applies. -->
823      <xsl:when test="$following.spans = ''">0</xsl:when>
824      <xsl:otherwise>
825        <xsl:call-template name="inherited.table.attribute">
826          <xsl:with-param name="entry" select="."/>
827          <xsl:with-param name="colnum" select="$entry.colnum"/>
828          <xsl:with-param name="attribute" select="'colsep'"/>
829        </xsl:call-template>
830      </xsl:otherwise>
831    </xsl:choose>
832  </xsl:variable>
833
834  <xsl:variable name="valign">
835    <xsl:call-template name="inherited.table.attribute">
836      <xsl:with-param name="entry" select="."/>
837      <xsl:with-param name="colnum" select="$entry.colnum"/>
838      <xsl:with-param name="attribute" select="'valign'"/>
839    </xsl:call-template>
840  </xsl:variable>
841
842  <xsl:variable name="align">
843    <xsl:call-template name="inherited.table.attribute">
844      <xsl:with-param name="entry" select="."/>
845      <xsl:with-param name="colnum" select="$entry.colnum"/>
846      <xsl:with-param name="attribute" select="'align'"/>
847    </xsl:call-template>
848  </xsl:variable>
849
850  <xsl:variable name="char">
851    <xsl:call-template name="inherited.table.attribute">
852      <xsl:with-param name="entry" select="."/>
853      <xsl:with-param name="colnum" select="$entry.colnum"/>
854      <xsl:with-param name="attribute" select="'char'"/>
855    </xsl:call-template>
856  </xsl:variable>
857
858  <xsl:variable name="charoff">
859    <xsl:call-template name="inherited.table.attribute">
860      <xsl:with-param name="entry" select="."/>
861      <xsl:with-param name="colnum" select="$entry.colnum"/>
862      <xsl:with-param name="attribute" select="'charoff'"/>
863    </xsl:call-template>
864  </xsl:variable>
865
866  <xsl:choose>
867    <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
868      <xsl:call-template name="entry">
869        <xsl:with-param name="col" select="$col+1"/>
870        <xsl:with-param name="spans" select="substring-after($spans,':')"/>
871      </xsl:call-template>
872    </xsl:when>
873
874    <xsl:when test="number($entry.colnum) &gt; $col">
875      <xsl:call-template name="empty.table.cell">
876        <xsl:with-param name="colnum" select="$col"/>
877      </xsl:call-template>
878      <xsl:call-template name="entry">
879        <xsl:with-param name="col" select="$col+1"/>
880        <xsl:with-param name="spans" select="substring-after($spans,':')"/>
881      </xsl:call-template>
882    </xsl:when>
883
884    <xsl:otherwise>
885      <xsl:variable name="cell.content">
886        <fo:block>
887          <xsl:call-template name="table.cell.block.properties"/>
888
889          <!-- are we missing any indexterms? -->
890          <xsl:if test="not(preceding-sibling::entry)
891                        and not(parent::row/preceding-sibling::row)">
892            <!-- this is the first entry of the first row -->
893            <xsl:if test="ancestor::thead or
894                          (ancestor::tbody
895                           and not(ancestor::tbody/preceding-sibling::thead
896                                   or ancestor::tbody/preceding-sibling::tbody))">
897              <!-- of the thead or the first tbody -->
898              <xsl:apply-templates select="ancestor::tgroup/preceding-sibling::indexterm"/>
899            </xsl:if>
900          </xsl:if>
901
902          <!--
903          <xsl:text>(</xsl:text>
904          <xsl:value-of select="$rowsep"/>
905          <xsl:text>,</xsl:text>
906          <xsl:value-of select="$colsep"/>
907          <xsl:text>)</xsl:text>
908          -->
909          <xsl:choose>
910            <xsl:when test="$empty.cell">
911              <xsl:text>&#160;</xsl:text>
912            </xsl:when>
913            <xsl:when test="self::entrytbl">
914              <xsl:variable name="prop-columns"
915                            select=".//colspec[contains(@colwidth, '*')]"/>
916              <fo:table xsl:use-attribute-sets="table.table.properties">
917                <xsl:if test="count($prop-columns) != 0">
918                  <xsl:attribute name="table-layout">fixed</xsl:attribute>
919                </xsl:if>
920                <xsl:call-template name="tgroup"/>
921              </fo:table>
922            </xsl:when>
923            <xsl:otherwise>
924              <xsl:apply-templates/>
925            </xsl:otherwise>
926          </xsl:choose>
927        </fo:block>
928      </xsl:variable>
929
930      <xsl:variable name="cell-orientation">
931        <xsl:call-template name="pi.dbfo_orientation">
932          <xsl:with-param name="node" select="ancestor-or-self::entry"/>
933        </xsl:call-template>
934      </xsl:variable>
935
936      <xsl:variable name="row-orientation">
937        <xsl:call-template name="pi.dbfo_orientation">
938          <xsl:with-param name="node" select="ancestor-or-self::row"/>
939        </xsl:call-template>
940      </xsl:variable>
941
942      <xsl:variable name="cell-width">
943        <xsl:call-template name="pi.dbfo_rotated-width">
944          <xsl:with-param name="node" select="ancestor-or-self::entry"/>
945        </xsl:call-template>
946      </xsl:variable>
947
948      <xsl:variable name="row-width">
949        <xsl:call-template name="pi.dbfo_rotated-width">
950          <xsl:with-param name="node" select="ancestor-or-self::row"/>
951        </xsl:call-template>
952      </xsl:variable>
953
954      <xsl:variable name="orientation">
955        <xsl:choose>
956          <xsl:when test="$cell-orientation != ''">
957            <xsl:value-of select="$cell-orientation"/>
958          </xsl:when>
959          <xsl:otherwise>
960            <xsl:value-of select="$row-orientation"/>
961          </xsl:otherwise>
962        </xsl:choose>
963      </xsl:variable>
964
965      <xsl:variable name="rotated-width">
966        <xsl:choose>
967          <xsl:when test="$cell-width != ''">
968            <xsl:value-of select="$cell-width"/>
969          </xsl:when>
970          <xsl:otherwise>
971            <xsl:value-of select="$row-width"/>
972          </xsl:otherwise>
973        </xsl:choose>
974      </xsl:variable>
975
976      <xsl:variable name="bgcolor">
977        <xsl:call-template name="pi.dbfo_bgcolor">
978          <xsl:with-param name="node" select="ancestor-or-self::entry"/>
979        </xsl:call-template>
980      </xsl:variable>
981
982      <fo:table-cell xsl:use-attribute-sets="table.cell.padding">
983        <xsl:call-template name="table.cell.properties">
984          <xsl:with-param name="bgcolor.pi" select="$bgcolor"/>
985          <xsl:with-param name="rowsep.inherit" select="$rowsep"/>
986          <xsl:with-param name="colsep.inherit" select="$colsep"/>
987          <xsl:with-param name="col" select="$col"/>
988          <xsl:with-param name="valign.inherit" select="$valign"/>
989          <xsl:with-param name="align.inherit" select="$align"/>
990          <xsl:with-param name="char.inherit" select="$char"/>
991        </xsl:call-template>
992
993        <xsl:call-template name="anchor"/>
994
995        <xsl:if test="@morerows">
996          <xsl:attribute name="number-rows-spanned">
997            <xsl:value-of select="@morerows+1"/>
998          </xsl:attribute>
999        </xsl:if>
1000
1001        <xsl:if test="$entry.colspan &gt; 1">
1002          <xsl:attribute name="number-columns-spanned">
1003            <xsl:value-of select="$entry.colspan"/>
1004          </xsl:attribute>
1005        </xsl:if>
1006
1007<!--
1008        <xsl:if test="@charoff">
1009          <xsl:attribute name="charoff">
1010            <xsl:value-of select="@charoff"/>
1011          </xsl:attribute>
1012        </xsl:if>
1013-->
1014
1015        <xsl:choose>
1016          <xsl:when test="$fop.extensions = 0 and $passivetex.extensions = 0
1017                          and $orientation != ''">
1018            <fo:block-container reference-orientation="{$orientation}">
1019              <xsl:if test="$rotated-width != ''">
1020                <xsl:attribute name="width">
1021                  <xsl:value-of select="$rotated-width"/>
1022                </xsl:attribute>
1023              </xsl:if>
1024              <xsl:copy-of select="$cell.content"/>
1025            </fo:block-container>
1026          </xsl:when>
1027          <xsl:otherwise>
1028            <xsl:copy-of select="$cell.content"/>
1029          </xsl:otherwise>
1030        </xsl:choose>
1031      </fo:table-cell>
1032
1033      <xsl:choose>
1034        <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
1035          <xsl:apply-templates select="(following-sibling::entry
1036                                       |following-sibling::entrytbl)[1]">
1037            <xsl:with-param name="col" select="$col+$entry.colspan"/>
1038            <xsl:with-param name="spans" select="$following.spans"/>
1039          </xsl:apply-templates>
1040        </xsl:when>
1041        <xsl:otherwise>
1042          <xsl:call-template name="finaltd">
1043            <xsl:with-param name="spans" select="$following.spans"/>
1044            <xsl:with-param name="col" select="$col+$entry.colspan"/>
1045          </xsl:call-template>
1046        </xsl:otherwise>
1047      </xsl:choose>
1048    </xsl:otherwise>
1049  </xsl:choose>
1050</xsl:template>
1051
1052<!-- Expand this template to add properties to any fo:table-cell -->
1053<xsl:template name="table.cell.properties">
1054  <xsl:param name="bgcolor.pi" select="''"/>
1055  <xsl:param name="rowsep.inherit" select="1"/>
1056  <xsl:param name="colsep.inherit" select="1"/>
1057  <xsl:param name="col" select="1"/>
1058  <xsl:param name="valign.inherit" select="''"/>
1059  <xsl:param name="align.inherit" select="''"/>
1060  <xsl:param name="char.inherit" select="''"/>
1061
1062  <xsl:choose>
1063    <xsl:when test="ancestor::tgroup">
1064      <xsl:if test="$bgcolor.pi != ''">
1065        <xsl:attribute name="background-color">
1066          <xsl:value-of select="$bgcolor.pi"/>
1067        </xsl:attribute>
1068      </xsl:if>
1069
1070      <xsl:if test="$rowsep.inherit &gt; 0">
1071        <xsl:call-template name="border">
1072          <xsl:with-param name="side" select="'bottom'"/>
1073        </xsl:call-template>
1074      </xsl:if>
1075
1076      <xsl:if test="$colsep.inherit &gt; 0 and
1077                      $col &lt; ancestor::tgroup/@cols">
1078        <xsl:call-template name="border">
1079          <xsl:with-param name="side" select="'right'"/>
1080        </xsl:call-template>
1081      </xsl:if>
1082
1083      <xsl:if test="$valign.inherit != ''">
1084        <xsl:attribute name="display-align">
1085          <xsl:choose>
1086            <xsl:when test="$valign.inherit='top'">before</xsl:when>
1087            <xsl:when test="$valign.inherit='middle'">center</xsl:when>
1088            <xsl:when test="$valign.inherit='bottom'">after</xsl:when>
1089            <xsl:otherwise>
1090              <xsl:message>
1091                <xsl:text>Unexpected valign value: </xsl:text>
1092                <xsl:value-of select="$valign.inherit"/>
1093                <xsl:text>, center used.</xsl:text>
1094              </xsl:message>
1095              <xsl:text>center</xsl:text>
1096            </xsl:otherwise>
1097          </xsl:choose>
1098        </xsl:attribute>
1099      </xsl:if>
1100
1101      <xsl:choose>
1102        <xsl:when test="$align.inherit = 'char' and $char.inherit != ''">
1103          <xsl:attribute name="text-align">
1104            <xsl:value-of select="$char.inherit"/>
1105          </xsl:attribute>
1106        </xsl:when>
1107        <xsl:when test="$align.inherit != ''">
1108          <xsl:attribute name="text-align">
1109            <xsl:value-of select="$align.inherit"/>
1110          </xsl:attribute>
1111        </xsl:when>
1112      </xsl:choose>
1113
1114    </xsl:when>
1115    <xsl:otherwise>
1116      <!-- HTML table -->
1117      <xsl:variable name="border" 
1118                    select="(ancestor::table |
1119                             ancestor::informaltable)[last()]/@border"/>
1120      <xsl:if test="$border != '' and $border != 0">
1121        <xsl:attribute name="border">
1122          <xsl:value-of select="$table.cell.border.thickness"/>
1123          <xsl:text> </xsl:text>
1124          <xsl:value-of select="$table.cell.border.style"/>
1125          <xsl:text> </xsl:text>
1126          <xsl:value-of select="$table.cell.border.color"/>
1127        </xsl:attribute>
1128      </xsl:if>
1129    </xsl:otherwise>
1130  </xsl:choose>
1131
1132</xsl:template>
1133
1134<!-- Expand this template to add properties to any cell's block -->
1135<xsl:template name="table.cell.block.properties">
1136  <!-- highlight this entry? -->
1137  <xsl:if test="ancestor::thead or ancestor::tfoot">
1138    <xsl:attribute name="font-weight">bold</xsl:attribute>
1139  </xsl:if>
1140</xsl:template>
1141
1142<xsl:template match="entry|entrytbl" name="sentry" mode="span">
1143  <xsl:param name="col" select="1"/>
1144  <xsl:param name="spans"/>
1145
1146  <xsl:variable name="entry.colnum">
1147    <xsl:call-template name="entry.colnum"/>
1148  </xsl:variable>
1149
1150  <xsl:variable name="entry.colspan">
1151    <xsl:choose>
1152      <xsl:when test="@spanname or @namest">
1153        <xsl:call-template name="calculate.colspan"/>
1154      </xsl:when>
1155      <xsl:otherwise>1</xsl:otherwise>
1156    </xsl:choose>
1157  </xsl:variable>
1158
1159  <xsl:variable name="following.spans">
1160    <xsl:call-template name="calculate.following.spans">
1161      <xsl:with-param name="colspan" select="$entry.colspan"/>
1162      <xsl:with-param name="spans" select="$spans"/>
1163    </xsl:call-template>
1164  </xsl:variable>
1165
1166  <xsl:choose>
1167    <xsl:when test="$spans != '' and not(starts-with($spans,'0:'))">
1168      <xsl:value-of select="substring-before($spans,':')-1"/>
1169      <xsl:text>:</xsl:text>
1170      <xsl:call-template name="sentry">
1171        <xsl:with-param name="col" select="$col+1"/>
1172        <xsl:with-param name="spans" select="substring-after($spans,':')"/>
1173      </xsl:call-template>
1174    </xsl:when>
1175
1176    <xsl:when test="number($entry.colnum) &gt; $col">
1177      <xsl:text>0:</xsl:text>
1178      <xsl:call-template name="sentry">
1179        <xsl:with-param name="col" select="$col+$entry.colspan"/>
1180        <xsl:with-param name="spans" select="$following.spans"/>
1181      </xsl:call-template>
1182    </xsl:when>
1183
1184    <xsl:otherwise>
1185      <xsl:call-template name="copy-string">
1186        <xsl:with-param name="count" select="$entry.colspan"/>
1187        <xsl:with-param name="string">
1188          <xsl:choose>
1189            <xsl:when test="@morerows">
1190              <xsl:value-of select="@morerows"/>
1191            </xsl:when>
1192            <xsl:otherwise>0</xsl:otherwise>
1193          </xsl:choose>
1194          <xsl:text>:</xsl:text>
1195        </xsl:with-param>
1196      </xsl:call-template>
1197
1198      <xsl:choose>
1199        <xsl:when test="following-sibling::entry|following-sibling::entrytbl">
1200          <xsl:apply-templates select="(following-sibling::entry
1201                                       |following-sibling::entrytbl)[1]"
1202                               mode="span">
1203            <xsl:with-param name="col" select="$col+$entry.colspan"/>
1204            <xsl:with-param name="spans" select="$following.spans"/>
1205          </xsl:apply-templates>
1206        </xsl:when>
1207        <xsl:otherwise>
1208          <xsl:call-template name="sfinaltd">
1209            <xsl:with-param name="spans" select="$following.spans"/>
1210          </xsl:call-template>
1211        </xsl:otherwise>
1212      </xsl:choose>
1213    </xsl:otherwise>
1214  </xsl:choose>
1215</xsl:template>
1216
1217<xsl:template name="generate.colgroup.raw">
1218  <xsl:param name="cols" select="1"/>
1219  <xsl:param name="count" select="1"/>
1220
1221  <xsl:choose>
1222    <xsl:when test="$count>$cols"></xsl:when>
1223    <xsl:otherwise>
1224      <xsl:call-template name="generate.col.raw">
1225        <xsl:with-param name="countcol" select="$count"/>
1226      </xsl:call-template>
1227      <xsl:call-template name="generate.colgroup.raw">
1228        <xsl:with-param name="cols" select="$cols"/>
1229        <xsl:with-param name="count" select="$count+1"/>
1230      </xsl:call-template>
1231    </xsl:otherwise>
1232  </xsl:choose>
1233</xsl:template>
1234
1235<xsl:template name="generate.colgroup">
1236  <xsl:param name="cols" select="1"/>
1237  <xsl:param name="count" select="1"/>
1238
1239  <xsl:choose>
1240    <xsl:when test="$count>$cols"></xsl:when>
1241    <xsl:otherwise>
1242      <xsl:call-template name="generate.col">
1243        <xsl:with-param name="countcol" select="$count"/>
1244      </xsl:call-template>
1245      <xsl:call-template name="generate.colgroup">
1246        <xsl:with-param name="cols" select="$cols"/>
1247        <xsl:with-param name="count" select="$count+1"/>
1248      </xsl:call-template>
1249    </xsl:otherwise>
1250  </xsl:choose>
1251</xsl:template>
1252
1253<xsl:template name="generate.col.raw">
1254  <!-- generate the table-column for column countcol -->
1255  <xsl:param name="countcol">1</xsl:param>
1256  <xsl:param name="colspecs" select="./colspec"/>
1257  <xsl:param name="count">1</xsl:param>
1258  <xsl:param name="colnum">1</xsl:param>
1259
1260  <xsl:choose>
1261    <xsl:when test="$count>count($colspecs)">
1262      <fo:table-column column-number="{$countcol}"/>
1263    </xsl:when>
1264    <xsl:otherwise>
1265      <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1266
1267      <xsl:variable name="colspec.colnum">
1268        <xsl:choose>
1269          <xsl:when test="$colspec/@colnum">
1270            <xsl:value-of select="$colspec/@colnum"/>
1271          </xsl:when>
1272          <xsl:otherwise>
1273            <xsl:value-of select="$colnum"/>
1274          </xsl:otherwise>
1275        </xsl:choose>
1276      </xsl:variable>
1277
1278      <xsl:variable name="colspec.colwidth">
1279        <xsl:choose>
1280          <xsl:when test="$colspec/@colwidth">
1281            <xsl:value-of select="$colspec/@colwidth"/>
1282          </xsl:when>
1283          <xsl:otherwise>1*</xsl:otherwise>
1284        </xsl:choose>
1285      </xsl:variable>
1286
1287      <xsl:choose>
1288        <xsl:when test="$colspec.colnum=$countcol">
1289          <fo:table-column column-number="{$countcol}">
1290            <xsl:attribute name="column-width">
1291              <xsl:value-of select="$colspec.colwidth"/>
1292            </xsl:attribute>
1293          </fo:table-column>
1294        </xsl:when>
1295        <xsl:otherwise>
1296          <xsl:call-template name="generate.col.raw">
1297            <xsl:with-param name="countcol" select="$countcol"/>
1298            <xsl:with-param name="colspecs" select="$colspecs"/>
1299            <xsl:with-param name="count" select="$count+1"/>
1300            <xsl:with-param name="colnum">
1301              <xsl:choose>
1302                <xsl:when test="$colspec/@colnum">
1303                  <xsl:value-of select="$colspec/@colnum + 1"/>
1304                </xsl:when>
1305                <xsl:otherwise>
1306                  <xsl:value-of select="$colnum + 1"/>
1307                </xsl:otherwise>
1308              </xsl:choose>
1309            </xsl:with-param>
1310           </xsl:call-template>
1311        </xsl:otherwise>
1312      </xsl:choose>
1313    </xsl:otherwise>
1314  </xsl:choose>
1315</xsl:template>
1316
1317<xsl:template name="generate.col">
1318  <!-- generate the table-column for column countcol -->
1319  <xsl:param name="countcol">1</xsl:param>
1320  <xsl:param name="colspecs" select="./colspec"/>
1321  <xsl:param name="count">1</xsl:param>
1322  <xsl:param name="colnum">1</xsl:param>
1323
1324  <xsl:choose>
1325    <xsl:when test="$count>count($colspecs)">
1326      <fo:table-column column-number="{$countcol}">
1327        <xsl:variable name="colwidth">
1328          <xsl:call-template name="calc.column.width"/>
1329        </xsl:variable>
1330        <xsl:if test="$colwidth != 'proportional-column-width(1)'">
1331          <xsl:attribute name="column-width">
1332            <xsl:value-of select="$colwidth"/>
1333          </xsl:attribute>
1334        </xsl:if>
1335      </fo:table-column>
1336    </xsl:when>
1337    <xsl:otherwise>
1338      <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
1339
1340      <xsl:variable name="colspec.colnum">
1341        <xsl:choose>
1342          <xsl:when test="$colspec/@colnum">
1343            <xsl:value-of select="$colspec/@colnum"/>
1344          </xsl:when>
1345          <xsl:otherwise>
1346            <xsl:value-of select="$colnum"/>
1347          </xsl:otherwise>
1348        </xsl:choose>
1349      </xsl:variable>
1350
1351      <xsl:variable name="colspec.colwidth">
1352        <xsl:choose>
1353          <xsl:when test="$colspec/@colwidth">
1354            <xsl:value-of select="$colspec/@colwidth"/>
1355          </xsl:when>
1356          <xsl:otherwise>1*</xsl:otherwise>
1357        </xsl:choose>
1358      </xsl:variable>
1359
1360      <xsl:choose>
1361        <xsl:when test="$colspec.colnum=$countcol">
1362          <fo:table-column column-number="{$countcol}">
1363            <xsl:variable name="colwidth">
1364              <xsl:call-template name="calc.column.width">
1365                <xsl:with-param name="colwidth">
1366                  <xsl:value-of select="$colspec.colwidth"/>
1367                </xsl:with-param>
1368              </xsl:call-template>
1369            </xsl:variable>
1370            <xsl:if test="$colwidth != 'proportional-column-width(1)'">
1371              <xsl:attribute name="column-width">
1372                <xsl:value-of select="$colwidth"/>
1373              </xsl:attribute>
1374            </xsl:if>
1375          </fo:table-column>
1376        </xsl:when>
1377        <xsl:otherwise>
1378          <xsl:call-template name="generate.col">
1379            <xsl:with-param name="countcol" select="$countcol"/>
1380            <xsl:with-param name="colspecs" select="$colspecs"/>
1381            <xsl:with-param name="count" select="$count+1"/>
1382            <xsl:with-param name="colnum">
1383              <xsl:choose>
1384                <xsl:when test="$colspec/@colnum">
1385                  <xsl:value-of select="$colspec/@colnum + 1"/>
1386                </xsl:when>
1387                <xsl:otherwise>
1388                  <xsl:value-of select="$colnum + 1"/>
1389                </xsl:otherwise>
1390              </xsl:choose>
1391            </xsl:with-param>
1392           </xsl:call-template>
1393        </xsl:otherwise>
1394      </xsl:choose>
1395    </xsl:otherwise>
1396  </xsl:choose>
1397</xsl:template>
1398
1399<doc:template name="calc.column.width" xmlns="">
1400<refpurpose>Calculate an XSL FO table column width specification from a
1401CALS table column width specification.</refpurpose>
1402
1403<refdescription>
1404<para>CALS expresses table column widths in the following basic
1405forms:</para>
1406
1407<itemizedlist>
1408<listitem>
1409<para><emphasis>99.99units</emphasis>, a fixed length specifier.</para>
1410</listitem>
1411<listitem>
1412<para><emphasis>99.99</emphasis>, a fixed length specifier without any units.</para>
1413</listitem>
1414<listitem>
1415<para><emphasis>99.99*</emphasis>, a relative length specifier.</para>
1416</listitem>
1417<listitem>
1418<para><emphasis>99.99*+99.99units</emphasis>, a combination of both.</para>
1419</listitem>
1420</itemizedlist>
1421
1422<para>The CALS units are points (pt), picas (pi), centimeters (cm),
1423millimeters (mm), and inches (in). These are the same units as XSL,
1424except that XSL abbreviates picas "pc" instead of "pi". If a length
1425specifier has no units, the CALS default unit (pt) is assumed.</para>
1426
1427<para>Relative length specifiers are represented in XSL with the
1428proportional-column-width() function.</para>
1429
1430<para>Here are some examples:</para>
1431
1432<itemizedlist>
1433<listitem>
1434<para>"36pt" becomes "36pt"</para>
1435</listitem>
1436<listitem>
1437<para>"3pi" becomes "3pc"</para>
1438</listitem>
1439<listitem>
1440<para>"36" becomes "36pt"</para>
1441</listitem>
1442<listitem>
1443<para>"3*" becomes "proportional-column-width(3)"</para>
1444</listitem>
1445<listitem>
1446<para>"3*+2pi" becomes "proportional-column-width(3)+2pc"</para>
1447</listitem>
1448<listitem>
1449<para>"1*+2" becomes "proportional-column-width(1)+2pt"</para>
1450</listitem>
1451</itemizedlist>
1452</refdescription>
1453
1454<refparameter>
1455<variablelist>
1456<varlistentry><term>colwidth</term>
1457<listitem>
1458<para>The CALS column width specification.</para>
1459</listitem>
1460</varlistentry>
1461</variablelist>
1462</refparameter>
1463
1464<refreturn>
1465<para>The XSL column width specification.</para>
1466</refreturn>
1467</doc:template>
1468
1469<xsl:template name="calc.column.width">
1470  <xsl:param name="colwidth">1*</xsl:param>
1471
1472  <!-- Ok, the colwidth could have any one of the following forms: -->
1473  <!--        1*       = proportional width -->
1474  <!--         *       = same as 1* -->
1475  <!--     1unit       = 1.0 units wide -->
1476  <!--         1       = 1pt wide -->
1477  <!--  1*+1unit       = proportional width + some fixed width -->
1478  <!--      1*+1       = proportional width + some fixed width -->
1479
1480  <!-- If it has a proportional width, translate it to XSL -->
1481  <xsl:if test="contains($colwidth, '*')">
1482    <xsl:text>proportional-column-width(</xsl:text>
1483    <xsl:choose>
1484      <xsl:when test="substring-before($colwidth, '*') != ''"> 
1485        <xsl:value-of select="substring-before($colwidth, '*')"/>
1486      </xsl:when>
1487      <xsl:otherwise>
1488         <xsl:text>1.00</xsl:text>
1489      </xsl:otherwise>
1490    </xsl:choose>
1491    <xsl:text>)</xsl:text>
1492  </xsl:if>
1493
1494  <!-- Now grab the non-proportional part of the specification -->
1495  <xsl:variable name="width-units">
1496    <xsl:choose>
1497      <xsl:when test="contains($colwidth, '*')">
1498        <xsl:value-of
1499             select="normalize-space(substring-after($colwidth, '*'))"/>
1500      </xsl:when>
1501      <xsl:otherwise>
1502        <xsl:value-of select="normalize-space($colwidth)"/>
1503      </xsl:otherwise>
1504    </xsl:choose>
1505  </xsl:variable>
1506
1507  <!-- Ok, now the width-units could have any one of the following forms: -->
1508  <!--                 = <empty string> -->
1509  <!--     1unit       = 1.0 units wide -->
1510  <!--         1       = 1pt wide -->
1511  <!-- with an optional leading sign -->
1512
1513  <!-- Grab the width part by blanking out the units part and discarding -->
1514  <!-- whitespace. It's not pretty, but it works. -->
1515  <xsl:variable name="width"
1516       select="normalize-space(translate($width-units,
1517                                         '+-0123456789.abcdefghijklmnopqrstuvwxyz',
1518                                         '+-0123456789.'))"/>
1519
1520  <!-- Grab the units part by blanking out the width part and discarding -->
1521  <!-- whitespace. It's not pretty, but it works. -->
1522  <xsl:variable name="units"
1523       select="normalize-space(translate($width-units,
1524                                         'abcdefghijklmnopqrstuvwxyz+-0123456789.',
1525                                         'abcdefghijklmnopqrstuvwxyz'))"/>
1526
1527  <!-- Output the width -->
1528  <xsl:value-of select="$width"/>
1529
1530  <!-- Output the units, translated appropriately -->
1531  <xsl:choose>
1532    <xsl:when test="$units = 'pi'">pc</xsl:when>
1533    <xsl:when test="$units = '' and $width != ''">pt</xsl:when>
1534    <xsl:otherwise><xsl:value-of select="$units"/></xsl:otherwise>
1535  </xsl:choose>
1536</xsl:template>
1537
1538<!-- ==================================================================== -->
1539
1540</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.