2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:fo="http://www.w3.org/1999/XSL/Format"
6 <!-- ********************************************************************
7 $Id: formal.xsl 8417 2009-04-24 16:20:18Z bobstayton $
8 ********************************************************************
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.
14 ******************************************************************** -->
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. -->
22 <xsl:template name="formal.object">
23 <xsl:param name="placement" select="'before'"/>
25 <xsl:variable name="id">
26 <xsl:call-template name="object.id"/>
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"/>
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"/>
43 <xsl:variable name="keep.together">
44 <xsl:call-template name="pi.dbfo_keep-together"/>
48 <!-- tables have their own templates and
49 are not handled by formal.object -->
50 <xsl:when test="self::figure">
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>
57 <xsl:copy-of select="$content"/>
60 <xsl:when test="self::example">
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>
67 <xsl:copy-of select="$content"/>
70 <xsl:when test="self::equation">
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>
77 <xsl:copy-of select="$content"/>
80 <xsl:when test="self::procedure">
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>
87 <xsl:copy-of select="$content"/>
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>
97 <xsl:copy-of select="$content"/>
103 <xsl:template name="formal.object.heading">
104 <xsl:param name="object" select="."/>
105 <xsl:param name="placement" select="'before'"/>
107 <fo:block xsl:use-attribute-sets="formal.title.properties">
109 <xsl:when test="$placement = 'before'">
111 name="keep-with-next.within-column">always</xsl:attribute>
115 name="keep-with-previous.within-column">always</xsl:attribute>
118 <xsl:apply-templates select="$object" mode="object.title.markup">
119 <xsl:with-param name="allow-anchors" select="1"/>
120 </xsl:apply-templates>
124 <xsl:template name="informal.object">
125 <xsl:variable name="id">
126 <xsl:call-template name="object.id"/>
129 <xsl:variable name="keep.together">
130 <xsl:call-template name="pi.dbfo_keep-together"/>
133 <!-- Some don't have a pgwide attribute, so may use a PI -->
134 <xsl:variable name="pgwide.pi">
135 <xsl:call-template name="pi.dbfo_pgwide"/>
138 <xsl:variable name="pgwide">
140 <xsl:when test="@pgwide">
141 <xsl:value-of select="@pgwide"/>
143 <xsl:when test="$pgwide.pi">
144 <xsl:value-of select="$pgwide.pi"/>
146 <!-- child element may set pgwide -->
147 <xsl:when test="*[@pgwide]">
148 <xsl:value-of select="*[@pgwide][1]/@pgwide"/>
154 <!-- informaltables have their own templates and
155 are not handled by formal.object -->
156 <xsl:when test="local-name(.) = 'equation'">
158 <xsl:when test="$pgwide = '1'">
160 xsl:use-attribute-sets="pgwide.properties
161 equation.properties">
162 <xsl:if test="$keep.together != ''">
163 <xsl:attribute name="keep-together.within-column"><xsl:value-of
164 select="$keep.together"/></xsl:attribute>
166 <xsl:apply-templates/>
171 xsl:use-attribute-sets="equation.properties">
172 <xsl:if test="$keep.together != ''">
173 <xsl:attribute name="keep-together.within-column"><xsl:value-of
174 select="$keep.together"/></xsl:attribute>
176 <xsl:apply-templates/>
181 <xsl:when test="local-name(.) = 'procedure'">
183 xsl:use-attribute-sets="procedure.properties">
184 <xsl:if test="$keep.together != ''">
185 <xsl:attribute name="keep-together.within-column"><xsl:value-of
186 select="$keep.together"/></xsl:attribute>
188 <xsl:apply-templates/>
191 <xsl:when test="local-name(.) = 'informalfigure'">
193 <xsl:when test="$pgwide = '1'">
195 xsl:use-attribute-sets="pgwide.properties
196 informalfigure.properties">
197 <xsl:if test="$keep.together != ''">
198 <xsl:attribute name="keep-together.within-column"><xsl:value-of
199 select="$keep.together"/></xsl:attribute>
201 <xsl:apply-templates/>
206 xsl:use-attribute-sets="informalfigure.properties">
207 <xsl:if test="$keep.together != ''">
208 <xsl:attribute name="keep-together.within-column"><xsl:value-of
209 select="$keep.together"/></xsl:attribute>
211 <xsl:apply-templates/>
216 <xsl:when test="local-name(.) = 'informalexample'">
218 <xsl:when test="$pgwide = '1'">
220 xsl:use-attribute-sets="pgwide.properties
221 informalexample.properties">
222 <xsl:if test="$keep.together != ''">
223 <xsl:attribute name="keep-together.within-column"><xsl:value-of
224 select="$keep.together"/></xsl:attribute>
226 <xsl:apply-templates/>
231 xsl:use-attribute-sets="informalexample.properties">
232 <xsl:if test="$keep.together != ''">
233 <xsl:attribute name="keep-together.within-column"><xsl:value-of
234 select="$keep.together"/></xsl:attribute>
236 <xsl:apply-templates/>
241 <xsl:when test="local-name(.) = 'informalequation'">
243 <xsl:when test="$pgwide = '1'">
245 xsl:use-attribute-sets="pgwide.properties
246 informalequation.properties">
247 <xsl:if test="$keep.together != ''">
248 <xsl:attribute name="keep-together.within-column"><xsl:value-of
249 select="$keep.together"/></xsl:attribute>
251 <xsl:apply-templates/>
256 xsl:use-attribute-sets="informalequation.properties">
257 <xsl:if test="$keep.together != ''">
258 <xsl:attribute name="keep-together.within-column"><xsl:value-of
259 select="$keep.together"/></xsl:attribute>
261 <xsl:apply-templates/>
268 xsl:use-attribute-sets="informal.object.properties">
269 <xsl:if test="$keep.together != ''">
270 <xsl:attribute name="keep-together.within-column"><xsl:value-of
271 select="$keep.together"/></xsl:attribute>
273 <xsl:apply-templates/>
279 <xsl:template name="semiformal.object">
280 <xsl:param name="placement" select="'before'"/>
282 <xsl:when test="./title">
283 <xsl:call-template name="formal.object">
284 <xsl:with-param name="placement" select="$placement"/>
288 <xsl:call-template name="informal.object"/>
293 <xsl:template match="figure">
294 <xsl:variable name="param.placement"
295 select="substring-after(normalize-space($formal.title.placement),
296 concat(local-name(.), ' '))"/>
298 <xsl:variable name="placement">
300 <xsl:when test="contains($param.placement, ' ')">
301 <xsl:value-of select="substring-before($param.placement, ' ')"/>
303 <xsl:when test="$param.placement = ''">before</xsl:when>
305 <xsl:value-of select="$param.placement"/>
310 <xsl:variable name="figure">
312 <xsl:when test="@pgwide = '1'">
313 <fo:block xsl:use-attribute-sets="pgwide.properties">
314 <xsl:call-template name="formal.object">
315 <xsl:with-param name="placement" select="$placement"/>
320 <xsl:call-template name="formal.object">
321 <xsl:with-param name="placement" select="$placement"/>
327 <xsl:variable name="floatstyle">
328 <xsl:call-template name="floatstyle"/>
332 <xsl:when test="$floatstyle != ''">
333 <xsl:call-template name="floater">
334 <xsl:with-param name="position" select="$floatstyle"/>
335 <xsl:with-param name="content" select="$figure"/>
339 <xsl:copy-of select="$figure"/>
344 <xsl:template match="example">
345 <xsl:variable name="param.placement"
346 select="substring-after(normalize-space($formal.title.placement),
347 concat(local-name(.), ' '))"/>
349 <xsl:variable name="placement">
351 <xsl:when test="contains($param.placement, ' ')">
352 <xsl:value-of select="substring-before($param.placement, ' ')"/>
354 <xsl:when test="$param.placement = ''">before</xsl:when>
356 <xsl:value-of select="$param.placement"/>
361 <!-- Example doesn't have a pgwide attribute, so may use a PI -->
362 <xsl:variable name="pgwide.pi">
363 <xsl:call-template name="pi.dbfo_pgwide"/>
366 <xsl:variable name="pgwide">
368 <xsl:when test="$pgwide.pi">
369 <xsl:value-of select="$pgwide.pi"/>
371 <!-- child element may set pgwide -->
372 <xsl:when test="*[@pgwide]">
373 <xsl:value-of select="*[@pgwide][1]/@pgwide"/>
378 <!-- Get align value from internal mediaobject -->
379 <xsl:variable name="align">
380 <xsl:if test="mediaobject|mediaobjectco">
381 <xsl:variable name="olist" select="mediaobject/imageobject
382 |mediaobjectco/imageobjectco
383 |mediaobject/videoobject
384 |mediaobject/audioobject
385 |mediaobject/textobject"/>
387 <xsl:variable name="object.index">
388 <xsl:call-template name="select.mediaobject.index">
389 <xsl:with-param name="olist" select="$olist"/>
390 <xsl:with-param name="count" select="1"/>
394 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
396 <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
400 <xsl:variable name="example">
402 <xsl:when test="$pgwide = '1'">
403 <fo:block xsl:use-attribute-sets="pgwide.properties">
404 <xsl:if test="$align != ''">
405 <xsl:attribute name="text-align">
406 <xsl:value-of select="$align"/>
409 <xsl:call-template name="formal.object">
410 <xsl:with-param name="placement" select="$placement"/>
416 <xsl:if test="$align != ''">
417 <xsl:attribute name="text-align">
418 <xsl:value-of select="$align"/>
421 <xsl:call-template name="formal.object">
422 <xsl:with-param name="placement" select="$placement"/>
429 <xsl:variable name="floatstyle">
430 <xsl:call-template name="floatstyle"/>
434 <xsl:when test="$floatstyle != ''">
435 <xsl:call-template name="floater">
436 <xsl:with-param name="position" select="$floatstyle"/>
437 <xsl:with-param name="content" select="$example"/>
441 <xsl:copy-of select="$example"/>
447 <!-- Unified handling of CALS and HTML tables, formal and not -->
448 <!-- Creates a hierarchy of nested containers:
449 - Outer container does a float.
450 - Nested container does block-container for rotation
451 - Nested block contains title, layout table and footnotes
452 - Nested layout table placeholder template supports extensions.
453 - fo:table is innermost.
454 Created from the innermost and working out.
455 Not all layers apply to every table.
457 <xsl:template match="table|informaltable">
458 <xsl:if test="tgroup/tbody/tr
461 <xsl:message terminate="yes">
462 <xsl:text>Broken table: tr descendent of CALS Table.</xsl:text>
463 <xsl:text>The text in the first tr is: </xsl:text>
465 select="(tgroup//tr)[1]"/>
468 <xsl:if test="not(tgroup) and .//row">
469 <xsl:message terminate="yes">
470 <xsl:text>Broken table: row descendent of HTML table.</xsl:text>
471 <xsl:text>The text in the first row is: </xsl:text>
477 <!-- Contains fo:table, not title or footnotes -->
478 <xsl:variable name="table.content">
479 <xsl:call-template name="make.table.content"/>
482 <!-- Optional layout table template for extensions -->
483 <xsl:variable name="table.layout">
484 <xsl:call-template name="table.layout">
485 <xsl:with-param name="table.content" select="$table.content"/>
489 <!-- fo:block contains title, layout table, and footnotes -->
490 <xsl:variable name="table.block">
491 <xsl:call-template name="table.block">
492 <xsl:with-param name="table.layout" select="$table.layout"/>
496 <!-- pgwide or orient container -->
497 <xsl:variable name="table.container">
498 <xsl:call-template name="table.container">
499 <xsl:with-param name="table.block" select="$table.block"/>
503 <!-- float or not -->
504 <xsl:variable name="floatstyle">
505 <xsl:call-template name="floatstyle"/>
509 <xsl:when test="$floatstyle != ''">
510 <xsl:call-template name="floater">
511 <xsl:with-param name="position" select="$floatstyle"/>
512 <xsl:with-param name="content" select="$table.container"/>
516 <xsl:copy-of select="$table.container"/>
522 <xsl:template match="equation">
523 <xsl:variable name="param.placement"
524 select="substring-after(normalize-space($formal.title.placement),
525 concat(local-name(.), ' '))"/>
527 <xsl:variable name="placement">
529 <xsl:when test="contains($param.placement, ' ')">
530 <xsl:value-of select="substring-before($param.placement, ' ')"/>
532 <xsl:when test="$param.placement = ''">before</xsl:when>
534 <xsl:value-of select="$param.placement"/>
539 <!-- Equation doesn't have a pgwide attribute, so may use a PI -->
540 <xsl:variable name="pgwide">
541 <xsl:call-template name="pi.dbfo_pgwide"/>
544 <xsl:variable name="equation">
546 <xsl:when test="$pgwide = '1'">
547 <fo:block xsl:use-attribute-sets="pgwide.properties">
548 <xsl:call-template name="semiformal.object">
549 <xsl:with-param name="placement" select="$placement"/>
554 <xsl:call-template name="semiformal.object">
555 <xsl:with-param name="placement" select="$placement"/>
561 <xsl:variable name="floatstyle">
562 <xsl:call-template name="floatstyle"/>
566 <xsl:when test="$floatstyle != ''">
567 <xsl:call-template name="floater">
568 <xsl:with-param name="position" select="$floatstyle"/>
569 <xsl:with-param name="content" select="$equation"/>
573 <xsl:copy-of select="$equation"/>
578 <xsl:template match="figure/title"></xsl:template>
579 <xsl:template match="figure/titleabbrev"></xsl:template>
580 <xsl:template match="table/title"></xsl:template>
581 <xsl:template match="table/titleabbrev"></xsl:template>
582 <xsl:template match="table/textobject"></xsl:template>
583 <xsl:template match="example/title"></xsl:template>
584 <xsl:template match="example/titleabbrev"></xsl:template>
585 <xsl:template match="equation/title"></xsl:template>
586 <xsl:template match="equation/titleabbrev"></xsl:template>
588 <xsl:template match="informalfigure">
589 <xsl:call-template name="informal.object"/>
592 <xsl:template match="informalexample">
593 <xsl:call-template name="informal.object"/>
596 <xsl:template match="informaltable/textobject"></xsl:template>
598 <xsl:template match="informalequation">
599 <xsl:call-template name="informal.object"/>
602 <xsl:template name="floatstyle">
603 <xsl:if test="(@float and @float != '0') or @floatstyle != ''">
605 <xsl:when test="@floatstyle != ''">
606 <xsl:value-of select="@floatstyle"/>
608 <xsl:when test="@float = '1'">
609 <xsl:value-of select="$default.float.class"/>
612 <xsl:value-of select="@float"/>