2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4 exclude-result-prefixes="doc"
7 <!-- ********************************************************************
8 $Id: table.xsl 8392 2009-04-01 08:47:55Z bobstayton $
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://docbook.sf.net/release/xsl/current/ for
13 copyright and other information.
15 ******************************************************************** -->
17 <!-- ==================================================================== -->
19 <xsl:template name="blank.spans">
20 <xsl:param name="cols" select="1"/>
21 <xsl:if test="$cols > 0">
22 <xsl:text>0:</xsl:text>
23 <xsl:call-template name="blank.spans">
24 <xsl:with-param name="cols" select="$cols - 1"/>
29 <xsl:template name="calculate.following.spans">
30 <xsl:param name="colspan" select="1"/>
31 <xsl:param name="spans" select="''"/>
34 <xsl:when test="$colspan > 0">
35 <xsl:call-template name="calculate.following.spans">
36 <xsl:with-param name="colspan" select="$colspan - 1"/>
37 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
41 <xsl:value-of select="$spans"/>
46 <xsl:template name="finaltd">
47 <xsl:param name="spans"/>
48 <xsl:param name="col" select="0"/>
50 <xsl:if test="$spans != ''">
52 <xsl:when test="starts-with($spans,'0:')">
53 <xsl:call-template name="empty.table.cell">
54 <xsl:with-param name="colnum" select="$col"/>
57 <xsl:otherwise></xsl:otherwise>
60 <xsl:call-template name="finaltd">
61 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
62 <xsl:with-param name="col" select="$col+1"/>
67 <xsl:template name="sfinaltd">
68 <xsl:param name="spans"/>
70 <xsl:if test="$spans != ''">
72 <xsl:when test="starts-with($spans,'0:')">0:</xsl:when>
74 <xsl:value-of select="substring-before($spans,':')-1"/>
75 <xsl:text>:</xsl:text>
79 <xsl:call-template name="sfinaltd">
80 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
85 <xsl:template name="entry.colnum">
86 <xsl:param name="entry" select="."/>
89 <xsl:when test="$entry/@spanname">
90 <xsl:variable name="spanname" select="$entry/@spanname"/>
91 <xsl:variable name="spanspec"
92 select="($entry/ancestor::tgroup/spanspec[@spanname=$spanname]
93 |$entry/ancestor::entrytbl/spanspec[@spanname=$spanname])[last()]"/>
94 <xsl:variable name="colspec"
95 select="($entry/ancestor::tgroup/colspec[@colname=$spanspec/@namest]
96 |$entry/ancestor::entrytbl/colspec[@colname=$spanspec/@namest])[last()]"/>
97 <xsl:call-template name="colspec.colnum">
98 <xsl:with-param name="colspec" select="$colspec"/>
101 <xsl:when test="$entry/@colname">
102 <xsl:variable name="colname" select="$entry/@colname"/>
103 <xsl:variable name="colspec"
104 select="($entry/ancestor::tgroup/colspec[@colname=$colname]
105 |$entry/ancestor::entrytbl/colspec[@colname=$colname])[last()]"/>
106 <xsl:call-template name="colspec.colnum">
107 <xsl:with-param name="colspec" select="$colspec"/>
110 <xsl:when test="$entry/@namest">
111 <xsl:variable name="namest" select="$entry/@namest"/>
112 <xsl:variable name="colspec"
113 select="($entry/ancestor::tgroup/colspec[@colname=$namest]
114 |$entry/ancestor::entrytbl/colspec[@colname=$namest])[last()]"/>
115 <xsl:call-template name="colspec.colnum">
116 <xsl:with-param name="colspec" select="$colspec"/>
119 <!-- no idea, return 0 -->
120 <xsl:otherwise>0</xsl:otherwise>
124 <doc:template name="entry.colnum" xmlns="">
125 <refpurpose>Determine the column number in which a given entry occurs</refpurpose>
126 <refdescription id="entry.colnum-desc">
127 <para>If an <tag>entry</tag> has a
128 <tag class="attribute">colname</tag> or
129 <tag class="attribute">namest</tag> attribute, this template
130 will determine the number of the column in which the entry should occur.
131 For other <tag>entry</tag>s, nothing is returned.</para>
133 <refparameter id="entry.colnum-params">
135 <varlistentry><term>entry</term>
137 <para>The <tag>entry</tag>-element which is to be tested.</para>
143 <refreturn id="entry.colnum-returns">
144 <para>This template returns the column number if it can be determined,
145 or 0 (the empty string)</para>
149 <xsl:template name="colspec.colnum">
150 <xsl:param name="colspec" select="."/>
152 <xsl:when test="$colspec/@colnum">
153 <xsl:value-of select="$colspec/@colnum"/>
155 <xsl:when test="$colspec/preceding-sibling::colspec">
156 <xsl:variable name="prec.colspec.colnum">
157 <xsl:call-template name="colspec.colnum">
158 <xsl:with-param name="colspec"
159 select="$colspec/preceding-sibling::colspec[1]"/>
162 <xsl:value-of select="$prec.colspec.colnum + 1"/>
164 <xsl:otherwise>1</xsl:otherwise>
168 <xsl:template name="calculate.colspan">
169 <xsl:param name="entry" select="."/>
170 <xsl:variable name="spanname" select="$entry/@spanname"/>
171 <xsl:variable name="spanspec"
172 select="($entry/ancestor::tgroup/spanspec[@spanname=$spanname]
173 |$entry/ancestor::entrytbl/spanspec[@spanname=$spanname])[last()]"/>
175 <xsl:variable name="namest">
177 <xsl:when test="@spanname">
178 <xsl:value-of select="$spanspec/@namest"/>
181 <xsl:value-of select="$entry/@namest"/>
186 <xsl:variable name="nameend">
188 <xsl:when test="@spanname">
189 <xsl:value-of select="$spanspec/@nameend"/>
192 <xsl:value-of select="$entry/@nameend"/>
197 <xsl:variable name="scol">
198 <xsl:call-template name="colspec.colnum">
199 <xsl:with-param name="colspec"
200 select="($entry/ancestor::tgroup/colspec[@colname=$namest]
201 |$entry/ancestor::entrytbl/colspec[@colname=$namest])[last()]"/>
205 <xsl:variable name="ecol">
206 <xsl:call-template name="colspec.colnum">
207 <xsl:with-param name="colspec"
208 select="($entry/ancestor::tgroup/colspec[@colname=$nameend]
209 |$entry/ancestor::entrytbl/colspec[@colname=$nameend])[last()]"/>
214 <xsl:when test="$namest != '' and $nameend != ''">
216 <xsl:when test="number($ecol) >= number($scol)">
217 <xsl:value-of select="number($ecol) - number($scol) + 1"/>
220 <xsl:value-of select="number($scol) - number($ecol) + 1"/>
224 <xsl:otherwise>1</xsl:otherwise>
228 <xsl:template name="calculate.rowsep">
229 <xsl:param name="entry" select="."/>
230 <xsl:param name="colnum" select="0"/>
232 <xsl:call-template name="inherited.table.attribute">
233 <xsl:with-param name="entry" select="$entry"/>
234 <xsl:with-param name="colnum" select="$colnum"/>
235 <xsl:with-param name="attribute" select="'rowsep'"/>
239 <xsl:template name="calculate.colsep">
240 <xsl:param name="entry" select="."/>
241 <xsl:param name="colnum" select="0"/>
243 <xsl:call-template name="inherited.table.attribute">
244 <xsl:with-param name="entry" select="$entry"/>
245 <xsl:with-param name="colnum" select="$colnum"/>
246 <xsl:with-param name="attribute" select="'colsep'"/>
250 <xsl:template name="inherited.table.attribute">
251 <xsl:param name="entry" select="."/>
252 <xsl:param name="row" select="$entry/ancestor-or-self::row[1]"/>
253 <xsl:param name="colnum" select="0"/>
254 <xsl:param name="attribute" select="'colsep'"/>
256 <xsl:variable name="tgroup" select="$row/parent::*/parent::tgroup[1]"/>
257 <xsl:variable name="tbody" select="$row/parent::*[1]"/>
259 <xsl:variable name="table" select="($tgroup/ancestor::table
260 |$tgroup/ancestor::informaltable
261 |$entry/ancestor::entrytbl)[last()]"/>
263 <xsl:variable name="entry.value">
264 <xsl:call-template name="get-attribute">
265 <xsl:with-param name="element" select="$entry"/>
266 <xsl:with-param name="attribute" select="$attribute"/>
270 <xsl:variable name="row.value">
271 <xsl:call-template name="get-attribute">
272 <xsl:with-param name="element" select="$row"/>
273 <xsl:with-param name="attribute" select="$attribute"/>
277 <xsl:variable name="span.value">
278 <xsl:if test="$entry/@spanname">
279 <xsl:variable name="spanname" select="$entry/@spanname"/>
280 <xsl:variable name="spanspec"
281 select="$tgroup/spanspec[@spanname=$spanname]"/>
282 <xsl:variable name="span.colspec"
283 select="$tgroup/colspec[@colname=$spanspec/@namest]"/>
285 <xsl:variable name="spanspec.value">
286 <xsl:call-template name="get-attribute">
287 <xsl:with-param name="element" select="$spanspec"/>
288 <xsl:with-param name="attribute" select="$attribute"/>
292 <xsl:variable name="scolspec.value">
293 <xsl:call-template name="get-attribute">
294 <xsl:with-param name="element" select="$span.colspec"/>
295 <xsl:with-param name="attribute" select="$attribute"/>
300 <xsl:when test="$spanspec.value != ''">
301 <xsl:value-of select="$spanspec.value"/>
303 <xsl:when test="$scolspec.value != ''">
304 <xsl:value-of select="$scolspec.value"/>
306 <xsl:otherwise></xsl:otherwise>
311 <xsl:variable name="namest.value">
312 <xsl:if test="$entry/@namest">
313 <xsl:variable name="namest" select="$entry/@namest"/>
314 <xsl:variable name="colspec"
315 select="$tgroup/colspec[@colname=$namest]"/>
317 <xsl:variable name="inner.namest.value">
318 <xsl:call-template name="get-attribute">
319 <xsl:with-param name="element" select="$colspec"/>
320 <xsl:with-param name="attribute" select="$attribute"/>
325 <xsl:when test="$inner.namest.value">
326 <xsl:value-of select="$inner.namest.value"/>
328 <xsl:otherwise></xsl:otherwise>
333 <xsl:variable name="tgroup.value">
334 <xsl:call-template name="get-attribute">
335 <xsl:with-param name="element" select="$tgroup"/>
336 <xsl:with-param name="attribute" select="$attribute"/>
340 <xsl:variable name="tbody.value">
341 <xsl:call-template name="get-attribute">
342 <xsl:with-param name="element" select="$tbody"/>
343 <xsl:with-param name="attribute" select="$attribute"/>
347 <xsl:variable name="table.value">
348 <xsl:call-template name="get-attribute">
349 <xsl:with-param name="element" select="$table"/>
350 <xsl:with-param name="attribute" select="$attribute"/>
354 <xsl:variable name="default.value">
355 <!-- This section used to say that rowsep and colsep have defaults based -->
356 <!-- on the frame setting. Further reflection and closer examination of the -->
357 <!-- CALS spec reveals I was mistaken. The default is "1" for rowsep and colsep. -->
358 <!-- For everything else, the default is the tgroup value -->
360 <xsl:when test="$tgroup.value != ''">
361 <xsl:value-of select="$tgroup.value"/>
363 <xsl:when test="$attribute = 'rowsep'">1</xsl:when>
364 <xsl:when test="$attribute = 'colsep'">1</xsl:when>
365 <xsl:otherwise><!-- empty --></xsl:otherwise>
369 <xsl:variable name="calc.colvalue">
370 <xsl:if test="$colnum > 0">
371 <xsl:call-template name="colnum.colspec">
372 <xsl:with-param name="colnum" select="$colnum"/>
373 <xsl:with-param name="attribute" select="$attribute"/>
379 <xsl:when test="$entry.value != ''">
380 <xsl:value-of select="$entry.value"/>
382 <xsl:when test="$row.value != ''">
383 <xsl:value-of select="$row.value"/>
385 <xsl:when test="$span.value != ''">
386 <xsl:value-of select="$span.value"/>
388 <xsl:when test="$namest.value != ''">
389 <xsl:value-of select="$namest.value"/>
391 <xsl:when test="$calc.colvalue != ''">
392 <xsl:value-of select="$calc.colvalue"/>
394 <xsl:when test="$tbody.value != ''">
395 <xsl:value-of select="$tbody.value"/>
397 <xsl:when test="$tgroup.value != ''">
398 <xsl:value-of select="$tgroup.value"/>
400 <xsl:when test="$table.value != ''">
401 <xsl:value-of select="$table.value"/>
404 <xsl:value-of select="$default.value"/>
409 <xsl:template name="colnum.colspec">
410 <xsl:param name="colnum" select="0"/>
411 <xsl:param name="attribute" select="'colname'"/>
412 <xsl:param name="colspec.ancestor"
413 select="(ancestor::tgroup|ancestor::entrytbl)
414 [position() = last()]"/>
415 <xsl:param name="colspecs" select="$colspec.ancestor/colspec"/>
416 <xsl:param name="count" select="1"/>
419 <xsl:when test="not($colspecs) or $count > $colnum">
422 <xsl:when test="$colspecs[1]/@colnum">
424 <xsl:when test="$colspecs[1]/@colnum = $colnum">
425 <xsl:call-template name="get-attribute">
426 <xsl:with-param name="element" select="$colspecs[1]"/>
427 <xsl:with-param name="attribute" select="$attribute"/>
431 <xsl:call-template name="colnum.colspec">
432 <xsl:with-param name="colnum" select="$colnum"/>
433 <xsl:with-param name="attribute" select="$attribute"/>
434 <xsl:with-param name="colspecs"
435 select="$colspecs[position()>1]"/>
436 <xsl:with-param name="count"
437 select="$colspecs[1]/@colnum+1"/>
444 <xsl:when test="$count = $colnum">
445 <xsl:call-template name="get-attribute">
446 <xsl:with-param name="element" select="$colspecs[1]"/>
447 <xsl:with-param name="attribute" select="$attribute"/>
451 <xsl:call-template name="colnum.colspec">
452 <xsl:with-param name="colnum" select="$colnum"/>
453 <xsl:with-param name="attribute" select="$attribute"/>
454 <xsl:with-param name="colspecs"
455 select="$colspecs[position()>1]"/>
456 <xsl:with-param name="count" select="$count+1"/>
464 <xsl:template name="get-attribute">
465 <xsl:param name="element" select="."/>
466 <xsl:param name="attribute" select="''"/>
468 <xsl:for-each select="$element/@*">
469 <xsl:if test="local-name(.) = $attribute">
470 <xsl:value-of select="."/>
475 <xsl:template name="consume-row">
476 <xsl:param name="spans"/>
478 <xsl:if test="contains($spans,':')">
479 <xsl:value-of select="substring-before($spans,':') - 1"/>
480 <xsl:text>:</xsl:text>
481 <xsl:call-template name="consume-row">
482 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
487 <!-- Returns the table style for the context element -->
488 <xsl:template name="tabstyle">
489 <xsl:param name="node" select="."/>
491 <xsl:variable name="tgroup" select="$node/tgroup[1] |
492 $node/ancestor-or-self::tgroup[1]"/>
494 <xsl:variable name="table"
495 select="($node/ancestor-or-self::table |
496 $node/ancestor-or-self::informaltable)[last()]"/>
498 <xsl:variable name="tabstyle">
500 <xsl:when test="$table/@tabstyle != ''">
501 <xsl:value-of select="normalize-space($table/@tabstyle)"/>
503 <xsl:when test="$tgroup/@tgroupstyle != ''">
504 <xsl:value-of select="normalize-space($tgroup/@tgroupstyle)"/>
511 <xsl:value-of select="$tabstyle"/>