2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:d="http://docbook.org/ns/docbook"
4 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
5 exclude-result-prefixes="doc d"
8 <!-- ********************************************************************
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://cdn.docbook.org/release/xsl/current/ for
12 copyright and other information.
14 ******************************************************************** -->
16 <!-- ==================================================================== -->
18 <xsl:template name="blank.spans">
19 <xsl:param name="cols" select="1"/>
20 <xsl:if test="$cols > 0">
21 <xsl:text>0:</xsl:text>
22 <xsl:call-template name="blank.spans">
23 <xsl:with-param name="cols" select="$cols - 1"/>
28 <xsl:template name="calculate.following.spans">
29 <xsl:param name="colspan" select="1"/>
30 <xsl:param name="spans" select="''"/>
33 <xsl:when test="$colspan > 0">
34 <xsl:call-template name="calculate.following.spans">
35 <xsl:with-param name="colspan" select="$colspan - 1"/>
36 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
40 <xsl:value-of select="$spans"/>
45 <xsl:template name="finaltd">
46 <xsl:param name="spans"/>
47 <xsl:param name="col" select="0"/>
49 <xsl:if test="$spans != ''">
51 <xsl:when test="starts-with($spans,'0:')">
52 <xsl:call-template name="empty.table.cell">
53 <xsl:with-param name="colnum" select="$col"/>
56 <xsl:otherwise></xsl:otherwise>
59 <xsl:call-template name="finaltd">
60 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
61 <xsl:with-param name="col" select="$col+1"/>
66 <xsl:template name="sfinaltd">
67 <xsl:param name="spans"/>
69 <xsl:if test="$spans != ''">
71 <xsl:when test="starts-with($spans,'0:')">0:</xsl:when>
73 <xsl:value-of select="substring-before($spans,':')-1"/>
74 <xsl:text>:</xsl:text>
78 <xsl:call-template name="sfinaltd">
79 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
84 <xsl:template name="entry.colnum">
85 <xsl:param name="entry" select="."/>
88 <xsl:when test="$entry/@spanname">
89 <xsl:variable name="spanname" select="$entry/@spanname"/>
90 <xsl:variable name="spanspec"
91 select="($entry/ancestor::d:tgroup/d:spanspec[@spanname=$spanname]
92 |$entry/ancestor::d:entrytbl/d:spanspec[@spanname=$spanname])[last()]"/>
93 <xsl:variable name="colspec"
94 select="($entry/ancestor::d:tgroup/d:colspec[@colname=$spanspec/@namest]
95 |$entry/ancestor::d:entrytbl/d:colspec[@colname=$spanspec/@namest])[last()]"/>
96 <xsl:call-template name="colspec.colnum">
97 <xsl:with-param name="colspec" select="$colspec"/>
100 <xsl:when test="$entry/@colname">
101 <xsl:variable name="colname" select="$entry/@colname"/>
102 <xsl:variable name="colspec"
103 select="($entry/ancestor::d:tgroup/d:colspec[@colname=$colname]
104 |$entry/ancestor::d:entrytbl/d:colspec[@colname=$colname])[last()]"/>
105 <xsl:call-template name="colspec.colnum">
106 <xsl:with-param name="colspec" select="$colspec"/>
109 <xsl:when test="$entry/@namest">
110 <xsl:variable name="namest" select="$entry/@namest"/>
111 <xsl:variable name="colspec"
112 select="($entry/ancestor::d:tgroup/d:colspec[@colname=$namest]
113 |$entry/ancestor::d:entrytbl/d:colspec[@colname=$namest])[last()]"/>
114 <xsl:call-template name="colspec.colnum">
115 <xsl:with-param name="colspec" select="$colspec"/>
118 <!-- no idea, return 0 -->
119 <xsl:otherwise>0</xsl:otherwise>
123 <doc:template name="entry.colnum" xmlns="">
124 <refpurpose>Determine the column number in which a given entry occurs</refpurpose>
125 <refdescription id="entry.colnum-desc">
126 <para>If an <tag>entry</tag> has a
127 <tag class="attribute">colname</tag> or
128 <tag class="attribute">namest</tag> attribute, this template
129 will determine the number of the column in which the entry should occur.
130 For other <tag>entry</tag>s, nothing is returned.</para>
132 <refparameter id="entry.colnum-params">
134 <varlistentry><term>entry</term>
136 <para>The <tag>entry</tag>-element which is to be tested.</para>
142 <refreturn id="entry.colnum-returns">
143 <para>This template returns the column number if it can be determined,
144 or 0 (the empty string)</para>
148 <xsl:template name="colspec.colnum">
149 <xsl:param name="colspec" select="."/>
151 <xsl:when test="$colspec/@colnum">
152 <xsl:value-of select="$colspec/@colnum"/>
154 <xsl:when test="$colspec/preceding-sibling::d:colspec">
155 <xsl:variable name="prec.colspec.colnum">
156 <xsl:call-template name="colspec.colnum">
157 <xsl:with-param name="colspec"
158 select="$colspec/preceding-sibling::d:colspec[1]"/>
161 <xsl:value-of select="$prec.colspec.colnum + 1"/>
163 <xsl:otherwise>1</xsl:otherwise>
167 <xsl:template name="calculate.colspan">
168 <xsl:param name="entry" select="."/>
169 <xsl:variable name="spanname" select="$entry/@spanname"/>
170 <xsl:variable name="spanspec"
171 select="($entry/ancestor::d:tgroup/d:spanspec[@spanname=$spanname]
172 |$entry/ancestor::d:entrytbl/d:spanspec[@spanname=$spanname])[last()]"/>
174 <xsl:variable name="namest">
176 <xsl:when test="@spanname">
177 <xsl:value-of select="$spanspec/@namest"/>
180 <xsl:value-of select="$entry/@namest"/>
185 <xsl:variable name="nameend">
187 <xsl:when test="@spanname">
188 <xsl:value-of select="$spanspec/@nameend"/>
191 <xsl:value-of select="$entry/@nameend"/>
196 <xsl:variable name="scol">
197 <xsl:call-template name="colspec.colnum">
198 <xsl:with-param name="colspec"
199 select="($entry/ancestor::d:tgroup/d:colspec[@colname=$namest]
200 |$entry/ancestor::d:entrytbl/d:colspec[@colname=$namest])[last()]"/>
204 <xsl:variable name="ecol">
205 <xsl:call-template name="colspec.colnum">
206 <xsl:with-param name="colspec"
207 select="($entry/ancestor::d:tgroup/d:colspec[@colname=$nameend]
208 |$entry/ancestor::d:entrytbl/d:colspec[@colname=$nameend])[last()]"/>
213 <xsl:when test="$namest != '' and $nameend != ''">
215 <xsl:when test="number($ecol) >= number($scol)">
216 <xsl:value-of select="number($ecol) - number($scol) + 1"/>
219 <xsl:value-of select="number($scol) - number($ecol) + 1"/>
223 <xsl:otherwise>1</xsl:otherwise>
227 <xsl:template name="calculate.rowsep">
228 <xsl:param name="entry" select="."/>
229 <xsl:param name="colnum" select="0"/>
231 <xsl:call-template name="inherited.table.attribute">
232 <xsl:with-param name="entry" select="$entry"/>
233 <xsl:with-param name="colnum" select="$colnum"/>
234 <xsl:with-param name="attribute" select="'rowsep'"/>
238 <xsl:template name="calculate.colsep">
239 <xsl:param name="entry" select="."/>
240 <xsl:param name="colnum" select="0"/>
242 <xsl:call-template name="inherited.table.attribute">
243 <xsl:with-param name="entry" select="$entry"/>
244 <xsl:with-param name="colnum" select="$colnum"/>
245 <xsl:with-param name="attribute" select="'colsep'"/>
249 <xsl:template name="inherited.table.attribute">
250 <xsl:param name="entry" select="."/>
251 <xsl:param name="row" select="$entry/ancestor-or-self::d:row[1]"/>
252 <xsl:param name="colnum" select="0"/>
253 <xsl:param name="attribute" select="'colsep'"/>
255 <xsl:variable name="tgroup" select="$row/parent::*/parent::d:tgroup[1]"/>
256 <xsl:variable name="tbody" select="$row/parent::*[1]"/>
258 <xsl:variable name="table" select="($tgroup/ancestor::d:table
259 |$tgroup/ancestor::d:informaltable
260 |$entry/ancestor::d:entrytbl)[last()]"/>
262 <xsl:variable name="entry.value">
263 <xsl:call-template name="get-attribute">
264 <xsl:with-param name="element" select="$entry"/>
265 <xsl:with-param name="attribute" select="$attribute"/>
269 <xsl:variable name="row.value">
270 <xsl:call-template name="get-attribute">
271 <xsl:with-param name="element" select="$row"/>
272 <xsl:with-param name="attribute" select="$attribute"/>
276 <xsl:variable name="span.value">
277 <xsl:if test="$entry/@spanname">
278 <xsl:variable name="spanname" select="$entry/@spanname"/>
279 <xsl:variable name="spanspec"
280 select="$tgroup/d:spanspec[@spanname=$spanname]"/>
281 <xsl:variable name="span.colspec"
282 select="$tgroup/d:colspec[@colname=$spanspec/@namest]"/>
284 <xsl:variable name="spanspec.value">
285 <xsl:call-template name="get-attribute">
286 <xsl:with-param name="element" select="$spanspec"/>
287 <xsl:with-param name="attribute" select="$attribute"/>
291 <xsl:variable name="scolspec.value">
292 <xsl:call-template name="get-attribute">
293 <xsl:with-param name="element" select="$span.colspec"/>
294 <xsl:with-param name="attribute" select="$attribute"/>
299 <xsl:when test="$spanspec.value != ''">
300 <xsl:value-of select="$spanspec.value"/>
302 <xsl:when test="$scolspec.value != ''">
303 <xsl:value-of select="$scolspec.value"/>
305 <xsl:otherwise></xsl:otherwise>
310 <xsl:variable name="namest.value">
311 <xsl:if test="$entry/@namest">
312 <xsl:variable name="namest" select="$entry/@namest"/>
313 <xsl:variable name="colspec"
314 select="$tgroup/d:colspec[@colname=$namest]"/>
316 <xsl:variable name="inner.namest.value">
317 <xsl:call-template name="get-attribute">
318 <xsl:with-param name="element" select="$colspec"/>
319 <xsl:with-param name="attribute" select="$attribute"/>
324 <xsl:when test="$inner.namest.value">
325 <xsl:value-of select="$inner.namest.value"/>
327 <xsl:otherwise></xsl:otherwise>
332 <xsl:variable name="tgroup.value">
333 <xsl:call-template name="get-attribute">
334 <xsl:with-param name="element" select="$tgroup"/>
335 <xsl:with-param name="attribute" select="$attribute"/>
339 <xsl:variable name="tbody.value">
340 <xsl:call-template name="get-attribute">
341 <xsl:with-param name="element" select="$tbody"/>
342 <xsl:with-param name="attribute" select="$attribute"/>
346 <xsl:variable name="table.value">
347 <xsl:call-template name="get-attribute">
348 <xsl:with-param name="element" select="$table"/>
349 <xsl:with-param name="attribute" select="$attribute"/>
353 <xsl:variable name="default.value">
354 <!-- This section used to say that rowsep and colsep have defaults based -->
355 <!-- on the frame setting. Further reflection and closer examination of the -->
356 <!-- CALS spec reveals I was mistaken. The default is "1" for rowsep and colsep. -->
357 <!-- For everything else, the default is the tgroup value -->
359 <xsl:when test="$tgroup.value != ''">
360 <xsl:value-of select="$tgroup.value"/>
362 <xsl:when test="$attribute = 'rowsep'">1</xsl:when>
363 <xsl:when test="$attribute = 'colsep'">1</xsl:when>
364 <xsl:otherwise><!-- empty --></xsl:otherwise>
368 <xsl:variable name="calc.colvalue">
369 <xsl:if test="$colnum > 0">
370 <xsl:call-template name="colnum.colspec">
371 <xsl:with-param name="colnum" select="$colnum"/>
372 <xsl:with-param name="attribute" select="$attribute"/>
378 <xsl:when test="$entry.value != ''">
379 <xsl:value-of select="$entry.value"/>
381 <xsl:when test="$row.value != ''">
382 <xsl:value-of select="$row.value"/>
384 <xsl:when test="$span.value != ''">
385 <xsl:value-of select="$span.value"/>
387 <xsl:when test="$namest.value != ''">
388 <xsl:value-of select="$namest.value"/>
390 <xsl:when test="$calc.colvalue != ''">
391 <xsl:value-of select="$calc.colvalue"/>
393 <xsl:when test="$tbody.value != ''">
394 <xsl:value-of select="$tbody.value"/>
396 <xsl:when test="$tgroup.value != ''">
397 <xsl:value-of select="$tgroup.value"/>
399 <xsl:when test="$table.value != ''">
400 <xsl:value-of select="$table.value"/>
403 <xsl:value-of select="$default.value"/>
408 <xsl:template name="colnum.colspec">
409 <xsl:param name="colnum" select="0"/>
410 <xsl:param name="attribute" select="'colname'"/>
411 <xsl:param name="colspec.ancestor"
412 select="(ancestor::d:tgroup|ancestor::d:entrytbl)
413 [position() = last()]"/>
414 <xsl:param name="colspecs" select="$colspec.ancestor/d:colspec"/>
415 <xsl:param name="count" select="1"/>
418 <xsl:when test="not($colspecs) or $count > $colnum">
421 <xsl:when test="$colspecs[1]/@colnum">
423 <xsl:when test="$colspecs[1]/@colnum = $colnum">
424 <xsl:call-template name="get-attribute">
425 <xsl:with-param name="element" select="$colspecs[1]"/>
426 <xsl:with-param name="attribute" select="$attribute"/>
430 <xsl:call-template name="colnum.colspec">
431 <xsl:with-param name="colnum" select="$colnum"/>
432 <xsl:with-param name="attribute" select="$attribute"/>
433 <xsl:with-param name="colspecs"
434 select="$colspecs[position()>1]"/>
435 <xsl:with-param name="count"
436 select="$colspecs[1]/@colnum+1"/>
443 <xsl:when test="$count = $colnum">
444 <xsl:call-template name="get-attribute">
445 <xsl:with-param name="element" select="$colspecs[1]"/>
446 <xsl:with-param name="attribute" select="$attribute"/>
450 <xsl:call-template name="colnum.colspec">
451 <xsl:with-param name="colnum" select="$colnum"/>
452 <xsl:with-param name="attribute" select="$attribute"/>
453 <xsl:with-param name="colspecs"
454 select="$colspecs[position()>1]"/>
455 <xsl:with-param name="count" select="$count+1"/>
463 <xsl:template name="get-attribute">
464 <xsl:param name="element" select="."/>
465 <xsl:param name="attribute" select="''"/>
467 <xsl:for-each select="$element/@*">
468 <xsl:if test="local-name(.) = $attribute">
469 <xsl:value-of select="."/>
474 <xsl:template name="consume-row">
475 <xsl:param name="spans"/>
477 <xsl:if test="contains($spans,':')">
478 <xsl:value-of select="substring-before($spans,':') - 1"/>
479 <xsl:text>:</xsl:text>
480 <xsl:call-template name="consume-row">
481 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
486 <!-- Returns the table style for the context element -->
487 <xsl:template name="tabstyle">
488 <xsl:param name="node" select="."/>
490 <xsl:variable name="tgroup" select="$node/d:tgroup[1] |
491 $node/ancestor-or-self::d:tgroup[1]"/>
493 <xsl:variable name="table"
494 select="($node/ancestor-or-self::d:table |
495 $node/ancestor-or-self::d:informaltable)[last()]"/>
497 <xsl:variable name="tabstyle">
499 <xsl:when test="$table/@tabstyle != ''">
500 <xsl:value-of select="normalize-space($table/@tabstyle)"/>
502 <xsl:when test="$tgroup/@tgroupstyle != ''">
503 <xsl:value-of select="normalize-space($tgroup/@tgroupstyle)"/>
510 <xsl:value-of select="$tabstyle"/>