source: BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/common/table.xsl@ 48e10ed

clfs-1.2 clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 48e10ed was f8c4e94, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added LFS XSL Stylesheets.

  • Property mode set to 100644
File size: 17.7 KB
Line 
1<?xml version="1.0"?>
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"
5 version="1.0">
6
7<!-- ********************************************************************
8 $Id$
9 ********************************************************************
10
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.
14
15 ******************************************************************** -->
16
17<!-- ==================================================================== -->
18
19<xsl:template name="blank.spans">
20 <xsl:param name="cols" select="1"/>
21 <xsl:if test="$cols &gt; 0">
22 <xsl:text>0:</xsl:text>
23 <xsl:call-template name="blank.spans">
24 <xsl:with-param name="cols" select="$cols - 1"/>
25 </xsl:call-template>
26 </xsl:if>
27</xsl:template>
28
29<xsl:template name="calculate.following.spans">
30 <xsl:param name="colspan" select="1"/>
31 <xsl:param name="spans" select="''"/>
32
33 <xsl:choose>
34 <xsl:when test="$colspan &gt; 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,':')"/>
38 </xsl:call-template>
39 </xsl:when>
40 <xsl:otherwise>
41 <xsl:value-of select="$spans"/>
42 </xsl:otherwise>
43 </xsl:choose>
44</xsl:template>
45
46<xsl:template name="finaltd">
47 <xsl:param name="spans"/>
48 <xsl:param name="col" select="0"/>
49
50 <xsl:if test="$spans != ''">
51 <xsl:choose>
52 <xsl:when test="starts-with($spans,'0:')">
53 <xsl:call-template name="empty.table.cell">
54 <xsl:with-param name="colnum" select="$col"/>
55 </xsl:call-template>
56 </xsl:when>
57 <xsl:otherwise></xsl:otherwise>
58 </xsl:choose>
59
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"/>
63 </xsl:call-template>
64 </xsl:if>
65</xsl:template>
66
67<xsl:template name="sfinaltd">
68 <xsl:param name="spans"/>
69
70 <xsl:if test="$spans != ''">
71 <xsl:choose>
72 <xsl:when test="starts-with($spans,'0:')">0:</xsl:when>
73 <xsl:otherwise>
74 <xsl:value-of select="substring-before($spans,':')-1"/>
75 <xsl:text>:</xsl:text>
76 </xsl:otherwise>
77 </xsl:choose>
78
79 <xsl:call-template name="sfinaltd">
80 <xsl:with-param name="spans" select="substring-after($spans,':')"/>
81 </xsl:call-template>
82 </xsl:if>
83</xsl:template>
84
85<xsl:template name="entry.colnum">
86 <xsl:param name="entry" select="."/>
87
88 <xsl:choose>
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"/>
99 </xsl:call-template>
100 </xsl:when>
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"/>
108 </xsl:call-template>
109 </xsl:when>
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"/>
117 </xsl:call-template>
118 </xsl:when>
119 <!-- no idea, return 0 -->
120 <xsl:otherwise>0</xsl:otherwise>
121 </xsl:choose>
122</xsl:template>
123
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
130will determine the number of the column in which the entry should occur.
131For other <tag>entry</tag>s, nothing is returned.</para>
132</refdescription>
133<refparameter id="entry.colnum-params">
134<variablelist>
135<varlistentry><term>entry</term>
136<listitem>
137<para>The <tag>entry</tag>-element which is to be tested.</para>
138</listitem>
139</varlistentry>
140</variablelist>
141</refparameter>
142
143<refreturn id="entry.colnum-returns">
144<para>This template returns the column number if it can be determined,
145or 0 (the empty string)</para>
146</refreturn>
147</doc:template>
148
149<xsl:template name="colspec.colnum">
150 <xsl:param name="colspec" select="."/>
151 <xsl:choose>
152 <xsl:when test="$colspec/@colnum">
153 <xsl:value-of select="$colspec/@colnum"/>
154 </xsl:when>
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]"/>
160 </xsl:call-template>
161 </xsl:variable>
162 <xsl:value-of select="$prec.colspec.colnum + 1"/>
163 </xsl:when>
164 <xsl:otherwise>1</xsl:otherwise>
165 </xsl:choose>
166</xsl:template>
167
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()]"/>
174
175 <xsl:variable name="namest">
176 <xsl:choose>
177 <xsl:when test="@spanname">
178 <xsl:value-of select="$spanspec/@namest"/>
179 </xsl:when>
180 <xsl:otherwise>
181 <xsl:value-of select="$entry/@namest"/>
182 </xsl:otherwise>
183 </xsl:choose>
184 </xsl:variable>
185
186 <xsl:variable name="nameend">
187 <xsl:choose>
188 <xsl:when test="@spanname">
189 <xsl:value-of select="$spanspec/@nameend"/>
190 </xsl:when>
191 <xsl:otherwise>
192 <xsl:value-of select="$entry/@nameend"/>
193 </xsl:otherwise>
194 </xsl:choose>
195 </xsl:variable>
196
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()]"/>
202 </xsl:call-template>
203 </xsl:variable>
204
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()]"/>
210 </xsl:call-template>
211 </xsl:variable>
212
213 <xsl:choose>
214 <xsl:when test="$namest != '' and $nameend != ''">
215 <xsl:choose>
216 <xsl:when test="number($ecol) &gt;= number($scol)">
217 <xsl:value-of select="number($ecol) - number($scol) + 1"/>
218 </xsl:when>
219 <xsl:otherwise>
220 <xsl:value-of select="number($scol) - number($ecol) + 1"/>
221 </xsl:otherwise>
222 </xsl:choose>
223 </xsl:when>
224 <xsl:otherwise>1</xsl:otherwise>
225 </xsl:choose>
226</xsl:template>
227
228<xsl:template name="calculate.rowsep">
229 <xsl:param name="entry" select="."/>
230 <xsl:param name="colnum" select="0"/>
231
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'"/>
236 </xsl:call-template>
237</xsl:template>
238
239<xsl:template name="calculate.colsep">
240 <xsl:param name="entry" select="."/>
241 <xsl:param name="colnum" select="0"/>
242
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'"/>
247 </xsl:call-template>
248</xsl:template>
249
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'"/>
255
256 <xsl:variable name="tgroup" select="$row/parent::*/parent::tgroup[1]"/>
257 <xsl:variable name="tbody" select="$row/parent::*[1]"/>
258
259 <xsl:variable name="table" select="($tgroup/ancestor::table
260 |$tgroup/ancestor::informaltable
261 |$entry/ancestor::entrytbl)[last()]"/>
262
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"/>
267 </xsl:call-template>
268 </xsl:variable>
269
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"/>
274 </xsl:call-template>
275 </xsl:variable>
276
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]"/>
284
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"/>
289 </xsl:call-template>
290 </xsl:variable>
291
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"/>
296 </xsl:call-template>
297 </xsl:variable>
298
299 <xsl:choose>
300 <xsl:when test="$spanspec.value != ''">
301 <xsl:value-of select="$spanspec.value"/>
302 </xsl:when>
303 <xsl:when test="$scolspec.value != ''">
304 <xsl:value-of select="$scolspec.value"/>
305 </xsl:when>
306 <xsl:otherwise></xsl:otherwise>
307 </xsl:choose>
308 </xsl:if>
309 </xsl:variable>
310
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]"/>
316
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"/>
321 </xsl:call-template>
322 </xsl:variable>
323
324 <xsl:choose>
325 <xsl:when test="$inner.namest.value">
326 <xsl:value-of select="$inner.namest.value"/>
327 </xsl:when>
328 <xsl:otherwise></xsl:otherwise>
329 </xsl:choose>
330 </xsl:if>
331 </xsl:variable>
332
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"/>
337 </xsl:call-template>
338 </xsl:variable>
339
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"/>
344 </xsl:call-template>
345 </xsl:variable>
346
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"/>
351 </xsl:call-template>
352 </xsl:variable>
353
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 -->
359 <xsl:choose>
360 <xsl:when test="$tgroup.value != ''">
361 <xsl:value-of select="$tgroup.value"/>
362 </xsl:when>
363 <xsl:when test="$attribute = 'rowsep'">1</xsl:when>
364 <xsl:when test="$attribute = 'colsep'">1</xsl:when>
365 <xsl:otherwise><!-- empty --></xsl:otherwise>
366 </xsl:choose>
367 </xsl:variable>
368
369 <xsl:variable name="calc.colvalue">
370 <xsl:if test="$colnum &gt; 0">
371 <xsl:call-template name="colnum.colspec">
372 <xsl:with-param name="colnum" select="$colnum"/>
373 <xsl:with-param name="attribute" select="$attribute"/>
374 </xsl:call-template>
375 </xsl:if>
376 </xsl:variable>
377
378 <xsl:choose>
379 <xsl:when test="$entry.value != ''">
380 <xsl:value-of select="$entry.value"/>
381 </xsl:when>
382 <xsl:when test="$row.value != ''">
383 <xsl:value-of select="$row.value"/>
384 </xsl:when>
385 <xsl:when test="$span.value != ''">
386 <xsl:value-of select="$span.value"/>
387 </xsl:when>
388 <xsl:when test="$namest.value != ''">
389 <xsl:value-of select="$namest.value"/>
390 </xsl:when>
391 <xsl:when test="$calc.colvalue != ''">
392 <xsl:value-of select="$calc.colvalue"/>
393 </xsl:when>
394 <xsl:when test="$tbody.value != ''">
395 <xsl:value-of select="$tbody.value"/>
396 </xsl:when>
397 <xsl:when test="$tgroup.value != ''">
398 <xsl:value-of select="$tgroup.value"/>
399 </xsl:when>
400 <xsl:when test="$table.value != ''">
401 <xsl:value-of select="$table.value"/>
402 </xsl:when>
403 <xsl:otherwise>
404 <xsl:value-of select="$default.value"/>
405 </xsl:otherwise>
406 </xsl:choose>
407</xsl:template>
408
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"/>
417
418 <xsl:choose>
419 <xsl:when test="not($colspecs) or $count &gt; $colnum">
420 <!-- nop -->
421 </xsl:when>
422 <xsl:when test="$colspecs[1]/@colnum">
423 <xsl:choose>
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"/>
428 </xsl:call-template>
429 </xsl:when>
430 <xsl:otherwise>
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()&gt;1]"/>
436 <xsl:with-param name="count"
437 select="$colspecs[1]/@colnum+1"/>
438 </xsl:call-template>
439 </xsl:otherwise>
440 </xsl:choose>
441 </xsl:when>
442 <xsl:otherwise>
443 <xsl:choose>
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"/>
448 </xsl:call-template>
449 </xsl:when>
450 <xsl:otherwise>
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()&gt;1]"/>
456 <xsl:with-param name="count" select="$count+1"/>
457 </xsl:call-template>
458 </xsl:otherwise>
459 </xsl:choose>
460 </xsl:otherwise>
461 </xsl:choose>
462</xsl:template>
463
464<xsl:template name="get-attribute">
465 <xsl:param name="element" select="."/>
466 <xsl:param name="attribute" select="''"/>
467
468 <xsl:for-each select="$element/@*">
469 <xsl:if test="local-name(.) = $attribute">
470 <xsl:value-of select="."/>
471 </xsl:if>
472 </xsl:for-each>
473</xsl:template>
474
475<xsl:template name="consume-row">
476 <xsl:param name="spans"/>
477
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,':')"/>
483 </xsl:call-template>
484 </xsl:if>
485</xsl:template>
486
487<!-- Returns the table style for the context element -->
488<xsl:template name="tabstyle">
489 <xsl:param name="node" select="."/>
490
491 <xsl:variable name="tgroup" select="$node/tgroup[1] |
492 $node/ancestor-or-self::tgroup[1]"/>
493
494 <xsl:variable name="table"
495 select="($node/ancestor-or-self::table |
496 $node/ancestor-or-self::informaltable)[1]"/>
497
498 <xsl:variable name="tabstyle">
499 <xsl:choose>
500 <xsl:when test="$table/@tabstyle != ''">
501 <xsl:value-of select="normalize-space($table/@tabstyle)"/>
502 </xsl:when>
503 <xsl:when test="$tgroup/@tgroupstyle != ''">
504 <xsl:value-of select="normalize-space($tgroup/@tgroupstyle)"/>
505 </xsl:when>
506 <xsl:otherwise>
507 </xsl:otherwise>
508 </xsl:choose>
509 </xsl:variable>
510
511 <xsl:value-of select="$tabstyle"/>
512</xsl:template>
513
514</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.