summaryrefslogtreecommitdiff
path: root/docs/docbook/xslt/db2latex/table.mod.xsl
blob: 0edb4ad2cc44773efc79464a47e6105068590115 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
<?xml version='1.0'?>
<!--############################################################################# 
|- #############################################################################
|														
|   PURPOSE:
+ ############################################################################## -->
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
    exclude-result-prefixes="doc" version='1.0'>



    <!--############################################################################# -->
    <!-- DOCUMENTATION                                                                -->
    <doc:reference id="table" xmlns="">
	<referenceinfo>
	    <releaseinfo role="meta">
	    </releaseinfo>
	    <authorgroup>
		<firstname>Ramon</firstname> <surname>Casellas</surname>
		<firstname>James</firstname> <surname>Devenish</surname>
	    </authorgroup>
	    <copyright>
		<year>2000</year> <year>2001</year> <year>2002</year> <year>2003</year>
		<holder>Ramon Casellas</holder>
	    </copyright>
	</referenceinfo>

	<title>Tables <filename>table.mod.xsl</filename></title>
	<partintro>
	    <section><title>Introduction</title>
		<para></para>
	    </section>
	</partintro>
    </doc:reference>




    <!--############################################################################# -->
    <!-- DOCUMENTATION -->
    <doc:template match="table|informaltable" xmlns="">
	<refpurpose>XSL template for docbook tables.  </refpurpose>
	<refdescription>
	    <para></para>
	    <formalpara><title>Remarks and Bugs</title>
		<itemizedlist>
		</itemizedlist>
	    </formalpara>
	    <formalpara><title>Default Behaviour</title>
		<screen></screen>
	    </formalpara>
	</refdescription>
    </doc:template>
    <!--############################################################################# -->

	<xsl:template match="table">
	<xsl:variable name="placement">
		<xsl:call-template name="generate.formal.title.placement">
			<xsl:with-param name="object" select="local-name(.)" />
		</xsl:call-template>
	</xsl:variable>
	<xsl:variable name="caption">
		<xsl:text>\caption{</xsl:text>
		<xsl:apply-templates select="title" mode="caption.mode"/>
		<xsl:text>}&#10;</xsl:text>
	</xsl:variable>
	<xsl:call-template name="map.begin"/>
	<xsl:if test="$placement='before'">
		<xsl:text>\captionswapskip{}</xsl:text>
		<xsl:value-of select="$caption" />
		<xsl:text>\captionswapskip{}</xsl:text>
	</xsl:if>
	<xsl:apply-templates/>
	<xsl:if test="$placement!='before'"><xsl:value-of select="$caption" /></xsl:if>
	<xsl:call-template name="map.end"/>
	</xsl:template>

	<xsl:template match="table/title"/>
	<xsl:template match="table/title" mode="caption.mode"><xsl:apply-templates /></xsl:template>

	<xsl:template match="informaltable">
	<xsl:call-template name="map.begin"/>
	<xsl:apply-templates/>
	<xsl:call-template name="map.end"/>
	</xsl:template>

	
    <xsl:template name="table.format.tabularx">
	<xsl:param name="cols" select="1"/>
	<xsl:param name="i" select="1"/>
	<xsl:param name="colsep" select="1"/>
	<!-- sum of numeric portions in 1*-like colwidths -->
	<xsl:param name="starfactor" select="0"/>
	<xsl:choose>
	    <!-- Out of the recursive iteration -->
	    <xsl:when test="$i > $cols"></xsl:when>
	    <!-- There are still columns to count -->
	    <xsl:otherwise>
		<xsl:variable name="width">
			<xsl:variable name="userchoice" select="colspec[@colnum=$i]/@colwidth"/>
			<xsl:variable name="cells" select="thead/row/entry[$i]|tbody/row/entry[$i]"/>
			<xsl:choose>
				<xsl:when test="string-length($userchoice)=0 and count($cells//itemizedlist|$cells//orderedlist|$cells//variablelist)&gt;0">
					<!-- In these specific circumstances, we MUST use a line-wrapped column
					     and yet the user hasn't specified one. -->
					<xsl:value-of select="'1*'"/>
				</xsl:when>
				<xsl:otherwise>
					<!-- In the general case, we just do what the user wants (may even
					     have no pre-specified width). -->
					<xsl:value-of select="$userchoice"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<!-- Try to take heed of colspecs -->
		<xsl:choose>
			<xsl:when test="$width!=''">
				<xsl:text>&gt;{</xsl:text>
				<xsl:if test="contains($width,'*')">
					<!-- see tabularx documentation -->
					<xsl:text>\hsize=</xsl:text>
					<xsl:value-of select="substring-before($width,'*') * $starfactor" />
					<xsl:text>\hsize</xsl:text>
				</xsl:if>
				<xsl:choose>
					<xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>\RaggedRight</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>\RaggedLeft</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>\Centering</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='char'"><xsl:message>Table column char alignment is not supported.</xsl:message></xsl:when>
				</xsl:choose>
				<xsl:text>}</xsl:text>
				<xsl:choose>
					<xsl:when test="contains($width,'*')">
						<xsl:text>X</xsl:text>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>p{</xsl:text><xsl:value-of select="$width" /><xsl:text>}</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
				<xsl:if test="$i&lt;$cols and $colsep='1'">
					<xsl:text>|</xsl:text>
				</xsl:if>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>l</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>r</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>c</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='justify'"><xsl:text>X</xsl:text></xsl:when>
					<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>
					<xsl:otherwise><xsl:text>c</xsl:text></xsl:otherwise>
				</xsl:choose>
				<xsl:if test="$i&lt;$cols and $colsep='1'">
					<xsl:text>|</xsl:text>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
		<!-- Recursive for next column -->
		<xsl:call-template name="table.format.tabularx">
		    <xsl:with-param name="i" select="$i+1"/>
		    <xsl:with-param name="cols" select="$cols"/>
		    <xsl:with-param name="starfactor" select="$starfactor"/>
		</xsl:call-template>
	    </xsl:otherwise>
	</xsl:choose>
    </xsl:template>
	

    <!-- FIX THIS -->
    <xsl:template name="table.format.tabular">
	<xsl:param name="cols" select="1"/>
	<xsl:param name="i" select="1"/>
	<xsl:param name="colsep" select="1"/>
	<xsl:choose>
	    <!-- Out of the recursive iteration -->
	    <xsl:when test="$i > $cols"></xsl:when>
	    <!-- There are still columns to count -->
	    <xsl:otherwise>
		<!-- Try to take heed of colspecs -->
		<xsl:choose>
			<!-- RC 2003/03/19 : Added first 'test' : colspec[@colnum=$i] for xsltproc 
				Before this patch, parsing the doc with xsltproc the xsl:when clause 
				was evaluated to 'true' even if there was no colspec for the column
			-->
			<xsl:when test="colspec[@colnum=$i] and colspec[@colnum=$i]/@colwidth!='' and not(contains(colspec[@colnum=$i]/@colwidth,'*'))">
				<xsl:choose>
					<xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>&gt;{\RaggedRight}</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>&gt;{\RaggedLeft}</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>&gt;{\Centering}</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='char'"><xsl:message>Table column char alignment is not supported.</xsl:message></xsl:when>
				</xsl:choose>
				<xsl:text>p{</xsl:text><xsl:value-of select="colspec[@colnum=$i]/@colwidth" /><xsl:text>}</xsl:text>
				<xsl:if test="$i&lt;$cols and $colsep='1'">
					<xsl:text>|</xsl:text>
				</xsl:if>
			</xsl:when>
			<xsl:otherwise>
				<xsl:choose>
					<xsl:when test="colspec[@colnum=$i]/@align='left'"><xsl:text>l</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='right'"><xsl:text>r</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='center'"><xsl:text>c</xsl:text></xsl:when>
					<xsl:when test="colspec[@colnum=$i]/@align='justify'"><xsl:text>l</xsl:text></xsl:when>
					<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>
					<xsl:otherwise><xsl:text>c</xsl:text></xsl:otherwise>
				</xsl:choose>
				<xsl:if test="$i&lt;$cols and $colsep='1'">
					<xsl:text>|</xsl:text>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
		<!-- Recursive for next column -->
		<xsl:call-template name="table.format.tabular">
		    <xsl:with-param name="i" select="$i+1"/>
		    <xsl:with-param name="cols" select="$cols"/>
		</xsl:call-template>
	    </xsl:otherwise>
	</xsl:choose>
    </xsl:template>



	<!-- See tabularx documentation. -->
	<!-- For example, if we have a 1* column and a 3* column, then the
	     the hsizes for each column are (1/(1+3)*2) and (3/(1+3)*2).
		 The ratio of these to the star values (star values being 1 and 3)
		 is 2/(1+3).
		 BUT it is now very complicated because it takes into account columns
		 where the user has not specified a width but LaTeX requires a
		 fixed-width column (i.e. specialcols may vary).
		 Relies on there being (a) colspecs for every column or (b) no
		 colspecs.
	 -->
	<xsl:template name="generate.starfactor">
		<xsl:param name="i" select="1"/>
		<xsl:param name="cols" select="count(colspec)"/>
		<xsl:param name="sum" select="0"/>
		<xsl:param name="specialcols" select="count(colspec[contains(@colwidth,'*')])"/>
		<xsl:choose>
			<xsl:when test="$i&lt;=$cols and colspec[position()=$i and contains(@colwidth,'*')]">
				<!-- a * column -->
				<xsl:call-template name="generate.starfactor">
					<xsl:with-param name="i" select="$i+1"/>
					<xsl:with-param name="cols" select="$cols"/>
					<xsl:with-param name="sum" select="$sum+substring-before(colspec[$i]/@colwidth,'*')"/>
					<xsl:with-param name="specialcols" select="$specialcols"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="$i&lt;=$cols">
				<!-- not a * column, but we are going to pretend that it is -->
				<xsl:variable name="cells" select="thead/row/entry[$i]|tbody/row/entry[$i]"/>
				<xsl:variable name="problems" select="count($cells//itemizedlist|$cells//orderedlist|$cells//variablelist)"/>
				<xsl:choose>
					<xsl:when test="$problems &gt; 0">
						<xsl:call-template name="generate.starfactor">
							<xsl:with-param name="i" select="$i+1"/>
							<xsl:with-param name="cols" select="$cols"/>
							<xsl:with-param name="sum" select="$sum+1"/>
							<xsl:with-param name="specialcols" select="$specialcols+1"/>
						</xsl:call-template>
					</xsl:when>
					<xsl:otherwise>
						<xsl:call-template name="generate.starfactor">
							<xsl:with-param name="i" select="$i+1"/>
							<xsl:with-param name="cols" select="$cols"/>
							<xsl:with-param name="sum" select="$sum"/>
							<xsl:with-param name="specialcols" select="$specialcols"/>
						</xsl:call-template>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$specialcols div $sum"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	

    <xsl:template match="tgroup">
	<xsl:variable name="align" select="@align"/>
	<xsl:variable name="frame">
		<xsl:choose>
			<xsl:when test="string-length(../@frame)&lt;1">all</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="../@frame"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="colspecs" select="./colspec"/>
	<xsl:variable name="usex">
		<xsl:choose>
			<!-- if there are lists within cells, we need tabularx -->
			<xsl:when test="$latex.use.tabularx=1 and (descendant::itemizedlist|descendant::orderedlist|descendant::variablelist)">
				<xsl:text>1</xsl:text>
			</xsl:when>
			<!-- if there are instances of 1*-style colwidths, we need tabularx -->
			<xsl:when test="$latex.use.tabularx=1 and contains(colspec/@colwidth,'*')">
				<xsl:text>1</xsl:text>
			</xsl:when>
			<!-- if there are colspecs with 'justify' alignment and no explicit width, we need tabularx -->
			<xsl:when test="$latex.use.tabularx=1 and count(colspec[@align='justify'])&gt;0">
				<xsl:text>1</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>0</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="useminipage">
		<!-- Hack to get around LaTeX issue with tabular (not necessary with tabularx).
		This is NOT a good solution, and has problems of its own, but at least the footnotes
		do not actually disappear (which is what would otherwise happen). -->
		<xsl:if test="count(.//footnote)!=0">1</xsl:if>
	</xsl:variable>
	<xsl:choose>
		<xsl:when test="$usex='1'">
			<xsl:text>\begin{tabularx}{\linewidth}{</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:if test="$useminipage='1'"><xsl:text>\begin{minipage}{\linewidth}&#10;</xsl:text></xsl:if>
			<xsl:text>\begin{tabular}{</xsl:text>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:if test="$frame='all' or $frame='sides'">
	    <xsl:text>|</xsl:text>
	</xsl:if>
	<xsl:choose>
		<xsl:when test="$usex=1">
			<xsl:call-template name="table.format.tabularx">
				<xsl:with-param name="cols" select="@cols"/>
				<xsl:with-param name="starfactor">
					<xsl:call-template name="generate.starfactor">
						<xsl:with-param name="cols" select="@cols"/>
					</xsl:call-template>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="table.format.tabular">
				<xsl:with-param name="cols" select="@cols"/>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:if test="$frame='all' or $frame='sides'">
	    <xsl:text>|</xsl:text>
	</xsl:if>
	<xsl:text>}&#10;</xsl:text>
	<xsl:if test="$frame!='sides' and $frame!='none' and $frame!='bottom'">
	    <xsl:text>\hline &#10;</xsl:text>
	</xsl:if>
	<!-- APPLY TEMPLATES -->
	<xsl:apply-templates/>
	<!--                 -->
	<xsl:if test="$frame!='sides' and $frame!='none' and $frame!='top'">
	    <xsl:text>\hline &#10;</xsl:text>
	</xsl:if>
	<xsl:choose>
		<xsl:when test="$usex=1">
			<xsl:text>\end{tabularx}&#10;</xsl:text>
		</xsl:when>
		<xsl:otherwise>
			<xsl:text>\end{tabular}&#10;</xsl:text>
			<xsl:if test="$useminipage='1'"><xsl:text>\end{minipage}&#10;</xsl:text></xsl:if>
		</xsl:otherwise>
	</xsl:choose>
    </xsl:template>



    <!--
    <xsl:template name="generate.col">
	<xsl:param name="countcol">1</xsl:param>
    </xsl:template>
    -->

    <xsl:template match="colspec"></xsl:template>
    <xsl:template match="spanspec"></xsl:template>




    <xsl:template match="thead|tfoot">
	<xsl:if test="@align">
	    <xsl:attribute name="align">
		<xsl:value-of select="@align"/>
	    </xsl:attribute>
	</xsl:if>
	<xsl:if test="@char">
	    <xsl:attribute name="char">
		<xsl:value-of select="@char"/>
	    </xsl:attribute>
	</xsl:if>
	<xsl:if test="@charoff">
	    <xsl:attribute name="charoff">
		<xsl:value-of select="@charoff"/>
	    </xsl:attribute>
	</xsl:if>
	<xsl:if test="@valign">
	    <xsl:attribute name="valign">
		<xsl:value-of select="@valign"/>
	    </xsl:attribute>
	</xsl:if>
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="thead/row/entry|tfoot/row/entry">
	<xsl:call-template name="latex.entry.prealign"/>
	<xsl:call-template name="latex.thead.row.entry"/>
	<xsl:call-template name="latex.entry.postalign"/>
	<xsl:choose>
		<xsl:when test="position()=last()"><xsl:text> \tabularnewline&#10;</xsl:text></xsl:when>
		<xsl:otherwise><xsl:call-template name="generate.latex.cell.separator"/></xsl:otherwise>
	</xsl:choose> 
    </xsl:template>

    <xsl:template match="tbody">
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="row">
	<xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="tbody/row|thead/row|tfoot/row">
	<xsl:apply-templates/>
	<!-- The rule below the last row in the table is controlled by the 
	Frame attribute of the enclosing Table or InformalTable and the RowSep 
	of the last row is ignored. If unspecified, this attribute is 
	inherited from enclosing elements, rowsep=1 by default. -->
	<xsl:variable name="parent_position" select="count(../preceding-sibling::node())+1"/>
	<xsl:variable name="grandparent_children" select="count(../../child::node())"/>
	<xsl:if test="(count(@rowsep)=0 or @rowsep='1') and (position() != last() or $parent_position &lt; $grandparent_children)">
	    <xsl:text> \hline &#10;</xsl:text>
	</xsl:if>
    </xsl:template>


    <xsl:template match="tbody/row/entry">
	<xsl:call-template name="latex.entry.prealign"/>
	<xsl:apply-templates/>
	<xsl:call-template name="latex.entry.postalign"/>
	<xsl:choose>
		<xsl:when test="position()=last()"><xsl:text> \tabularnewline&#10;</xsl:text></xsl:when>
		<xsl:otherwise><xsl:call-template name="generate.latex.cell.separator"/></xsl:otherwise>
	</xsl:choose> 
    </xsl:template>


	<xsl:template name="latex.entry.prealign">
	<xsl:variable name="span">
		<xsl:choose>
			<xsl:when test="@spanname!=''">
				<xsl:call-template name="calculate.colspan">
					<xsl:with-param name="namest" select="../../../spanspec[@spanname=@spanname]/@namest"/>
					<xsl:with-param name="nameend" select="../../../spanspec[@spanname=@spanname]/@nameend"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:when test="@namest!=''">
				<xsl:call-template name="calculate.colspan"/>
			</xsl:when>
			<xsl:otherwise>-1</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:if test="$span &gt; 1">
		<xsl:text>\multicolumn{</xsl:text>
		<xsl:value-of select="$span"/>
		<xsl:text>|}{</xsl:text><!-- TODO take heed of @colsep -->
		<xsl:choose>
			<xsl:when test="@align='left'"><xsl:text>l</xsl:text></xsl:when>
			<xsl:when test="@align='right'"><xsl:text>r</xsl:text></xsl:when>
			<xsl:when test="@align='center'"><xsl:text>c</xsl:text></xsl:when>
			<xsl:when test="@align='char'">c<xsl:message>Table entry char alignment is not supported.</xsl:message></xsl:when>
			<xsl:otherwise>c</xsl:otherwise>
		</xsl:choose>
	<!-- use this as a hook for some general warnings -->
		<xsl:text>}</xsl:text>
	</xsl:if>
	<!-- this is used when the entry's align spec wants to override the column default -->
	<xsl:if test="$span &lt; 1">
		<xsl:choose>
			<xsl:when test="@align='left'"><xsl:text>\docbooktolatexalignll </xsl:text></xsl:when>
			<xsl:when test="@align='right'"><xsl:text>\docbooktolatexalignrl </xsl:text></xsl:when>
			<xsl:when test="@align='center'"><xsl:text>\docbooktolatexaligncl </xsl:text></xsl:when>
			<xsl:when test="@align='char'"><xsl:message>Table entry char alignment is not supported.</xsl:message></xsl:when>
		</xsl:choose>
	</xsl:if>
	<xsl:text>{</xsl:text>
	<xsl:if test="@rotate='1'">
		<xsl:text>\rotatebox{90}</xsl:text>
		<xsl:if test="@align!=''"><xsl:message>entry[@rotate='1' and @align!=''] probably doesn't work.</xsl:message></xsl:if>
	</xsl:if>
	<xsl:text>{</xsl:text>
	<!-- use this as a hook for some general warnings -->
	<xsl:if test="@morerows!=''"><xsl:message>The morerows attribute is not supported.</xsl:message></xsl:if>
	</xsl:template>

	<xsl:template name="latex.entry.postalign">
	<xsl:text>}}</xsl:text>
	<!-- this is used when the entry's align spec wants to override the column default -->
	<xsl:if test="@namest='' and @spanspec=''"><!-- TODO improve -->
		<xsl:choose>
			<xsl:when test="@align='left'"><xsl:text>\docbooktolatexalignlr </xsl:text></xsl:when>
			<xsl:when test="@align='right'"><xsl:text>\docbooktolatexalignrr </xsl:text></xsl:when>
			<xsl:when test="@align='center'"><xsl:text>\docbooktolatexaligncr </xsl:text></xsl:when>
		</xsl:choose>
	</xsl:if>
	</xsl:template>













    <xsl:template name="process.cell">
	<xsl:param name="cellgi">td</xsl:param>
	<xsl:variable name="empty.cell" select="count(node()) = 0"/>

	<xsl:element name="{$cellgi}">
	    <xsl:if test="@morerows">
		<xsl:attribute name="rowspan">
		    <xsl:value-of select="@morerows+1"/>
		</xsl:attribute>
	    </xsl:if>
	    <xsl:if test="@namest">
		<xsl:attribute name="colspan">
		    <xsl:call-template name="calculate.colspan"/>
		</xsl:attribute>
	    </xsl:if>
	    <xsl:if test="@align">
		<xsl:attribute name="align">
		    <xsl:value-of select="@align"/>
		</xsl:attribute>
	    </xsl:if>
	    <xsl:if test="@char">
		<xsl:attribute name="char">
		    <xsl:value-of select="@char"/>
		</xsl:attribute>
	    </xsl:if>
	    <xsl:if test="@charoff">
		<xsl:attribute name="charoff">
		    <xsl:value-of select="@charoff"/>
		</xsl:attribute>
	    </xsl:if>
	    <xsl:if test="@valign">
		<xsl:attribute name="valign">
		    <xsl:value-of select="@valign"/>
		</xsl:attribute>
	    </xsl:if>

	    <xsl:choose>
		<xsl:when test="$empty.cell">
		    <xsl:text>&#160;</xsl:text>
		</xsl:when>
		<xsl:otherwise>
		    <xsl:apply-templates/>
		</xsl:otherwise>
	    </xsl:choose>
	</xsl:element>
    </xsl:template>

    <xsl:template name="generate.colgroup">
	<xsl:param name="cols" select="1"/>
	<xsl:param name="count" select="1"/>
	<xsl:choose>
	    <xsl:when test="$count>$cols"></xsl:when>
	    <xsl:otherwise>
		<xsl:call-template name="generate.col">
		    <xsl:with-param name="countcol" select="$count"/>
		</xsl:call-template>
		<xsl:call-template name="generate.colgroup">
		    <xsl:with-param name="cols" select="$cols"/>
		    <xsl:with-param name="count" select="$count+1"/>
		</xsl:call-template>
	    </xsl:otherwise>
	</xsl:choose>
    </xsl:template>

    <xsl:template name="generate.col">
	<xsl:param name="countcol">1</xsl:param>
	<xsl:param name="colspecs" select="./colspec"/>
	<xsl:param name="count">1</xsl:param>
	<xsl:param name="colnum">1</xsl:param>

	<xsl:choose>
	    <xsl:when test="$count>count($colspecs)">
		<col/>
	    </xsl:when>
	    <xsl:otherwise>
		<xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
		<xsl:variable name="colspec.colnum">
		    <xsl:choose>
			<xsl:when test="$colspec/@colnum">
			    <xsl:value-of select="$colspec/@colnum"/>
			</xsl:when>
			<xsl:otherwise>
			    <xsl:value-of select="$colnum"/>
			</xsl:otherwise>
		    </xsl:choose>
		</xsl:variable>

		<xsl:choose>
		    <xsl:when test="$colspec.colnum=$countcol">
			<col>
			    <xsl:if test="$colspec/@align">
				<xsl:attribute name="align">
				    <xsl:value-of select="$colspec/@align"/>
				</xsl:attribute>
			    </xsl:if>
			    <xsl:if test="$colspec/@char">
				<xsl:attribute name="char">
				    <xsl:value-of select="$colspec/@char"/>
				</xsl:attribute>
			    </xsl:if>
			    <xsl:if test="$colspec/@charoff">
				<xsl:attribute name="charoff">
				    <xsl:value-of select="$colspec/@charoff"/>
				</xsl:attribute>
			    </xsl:if>
			</col>
		    </xsl:when>
		    <xsl:otherwise>
			<xsl:call-template name="generate.col">
			    <xsl:with-param name="countcol" select="$countcol"/>
			    <xsl:with-param name="colspecs" select="$colspecs"/>
			    <xsl:with-param name="count" select="$count+1"/>
			    <xsl:with-param name="colnum">
				<xsl:choose>
				    <xsl:when test="$colspec/@colnum">
					<xsl:value-of select="$colspec/@colnum + 1"/>
				    </xsl:when>
				    <xsl:otherwise>
					<xsl:value-of select="$colnum + 1"/>
				    </xsl:otherwise>
				</xsl:choose>
			    </xsl:with-param>
			</xsl:call-template>
		    </xsl:otherwise>
		</xsl:choose>
	    </xsl:otherwise>
	</xsl:choose>

    </xsl:template>

    <xsl:template name="colspec.colnum">
	<!-- when this macro is called, the current context must be an entry -->
	<xsl:param name="colname"></xsl:param>
	<!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
	<xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
	<xsl:param name="count">1</xsl:param>
	<xsl:param name="colnum">1</xsl:param>
	<xsl:choose>
	    <xsl:when test="$count>count($colspecs)"></xsl:when>
	    <xsl:otherwise>
		<xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
		<!--
		<xsl:value-of select="$count"/>:
		<xsl:value-of select="$colspec/@colname"/>=
		<xsl:value-of select="$colnum"/>
		-->
		<xsl:choose>
		    <xsl:when test="$colspec/@colname=$colname">
			<xsl:choose>
			    <xsl:when test="$colspec/@colnum">
				<xsl:value-of select="$colspec/@colnum"/>
			    </xsl:when>
			    <xsl:otherwise>
				<xsl:value-of select="$colnum"/>
			    </xsl:otherwise>
			</xsl:choose>
		    </xsl:when>
		    <xsl:otherwise>
			<xsl:call-template name="colspec.colnum">
			    <xsl:with-param name="colname" select="$colname"/>
			    <xsl:with-param name="colspecs" select="$colspecs"/>
			    <xsl:with-param name="count" select="$count+1"/>
			    <xsl:with-param name="colnum">
				<xsl:choose>
				    <xsl:when test="$colspec/@colnum">
					<xsl:value-of select="$colspec/@colnum + 1"/>
				    </xsl:when>
				    <xsl:otherwise>
					<xsl:value-of select="$colnum + 1"/>
				    </xsl:otherwise>
				</xsl:choose>
			    </xsl:with-param>
			</xsl:call-template>
		    </xsl:otherwise>
		</xsl:choose>
	    </xsl:otherwise>
	</xsl:choose>
    </xsl:template>

    <xsl:template name="colspec.colwidth">
	<!-- when this macro is called, the current context must be an entry -->
	<xsl:param name="colname"></xsl:param>
	<!-- .. = row, ../.. = thead|tbody, ../../.. = tgroup -->
	<xsl:param name="colspecs" select="../../../../tgroup/colspec"/>
	<xsl:param name="count">1</xsl:param>
	<xsl:choose>
	    <xsl:when test="$count>count($colspecs)"></xsl:when>
	    <xsl:otherwise>
		<xsl:variable name="colspec" select="$colspecs[$count=position()]"/>
		<xsl:choose>
		    <xsl:when test="$colspec/@colname=$colname">
			<xsl:value-of select="$colspec/@colwidth"/>
		    </xsl:when>
		    <xsl:otherwise>
			<xsl:call-template name="colspec.colwidth">
			    <xsl:with-param name="colname" select="$colname"/>
			    <xsl:with-param name="colspecs" select="$colspecs"/>
			    <xsl:with-param name="count" select="$count+1"/>
			</xsl:call-template>
		    </xsl:otherwise>
		</xsl:choose>
	    </xsl:otherwise>
	</xsl:choose>
    </xsl:template>

    <xsl:template name="calculate.colspan">
	<xsl:param name="namest" select="@namest"/>
	<xsl:param name="nameend" select="@nameend"/>
	<xsl:variable name="scol">
	    <xsl:call-template name="colspec.colnum">
		<xsl:with-param name="colname" select="$namest"/>
	    </xsl:call-template>
	</xsl:variable>
	<xsl:variable name="ecol">
	    <xsl:call-template name="colspec.colnum">
		<xsl:with-param name="colname" select="$nameend"/>
	    </xsl:call-template>
	</xsl:variable>
	<xsl:value-of select="$ecol - $scol + 1"/>
    </xsl:template>

</xsl:stylesheet>