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 <!-- ********************************************************************
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://nwalsh.com/docbook/xsl/ for copyright
13 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>
127 <para>If an <sgmltag>entry</sgmltag> has a
128 <sgmltag class="attribute">colname</sgmltag> or
129 <sgmltag class="attribute">namest</sgmltag> attribute, this template
130 will determine the number of the column in which the entry should occur.
131 For other <sgmltag>entry</sgmltag>s, nothing is returned.</para>
135 <varlistentry><term>entry</term>
137 <para>The <sgmltag>entry</sgmltag>-element which is to be tested.</para>
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="$ecol >= $scol">
217 <xsl:value-of select="$ecol - $scol + 1"/>
220 <xsl:value-of select="$scol - $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/ancestor::tgroup[1]"/>
258 <xsl:variable name="table" select="($tgroup/ancestor::table
259 |$tgroup/ancestor::informaltable)[last()]"/>
261 <xsl:variable name="entry.value">
262 <xsl:call-template name="get-attribute">
263 <xsl:with-param name="element" select="$entry"/>
264 <xsl:with-param name="attribute" select="$attribute"/>
268 <xsl:variable name="row.value">
269 <xsl:call-template name="get-attribute">
270 <xsl:with-param name="element" select="$row"/>
271 <xsl:with-param name="attribute" select="$attribute"/>
275 <xsl:variable name="span.value">
276 <xsl:if test="$entry/@spanname">
277 <xsl:variable name="spanname" select="$entry/@spanname"/>
278 <xsl:variable name="spanspec"
279 select="$tgroup/spanspec[@spanname=$spanname]"/>
280 <xsl:variable name="span.colspec"
281 select="$tgroup/colspec[@colname=$spanspec/@namest]"/>
283 <xsl:variable name="spanspec.value">
284 <xsl:call-template name="get-attribute">
285 <xsl:with-param name="element" select="$spanspec"/>
286 <xsl:with-param name="attribute" select="$attribute"/>
290 <xsl:variable name="scolspec.value">
291 <xsl:call-template name="get-attribute">
292 <xsl:with-param name="element" select="$span.colspec"/>
293 <xsl:with-param name="attribute" select="$attribute"/>
298 <xsl:when test="$spanspec.value != ''">
299 <xsl:value-of select="$spanspec.value"/>
301 <xsl:when test="$scolspec.value != ''">
302 <xsl:value-of select="$scolspec.value"/>
304 <xsl:otherwise></xsl:otherwise>
309 <xsl:variable name="namest.value">
310 <xsl:if test="$entry/@namest">
311 <xsl:variable name="namest" select="$entry/@namest"/>
312 <xsl:variable name="colspec"
313 select="$tgroup/colspec[@colname=$namest]"/>
315 <xsl:variable name="inner.namest.value">
316 <xsl:call-template name="get-attribute">
317 <xsl:with-param name="element" select="$colspec"/>
318 <xsl:with-param name="attribute" select="$attribute"/>
323 <xsl:when test="$inner.namest.value">
324 <xsl:value-of select="$inner.namest.value"/>
326 <xsl:otherwise></xsl:otherwise>
331 <xsl:variable name="tgroup.value">
332 <xsl:call-template name="get-attribute">
333 <xsl:with-param name="element" select="$tgroup"/>
334 <xsl:with-param name="attribute" select="$attribute"/>
338 <xsl:variable name="table.value">
339 <xsl:call-template name="get-attribute">
340 <xsl:with-param name="element" select="$table"/>
341 <xsl:with-param name="attribute" select="$attribute"/>
345 <xsl:variable name="default.value">
346 <!-- This section used to say that rowsep and colsep have defaults based -->
347 <!-- on the frame setting. Further reflection and closer examination of the -->
348 <!-- CALS spec reveals I was mistaken. The default is "1" for rowsep and colsep. -->
349 <!-- For everything else, the default is the tgroup value -->
351 <xsl:when test="$tgroup.value != ''">
352 <xsl:value-of select="$tgroup.value"/>
354 <xsl:when test="$attribute = 'rowsep'">1</xsl:when>
355 <xsl:when test="$attribute = 'colsep'">1</xsl:when>
356 <xsl:otherwise><!-- empty --></xsl:otherwise>
360 <xsl:variable name="calc.colvalue">
361 <xsl:if test="$colnum > 0">
362 <xsl:call-template name="colnum.colspec">
363 <xsl:with-param name="colnum" select="$colnum"/>
364 <xsl:with-param name="attribute" select="$attribute"/>
370 <xsl:when test="$entry.value != ''">
371 <xsl:value-of select="$entry.value"/>
373 <xsl:when test="$row.value != ''">
374 <xsl:value-of select="$row.value"/>
376 <xsl:when test="$span.value != ''">
377 <xsl:value-of select="$span.value"/>
379 <xsl:when test="$namest.value != ''">
380 <xsl:value-of select="$namest.value"/>
382 <xsl:when test="$calc.colvalue != ''">
383 <xsl:value-of select="$calc.colvalue"/>
385 <xsl:when test="$tgroup.value != ''">
386 <xsl:value-of select="$tgroup.value"/>
388 <xsl:when test="$table.value != ''">
389 <xsl:value-of select="$table.value"/>
392 <xsl:value-of select="$default.value"/>
397 <xsl:template name="colnum.colspec">
398 <xsl:param name="colnum" select="0"/>
399 <xsl:param name="attribute" select="'colname'"/>
400 <xsl:param name="colspecs" select="ancestor::tgroup/colspec"/>
401 <xsl:param name="count" select="1"/>
404 <xsl:when test="not($colspecs) or $count > $colnum">
407 <xsl:when test="$colspecs[1]/@colnum">
409 <xsl:when test="$colspecs[1]/@colnum = $colnum">
410 <xsl:call-template name="get-attribute">
411 <xsl:with-param name="element" select="$colspecs[1]"/>
412 <xsl:with-param name="attribute" select="$attribute"/>
416 <xsl:call-template name="colnum.colspec">
417 <xsl:with-param name="colnum" select="$colnum"/>
418 <xsl:with-param name="attribute" select="$attribute"/>
419 <xsl:with-param name="colspecs"
420 select="$colspecs[position()>1]"/>
421 <xsl:with-param name="count"
422 select="$colspecs[1]/@colnum+1"/>
429 <xsl:when test="$count = $colnum">
430 <xsl:call-template name="get-attribute">
431 <xsl:with-param name="element" select="$colspecs[1]"/>
432 <xsl:with-param name="attribute" select="$attribute"/>
436 <xsl:call-template name="colnum.colspec">
437 <xsl:with-param name="colnum" select="$colnum"/>
438 <xsl:with-param name="attribute" select="$attribute"/>
439 <xsl:with-param name="colspecs"
440 select="$colspecs[position()>1]"/>
441 <xsl:with-param name="count" select="$count+1"/>
449 <xsl:template name="get-attribute">
450 <xsl:param name="element" select="."/>
451 <xsl:param name="attribute" select="''"/>
453 <xsl:for-each select="$element/@*">
454 <xsl:if test="local-name(.) = $attribute">
455 <xsl:value-of select="."/>