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 8544 2009-12-02 06:06:53Z 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:call-template name="equation.without.title"/>
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:call-template name="equation.without.title"/>
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="equation.without.title">
280 <!-- Lay out equation and number next to equation using a table -->
281 <fo:table table-layout="fixed" width="100%">
282 <fo:table-column column-width="proportional-column-width(15)"/>
283 <fo:table-column column-width="proportional-column-width(1)"/>
284 <fo:table-body start-indent="0pt" end-indent="0pt">
286 <fo:table-cell padding-end="6pt">
288 <xsl:apply-templates/>
291 <fo:table-cell xsl:use-attribute-sets="equation.number.properties">
293 <xsl:text>(</xsl:text>
294 <xsl:apply-templates select="." mode="label.markup"/>
295 <xsl:text>)</xsl:text>
303 <xsl:template name="semiformal.object">
304 <xsl:param name="placement" select="'before'"/>
306 <xsl:when test="title or info/title">
307 <xsl:call-template name="formal.object">
308 <xsl:with-param name="placement" select="$placement"/>
312 <xsl:call-template name="informal.object"/>
317 <xsl:template match="figure">
318 <xsl:variable name="param.placement"
319 select="substring-after(normalize-space($formal.title.placement),
320 concat(local-name(.), ' '))"/>
322 <xsl:variable name="placement">
324 <xsl:when test="contains($param.placement, ' ')">
325 <xsl:value-of select="substring-before($param.placement, ' ')"/>
327 <xsl:when test="$param.placement = ''">before</xsl:when>
329 <xsl:value-of select="$param.placement"/>
334 <xsl:variable name="figure">
336 <xsl:when test="@pgwide = '1'">
337 <fo:block xsl:use-attribute-sets="pgwide.properties">
338 <xsl:call-template name="formal.object">
339 <xsl:with-param name="placement" select="$placement"/>
344 <xsl:call-template name="formal.object">
345 <xsl:with-param name="placement" select="$placement"/>
351 <xsl:variable name="floatstyle">
352 <xsl:call-template name="floatstyle"/>
356 <xsl:when test="$floatstyle != ''">
357 <xsl:call-template name="floater">
358 <xsl:with-param name="position" select="$floatstyle"/>
359 <xsl:with-param name="content" select="$figure"/>
363 <xsl:copy-of select="$figure"/>
368 <xsl:template match="example">
369 <xsl:variable name="param.placement"
370 select="substring-after(normalize-space($formal.title.placement),
371 concat(local-name(.), ' '))"/>
373 <xsl:variable name="placement">
375 <xsl:when test="contains($param.placement, ' ')">
376 <xsl:value-of select="substring-before($param.placement, ' ')"/>
378 <xsl:when test="$param.placement = ''">before</xsl:when>
380 <xsl:value-of select="$param.placement"/>
385 <!-- Example doesn't have a pgwide attribute, so may use a PI -->
386 <xsl:variable name="pgwide.pi">
387 <xsl:call-template name="pi.dbfo_pgwide"/>
390 <xsl:variable name="pgwide">
392 <xsl:when test="$pgwide.pi">
393 <xsl:value-of select="$pgwide.pi"/>
395 <!-- child element may set pgwide -->
396 <xsl:when test="*[@pgwide]">
397 <xsl:value-of select="*[@pgwide][1]/@pgwide"/>
402 <!-- Get align value from internal mediaobject -->
403 <xsl:variable name="align">
404 <xsl:if test="mediaobject|mediaobjectco">
405 <xsl:variable name="olist" select="mediaobject/imageobject
406 |mediaobjectco/imageobjectco
407 |mediaobject/videoobject
408 |mediaobject/audioobject
409 |mediaobject/textobject"/>
411 <xsl:variable name="object.index">
412 <xsl:call-template name="select.mediaobject.index">
413 <xsl:with-param name="olist" select="$olist"/>
414 <xsl:with-param name="count" select="1"/>
418 <xsl:variable name="object" select="$olist[position() = $object.index]"/>
420 <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
424 <xsl:variable name="example">
426 <xsl:when test="$pgwide = '1'">
427 <fo:block xsl:use-attribute-sets="pgwide.properties">
428 <xsl:if test="$align != ''">
429 <xsl:attribute name="text-align">
430 <xsl:value-of select="$align"/>
433 <xsl:call-template name="formal.object">
434 <xsl:with-param name="placement" select="$placement"/>
440 <xsl:if test="$align != ''">
441 <xsl:attribute name="text-align">
442 <xsl:value-of select="$align"/>
445 <xsl:call-template name="formal.object">
446 <xsl:with-param name="placement" select="$placement"/>
453 <xsl:variable name="floatstyle">
454 <xsl:call-template name="floatstyle"/>
458 <xsl:when test="$floatstyle != ''">
459 <xsl:call-template name="floater">
460 <xsl:with-param name="position" select="$floatstyle"/>
461 <xsl:with-param name="content" select="$example"/>
465 <xsl:copy-of select="$example"/>
471 <!-- Unified handling of CALS and HTML tables, formal and not -->
472 <!-- Creates a hierarchy of nested containers:
473 - Outer container does a float.
474 - Nested container does block-container for rotation
475 - Nested block contains title, layout table and footnotes
476 - Nested layout table placeholder template supports extensions.
477 - fo:table is innermost.
478 Created from the innermost and working out.
479 Not all layers apply to every table.
481 <xsl:template match="table|informaltable">
482 <xsl:if test="tgroup/tbody/tr
485 <xsl:message terminate="yes">
486 <xsl:text>Broken table: tr descendent of CALS Table.</xsl:text>
487 <xsl:text>The text in the first tr is: </xsl:text>
489 select="(tgroup//tr)[1]"/>
492 <xsl:if test="not(tgroup) and .//row">
493 <xsl:message terminate="yes">
494 <xsl:text>Broken table: row descendent of HTML table.</xsl:text>
495 <xsl:text>The text in the first row is: </xsl:text>
501 <!-- Contains fo:table, not title or footnotes -->
502 <xsl:variable name="table.content">
503 <xsl:call-template name="make.table.content"/>
506 <!-- Optional layout table template for extensions -->
507 <xsl:variable name="table.layout">
508 <xsl:call-template name="table.layout">
509 <xsl:with-param name="table.content" select="$table.content"/>
513 <!-- fo:block contains title, layout table, and footnotes -->
514 <xsl:variable name="table.block">
515 <xsl:call-template name="table.block">
516 <xsl:with-param name="table.layout" select="$table.layout"/>
520 <!-- pgwide or orient container -->
521 <xsl:variable name="table.container">
522 <xsl:call-template name="table.container">
523 <xsl:with-param name="table.block" select="$table.block"/>
527 <!-- float or not -->
528 <xsl:variable name="floatstyle">
529 <xsl:call-template name="floatstyle"/>
533 <xsl:when test="$floatstyle != ''">
534 <xsl:call-template name="floater">
535 <xsl:with-param name="position" select="$floatstyle"/>
536 <xsl:with-param name="content" select="$table.container"/>
540 <xsl:copy-of select="$table.container"/>
546 <xsl:template match="equation">
547 <xsl:variable name="param.placement"
548 select="substring-after(normalize-space($formal.title.placement),
549 concat(local-name(.), ' '))"/>
551 <xsl:variable name="placement">
553 <xsl:when test="contains($param.placement, ' ')">
554 <xsl:value-of select="substring-before($param.placement, ' ')"/>
556 <xsl:when test="$param.placement = ''">before</xsl:when>
558 <xsl:value-of select="$param.placement"/>
563 <!-- Equation doesn't have a pgwide attribute, so may use a PI -->
564 <xsl:variable name="pgwide">
565 <xsl:call-template name="pi.dbfo_pgwide"/>
568 <xsl:variable name="equation">
570 <xsl:when test="$pgwide = '1'">
571 <fo:block xsl:use-attribute-sets="pgwide.properties">
572 <xsl:call-template name="semiformal.object">
573 <xsl:with-param name="placement" select="$placement"/>
578 <xsl:call-template name="semiformal.object">
579 <xsl:with-param name="placement" select="$placement"/>
585 <xsl:variable name="floatstyle">
586 <xsl:call-template name="floatstyle"/>
590 <xsl:when test="$floatstyle != ''">
591 <xsl:call-template name="floater">
592 <xsl:with-param name="position" select="$floatstyle"/>
593 <xsl:with-param name="content" select="$equation"/>
597 <xsl:copy-of select="$equation"/>
602 <xsl:template match="figure/title"></xsl:template>
603 <xsl:template match="figure/titleabbrev"></xsl:template>
604 <xsl:template match="table/title"></xsl:template>
605 <xsl:template match="table/titleabbrev"></xsl:template>
606 <xsl:template match="table/textobject"></xsl:template>
607 <xsl:template match="example/title"></xsl:template>
608 <xsl:template match="example/titleabbrev"></xsl:template>
609 <xsl:template match="equation/title"></xsl:template>
610 <xsl:template match="equation/titleabbrev"></xsl:template>
612 <xsl:template match="informalfigure">
613 <xsl:call-template name="informal.object"/>
616 <xsl:template match="informalexample">
617 <xsl:call-template name="informal.object"/>
620 <xsl:template match="informaltable/textobject"></xsl:template>
622 <xsl:template match="informalequation">
623 <xsl:call-template name="informal.object"/>
626 <xsl:template name="floatstyle">
627 <xsl:if test="(@float and @float != '0') or @floatstyle != ''">
629 <xsl:when test="@floatstyle != ''">
630 <xsl:value-of select="@floatstyle"/>
632 <xsl:when test="@float = '1'">
633 <xsl:value-of select="$default.float.class"/>
636 <xsl:value-of select="@float"/>