Debian Codegraph @

xsl/htmltbl.xsl

raw
1 <?xml version='1.0' encoding="utf-8" ?>
2
3 <xsl:stylesheet
4 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
5 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
6 xmlns:exsl="http://exslt.org/common"
7 exclude-result-prefixes="doc exsl" version='1.0'>
8
9 <xsl:param name="default.table.rules">none</xsl:param>
10
11
12
13 <xsl:template match="table|informaltable" mode="htmlTable">
14 <xsl:param name="tabletype">tabular</xsl:param>
15 <xsl:param name="tablewidth">\linewidth-2\tabcolsep</xsl:param>
16 <xsl:param name="tableframe">all</xsl:param>
17
18 <xsl:variable name="numcols">
19 <xsl:call-template name="widest-html-row">
20 <xsl:with-param name="rows" select=".//tr"/>
21 </xsl:call-template>
22 </xsl:variable>
23
24 <!-- Get the specified table width -->
25 <xsl:variable name="table.width">
26 <xsl:call-template name="table.width">
27 <xsl:with-param name="fullwidth" select="$tablewidth"/>
28 </xsl:call-template>
29 </xsl:variable>
30
31 <!-- Find the table width -->
32 <xsl:variable name="width">
33 <xsl:choose>
34 <xsl:when test="not(contains($table.width,'auto'))">
35 <xsl:value-of select="$table.width"/>
36 </xsl:when>
37 <xsl:otherwise>
38 <xsl:call-template name="table.width">
39 <xsl:with-param name="fullwidth" select="$tablewidth"/>
40 <xsl:with-param name="exclude" select="'auto'"/>
41 </xsl:call-template>
42 </xsl:otherwise>
43 </xsl:choose>
44 </xsl:variable>
45
46 <!-- Now the frame style -->
47 <xsl:variable name="frame">
48 <xsl:choose>
49 <xsl:when test="@frame">
50 <xsl:call-template name="cals.frame">
51 <xsl:with-param name="frame" select="@frame"/>
52 </xsl:call-template>
53 </xsl:when>
54 <xsl:otherwise><xsl:value-of select="$tableframe"/></xsl:otherwise>
55 </xsl:choose>
56 </xsl:variable>
57
58 <xsl:variable name="colspec">
59 <xsl:choose>
60 <xsl:when test="colgroup or col">
61 <xsl:apply-templates select="(colgroup|col)[1]"
62 mode="make.colspec">
63 <xsl:with-param name="colnum" select="1"/>
64 <xsl:with-param name="colmax" select="$numcols"/>
65 </xsl:apply-templates>
66 </xsl:when>
67 <xsl:otherwise>
68 <xsl:call-template name="make.colspec.default">
69 <xsl:with-param name="colnum" select="1"/>
70 <xsl:with-param name="colmax" select="$numcols"/>
71 </xsl:call-template>
72 </xsl:otherwise>
73 </xsl:choose>
74 </xsl:variable>
75
76 <!-- Build the <row>s from the <tr>s -->
77 <xsl:variable name="rows-head" select="tr[child::th]"/>
78 <xsl:variable name="rows-body" select="tr[not(child::th)]"/>
79
80 <xsl:variable name="rows">
81 <!-- First the header -->
82 <xsl:choose>
83 <xsl:when test="thead">
84 <xsl:apply-templates select="thead" mode="htmlTable">
85 <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
86 </xsl:apply-templates>
87 </xsl:when>
88 <xsl:otherwise>
89 <xsl:apply-templates select="$rows-head[1]" mode="htmlTable">
90 <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
91 <xsl:with-param name="rownum" select="1"/>
92 <xsl:with-param name="context" select="'thead'"/>
93 </xsl:apply-templates>
94 </xsl:otherwise>
95 </xsl:choose>
96
97 <!-- Then the body -->
98 <xsl:choose>
99 <xsl:when test="tbody">
100 <xsl:apply-templates select="tbody" mode="htmlTable">
101 <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
102 </xsl:apply-templates>
103 </xsl:when>
104 <xsl:otherwise>
105 <xsl:apply-templates select="$rows-body[1]" mode="htmlTable">
106 <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
107 <xsl:with-param name="rownum" select="count($rows-head) +
108 count(thead/*) + 1"/>
109 </xsl:apply-templates>
110 </xsl:otherwise>
111 </xsl:choose>
112 <xsl:apply-templates select="tfoot/tr[1]" mode="htmlTable">
113 <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
114 <xsl:with-param name="rownum" select="count(.//tr[not(parent::tfoot)])+1"/>
115 </xsl:apply-templates>
116 </xsl:variable>
117
118 <!-- Complete the colspecs @width from the fully expended <row>s -->
119 <xsl:variable name="colspec2">
120 <xsl:call-template name="build.colwidth">
121 <xsl:with-param name="colspec" select="exsl:node-set($colspec)"/>
122 <xsl:with-param name="rows" select="exsl:node-set($rows)"/>
123 </xsl:call-template>
124 </xsl:variable>
125
126 <!-- TIP: to check the built RTF elements, uncomment and call testtbl.xsl
127 <xsl:copy-of select="exsl:node-set($colspec2)"/>
128 <xsl:copy-of select="exsl:node-set($rows)"/>
129 -->
130
131 <xsl:variable name="t.rows" select="exsl:node-set($rows)"/>
132
133 <xsl:text>\begingroup%&#10;</xsl:text>
134
135 <!-- Set cellpadding, but only on columns -->
136 <xsl:if test="@cellpadding">
137 <xsl:text>\setlength{\tabcolsep}{</xsl:text>
138 <xsl:choose>
139 <xsl:when test="contains(@cellpadding, '%')">
140 <xsl:value-of
141 select="number(substring-before(@cellpadding,'%')) div 100"/>
142 <xsl:text>\linewidth</xsl:text>
143 </xsl:when>
144 <xsl:otherwise>
145 <xsl:value-of select="@cellpadding"/>
146 </xsl:otherwise>
147 </xsl:choose>
148 <xsl:text>}%&#10;</xsl:text>
149 </xsl:if>
150
151 <xsl:text>\setlength{\tablewidth}{</xsl:text>
152 <xsl:value-of select="$width"/>
153 <xsl:text>}%&#10;</xsl:text>
154
155 <xsl:if test="$tabletype != 'tabularx'">
156 <xsl:call-template name="tbl.sizes">
157 <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
158 <xsl:with-param name="width" select="$width"/>
159 </xsl:call-template>
160 </xsl:if>
161
162 <xsl:if test="$tabletype = 'tabularx'">
163 <xsl:call-template name="tbl.valign.x">
164 <xsl:with-param name="valign" select="@valign"/>
165 </xsl:call-template>
166 </xsl:if>
167
168 <!-- Translate the table to latex -->
169
170 <!-- Start the table declaration -->
171 <xsl:call-template name="tbl.begin">
172 <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
173 <xsl:with-param name="tabletype" select="$tabletype"/>
174 <xsl:with-param name="width" select="$width"/>
175 </xsl:call-template>
176
177 <!-- Need a top line? -->
178 <xsl:if test="$frame = 'all' or $frame = 'top' or $frame = 'topbot'">
179 <xsl:text>\hline</xsl:text>
180 </xsl:if>
181 <xsl:text>&#10;</xsl:text>
182
183 <!-- First, the head rows -->
184 <xsl:variable name="headrows">
185 <xsl:apply-templates select="$t.rows/*[@type='thead']"
186 mode="htmlTable">
187 <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
188 <xsl:with-param name="context" select="'thead'"/>
189 <xsl:with-param name="frame" select="$frame"/>
190 </xsl:apply-templates>
191 </xsl:variable>
192
193 <xsl:apply-templates select="." mode="newtbl.endhead">
194 <xsl:with-param name="tabletype" select="$tabletype"/>
195 <xsl:with-param name="headrows" select="$headrows"/>
196 </xsl:apply-templates>
197
198 <!-- Then, the body rows -->
199 <xsl:apply-templates select="$t.rows/*[@type!='thead']"
200 mode="htmlTable">
201 <xsl:with-param name="colspec" select="exsl:node-set($colspec2)"/>
202 <xsl:with-param name="context" select="'tbody'"/>
203 <xsl:with-param name="frame" select="$frame"/>
204 </xsl:apply-templates>
205
206 <!-- Need a bottom line? -->
207 <xsl:if test="$frame = 'all' or $frame = 'bottom' or $frame = 'topbot'">
208 <xsl:text>\hline</xsl:text>
209 </xsl:if>
210 <xsl:text>&#10;</xsl:text>
211
212 <xsl:text>\end{</xsl:text>
213 <xsl:value-of select="$tabletype"/>
214 <xsl:text>}\endgroup%&#10;</xsl:text>
215
216 </xsl:template>
217
218
219 <!-- Build the latex row from the <row> element -->
220 <xsl:template match="row" mode="htmlTable">
221 <xsl:param name="colspec"/>
222 <xsl:param name="context"/>
223 <xsl:param name="frame"/>
224
225 <xsl:apply-templates mode="newtbl">
226 <xsl:with-param name="colspec" select="$colspec"/>
227 <xsl:with-param name="context" select="$context"/>
228 <xsl:with-param name="frame" select="$frame"/>
229 <xsl:with-param name="rownum" select="@rownum"/>
230 </xsl:apply-templates>
231
232 <!-- End this row -->
233 <xsl:text>\tabularnewline&#10;</xsl:text>
234
235 <!-- Now process rowseps only if not the last row -->
236 <xsl:if test="@rowsep=1">
237 <xsl:choose>
238 <xsl:when test="$newtbl.use.hhline='1'">
239 <xsl:call-template name="hhline.build">
240 <xsl:with-param name="entries" select="."/>
241 <xsl:with-param name="rownum" select="@rownum"/>
242 </xsl:call-template>
243 </xsl:when>
244 <xsl:otherwise>
245 <xsl:call-template name="clines.build">
246 <xsl:with-param name="entries" select="."/>
247 <xsl:with-param name="rownum" select="@rownum"/>
248 </xsl:call-template>
249 </xsl:otherwise>
250 </xsl:choose>
251 </xsl:if>
252 </xsl:template>
253
254
255 <xsl:template match="thead" mode="htmlTable">
256 <xsl:param name="colspec"/>
257 <xsl:apply-templates select="tr[1]" mode="htmlTable">
258 <xsl:with-param name="colspec" select="$colspec"/>
259 <xsl:with-param name="rownum" select="1"/>
260 </xsl:apply-templates>
261 </xsl:template>
262
263
264 <xsl:template match="tbody" mode="htmlTable">
265 <xsl:param name="colspec"/>
266 <xsl:apply-templates select="tr[1]" mode="htmlTable">
267 <xsl:with-param name="colspec" select="$colspec"/>
268 <xsl:with-param name="rownum"
269 select="count(preceding-sibling::*[self::tbody or
270 self::thead]/*)+1"/>
271 </xsl:apply-templates>
272 </xsl:template>
273
274
275 <!-- Build an intermediate <row> element from a <tr> only if the row
276 has the required 'context'
277 -->
278 <xsl:template match="tr" mode="htmlTable">
279 <xsl:param name="rownum"/>
280 <xsl:param name="colspec"/>
281 <xsl:param name="oldentries"><nop/></xsl:param>
282 <xsl:param name="context"/>
283
284 <xsl:variable name="type">
285 <xsl:choose>
286 <xsl:when test="parent::thead">thead</xsl:when>
287 <xsl:when test="parent::tbody">tbody</xsl:when>
288 <xsl:when test="parent::tfoot">tfoot</xsl:when>
289 <!-- 'tr' contain 'th' and is not in a t* group -->
290 <xsl:when test="th">thead</xsl:when>
291 <xsl:otherwise>tbody</xsl:otherwise>
292 </xsl:choose>
293 </xsl:variable>
294
295 <xsl:if test="$context='' or $type=$context">
296 <xsl:variable name="entries">
297 <xsl:apply-templates select="(td|th)[1]" mode="htmlTable">
298 <xsl:with-param name="colspec" select="$colspec"/>
299 <xsl:with-param name="rownum" select="$rownum"/>
300 <xsl:with-param name="colnum" select="1"/>
301 <xsl:with-param name="entries" select="exsl:node-set($oldentries)"/>
302 </xsl:apply-templates>
303 </xsl:variable>
304
305 <row type='{$type}' rownum='{$rownum}'>
306 <xsl:call-template name="html.table.row.rules"/>
307 <xsl:copy-of select="$entries"/>
308 </row>
309
310 <xsl:apply-templates select="following-sibling::tr[1]" mode="htmlTable">
311 <xsl:with-param name="colspec" select="$colspec"/>
312 <xsl:with-param name="rownum" select="$rownum + 1"/>
313 <xsl:with-param name="oldentries" select="$entries"/>
314 <xsl:with-param name="context" select="$context"/>
315 </xsl:apply-templates>
316 </xsl:if>
317
318 </xsl:template>
319
320 <!-- ==================================================================== -->
321
322 <!-- This template writes rowsep equivalant for html tables -->
323 <xsl:template name="html.table.row.rules">
324 <xsl:variable name="border"
325 select="(ancestor::table |
326 ancestor::informaltable)[last()]/@border"/>
327 <xsl:variable name="table.rules"
328 select="(ancestor::table |
329 ancestor::informaltable)[last()]/@rules"/>
330
331 <xsl:variable name="rules">
332 <xsl:choose>
333 <xsl:when test="$table.rules != ''">
334 <xsl:value-of select="$table.rules"/>
335 </xsl:when>
336 <xsl:when test="$border != '' and number($border) != 0">
337 <xsl:value-of select="'all'"/>
338 </xsl:when>
339 <xsl:when test="$border != '' and number($border) = 0">
340 <xsl:value-of select="'none'"/>
341 </xsl:when>
342 <xsl:when test="$default.table.rules != ''">
343 <xsl:value-of select="$default.table.rules"/>
344 </xsl:when>
345 </xsl:choose>
346 </xsl:variable>
347
348 <xsl:choose>
349
350 <xsl:when test="$rules = 'none'">
351 <xsl:attribute name="rowsep">0</xsl:attribute>
352 </xsl:when>
353
354 <xsl:when test="$rules = 'cols'">
355 <xsl:attribute name="rowsep">0</xsl:attribute>
356 </xsl:when>
357
358 <!-- If not the last row, add border below -->
359 <xsl:when test="$rules = 'rows' or $rules = 'all'">
360 <xsl:variable name="rowborder">
361 <xsl:choose>
362 <!-- If in thead and tbody has rows, add border -->
363 <xsl:when test="parent::thead/
364 following-sibling::tbody/tr">1</xsl:when>
365 <!-- If in tbody and tfoot has rows, add border -->
366 <xsl:when test="parent::tbody/
367 following-sibling::tfoot/tr">1</xsl:when>
368 <!-- If in thead and table has body rows, add border -->
369 <xsl:when test="parent::thead/
370 following-sibling::tr">1</xsl:when>
371 <xsl:when test="parent::tbody/
372 preceding-sibling::tfoot/tr">1</xsl:when>
373 <xsl:when test="preceding-sibling::tfoot/tr">1</xsl:when>
374 <!-- If following rows, but not rowspan reaches last row -->
375 <xsl:when test="following-sibling::tr and
376 not(@rowspan = count(following-sibling::tr) + 1)">1</xsl:when>
377 <xsl:otherwise>0</xsl:otherwise>
378 </xsl:choose>
379 </xsl:variable>
380
381 <xsl:if test="$rowborder = 1">
382 <xsl:attribute name="rowsep">1</xsl:attribute>
383 </xsl:if>
384 </xsl:when>
385
386 <!-- rules only between 'thead' and 'tbody', or 'tbody' and 'tfoot' -->
387 <xsl:when test="$rules = 'groups' and parent::thead
388 and not(following-sibling::tr)">
389 <xsl:attribute name="rowsep">1</xsl:attribute>
390 </xsl:when>
391 <xsl:when test="$rules = 'groups' and parent::tfoot
392 and not(preceding-sibling::tr)">
393 <xsl:attribute name="rowsep">1</xsl:attribute>
394 </xsl:when>
395 </xsl:choose>
396 </xsl:template>
397
398 <xsl:template name="html.table.column.rules">
399 <xsl:param name="colnum"/>
400 <xsl:param name="colmax"/>
401
402 <xsl:variable name="border"
403 select="(ancestor-or-self::table |
404 ancestor-or-self::informaltable)[last()]/@border"/>
405 <xsl:variable name="table.rules"
406 select="(ancestor-or-self::table |
407 ancestor-or-self::informaltable)[last()]/@rules"/>
408
409 <xsl:variable name="rules">
410 <xsl:choose>
411 <xsl:when test="$table.rules != ''">
412 <xsl:value-of select="$table.rules"/>
413 </xsl:when>
414 <xsl:when test="$border != '' and number($border) != 0">
415 <xsl:value-of select="'all'"/>
416 </xsl:when>
417 <xsl:when test="$border != '' and number($border) = 0">
418 <xsl:value-of select="'none'"/>
419 </xsl:when>
420 <xsl:when test="$default.table.rules != ''">
421 <xsl:value-of select="$default.table.rules"/>
422 </xsl:when>
423 </xsl:choose>
424 </xsl:variable>
425
426 <xsl:choose>
427 <xsl:when test="$rules = 'none'">
428 <xsl:attribute name="colsep">0</xsl:attribute>
429 </xsl:when>
430 <xsl:when test="$rules = 'rows'">
431 <xsl:attribute name="colsep">0</xsl:attribute>
432 </xsl:when>
433 <xsl:when test="$rules = 'groups'">
434 <xsl:attribute name="colsep">0</xsl:attribute>
435 </xsl:when>
436 <!-- If not the last column, add border after -->
437 <xsl:when test="($rules = 'cols' or $rules = 'all') and
438 ($colnum &lt; $colmax)">
439 <xsl:attribute name="colsep">1</xsl:attribute>
440 </xsl:when>
441 </xsl:choose>
442 </xsl:template>
443
444 <!-- ==================================================================== -->
445
446 <xsl:template match="td|th" mode="htmlTable">
447 <xsl:param name="rownum"/>
448 <xsl:param name="colnum"/>
449 <xsl:param name="colspec"/>
450 <xsl:param name="entries"/>
451
452 <xsl:variable name="cols" select="count($colspec/*)"/>
453
454 <xsl:if test="$colnum &lt;= $cols">
455
456 <xsl:variable name="entry"
457 select="$entries/*[self::entry or self::entrytbl]
458 [@colstart=$colnum and
459 @rowend &gt;= $rownum]"/>
460
461 <!-- Do we have an existing entry element from a previous row that -->
462 <!-- should be copied into this row? -->
463 <xsl:choose><xsl:when test="$entry">
464 <!-- Just copy this entry then -->
465 <xsl:copy-of select="$entry"/>
466
467 <!-- Process the next column using this current entry -->
468 <xsl:apply-templates mode="htmlTable" select=".">
469 <xsl:with-param name="colnum"
470 select="$entries/entry[@colstart=$colnum]/@colend + 1"/>
471 <xsl:with-param name="rownum" select="$rownum"/>
472 <xsl:with-param name="colspec" select="$colspec"/>
473 <xsl:with-param name="entries" select="$entries"/>
474 </xsl:apply-templates>
475 </xsl:when><xsl:otherwise>
476
477 <xsl:variable name="colstart" select="$colnum"/>
478
479 <xsl:variable name="colend">
480 <xsl:choose>
481 <xsl:when test="@colspan">
482 <xsl:value-of select="@colspan + $colnum -1"/>
483 </xsl:when>
484 <xsl:otherwise>
485 <xsl:value-of select="$colnum"/>
486 </xsl:otherwise>
487 </xsl:choose>
488 </xsl:variable>
489
490 <xsl:variable name="rowend">
491 <xsl:choose>
492 <xsl:when test="@rowspan">
493 <xsl:value-of select="@rowspan + $rownum -1"/>
494 </xsl:when>
495 <xsl:otherwise>
496 <xsl:value-of select="$rownum"/>
497 </xsl:otherwise>
498 </xsl:choose>
499 </xsl:variable>
500
501 <xsl:variable name="rowcolor" select="parent::tr/@bgcolor"/>
502
503 <xsl:variable name="col" select="$colspec/colspec[@colnum=$colstart]"/>
504
505 <xsl:variable name="bgcolor">
506 <xsl:choose>
507 <xsl:when test="$rowcolor != ''">
508 <xsl:value-of select="$rowcolor"/>
509 </xsl:when>
510 <xsl:when test="$col/@bgcolor">
511 <xsl:value-of select="$col/@bgcolor"/>
512 </xsl:when>
513 <xsl:when test="ancestor::*[@bgcolor]">
514 <xsl:value-of select="ancestor::*[@bgcolor][last()]/@bgcolor"/>
515 </xsl:when>
516 </xsl:choose>
517 </xsl:variable>
518
519 <xsl:variable name="valign">
520 <xsl:choose>
521 <xsl:when test="../@valign">
522 <xsl:value-of select="../@valign"/>
523 </xsl:when>
524 <xsl:when test="$col/@valign">
525 <xsl:value-of select="$col/@valign"/>
526 </xsl:when>
527 <xsl:when test="ancestor::*[@valign]">
528 <xsl:value-of select="ancestor::*[@valign][last()]/@valign"/>
529 </xsl:when>
530 </xsl:choose>
531 </xsl:variable>
532
533 <xsl:variable name="align">
534 <xsl:choose>
535 <xsl:when test="../@align">
536 <xsl:value-of select="../@align"/>
537 </xsl:when>
538 <xsl:when test="$col/@align">
539 <xsl:value-of select="$col/@align"/>
540 </xsl:when>
541 <xsl:when test="ancestor::*[@align]">
542 <xsl:value-of select="ancestor::*[@align][last()]/@align"/>
543 </xsl:when>
544 </xsl:choose>
545 </xsl:variable>
546
547 <entry>
548 <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
549 <xsl:attribute name="colstart">
550 <xsl:value-of select="$colstart"/>
551 </xsl:attribute>
552 <xsl:attribute name="colend">
553 <xsl:value-of select="$colend"/>
554 </xsl:attribute>
555 <xsl:attribute name="rowstart">
556 <xsl:value-of select="$rownum"/>
557 </xsl:attribute>
558 <xsl:attribute name="rowend">
559 <xsl:value-of select="$rowend"/>
560 </xsl:attribute>
561 <xsl:if test="$rowend &gt; $rownum">
562 <xsl:attribute name="morerows">
563 <xsl:value-of select="$rowend - $rownum"/>
564 </xsl:attribute>
565 </xsl:if>
566 <xsl:if test="$col/@colsep = 1">
567 <xsl:attribute name="colsep">
568 <xsl:value-of select="1"/>
569 </xsl:attribute>
570 </xsl:if>
571 <xsl:if test="not(@bgcolor) and $bgcolor != ''">
572 <xsl:attribute name="bgcolor">
573 <xsl:value-of select="$bgcolor"/>
574 </xsl:attribute>
575 </xsl:if>
576 <xsl:if test="not(@valign) and $valign != ''">
577 <xsl:attribute name="valign">
578 <xsl:value-of select="$valign"/>
579 </xsl:attribute>
580 </xsl:if>
581 <xsl:if test="not(@align) and $align != ''">
582 <xsl:attribute name="align">
583 <xsl:value-of select="$align"/>
584 </xsl:attribute>
585 </xsl:if>
586 <xsl:element name="output">
587 <xsl:apply-templates select="." mode="output"/>
588 </xsl:element>
589 </entry>
590
591 <xsl:choose>
592 <xsl:when test="following-sibling::*[self::td or self::th]">
593
594 <xsl:apply-templates
595 select="following-sibling::*[self::td or self::th][1]"
596 mode="htmlTable">
597 <xsl:with-param name="colspec" select="$colspec"/>
598 <xsl:with-param name="rownum" select="$rownum"/>
599 <xsl:with-param name="colnum" select="$colend + 1"/>
600 <xsl:with-param name="entries" select="$entries"/>
601 </xsl:apply-templates>
602
603 </xsl:when>
604 <xsl:when test="$colend &lt; $cols">
605 <!-- Create more blank entries to pad the row -->
606 <xsl:call-template name="tbl.blankentry">
607 <xsl:with-param name="colnum" select="$colend + 1"/>
608 <xsl:with-param name="colend" select="$cols"/>
609 <xsl:with-param name="colspec" select="$colspec"/>
610 <xsl:with-param name="rownum" select="$rownum"/>
611 <xsl:with-param name="entries" select="$entries"/>
612 <xsl:with-param name="rowcolor" select="$rowcolor"/>
613 </xsl:call-template>
614
615 </xsl:when>
616 </xsl:choose>
617 </xsl:otherwise></xsl:choose>
618 </xsl:if>
619 </xsl:template>
620
621 <!-- Process the entry content, and remove spurious empty lines -->
622 <xsl:template match="td|th" mode="output">
623 <xsl:call-template name="normalize-border">
624 <xsl:with-param name="string">
625 <xsl:apply-templates/>
626 </xsl:with-param>
627 </xsl:call-template>
628 </xsl:template>
629
630
631 <!-- ==================================================================== -->
632
633 <xsl:template match="tr" mode="span">
634 <xsl:param name="currow"/>
635 <xsl:variable name="tr.pos" select="position()"/>
636 <xsl:variable name="spantds" select="td[@rowspan][$tr.pos + @rowspan &gt;
637 $currow]"/>
638 <xsl:if test="$spantds">
639 <span rownum="{$currow}" p="{$tr.pos}">
640 <xsl:attribute name="value">
641 <xsl:value-of
642 select="sum($spantds/@colspan)+count($spantds[not(@colspan)])"/>
643 </xsl:attribute>
644 </span>
645 </xsl:if>
646 </xsl:template>
647
648
649 <xsl:template name="widest-html-row">
650 <xsl:param name="rows" select="''"/>
651 <xsl:param name="count" select="0"/>
652 <xsl:param name="currow" select="1"/>
653 <xsl:variable name="row" select="$rows[position()=$currow]"/>
654 <xsl:choose>
655 <xsl:when test="not($row)">
656 <xsl:value-of select="$count"/>
657 </xsl:when>
658 <xsl:otherwise>
659 <xsl:variable name="count1" select="count($row/*[not(@colspan)])"/>
660 <xsl:variable name="count2" select="sum($row/*/@colspan)"/>
661 <xsl:variable name="countn" select="$count1 + $count2"/>
662
663 <!-- retrieve the previous <td>s that contain a @rowspan
664 that span over the current row -->
665 <xsl:variable name="spantds">
666 <xsl:apply-templates
667 select="$rows[position() &lt; $currow]"
668 mode="span">
669 <xsl:with-param name="currow" select="$currow"/>
670 </xsl:apply-templates>
671 </xsl:variable>
672
673 <!-- get the additional columns implied by the upward spanning <td> -->
674 <xsl:variable name="addcols"
675 select="sum(exsl:node-set($spantds)/*/@value)"/>
676
677 <!-- TIP: uncomment to debug the column count algorithm
678 <foo> <xsl:copy-of select="$spantds"/> </foo>
679
680 <xsl:message>
681 <xsl:text>p=</xsl:text><xsl:value-of select="$currow"/>
682 <xsl:text> c=</xsl:text><xsl:value-of select="$count"/>
683 <xsl:text> s=</xsl:text><xsl:value-of select="$addcols"/>
684 </xsl:message>
685 -->
686
687 <xsl:choose>
688 <xsl:when test="$count &gt; ($countn + $addcols)">
689 <xsl:call-template name="widest-html-row">
690 <xsl:with-param name="rows" select="$rows"/>
691 <xsl:with-param name="count" select="$count"/>
692 <xsl:with-param name="currow" select="$currow + 1"/>
693 </xsl:call-template>
694 </xsl:when>
695 <xsl:otherwise>
696 <xsl:call-template name="widest-html-row">
697 <xsl:with-param name="rows" select="$rows"/>
698 <xsl:with-param name="count" select="$countn + $addcols"/>
699 <xsl:with-param name="currow" select="$currow + 1"/>
700 </xsl:call-template>
701 </xsl:otherwise>
702 </xsl:choose>
703 </xsl:otherwise>
704 </xsl:choose>
705 </xsl:template>
706
707 <!-- ==================================================================== -->
708
709 <xsl:template name="build.colwidth">
710 <xsl:param name="colspec"/>
711 <xsl:param name="rows"/>
712
713 <xsl:for-each select="$colspec/*">
714 <xsl:variable name="pos" select="position()"/>
715 <xsl:variable name="colentries"
716 select="$rows/row/entry[@colstart &lt;= $pos and
717 @colend &gt;= $pos][@width]"/>
718
719 <xsl:variable name="pct">
720 <xsl:call-template name="max.percent">
721 <xsl:with-param name="entries" select="$colentries"/>
722 <xsl:with-param name="maxpct">
723 <xsl:choose>
724 <xsl:when test="substring(@width,string-length(@width))='%'">
725 <xsl:value-of select="number(substring-before(@width, '%'))"/>
726 </xsl:when>
727 <xsl:otherwise>
728 <xsl:value-of select="0"/>
729 </xsl:otherwise>
730 </xsl:choose>
731 </xsl:with-param>
732 </xsl:call-template>
733 </xsl:variable>
734 <xsl:variable name="fixed">
735 <xsl:call-template name="max.value">
736 <xsl:with-param name="entries" select="$colentries"/>
737 <xsl:with-param name="maxval">
738 <xsl:choose>
739 <xsl:when test="string(number(@width))!='NaN'">
740 <xsl:value-of select="number(@width)"/>
741 </xsl:when>
742 <xsl:otherwise>
743 <xsl:value-of select="0"/>
744 </xsl:otherwise>
745 </xsl:choose>
746 </xsl:with-param>
747 </xsl:call-template>
748 </xsl:variable>
749 <xsl:variable name="star">
750 <xsl:choose>
751 <xsl:when test="substring(@width,string-length(@width))='*'">
752 <xsl:value-of select="number(substring-before(@width, '*'))"/>
753 </xsl:when>
754 <xsl:otherwise>
755 <!-- '0*' is allowed and meaningfull, so use a negative number to
756 signify a missing star -->
757 <xsl:value-of select="-1"/>
758 </xsl:otherwise>
759 </xsl:choose>
760 </xsl:variable>
761
762 <!--
763 <xsl:message>
764 <xsl:value-of select="$pos"/>
765 <xsl:text>, </xsl:text>
766 <xsl:value-of select="count($colentries)"/>
767 <xsl:text> pct=</xsl:text><xsl:value-of select="$pct"/>
768 <xsl:text> val=</xsl:text><xsl:value-of select="$fixed"/>
769 <xsl:text> star=</xsl:text><xsl:value-of select="$star"/>
770 </xsl:message>
771 -->
772
773 <xsl:copy>
774 <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
775
776 <!-- Now, make precedences between the found width types -->
777 <xsl:choose>
778 <!-- the special form "0*" means to use the column's content width -->
779 <xsl:when test="$star = 0">
780 <xsl:attribute name="autowidth">1</xsl:attribute>
781 <!-- set a star to reserve some default space for the column -->
782 <xsl:attribute name="colwidth">
783 <xsl:text>\newtblstarfactor</xsl:text>
784 </xsl:attribute>
785 <xsl:attribute name="star">
786 <xsl:value-of select="1"/>
787 </xsl:attribute>
788 </xsl:when>
789 <xsl:when test="$star &gt; 0">
790 <xsl:attribute name="colwidth">
791 <xsl:value-of select="$star"/>
792 <xsl:text>\newtblstarfactor</xsl:text>
793 </xsl:attribute>
794 <xsl:attribute name="star">
795 <xsl:value-of select="$star"/>
796 </xsl:attribute>
797 </xsl:when>
798 <xsl:when test="$pct &gt; 0">
799 <xsl:variable name="width">
800 <xsl:value-of select="$pct div 100"/>
801 <xsl:text>\tablewidth</xsl:text>
802 </xsl:variable>
803 <xsl:attribute name="fixedwidth">
804 <xsl:value-of select="$width"/>
805 </xsl:attribute>
806 <xsl:attribute name="colwidth">
807 <xsl:value-of select="$width"/>
808 </xsl:attribute>
809 </xsl:when>
810 <xsl:when test="$fixed &gt; 0">
811 <!-- the width is expressed in 'px' bus is seen as 'pt' for tex -->
812 <xsl:variable name="width">
813 <xsl:value-of select="$fixed"/>
814 <xsl:text>pt</xsl:text>
815 </xsl:variable>
816 <xsl:attribute name="fixedwidth">
817 <xsl:value-of select="$width"/>
818 </xsl:attribute>
819 <xsl:attribute name="colwidth">
820 <xsl:value-of select="$width"/>
821 </xsl:attribute>
822 </xsl:when>
823 <xsl:otherwise>
824 <xsl:if test="@width != ''">
825 <xsl:message>
826 <xsl:text>Warning: Unrecognized width attribute (</xsl:text>
827 <xsl:value-of select="@width"/>
828 <xsl:text>) in column of HTML table</xsl:text>
829 </xsl:message>
830 </xsl:if>
831 <!-- no width specified: equivalent to a '*' -->
832 <xsl:attribute name="colwidth">
833 <xsl:text>\newtblstarfactor</xsl:text>
834 </xsl:attribute>
835 <xsl:attribute name="star">1</xsl:attribute>
836 </xsl:otherwise>
837 </xsl:choose>
838 </xsl:copy>
839 </xsl:for-each>
840 </xsl:template>
841
842
843 <!-- Find the maximum width expressed in percentage in column entries -->
844 <xsl:template name="max.percent">
845 <xsl:param name="entries"/>
846 <xsl:param name="maxpct" select="0"/>
847
848 <xsl:choose>
849 <xsl:when test="$entries">
850 <xsl:variable name="width" select="$entries[1]/@width"/>
851
852 <xsl:variable name="newpct">
853 <xsl:choose>
854 <xsl:when test="substring($width,string-length($width))='%'">
855 <xsl:variable name="pct"
856 select="number(substring-before($width, '%'))"/>
857 <xsl:choose>
858 <xsl:when test="$pct &gt; $maxpct">
859 <xsl:value-of select="$pct"/>
860 </xsl:when>
861 <xsl:otherwise>
862 <xsl:value-of select="$maxpct"/>
863 </xsl:otherwise>
864 </xsl:choose>
865 </xsl:when>
866 <xsl:otherwise>
867 <xsl:value-of select="$maxpct"/>
868 </xsl:otherwise>
869 </xsl:choose>
870 </xsl:variable>
871 <xsl:call-template name="max.percent">
872 <xsl:with-param name="maxpct" select="$newpct"/>
873 <xsl:with-param name="entries" select="$entries[position() &gt; 1]"/>
874 </xsl:call-template>
875 </xsl:when>
876 <xsl:otherwise>
877 <xsl:value-of select="$maxpct"/>
878 </xsl:otherwise>
879 </xsl:choose>
880 </xsl:template>
881
882 <!-- Find the maximum width expressed in numbers in column entries -->
883 <xsl:template name="max.value">
884 <xsl:param name="entries"/>
885 <xsl:param name="maxval" select="0"/>
886
887 <xsl:choose>
888 <xsl:when test="$entries">
889 <xsl:variable name="width" select="$entries[1]/@width"/>
890
891 <xsl:variable name="newval">
892 <xsl:choose>
893 <xsl:when test="string(number($width))!='NaN'">
894 <xsl:variable name="val" select="number($width)"/>
895 <xsl:choose>
896 <xsl:when test="$val &gt; $maxval">
897 <xsl:value-of select="$val"/>
898 </xsl:when>
899 <xsl:otherwise>
900 <xsl:value-of select="$maxval"/>
901 </xsl:otherwise>
902 </xsl:choose>
903 </xsl:when>
904 <xsl:otherwise>
905 <xsl:value-of select="$maxval"/>
906 </xsl:otherwise>
907 </xsl:choose>
908 </xsl:variable>
909 <xsl:call-template name="max.value">
910 <xsl:with-param name="maxval" select="$newval"/>
911 <xsl:with-param name="entries" select="$entries[position() &gt; 1]"/>
912 </xsl:call-template>
913 </xsl:when>
914 <xsl:otherwise>
915 <xsl:value-of select="$maxval"/>
916 </xsl:otherwise>
917 </xsl:choose>
918 </xsl:template>
919
920 <!-- ==================================================================== -->
921
922 <!-- Build empty default <colspec>s elements.
923 -->
924 <xsl:template name="make.colspec.default">
925 <xsl:param name="colmax"/>
926 <xsl:param name="colnum"/>
927
928 <xsl:if test="$colnum &lt;= $colmax">
929 <colspec>
930 <xsl:attribute name="colnum">
931 <xsl:value-of select="$colnum"/>
932 </xsl:attribute>
933 <xsl:call-template name="html.table.column.rules">
934 <xsl:with-param name="colnum" select="$colnum"/>
935 <xsl:with-param name="colmax" select="$colmax"/>
936 </xsl:call-template>
937 </colspec>
938
939 <xsl:call-template name="make.colspec.default">
940 <xsl:with-param name="colnum" select="$colnum + 1"/>
941 <xsl:with-param name="colmax" select="$colmax"/>
942 </xsl:call-template>
943 </xsl:if>
944 </xsl:template>
945
946 <!-- ==================================================================== -->
947
948 <!-- Build the equivalent <colspec>s elements from <colgroup>s and <col>s
949 and use default colspec for undefined <col>s in order to have a colspec
950 per actual column.
951 -->
952
953 <xsl:template match="colgroup" mode="make.colspec">
954 <xsl:param name="done" select="0"/>
955 <xsl:param name="colnum"/>
956 <xsl:param name="colmax"/>
957
958 <xsl:choose>
959 <xsl:when test="col">
960 <!-- the spec are handled by <col>s -->
961 <xsl:apply-templates select="col[1]" mode="make.colspec">
962 <xsl:with-param name="colnum" select="$colnum"/>
963 <xsl:with-param name="colmax" select="$colmax"/>
964 </xsl:apply-templates>
965 </xsl:when>
966 <xsl:otherwise>
967
968 <xsl:variable name="span">
969 <xsl:choose>
970 <xsl:when test="@span">
971 <xsl:value-of select="@span"/>
972 </xsl:when>
973 <xsl:otherwise>
974 <xsl:value-of select="1"/>
975 </xsl:otherwise>
976 </xsl:choose>
977 </xsl:variable>
978
979 <xsl:choose>
980 <xsl:when test="$done &lt; $span">
981 <!-- bgcolor specified via a PI -->
982 <xsl:variable name="bgcolor">
983 <xsl:call-template name="pi.dblatex_bgcolor"/>
984 </xsl:variable>
985
986 <colspec>
987 <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
988 <xsl:attribute name="colnum">
989 <xsl:value-of select="$colnum"/>
990 </xsl:attribute>
991 <xsl:if test="$bgcolor != ''">
992 <xsl:attribute name="bgcolor"><xsl:value-of select="$bgcolor"/>
993 </xsl:attribute>
994 </xsl:if>
995 <xsl:call-template name="html.table.column.rules">
996 <xsl:with-param name="colnum" select="$colnum"/>
997 <xsl:with-param name="colmax" select="$colmax"/>
998 </xsl:call-template>
999 </colspec>
1000
1001 <xsl:apply-templates select="." mode="make.colspec">
1002 <xsl:with-param name="done" select="$done + 1"/>
1003 <xsl:with-param name="colnum" select="$colnum + 1"/>
1004 <xsl:with-param name="colmax" select="$colmax"/>
1005 </xsl:apply-templates>
1006 </xsl:when>
1007 <xsl:when test="following-sibling::*[self::colgroup or self::col]">
1008 <xsl:apply-templates select="following-sibling::*[self::colgroup or
1009 self::col][1]"
1010 mode="make.colspec">
1011 <xsl:with-param name="colnum" select="$colnum"/>
1012 <xsl:with-param name="colmax" select="$colmax"/>
1013 </xsl:apply-templates>
1014 </xsl:when>
1015 <!-- build empty default <colspec>s for missing columns -->
1016 <xsl:when test="$colnum &lt;= $colmax">
1017 <xsl:call-template name="make.colspec.default">
1018 <xsl:with-param name="colmax" select="$colmax"/>
1019 <xsl:with-param name="colnum" select="$colnum"/>
1020 </xsl:call-template>
1021 </xsl:when>
1022 </xsl:choose>
1023 </xsl:otherwise>
1024 </xsl:choose>
1025 </xsl:template>
1026
1027 <xsl:template match="col" mode="make.colspec">
1028 <xsl:param name="done" select="0"/>
1029 <xsl:param name="colnum"/>
1030 <xsl:param name="colmax"/>
1031
1032 <!--
1033 <xsl:message>
1034 <xsl:text>p=</xsl:text>
1035 <xsl:value-of select="local-name()"/>
1036 <xsl:text> </xsl:text>
1037 <xsl:value-of select="generate-id()"/>
1038 <xsl:text> r=</xsl:text>
1039 <xsl:value-of select="$colnum"/>
1040 </xsl:message>
1041 -->
1042
1043 <xsl:variable name="span">
1044 <xsl:choose>
1045 <xsl:when test="@span">
1046 <xsl:value-of select="@span"/>
1047 </xsl:when>
1048 <xsl:otherwise>
1049 <xsl:value-of select="1"/>
1050 </xsl:otherwise>
1051 </xsl:choose>
1052 </xsl:variable>
1053
1054 <xsl:choose>
1055 <!-- clone the same <colspec> span times -->
1056 <xsl:when test="$done &lt; $span">
1057 <!-- bgcolor specified via a PI or a colgroup parent PI -->
1058 <xsl:variable name="bgcolor.pi">
1059 <xsl:call-template name="pi.dblatex_bgcolor"/>
1060 </xsl:variable>
1061 <xsl:variable name="bgcolor">
1062 <xsl:choose>
1063 <xsl:when test="$bgcolor.pi != ''">
1064 <xsl:value-of select="$bgcolor.pi"/>
1065 </xsl:when>
1066 <xsl:otherwise>
1067 <xsl:call-template name="pi.dblatex_bgcolor">
1068 <xsl:with-param name="node" select="parent::colgroup"/>
1069 </xsl:call-template>
1070 </xsl:otherwise>
1071 </xsl:choose>
1072 </xsl:variable>
1073
1074 <colspec>
1075 <xsl:for-each select="parent::colgroup/@*"><xsl:copy/></xsl:for-each>
1076 <xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
1077 <xsl:attribute name="colnum">
1078 <xsl:value-of select="$colnum"/>
1079 </xsl:attribute>
1080 <xsl:if test="$bgcolor != ''">
1081 <xsl:attribute name="bgcolor"><xsl:value-of select="$bgcolor"/>
1082 </xsl:attribute>
1083 </xsl:if>
1084 <xsl:call-template name="html.table.column.rules">
1085 <xsl:with-param name="colnum" select="$colnum"/>
1086 <xsl:with-param name="colmax" select="$colmax"/>
1087 </xsl:call-template>
1088 </colspec>
1089
1090 <xsl:apply-templates select="." mode="make.colspec">
1091 <xsl:with-param name="done" select="$done + 1"/>
1092 <xsl:with-param name="colnum" select="$colnum + 1"/>
1093 <xsl:with-param name="colmax" select="$colmax"/>
1094 </xsl:apply-templates>
1095 </xsl:when>
1096 <!-- process the next following <col*> -->
1097 <xsl:when test="following-sibling::*[self::colgroup or self::col]">
1098 <xsl:apply-templates
1099 select="following-sibling::*[self::col or self::colgroup][1]"
1100 mode="make.colspec">
1101 <xsl:with-param name="colnum" select="$colnum"/>
1102 <xsl:with-param name="colmax" select="$colmax"/>
1103 </xsl:apply-templates>
1104 </xsl:when>
1105 <!-- if <col> is a <colgroup> child, process the next <col*> at the parent
1106 level -->
1107 <xsl:when test="parent::colgroup[following-sibling::*[self::colgroup or
1108 self::col]]">
1109 <xsl:apply-templates select="parent::colgroup/
1110 following-sibling::*[self::col or
1111 self::colgroup][1]"
1112 mode="make.colspec">
1113 <xsl:with-param name="colnum" select="$colnum"/>
1114 <xsl:with-param name="colmax" select="$colmax"/>
1115 </xsl:apply-templates>
1116 </xsl:when>
1117 <!-- build empty default <colspec>s for missing columns -->
1118 <xsl:when test="$colnum &lt;= $colmax">
1119 <xsl:call-template name="make.colspec.default">
1120 <xsl:with-param name="colmax" select="$colmax"/>
1121 <xsl:with-param name="colnum" select="$colnum"/>
1122 </xsl:call-template>
1123 </xsl:when>
1124 </xsl:choose>
1125 </xsl:template>
1126
1127 </xsl:stylesheet>