This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[kai/samba.git] / docs / docbook / xslt / db2latex / table.mod.xsl
1 <?xml version='1.0'?>
2 <!--############################################################################# 
3 |       $Id: table.mod.xsl,v 1.1.2.1 2003/05/01 14:06:15 jelmer Exp $
4 |- #############################################################################
5 |       $Author: jelmer $
6 |                                                                                                               
7 |   PURPOSE:
8 + ############################################################################## -->
9 <xsl:stylesheet 
10     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
11     xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
12     exclude-result-prefixes="doc" version='1.0'>
13
14
15
16     <!--############################################################################# -->
17     <!-- DOCUMENTATION                                                                -->
18     <doc:reference id="table" xmlns="">
19         <referenceinfo>
20             <releaseinfo role="meta">
21                 $Id: table.mod.xsl,v 1.1.2.1 2003/05/01 14:06:15 jelmer Exp $
22             </releaseinfo>
23             <authorgroup>
24                 <firstname>Ramon</firstname> <surname>Casellas</surname>
25                 <firstname>James</firstname> <surname>Devenish</surname>
26             </authorgroup>
27             <copyright>
28                 <year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
29                 <holder>Ramon Casellas</holder>
30             </copyright>
31         </referenceinfo>
32
33         <title>Tables <filename>table.mod.xsl</filename></title>
34         <partintro>
35             <section><title>Introduction</title>
36                 <para></para>
37             </section>
38         </partintro>
39     </doc:reference>
40
41
42
43
44     <!--############################################################################# -->
45     <!-- DOCUMENTATION -->
46     <doc:template match="table|informaltable" xmlns="">
47         <refpurpose>XSL template for docbook tables.  </refpurpose>
48         <refdescription>
49             <para></para>
50             <formalpara><title>Remarks and Bugs</title>
51                 <itemizedlist>
52                 </itemizedlist>
53             </formalpara>
54             <formalpara><title>Default Behaviour</title>
55                 <screen></screen>
56             </formalpara>
57         </refdescription>
58     </doc:template>
59     <!--############################################################################# -->
60
61         <xsl:template match="table">
62         <xsl:variable name="placement">
63                 <xsl:call-template name="generate.formal.title.placement">
64                         <xsl:with-param name="object" select="local-name(.)" />
65                 </xsl:call-template>
66         </xsl:variable>
67         <xsl:variable name="caption">
68                 <xsl:text>\caption{</xsl:text>
69                 <xsl:apply-templates select="title" mode="caption.mode"/>
70                 <xsl:text>}&#10;</xsl:text>
71         </xsl:variable>
72         <xsl:call-template name="map.begin"/>
73         <xsl:if test="$placement='before'">
74                 <xsl:text>\captionswapskip{}</xsl:text>
75                 <xsl:value-of select="$caption" />
76                 <xsl:text>\captionswapskip{}</xsl:text>
77         </xsl:if>
78         <xsl:apply-templates/>
79         <xsl:if test="$placement!='before'"><xsl:value-of select="$caption" /></xsl:if>
80         <xsl:call-template name="map.end"/>
81         </xsl:template>
82
83         <xsl:template match="table/title"/>
84         <xsl:template match="table/title" mode="caption.mode"><xsl:apply-templates /></xsl:template>
85
86         <xsl:template match="informaltable">
87         <xsl:call-template name="map.begin"/>
88         <xsl:apply-templates/>
89         <xsl:call-template name="map.end"/>
90         </xsl:template>
91
92         
93     <xsl:template name="table.format.tabularx">
94         <xsl:param name="cols" select="1"/>
95         <xsl:param name="i" select="1"/>
96         <xsl:param name="colsep" select="1"/>
97         <!-- sum of numeric portions in 1*-like colwidths -->
98         <xsl:param name="starfactor" select="0"/>
99         <xsl:choose>
100             <!-- Out of the recursive iteration -->
101             <xsl:when test="$i > $cols"></xsl:when>
102             <!-- There are still columns to count -->
103             <xsl:otherwise>
104                 <xsl:variable name="width">
105                         <xsl:variable name="userchoice" select="colspec[@colnum=$i]/@colwidth"/>
106                         <xsl:variable name="cells" select="thead/row/entry[$i]|tbody/row/entry[$i]"/>
107                         <xsl:choose>
108                                 <xsl:when test="string-length($userchoice)=0 and count($cells//itemizedlist|$cells//orderedlist|$cells//variablelist)&gt;0">
109                                         <!-- In these specific circumstances, we MUST use a line-wrapped column
110                                              and yet the user hasn't specified one. -->
111                                         <xsl:value-of select="'1*'"/>
112                                 </xsl:when>
113                                 <xsl:otherwise>
114                                         <!-- In the general case, we just do what the user wants (may even
115                                              have no pre-specified width). -->
116                                         <xsl:value-of select="$userchoice"/>
117                                 </xsl:otherwise>
118                         </xsl:choose>
119                 </xsl:variable>
120                 <!-- Try to take heed of colspecs -->
121                 <xsl:choose>
122                         <xsl:when test="$width!=''">
123                                 <xsl:text>&gt;{</xsl:text>
124                                 <xsl:if test="contains($width,'*')">
125                                         <!-- see tabularx documentation -->
126                                         <xsl:text>\hsize=</xsl:text>
127                                         <xsl:value-of select="substring-before($width,'*') * $starfactor" />
128                                         <xsl:text>\hsize</xsl:text>
129                                 </xsl:if>
130                                 <xsl:choose>
131                                         <xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>\RaggedRight</xsl:text></xsl:when>
132                                         <xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>\RaggedLeft</xsl:text></xsl:when>
133                                         <xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>\Centering</xsl:text></xsl:when>
134                                         <xsl:when test="colspec[@colnum=$i]/@align='char'"><xsl:message>Table column char alignment is not supported.</xsl:message></xsl:when>
135                                 </xsl:choose>
136                                 <xsl:text>}</xsl:text>
137                                 <xsl:choose>
138                                         <xsl:when test="contains($width,'*')">
139                                                 <xsl:text>X</xsl:text>
140                                         </xsl:when>
141                                         <xsl:otherwise>
142                                                 <xsl:text>p{</xsl:text><xsl:value-of select="$width" /><xsl:text>}</xsl:text>
143                                         </xsl:otherwise>
144                                 </xsl:choose>
145                                 <xsl:if test="$i&lt;$cols and $colsep='1'">
146                                         <xsl:text>|</xsl:text>
147                                 </xsl:if>
148                         </xsl:when>
149                         <xsl:otherwise>
150                                 <xsl:choose>
151                                         <xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>l</xsl:text></xsl:when>
152                                         <xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>r</xsl:text></xsl:when>
153                                         <xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>c</xsl:text></xsl:when>
154                                         <xsl:when test="colspec[@colnum=$i]/@align='justify'"><xsl:text>X</xsl:text></xsl:when>
155                                         <xsl:when test="colspec[@colnum=$i]/@align='char'"><xsl:text>c</xsl:text><xsl:message>Table column char alignment is not supported.</xsl:message></xsl:when>
156                                         <xsl:otherwise><xsl:text>c</xsl:text></xsl:otherwise>
157                                 </xsl:choose>
158                                 <xsl:if test="$i&lt;$cols and $colsep='1'">
159                                         <xsl:text>|</xsl:text>
160                                 </xsl:if>
161                         </xsl:otherwise>
162                 </xsl:choose>
163                 <!-- Recursive for next column -->
164                 <xsl:call-template name="table.format.tabularx">
165                     <xsl:with-param name="i" select="$i+1"/>
166                     <xsl:with-param name="cols" select="$cols"/>
167                     <xsl:with-param name="starfactor" select="$starfactor"/>
168                 </xsl:call-template>
169             </xsl:otherwise>
170         </xsl:choose>
171     </xsl:template>
172         
173
174     <!-- FIX THIS -->
175     <xsl:template name="table.format.tabular">
176         <xsl:param name="cols" select="1"/>
177         <xsl:param name="i" select="1"/>
178         <xsl:param name="colsep" select="1"/>
179         <xsl:choose>
180             <!-- Out of the recursive iteration -->
181             <xsl:when test="$i > $cols"></xsl:when>
182             <!-- There are still columns to count -->
183             <xsl:otherwise>
184                 <!-- Try to take heed of colspecs -->
185                 <xsl:choose>
186                         <!-- RC 2003/03/19 : Added first 'test' : colspec[@colnum=$i] for xsltproc 
187                                 Before this patch, parsing the doc with xsltproc the xsl:when clause 
188                                 was evaluated to 'true' even if there was no colspec for the column
189                         -->
190                         <xsl:when test="colspec[@colnum=$i] and colspec[@colnum=$i]/@colwidth!='' and not(contains(colspec[@colnum=$i]/@colwidth,'*'))">
191                                 <xsl:choose>
192                                         <xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>&gt;{\RaggedRight}</xsl:text></xsl:when>
193                                         <xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>&gt;{\RaggedLeft}</xsl:text></xsl:when>
194                                         <xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>&gt;{\Centering}</xsl:text></xsl:when>
195                                         <xsl:when test="colspec[@colnum=$i]/@align='char'"><xsl:message>Table column char alignment is not supported.</xsl:message></xsl:when>
196                                 </xsl:choose>
197                                 <xsl:text>p{</xsl:text><xsl:value-of select="colspec[@colnum=$i]/@colwidth" /><xsl:text>}</xsl:text>
198                                 <xsl:if test="$i&lt;$cols and $colsep='1'">
199                                         <xsl:text>|</xsl:text>
200                                 </xsl:if>
201                         </xsl:when>
202                         <xsl:otherwise>
203                                 <xsl:choose>
204                                         <xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>l</xsl:text></xsl:when>
205                                         <xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>r</xsl:text></xsl:when>
206                                         <xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>c</xsl:text></xsl:when>
207                                         <xsl:when test="colspec[@colnum=$i]/@align='justify'"><xsl:text>l</xsl:text></xsl:when>
208                                         <xsl:when test="colspec[@colnum=$i]/@align='char'"><xsl:text>c</xsl:text><xsl:message>Table column char alignment is not supported.</xsl:message></xsl:when>
209                                         <xsl:otherwise><xsl:text>c</xsl:text></xsl:otherwise>
210                                 </xsl:choose>
211                                 <xsl:if test="$i&lt;$cols and $colsep='1'">
212                                         <xsl:text>|</xsl:text>
213                                 </xsl:if>
214                         </xsl:otherwise>
215                 </xsl:choose>
216                 <!-- Recursive for next column -->
217                 <xsl:call-template name="table.format.tabular">
218                     <xsl:with-param name="i" select="$i+1"/>
219                     <xsl:with-param name="cols" select="$cols"/>
220                 </xsl:call-template>
221             </xsl:otherwise>
222         </xsl:choose>
223     </xsl:template>
224
225
226
227         <!-- See tabularx documentation. -->
228         <!-- For example, if we have a 1* column and a 3* column, then the
229              the hsizes for each column are (1/(1+3)*2) and (3/(1+3)*2).
230                  The ratio of these to the star values (star values being 1 and 3)
231                  is 2/(1+3).
232                  BUT it is now very complicated because it takes into account columns
233                  where the user has not specified a width but LaTeX requires a
234                  fixed-width column (i.e. specialcols may vary).
235                  Relies on there being (a) colspecs for every column or (b) no
236                  colspecs.
237          -->
238         <xsl:template name="generate.starfactor">
239                 <xsl:param name="i" select="1"/>
240                 <xsl:param name="cols" select="count(colspec)"/>
241                 <xsl:param name="sum" select="0"/>
242                 <xsl:param name="specialcols" select="count(colspec[contains(@colwidth,'*')])"/>
243                 <xsl:choose>
244                         <xsl:when test="$i&lt;=$cols and colspec[position()=$i and contains(@colwidth,'*')]">
245                                 <!-- a * column -->
246                                 <xsl:call-template name="generate.starfactor">
247                                         <xsl:with-param name="i" select="$i+1"/>
248                                         <xsl:with-param name="cols" select="$cols"/>
249                                         <xsl:with-param name="sum" select="$sum+substring-before(colspec[$i]/@colwidth,'*')"/>
250                                         <xsl:with-param name="specialcols" select="$specialcols"/>
251                                 </xsl:call-template>
252                         </xsl:when>
253                         <xsl:when test="$i&lt;=$cols">
254                                 <!-- not a * column, but we are going to pretend that it is -->
255                                 <xsl:variable name="cells" select="thead/row/entry[$i]|tbody/row/entry[$i]"/>
256                                 <xsl:variable name="problems" select="count($cells//itemizedlist|$cells//orderedlist|$cells//variablelist)"/>
257                                 <xsl:choose>
258                                         <xsl:when test="$problems &gt; 0">
259                                                 <xsl:call-template name="generate.starfactor">
260                                                         <xsl:with-param name="i" select="$i+1"/>
261                                                         <xsl:with-param name="cols" select="$cols"/>
262                                                         <xsl:with-param name="sum" select="$sum+1"/>
263                                                         <xsl:with-param name="specialcols" select="$specialcols+1"/>
264                                                 </xsl:call-template>
265                                         </xsl:when>
266                                         <xsl:otherwise>
267                                                 <xsl:call-template name="generate.starfactor">
268                                                         <xsl:with-param name="i" select="$i+1"/>
269                                                         <xsl:with-param name="cols" select="$cols"/>
270                                                         <xsl:with-param name="sum" select="$sum"/>
271                                                         <xsl:with-param name="specialcols" select="$specialcols"/>
272                                                 </xsl:call-template>
273                                         </xsl:otherwise>
274                                 </xsl:choose>
275                         </xsl:when>
276                         <xsl:otherwise>
277                                 <xsl:value-of select="$specialcols div $sum"/>
278                         </xsl:otherwise>
279                 </xsl:choose>
280         </xsl:template>
281         
282
283     <xsl:template match="tgroup">
284         <xsl:variable name="align" select="@align"/>
285         <xsl:variable name="frame">
286                 <xsl:choose>
287                         <xsl:when test="string-length(../@frame)&lt;1">all</xsl:when>
288                         <xsl:otherwise>
289                                 <xsl:value-of select="../@frame"/>
290                         </xsl:otherwise>
291                 </xsl:choose>
292         </xsl:variable>
293         <xsl:variable name="colspecs" select="./colspec"/>
294         <xsl:variable name="usex">
295                 <xsl:choose>
296                         <!-- if there are lists within cells, we need tabularx -->
297                         <xsl:when test="$latex.use.tabularx=1 and (descendant::itemizedlist|descendant::orderedlist|descendant::variablelist)">
298                                 <xsl:text>1</xsl:text>
299                         </xsl:when>
300                         <!-- if there are instances of 1*-style colwidths, we need tabularx -->
301                         <xsl:when test="$latex.use.tabularx=1 and contains(colspec/@colwidth,'*')">
302                                 <xsl:text>1</xsl:text>
303                         </xsl:when>
304                         <!-- if there are colspecs with 'justify' alignment and no explicit width, we need tabularx -->
305                         <xsl:when test="$latex.use.tabularx=1 and count(colspec[@align='justify'])&gt;0">
306                                 <xsl:text>1</xsl:text>
307                         </xsl:when>
308                         <xsl:otherwise>
309                                 <xsl:text>0</xsl:text>
310                         </xsl:otherwise>
311                 </xsl:choose>
312         </xsl:variable>
313         <xsl:variable name="useminipage">
314                 <!-- Hack to get around LaTeX issue with tabular (not necessary with tabularx).
315                 This is NOT a good solution, and has problems of its own, but at least the footnotes
316                 do not actually disappear (which is what would otherwise happen). -->
317                 <xsl:if test="count(.//footnote)!=0">1</xsl:if>
318         </xsl:variable>
319         <xsl:choose>
320                 <xsl:when test="$usex='1'">
321                         <xsl:text>\begin{tabularx}{\linewidth}{</xsl:text>
322                 </xsl:when>
323                 <xsl:otherwise>
324                         <xsl:if test="$useminipage='1'"><xsl:text>\begin{minipage}{\linewidth}&#10;</xsl:text></xsl:if>
325                         <xsl:text>\begin{tabular}{</xsl:text>
326                 </xsl:otherwise>
327         </xsl:choose>
328         <xsl:if test="$frame='all' or $frame='sides'">
329             <xsl:text>|</xsl:text>
330         </xsl:if>
331         <xsl:choose>
332                 <xsl:when test="$usex=1">
333                         <xsl:call-template name="table.format.tabularx">
334                                 <xsl:with-param name="cols" select="@cols"/>
335                                 <xsl:with-param name="starfactor">
336                                         <xsl:call-template name="generate.starfactor">
337                                                 <xsl:with-param name="cols" select="@cols"/>
338                                         </xsl:call-template>
339                                 </xsl:with-param>
340                         </xsl:call-template>
341                 </xsl:when>
342                 <xsl:otherwise>
343                         <xsl:call-template name="table.format.tabular">
344                                 <xsl:with-param name="cols" select="@cols"/>
345                         </xsl:call-template>
346                 </xsl:otherwise>
347         </xsl:choose>
348         <xsl:if test="$frame='all' or $frame='sides'">
349             <xsl:text>|</xsl:text>
350         </xsl:if>
351         <xsl:text>}&#10;</xsl:text>
352         <xsl:if test="$frame!='sides' and $frame!='none' and $frame!='bottom'">
353             <xsl:text>\hline &#10;</xsl:text>
354         </xsl:if>
355         <!-- APPLY TEMPLATES -->
356         <xsl:apply-templates/>
357         <!--                 -->
358         <xsl:if test="$frame!='sides' and $frame!='none' and $frame!='top'">
359             <xsl:text>\hline &#10;</xsl:text>
360         </xsl:if>
361         <xsl:choose>
362                 <xsl:when test="$usex=1">
363                         <xsl:text>\end{tabularx}&#10;</xsl:text>
364                 </xsl:when>
365                 <xsl:otherwise>
366                         <xsl:text>\end{tabular}&#10;</xsl:text>
367                         <xsl:if test="$useminipage='1'"><xsl:text>\end{minipage}&#10;</xsl:text></xsl:if>
368                 </xsl:otherwise>
369         </xsl:choose>
370     </xsl:template>
371
372
373
374     <!--
375     <xsl:template name="generate.col">
376         <xsl:param name="countcol">1</xsl:param>
377     </xsl:template>
378     -->
379
380     <xsl:template match="colspec"></xsl:template>
381     <xsl:template match="spanspec"></xsl:template>
382
383
384
385
386     <xsl:template match="thead|tfoot">
387         <xsl:if test="@align">
388             <xsl:attribute name="align">
389                 <xsl:value-of select="@align"/>
390             </xsl:attribute>
391         </xsl:if>
392         <xsl:if test="@char">
393             <xsl:attribute name="char">
394                 <xsl:value-of select="@char"/>
395             </xsl:attribute>
396         </xsl:if>
397         <xsl:if test="@charoff">
398             <xsl:attribute name="charoff">
399                 <xsl:value-of select="@charoff"/>
400             </xsl:attribute>
401         </xsl:if>
402         <xsl:if test="@valign">
403             <xsl:attribute name="valign">
404                 <xsl:value-of select="@valign"/>
405             </xsl:attribute>
406         </xsl:if>
407         <xsl:apply-templates/>
408     </xsl:template>
409
410     <xsl:template match="thead/row/entry|tfoot/row/entry">
411         <xsl:call-template name="latex.entry.prealign"/>
412         <xsl:call-template name="latex.thead.row.entry"/>
413         <xsl:call-template name="latex.entry.postalign"/>
414         <xsl:choose>
415                 <xsl:when test="position()=last()"><xsl:text> \tabularnewline&#10;</xsl:text></xsl:when>
416                 <xsl:otherwise><xsl:call-template name="generate.latex.cell.separator"/></xsl:otherwise>
417         </xsl:choose> 
418     </xsl:template>
419
420     <xsl:template match="tbody">
421         <xsl:apply-templates/>
422     </xsl:template>
423
424     <xsl:template match="row">
425         <xsl:apply-templates/>
426     </xsl:template>
427
428     <xsl:template match="tbody/row|thead/row|tfoot/row">
429         <xsl:apply-templates/>
430         <!-- The rule below the last row in the table is controlled by the 
431         Frame attribute of the enclosing Table or InformalTable and the RowSep 
432         of the last row is ignored. If unspecified, this attribute is 
433         inherited from enclosing elements, rowsep=1 by default. -->
434         <xsl:variable name="parent_position" select="count(../preceding-sibling::node())+1"/>
435         <xsl:variable name="grandparent_children" select="count(../../child::node())"/>
436         <xsl:if test="(count(@rowsep)=0 or @rowsep='1') and (position() != last() or $parent_position &lt; $grandparent_children)">
437             <xsl:text> \hline &#10;</xsl:text>
438         </xsl:if>
439     </xsl:template>
440
441
442     <xsl:template match="tbody/row/entry">
443         <xsl:call-template name="latex.entry.prealign"/>
444         <xsl:apply-templates/>
445         <xsl:call-template name="latex.entry.postalign"/>
446         <xsl:choose>
447                 <xsl:when test="position()=last()"><xsl:text> \tabularnewline&#10;</xsl:text></xsl:when>
448                 <xsl:otherwise><xsl:call-template name="generate.latex.cell.separator"/></xsl:otherwise>
449         </xsl:choose> 
450     </xsl:template>
451
452
453         <xsl:template name="latex.entry.prealign">
454         <xsl:variable name="span">
455                 <xsl:choose>
456                         <xsl:when test="@spanname!=''">
457                                 <xsl:call-template name="calculate.colspan">
458                                         <xsl:with-param name="namest" select="../../../spanspec[@spanname=@spanname]/@namest"/>
459                                         <xsl:with-param name="nameend" select="../../../spanspec[@spanname=@spanname]/@nameend"/>
460                                 </xsl:call-template>
461                         </xsl:when>
462                         <xsl:when test="@namest!=''">
463                                 <xsl:call-template name="calculate.colspan"/>
464                         </xsl:when>
465                         <xsl:otherwise>-1</xsl:otherwise>
466                 </xsl:choose>
467         </xsl:variable>
468         <xsl:if test="$span &gt; 1">
469                 <xsl:text>\multicolumn{</xsl:text>
470                 <xsl:value-of select="$span"/>
471                 <xsl:text>|}{</xsl:text><!-- TODO take heed of @colsep -->
472                 <xsl:choose>
473                         <xsl:when test="@align='left'"><xsl:text>l</xsl:text></xsl:when>
474                         <xsl:when test="@align='right'"><xsl:text>r</xsl:text></xsl:when>
475                         <xsl:when test="@align='center'"><xsl:text>c</xsl:text></xsl:when>
476                         <xsl:when test="@align='char'">c<xsl:message>Table entry char alignment is not supported.</xsl:message></xsl:when>
477                         <xsl:otherwise>c</xsl:otherwise>
478                 </xsl:choose>
479         <!-- use this as a hook for some general warnings -->
480                 <xsl:text>}</xsl:text>
481         </xsl:if>
482         <!-- this is used when the entry's align spec wants to override the column default -->
483         <xsl:if test="$span &lt; 1">
484                 <xsl:choose>
485                         <xsl:when test="@align='left'"><xsl:text>\docbooktolatexalignll </xsl:text></xsl:when>
486                         <xsl:when test="@align='right'"><xsl:text>\docbooktolatexalignrl </xsl:text></xsl:when>
487                         <xsl:when test="@align='center'"><xsl:text>\docbooktolatexaligncl </xsl:text></xsl:when>
488                         <xsl:when test="@align='char'"><xsl:message>Table entry char alignment is not supported.</xsl:message></xsl:when>
489                 </xsl:choose>
490         </xsl:if>
491         <xsl:text>{</xsl:text>
492         <xsl:if test="@rotate='1'">
493                 <xsl:text>\rotatebox{90}</xsl:text>
494                 <xsl:if test="@align!=''"><xsl:message>entry[@rotate='1' and @align!=''] probably doesn't work.</xsl:message></xsl:if>
495         </xsl:if>
496         <xsl:text>{</xsl:text>
497         <!-- use this as a hook for some general warnings -->
498         <xsl:if test="@morerows!=''"><xsl:message>The morerows attribute is not supported.</xsl:message></xsl:if>
499         </xsl:template>
500
501         <xsl:template name="latex.entry.postalign">
502         <xsl:text>}}</xsl:text>
503         <!-- this is used when the entry's align spec wants to override the column default -->
504         <xsl:if test="@namest='' and @spanspec=''"><!-- TODO improve -->
505                 <xsl:choose>
506                         <xsl:when test="@align='left'"><xsl:text>\docbooktolatexalignlr </xsl:text></xsl:when>
507                         <xsl:when test="@align='right'"><xsl:text>\docbooktolatexalignrr </xsl:text></xsl:when>
508                         <xsl:when test="@align='center'"><xsl:text>\docbooktolatexaligncr </xsl:text></xsl:when>
509                 </xsl:choose>
510         </xsl:if>
511         </xsl:template>
512
513
514
515
516
517
518
519
520
521
522
523
524
525     <xsl:template name="process.cell">
526         <xsl:param name="cellgi">td</xsl:param>
527         <xsl:variable name="empty.cell" select="count(node()) = 0"/>
528
529         <xsl:element name="{$cellgi}">
530             <xsl:if test="@morerows">
531                 <xsl:attribute name="rowspan">
532                     <xsl:value-of select="@morerows+1"/>
533                 </xsl:attribute>
534             </xsl:if>
535             <xsl:if test="@namest">
536                 <xsl:attribute name="colspan">
537                     <xsl:call-template name="calculate.colspan"/>
538                 </xsl:attribute>
539             </xsl:if>
540             <xsl:if test="@align">
541                 <xsl:attribute name="align">
542                     <xsl:value-of select="@align"/>
543                 </xsl:attribute>
544             </xsl:if>
545             <xsl:if test="@char">
546                 <xsl:attribute name="char">
547                     <xsl:value-of select="@char"/>
548                 </xsl:attribute>
549             </xsl:if>
550             <xsl:if test="@charoff">
551                 <xsl:attribute name="charoff">
552                     <xsl:value-of select="@charoff"/>
553                 </xsl:attribute>
554             </xsl:if>
555             <xsl:if test="@valign">
556                 <xsl:attribute name="valign">
557                     <xsl:value-of select="@valign"/>
558                 </xsl:attribute>
559             </xsl:if>
560
561             <xsl:choose>
562                 <xsl:when test="$empty.cell">
563                     <xsl:text>&#160;</xsl:text>
564                 </xsl:when>
565                 <xsl:otherwise>
566                     <xsl:apply-templates/>
567                 </xsl:otherwise>
568             </xsl:choose>
569         </xsl:element>
570     </xsl:template>
571
572     <xsl:template name="generate.colgroup">
573         <xsl:param name="cols" select="1"/>
574         <xsl:param name="count" select="1"/>
575         <xsl:choose>
576             <xsl:when test="$count>$cols"></xsl:when>
577             <xsl:otherwise>
578                 <xsl:call-template name="generate.col">
579                     <xsl:with-param name="countcol" select="$count"/>
580                 </xsl:call-template>
581                 <xsl:call-template name="generate.colgroup">
582                     <xsl:with-param name="cols" select="$cols"/>
583                     <xsl:with-param name="count" select="$count+1"/>
584                 </xsl:call-template>
585             </xsl:otherwise>
586         </xsl:choose>
587     </xsl:template>
588
589     <xsl:template name="generate.col">
590         <xsl:param name="countcol">1</xsl:param>
591         <xsl:param name="colspecs" select="./colspec"/>
592         <xsl:param name="count">1</xsl:param>
593         <xsl:param name="colnum">1</xsl:param>
594
595         <xsl:choose>
596             <xsl:when test="$count>count($colspecs)">
597                 <col/>
598             </xsl:when>
599             <xsl:otherwise>
600                 <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
601                 <xsl:variable name="colspec.colnum">
602                     <xsl:choose>
603                         <xsl:when test="$colspec/@colnum">
604                             <xsl:value-of select="$colspec/@colnum"/>
605                         </xsl:when>
606                         <xsl:otherwise>
607                             <xsl:value-of select="$colnum"/>
608                         </xsl:otherwise>
609                     </xsl:choose>
610                 </xsl:variable>
611
612                 <xsl:choose>
613                     <xsl:when test="$colspec.colnum=$countcol">
614                         <col>
615                             <xsl:if test="$colspec/@align">
616                                 <xsl:attribute name="align">
617                                     <xsl:value-of select="$colspec/@align"/>
618                                 </xsl:attribute>
619                             </xsl:if>
620                             <xsl:if test="$colspec/@char">
621                                 <xsl:attribute name="char">
622                                     <xsl:value-of select="$colspec/@char"/>
623                                 </xsl:attribute>
624                             </xsl:if>
625                             <xsl:if test="$colspec/@charoff">
626                                 <xsl:attribute name="charoff">
627                                     <xsl:value-of select="$colspec/@charoff"/>
628                                 </xsl:attribute>
629                             </xsl:if>
630                         </col>
631                     </xsl:when>
632                     <xsl:otherwise>
633                         <xsl:call-template name="generate.col">
634                             <xsl:with-param name="countcol" select="$countcol"/>
635                             <xsl:with-param name="colspecs" select="$colspecs"/>
636                             <xsl:with-param name="count" select="$count+1"/>
637                             <xsl:with-param name="colnum">
638                                 <xsl:choose>
639                                     <xsl:when test="$colspec/@colnum">
640                                         <xsl:value-of select="$colspec/@colnum + 1"/>
641                                     </xsl:when>
642                                     <xsl:otherwise>
643                                         <xsl:value-of select="$colnum + 1"/>
644                                     </xsl:otherwise>
645                                 </xsl:choose>
646                             </xsl:with-param>
647                         </xsl:call-template>
648                     </xsl:otherwise>
649                 </xsl:choose>
650             </xsl:otherwise>
651         </xsl:choose>
652
653     </xsl:template>
654
655     <xsl:template name="colspec.colnum">
656         <!-- when this macro is called, the current context must be an entry -->
657         <xsl:param name="colname"></xsl:param>
658         <!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
659         <xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
660         <xsl:param name="count">1</xsl:param>
661         <xsl:param name="colnum">1</xsl:param>
662         <xsl:choose>
663             <xsl:when test="$count>count($colspecs)"></xsl:when>
664             <xsl:otherwise>
665                 <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
666                 <!--
667                 <xsl:value-of select="$count"/>:
668                 <xsl:value-of select="$colspec/@colname"/>=
669                 <xsl:value-of select="$colnum"/>
670                 -->
671                 <xsl:choose>
672                     <xsl:when test="$colspec/@colname=$colname">
673                         <xsl:choose>
674                             <xsl:when test="$colspec/@colnum">
675                                 <xsl:value-of select="$colspec/@colnum"/>
676                             </xsl:when>
677                             <xsl:otherwise>
678                                 <xsl:value-of select="$colnum"/>
679                             </xsl:otherwise>
680                         </xsl:choose>
681                     </xsl:when>
682                     <xsl:otherwise>
683                         <xsl:call-template name="colspec.colnum">
684                             <xsl:with-param name="colname" select="$colname"/>
685                             <xsl:with-param name="colspecs" select="$colspecs"/>
686                             <xsl:with-param name="count" select="$count+1"/>
687                             <xsl:with-param name="colnum">
688                                 <xsl:choose>
689                                     <xsl:when test="$colspec/@colnum">
690                                         <xsl:value-of select="$colspec/@colnum + 1"/>
691                                     </xsl:when>
692                                     <xsl:otherwise>
693                                         <xsl:value-of select="$colnum + 1"/>
694                                     </xsl:otherwise>
695                                 </xsl:choose>
696                             </xsl:with-param>
697                         </xsl:call-template>
698                     </xsl:otherwise>
699                 </xsl:choose>
700             </xsl:otherwise>
701         </xsl:choose>
702     </xsl:template>
703
704     <xsl:template name="colspec.colwidth">
705         <!-- when this macro is called, the current context must be an entry -->
706         <xsl:param name="colname"></xsl:param>
707         <!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
708         <xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
709         <xsl:param name="count">1</xsl:param>
710         <xsl:choose>
711             <xsl:when test="$count>count($colspecs)"></xsl:when>
712             <xsl:otherwise>
713                 <xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
714                 <xsl:choose>
715                     <xsl:when test="$colspec/@colname=$colname">
716                         <xsl:value-of select="$colspec/@colwidth"/>
717                     </xsl:when>
718                     <xsl:otherwise>
719                         <xsl:call-template name="colspec.colwidth">
720                             <xsl:with-param name="colname" select="$colname"/>
721                             <xsl:with-param name="colspecs" select="$colspecs"/>
722                             <xsl:with-param name="count" select="$count+1"/>
723                         </xsl:call-template>
724                     </xsl:otherwise>
725                 </xsl:choose>
726             </xsl:otherwise>
727         </xsl:choose>
728     </xsl:template>
729
730     <xsl:template name="calculate.colspan">
731         <xsl:param name="namest" select="@namest"/>
732         <xsl:param name="nameend" select="@nameend"/>
733         <xsl:variable name="scol">
734             <xsl:call-template name="colspec.colnum">
735                 <xsl:with-param name="colname" select="$namest"/>
736             </xsl:call-template>
737         </xsl:variable>
738         <xsl:variable name="ecol">
739             <xsl:call-template name="colspec.colnum">
740                 <xsl:with-param name="colname" select="$nameend"/>
741             </xsl:call-template>
742         </xsl:variable>
743         <xsl:value-of select="$ecol - $scol + 1"/>
744     </xsl:template>
745
746 </xsl:stylesheet>