source: BOOK/stylesheets/lfs-xsl/docbook-xsl-snapshot/fo/formal.xsl@ fea8fe7

systemd
Last change on this file since fea8fe7 was f8c4e94, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added LFS XSL Stylesheets.

  • Property mode set to 100644
File size: 17.9 KB
RevLine 
[f8c4e94]1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:fo="http://www.w3.org/1999/XSL/Format"
4 version='1.0'>
5
6<!-- ********************************************************************
7 $Id$
8 ********************************************************************
9
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://docbook.sf.net/release/xsl/current/ for
12 copyright and other information.
13
14 ******************************************************************** -->
15
16<!-- formal.object creates a basic block containing the
17 result of processing the object, including its title
18 and any keep-together properties.
19 The template calling formal.object may wrap these results in a
20 float or pgwide block. -->
21
22<xsl:template name="formal.object">
23 <xsl:param name="placement" select="'before'"/>
24
25 <xsl:variable name="id">
26 <xsl:call-template name="object.id"/>
27 </xsl:variable>
28
29 <xsl:variable name="content">
30 <xsl:if test="$placement = 'before'">
31 <xsl:call-template name="formal.object.heading">
32 <xsl:with-param name="placement" select="$placement"/>
33 </xsl:call-template>
34 </xsl:if>
35 <xsl:apply-templates/>
36 <xsl:if test="$placement != 'before'">
37 <xsl:call-template name="formal.object.heading">
38 <xsl:with-param name="placement" select="$placement"/>
39 </xsl:call-template>
40 </xsl:if>
41 </xsl:variable>
42
43 <xsl:variable name="keep.together">
44 <xsl:call-template name="pi.dbfo_keep-together"/>
45 </xsl:variable>
46
47 <xsl:choose>
48 <!-- tables have their own templates and
49 are not handled by formal.object -->
50 <xsl:when test="self::figure">
51 <fo:block id="{$id}"
52 xsl:use-attribute-sets="figure.properties">
53 <xsl:if test="$keep.together != ''">
54 <xsl:attribute name="keep-together.within-column"><xsl:value-of
55 select="$keep.together"/></xsl:attribute>
56 </xsl:if>
57 <xsl:copy-of select="$content"/>
58 </fo:block>
59 </xsl:when>
60 <xsl:when test="self::example">
61 <fo:block id="{$id}"
62 xsl:use-attribute-sets="example.properties">
63 <xsl:if test="$keep.together != ''">
64 <xsl:attribute name="keep-together.within-column"><xsl:value-of
65 select="$keep.together"/></xsl:attribute>
66 </xsl:if>
67 <xsl:copy-of select="$content"/>
68 </fo:block>
69 </xsl:when>
70 <xsl:when test="self::equation">
71 <fo:block id="{$id}"
72 xsl:use-attribute-sets="equation.properties">
73 <xsl:if test="$keep.together != ''">
74 <xsl:attribute name="keep-together.within-column"><xsl:value-of
75 select="$keep.together"/></xsl:attribute>
76 </xsl:if>
77 <xsl:copy-of select="$content"/>
78 </fo:block>
79 </xsl:when>
80 <xsl:when test="self::procedure">
81 <fo:block id="{$id}"
82 xsl:use-attribute-sets="procedure.properties">
83 <xsl:if test="$keep.together != ''">
84 <xsl:attribute name="keep-together.within-column"><xsl:value-of
85 select="$keep.together"/></xsl:attribute>
86 </xsl:if>
87 <xsl:copy-of select="$content"/>
88 </fo:block>
89 </xsl:when>
90 <xsl:otherwise>
91 <fo:block id="{$id}"
92 xsl:use-attribute-sets="formal.object.properties">
93 <xsl:if test="$keep.together != ''">
94 <xsl:attribute name="keep-together.within-column"><xsl:value-of
95 select="$keep.together"/></xsl:attribute>
96 </xsl:if>
97 <xsl:copy-of select="$content"/>
98 </fo:block>
99 </xsl:otherwise>
100 </xsl:choose>
101</xsl:template>
102
103<xsl:template name="formal.object.heading">
104 <xsl:param name="object" select="."/>
105 <xsl:param name="placement" select="'before'"/>
106
107 <fo:block xsl:use-attribute-sets="formal.title.properties">
108 <xsl:choose>
109 <xsl:when test="$placement = 'before'">
110 <xsl:attribute
111 name="keep-with-next.within-column">always</xsl:attribute>
112 </xsl:when>
113 <xsl:otherwise>
114 <xsl:attribute
115 name="keep-with-previous.within-column">always</xsl:attribute>
116 </xsl:otherwise>
117 </xsl:choose>
118 <xsl:apply-templates select="$object" mode="object.title.markup">
119 <xsl:with-param name="allow-anchors" select="1"/>
120 </xsl:apply-templates>
121 </fo:block>
122</xsl:template>
123
124<xsl:template name="informal.object">
125 <xsl:variable name="id">
126 <xsl:call-template name="object.id"/>
127 </xsl:variable>
128
129 <xsl:variable name="keep.together">
130 <xsl:call-template name="pi.dbfo_keep-together"/>
131 </xsl:variable>
132
133 <xsl:choose>
134 <!-- informaltables have their own templates and
135 are not handled by formal.object -->
136 <xsl:when test="local-name(.) = 'equation'">
137 <fo:block id="{$id}"
138 xsl:use-attribute-sets="equation.properties">
139 <xsl:if test="$keep.together != ''">
140 <xsl:attribute name="keep-together.within-column"><xsl:value-of
141 select="$keep.together"/></xsl:attribute>
142 </xsl:if>
143 <xsl:apply-templates/>
144 </fo:block>
145 </xsl:when>
146 <xsl:when test="local-name(.) = 'procedure'">
147 <fo:block id="{$id}"
148 xsl:use-attribute-sets="procedure.properties">
149 <xsl:if test="$keep.together != ''">
150 <xsl:attribute name="keep-together.within-column"><xsl:value-of
151 select="$keep.together"/></xsl:attribute>
152 </xsl:if>
153 <xsl:apply-templates/>
154 </fo:block>
155 </xsl:when>
156 <xsl:when test="local-name(.) = 'informalfigure'">
157 <fo:block id="{$id}"
158 xsl:use-attribute-sets="informalfigure.properties">
159 <xsl:if test="$keep.together != ''">
160 <xsl:attribute name="keep-together.within-column"><xsl:value-of
161 select="$keep.together"/></xsl:attribute>
162 </xsl:if>
163 <xsl:apply-templates/>
164 </fo:block>
165 </xsl:when>
166 <xsl:when test="local-name(.) = 'informalexample'">
167 <fo:block id="{$id}"
168 xsl:use-attribute-sets="informalexample.properties">
169 <xsl:if test="$keep.together != ''">
170 <xsl:attribute name="keep-together.within-column"><xsl:value-of
171 select="$keep.together"/></xsl:attribute>
172 </xsl:if>
173 <xsl:apply-templates/>
174 </fo:block>
175 </xsl:when>
176 <xsl:when test="local-name(.) = 'informalequation'">
177 <fo:block id="{$id}"
178 xsl:use-attribute-sets="informalequation.properties">
179 <xsl:apply-templates/>
180 </fo:block>
181 </xsl:when>
182 <xsl:otherwise>
183 <fo:block id="{$id}"
184 xsl:use-attribute-sets="informal.object.properties">
185 <xsl:if test="$keep.together != ''">
186 <xsl:attribute name="keep-together.within-column"><xsl:value-of
187 select="$keep.together"/></xsl:attribute>
188 </xsl:if>
189 <xsl:apply-templates/>
190 </fo:block>
191 </xsl:otherwise>
192 </xsl:choose>
193</xsl:template>
194
195<xsl:template name="semiformal.object">
196 <xsl:param name="placement" select="'before'"/>
197 <xsl:choose>
198 <xsl:when test="./title">
199 <xsl:call-template name="formal.object">
200 <xsl:with-param name="placement" select="$placement"/>
201 </xsl:call-template>
202 </xsl:when>
203 <xsl:otherwise>
204 <xsl:call-template name="informal.object"/>
205 </xsl:otherwise>
206 </xsl:choose>
207</xsl:template>
208
209<xsl:template match="figure">
210 <xsl:variable name="param.placement"
211 select="substring-after(normalize-space($formal.title.placement),
212 concat(local-name(.), ' '))"/>
213
214 <xsl:variable name="placement">
215 <xsl:choose>
216 <xsl:when test="contains($param.placement, ' ')">
217 <xsl:value-of select="substring-before($param.placement, ' ')"/>
218 </xsl:when>
219 <xsl:when test="$param.placement = ''">before</xsl:when>
220 <xsl:otherwise>
221 <xsl:value-of select="$param.placement"/>
222 </xsl:otherwise>
223 </xsl:choose>
224 </xsl:variable>
225
226 <xsl:variable name="figure">
227 <xsl:choose>
228 <xsl:when test="@pgwide = '1'">
229 <fo:block xsl:use-attribute-sets="pgwide.properties">
230 <xsl:call-template name="formal.object">
231 <xsl:with-param name="placement" select="$placement"/>
232 </xsl:call-template>
233 </fo:block>
234 </xsl:when>
235 <xsl:otherwise>
236 <xsl:call-template name="formal.object">
237 <xsl:with-param name="placement" select="$placement"/>
238 </xsl:call-template>
239 </xsl:otherwise>
240 </xsl:choose>
241 </xsl:variable>
242
243 <xsl:variable name="floatstyle">
244 <xsl:call-template name="floatstyle"/>
245 </xsl:variable>
246
247 <xsl:choose>
248 <xsl:when test="$floatstyle != ''">
249 <xsl:call-template name="floater">
250 <xsl:with-param name="position" select="$floatstyle"/>
251 <xsl:with-param name="content" select="$figure"/>
252 </xsl:call-template>
253 </xsl:when>
254 <xsl:otherwise>
255 <xsl:copy-of select="$figure"/>
256 </xsl:otherwise>
257 </xsl:choose>
258</xsl:template>
259
260<xsl:template match="example">
261 <xsl:variable name="param.placement"
262 select="substring-after(normalize-space($formal.title.placement),
263 concat(local-name(.), ' '))"/>
264
265 <xsl:variable name="placement">
266 <xsl:choose>
267 <xsl:when test="contains($param.placement, ' ')">
268 <xsl:value-of select="substring-before($param.placement, ' ')"/>
269 </xsl:when>
270 <xsl:when test="$param.placement = ''">before</xsl:when>
271 <xsl:otherwise>
272 <xsl:value-of select="$param.placement"/>
273 </xsl:otherwise>
274 </xsl:choose>
275 </xsl:variable>
276
277 <!-- Example doesn't have a pgwide attribute, so may use a PI -->
278 <xsl:variable name="pgwide.pi">
279 <xsl:call-template name="pi.dbfo_pgwide"/>
280 </xsl:variable>
281
282 <xsl:variable name="pgwide">
283 <xsl:choose>
284 <xsl:when test="$pgwide.pi">
285 <xsl:value-of select="$pgwide.pi"/>
286 </xsl:when>
287 <!-- child element may set pgwide -->
288 <xsl:when test="*[@pgwide]">
289 <xsl:value-of select="*[@pgwide][1]/@pgwide"/>
290 </xsl:when>
291 </xsl:choose>
292 </xsl:variable>
293
294 <!-- Get align value from internal mediaobject -->
295 <xsl:variable name="align">
296 <xsl:if test="mediaobject|mediaobjectco">
297 <xsl:variable name="olist" select="mediaobject/imageobject
298 |mediaobjectco/imageobjectco
299 |mediaobject/videoobject
300 |mediaobject/audioobject
301 |mediaobject/textobject"/>
302
303 <xsl:variable name="object.index">
304 <xsl:call-template name="select.mediaobject.index">
305 <xsl:with-param name="olist" select="$olist"/>
306 <xsl:with-param name="count" select="1"/>
307 </xsl:call-template>
308 </xsl:variable>
309
310 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
311
312 <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
313 </xsl:if>
314 </xsl:variable>
315
316 <xsl:variable name="example">
317 <xsl:choose>
318 <xsl:when test="$pgwide = '1'">
319 <fo:block xsl:use-attribute-sets="pgwide.properties">
320 <xsl:if test="$align != ''">
321 <xsl:attribute name="text-align">
322 <xsl:value-of select="$align"/>
323 </xsl:attribute>
324 </xsl:if>
325 <xsl:call-template name="formal.object">
326 <xsl:with-param name="placement" select="$placement"/>
327 </xsl:call-template>
328 </fo:block>
329 </xsl:when>
330 <xsl:otherwise>
331 <fo:block>
332 <xsl:if test="$align != ''">
333 <xsl:attribute name="text-align">
334 <xsl:value-of select="$align"/>
335 </xsl:attribute>
336 </xsl:if>
337 <xsl:call-template name="formal.object">
338 <xsl:with-param name="placement" select="$placement"/>
339 </xsl:call-template>
340 </fo:block>
341 </xsl:otherwise>
342 </xsl:choose>
343 </xsl:variable>
344
345 <xsl:variable name="floatstyle">
346 <xsl:call-template name="floatstyle"/>
347 </xsl:variable>
348
349 <xsl:choose>
350 <xsl:when test="$floatstyle != ''">
351 <xsl:call-template name="floater">
352 <xsl:with-param name="position" select="$floatstyle"/>
353 <xsl:with-param name="content" select="$example"/>
354 </xsl:call-template>
355 </xsl:when>
356 <xsl:otherwise>
357 <xsl:copy-of select="$example"/>
358 </xsl:otherwise>
359 </xsl:choose>
360
361</xsl:template>
362
363<!-- Unified handling of CALS and HTML tables, formal and not -->
364<!-- Creates a hierarchy of nested containers:
365 - Outer container does a float.
366 - Nested container does block-container for rotation
367 - Nested block contains title, layout table and footnotes
368 - Nested layout table placeholder template supports extensions.
369 - fo:table is innermost.
370 Created from the innermost and working out.
371 Not all layers apply to every table.
372-->
373<xsl:template match="table|informaltable">
374 <xsl:if test="tgroup/tbody/tr
375 |tgroup/thead/tr
376 |tgroup/tfoot/tr">
377 <xsl:message terminate="yes">
378 <xsl:text>Broken table: tr descendent of CALS Table.</xsl:text>
379 <xsl:text>The text in the first tr is:&#10;</xsl:text>
380 <xsl:value-of
381 select="(tgroup//tr)[1]"/>
382 </xsl:message>
383 </xsl:if>
384 <xsl:if test="not(tgroup) and .//row">
385 <xsl:message terminate="yes">
386 <xsl:text>Broken table: row descendent of HTML table.</xsl:text>
387 <xsl:text>The text in the first row is:&#10;</xsl:text>
388 <xsl:value-of
389 select=".//row[1]"/>
390 </xsl:message>
391 </xsl:if>
392
393 <!-- Contains fo:table, not title or footnotes -->
394 <xsl:variable name="table.content">
395 <xsl:call-template name="make.table.content"/>
396 </xsl:variable>
397
398 <!-- Optional layout table template for extensions -->
399 <xsl:variable name="table.layout">
400 <xsl:call-template name="table.layout">
401 <xsl:with-param name="table.content" select="$table.content"/>
402 </xsl:call-template>
403 </xsl:variable>
404
405 <!-- fo:block contains title, layout table, and footnotes -->
406 <xsl:variable name="table.block">
407 <xsl:call-template name="table.block">
408 <xsl:with-param name="table.layout" select="$table.layout"/>
409 </xsl:call-template>
410 </xsl:variable>
411
412 <!-- pgwide or orient container -->
413 <xsl:variable name="table.container">
414 <xsl:call-template name="table.container">
415 <xsl:with-param name="table.block" select="$table.block"/>
416 </xsl:call-template>
417 </xsl:variable>
418
419 <!-- float or not -->
420 <xsl:variable name="floatstyle">
421 <xsl:call-template name="floatstyle"/>
422 </xsl:variable>
423
424 <xsl:choose>
425 <xsl:when test="$floatstyle != ''">
426 <xsl:call-template name="floater">
427 <xsl:with-param name="position" select="$floatstyle"/>
428 <xsl:with-param name="content" select="$table.container"/>
429 </xsl:call-template>
430 </xsl:when>
431 <xsl:otherwise>
432 <xsl:copy-of select="$table.container"/>
433 </xsl:otherwise>
434 </xsl:choose>
435</xsl:template>
436
437
438<xsl:template match="equation">
439 <xsl:variable name="param.placement"
440 select="substring-after(normalize-space($formal.title.placement),
441 concat(local-name(.), ' '))"/>
442
443 <xsl:variable name="placement">
444 <xsl:choose>
445 <xsl:when test="contains($param.placement, ' ')">
446 <xsl:value-of select="substring-before($param.placement, ' ')"/>
447 </xsl:when>
448 <xsl:when test="$param.placement = ''">before</xsl:when>
449 <xsl:otherwise>
450 <xsl:value-of select="$param.placement"/>
451 </xsl:otherwise>
452 </xsl:choose>
453 </xsl:variable>
454
455 <!-- Equation doesn't have a pgwide attribute, so may use a PI -->
456 <xsl:variable name="pgwide">
457 <xsl:call-template name="pi.dbfo_pgwide"/>
458 </xsl:variable>
459
460 <xsl:variable name="equation">
461 <xsl:choose>
462 <xsl:when test="$pgwide = '1'">
463 <fo:block xsl:use-attribute-sets="pgwide.properties">
464 <xsl:call-template name="semiformal.object">
465 <xsl:with-param name="placement" select="$placement"/>
466 </xsl:call-template>
467 </fo:block>
468 </xsl:when>
469 <xsl:otherwise>
470 <xsl:call-template name="semiformal.object">
471 <xsl:with-param name="placement" select="$placement"/>
472 </xsl:call-template>
473 </xsl:otherwise>
474 </xsl:choose>
475 </xsl:variable>
476
477 <xsl:variable name="floatstyle">
478 <xsl:call-template name="floatstyle"/>
479 </xsl:variable>
480
481 <xsl:choose>
482 <xsl:when test="$floatstyle != ''">
483 <xsl:call-template name="floater">
484 <xsl:with-param name="position" select="$floatstyle"/>
485 <xsl:with-param name="content" select="$equation"/>
486 </xsl:call-template>
487 </xsl:when>
488 <xsl:otherwise>
489 <xsl:copy-of select="$equation"/>
490 </xsl:otherwise>
491 </xsl:choose>
492</xsl:template>
493
494<xsl:template match="figure/title"></xsl:template>
495<xsl:template match="figure/titleabbrev"></xsl:template>
496<xsl:template match="table/title"></xsl:template>
497<xsl:template match="table/titleabbrev"></xsl:template>
498<xsl:template match="table/textobject"></xsl:template>
499<xsl:template match="example/title"></xsl:template>
500<xsl:template match="example/titleabbrev"></xsl:template>
501<xsl:template match="equation/title"></xsl:template>
502<xsl:template match="equation/titleabbrev"></xsl:template>
503
504<xsl:template match="informalfigure">
505 <xsl:call-template name="informal.object"/>
506</xsl:template>
507
508<xsl:template match="informalexample">
509 <xsl:call-template name="informal.object"/>
510</xsl:template>
511
512<xsl:template match="informaltable/textobject"></xsl:template>
513
514<xsl:template match="informalequation">
515 <xsl:call-template name="informal.object"/>
516</xsl:template>
517
518<xsl:template name="floatstyle">
519 <xsl:if test="(@float and @float != '0') or @floatstyle != ''">
520 <xsl:choose>
521 <xsl:when test="@floatstyle != ''">
522 <xsl:value-of select="@floatstyle"/>
523 </xsl:when>
524 <xsl:when test="@float = '1'">
525 <xsl:value-of select="$default.float.class"/>
526 </xsl:when>
527 <xsl:otherwise>
528 <xsl:value-of select="@float"/>
529 </xsl:otherwise>
530 </xsl:choose>
531 </xsl:if>
532</xsl:template>
533
534</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.