]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/evergreen_docbook_files/docbook-xsl-1.75.2/fo/formal.xsl
Capitalized the start of a sentence in the bucket section of cataloging.
[working/Evergreen.git] / stylesheets / evergreen_docbook_files / docbook-xsl-1.75.2 / fo / formal.xsl
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: formal.xsl 8417 2009-04-24 16:20:18Z bobstayton $
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   <!-- 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"/>
136   </xsl:variable>
137
138   <xsl:variable name="pgwide">
139     <xsl:choose>
140       <xsl:when test="@pgwide">
141         <xsl:value-of select="@pgwide"/>
142       </xsl:when>
143       <xsl:when test="$pgwide.pi">
144         <xsl:value-of select="$pgwide.pi"/>
145       </xsl:when>
146       <!-- child element may set pgwide -->
147       <xsl:when test="*[@pgwide]">
148         <xsl:value-of select="*[@pgwide][1]/@pgwide"/>
149       </xsl:when>
150     </xsl:choose>
151   </xsl:variable>
152
153   <xsl:choose>
154     <!-- informaltables have their own templates and 
155          are not handled by formal.object -->
156     <xsl:when test="local-name(.) = 'equation'">
157       <xsl:choose>
158         <xsl:when test="$pgwide = '1'">
159           <fo:block id="{$id}"
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>
165             </xsl:if>
166             <xsl:apply-templates/>
167           </fo:block>
168         </xsl:when>
169         <xsl:otherwise>
170           <fo:block id="{$id}"
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>
175             </xsl:if>
176             <xsl:apply-templates/>
177           </fo:block>
178         </xsl:otherwise>
179       </xsl:choose>
180     </xsl:when>
181     <xsl:when test="local-name(.) = 'procedure'">
182       <fo:block id="{$id}"
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>
187         </xsl:if>
188         <xsl:apply-templates/>
189       </fo:block>
190     </xsl:when>
191     <xsl:when test="local-name(.) = 'informalfigure'">
192       <xsl:choose>
193         <xsl:when test="$pgwide = '1'">
194           <fo:block id="{$id}"
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>
200             </xsl:if>
201             <xsl:apply-templates/>
202           </fo:block>
203         </xsl:when>
204         <xsl:otherwise>
205           <fo:block id="{$id}"
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>
210             </xsl:if>
211             <xsl:apply-templates/>
212           </fo:block>
213         </xsl:otherwise>
214       </xsl:choose>
215     </xsl:when>
216     <xsl:when test="local-name(.) = 'informalexample'">
217       <xsl:choose>
218         <xsl:when test="$pgwide = '1'">
219           <fo:block id="{$id}"
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>
225             </xsl:if>
226             <xsl:apply-templates/>
227           </fo:block>
228         </xsl:when>
229         <xsl:otherwise>
230           <fo:block id="{$id}"
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>
235             </xsl:if>
236             <xsl:apply-templates/>
237           </fo:block>
238         </xsl:otherwise>
239       </xsl:choose>
240     </xsl:when>
241     <xsl:when test="local-name(.) = 'informalequation'">
242       <xsl:choose>
243         <xsl:when test="$pgwide = '1'">
244           <fo:block id="{$id}"
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>
250             </xsl:if>
251             <xsl:apply-templates/>
252           </fo:block>
253         </xsl:when>
254         <xsl:otherwise>
255           <fo:block id="{$id}"
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>
260             </xsl:if>
261             <xsl:apply-templates/>
262           </fo:block>
263         </xsl:otherwise>
264       </xsl:choose>
265     </xsl:when>
266     <xsl:otherwise>
267       <fo:block id="{$id}" 
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>
272         </xsl:if>
273         <xsl:apply-templates/>
274       </fo:block>
275     </xsl:otherwise>
276   </xsl:choose>
277 </xsl:template>
278
279 <xsl:template name="semiformal.object">
280   <xsl:param name="placement" select="'before'"/>
281   <xsl:choose>
282     <xsl:when test="./title">
283       <xsl:call-template name="formal.object">
284         <xsl:with-param name="placement" select="$placement"/>
285       </xsl:call-template>
286     </xsl:when>
287     <xsl:otherwise>
288       <xsl:call-template name="informal.object"/>
289     </xsl:otherwise>
290   </xsl:choose>
291 </xsl:template>
292
293 <xsl:template match="figure">
294   <xsl:variable name="param.placement"
295               select="substring-after(normalize-space($formal.title.placement),
296                                       concat(local-name(.), ' '))"/>
297
298   <xsl:variable name="placement">
299     <xsl:choose>
300       <xsl:when test="contains($param.placement, ' ')">
301         <xsl:value-of select="substring-before($param.placement, ' ')"/>
302       </xsl:when>
303       <xsl:when test="$param.placement = ''">before</xsl:when>
304       <xsl:otherwise>
305         <xsl:value-of select="$param.placement"/>
306       </xsl:otherwise>
307     </xsl:choose>
308   </xsl:variable>
309
310   <xsl:variable name="figure">
311     <xsl:choose>
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"/>
316           </xsl:call-template>
317         </fo:block>
318       </xsl:when>
319       <xsl:otherwise>
320         <xsl:call-template name="formal.object">
321           <xsl:with-param name="placement" select="$placement"/>
322         </xsl:call-template>
323       </xsl:otherwise>
324     </xsl:choose>
325   </xsl:variable>
326
327   <xsl:variable name="floatstyle">
328     <xsl:call-template name="floatstyle"/>
329   </xsl:variable>
330
331   <xsl:choose>
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"/>
336       </xsl:call-template>
337     </xsl:when>
338     <xsl:otherwise>
339       <xsl:copy-of select="$figure"/>
340     </xsl:otherwise>
341   </xsl:choose>
342 </xsl:template>
343
344 <xsl:template match="example">
345   <xsl:variable name="param.placement"
346              select="substring-after(normalize-space($formal.title.placement),
347                                      concat(local-name(.), ' '))"/>
348
349   <xsl:variable name="placement">
350     <xsl:choose>
351       <xsl:when test="contains($param.placement, ' ')">
352         <xsl:value-of select="substring-before($param.placement, ' ')"/>
353       </xsl:when>
354       <xsl:when test="$param.placement = ''">before</xsl:when>
355       <xsl:otherwise>
356         <xsl:value-of select="$param.placement"/>
357       </xsl:otherwise>
358     </xsl:choose>
359   </xsl:variable>
360
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"/>
364   </xsl:variable>
365
366   <xsl:variable name="pgwide">
367     <xsl:choose>
368       <xsl:when test="$pgwide.pi">
369         <xsl:value-of select="$pgwide.pi"/>
370       </xsl:when>
371       <!-- child element may set pgwide -->
372       <xsl:when test="*[@pgwide]">
373         <xsl:value-of select="*[@pgwide][1]/@pgwide"/>
374       </xsl:when>
375     </xsl:choose>
376   </xsl:variable>
377
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"/>
386
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"/>
391         </xsl:call-template>
392       </xsl:variable>
393
394       <xsl:variable name="object" select="$olist[position() = $object.index]"/>
395
396       <xsl:value-of select="$object/descendant::imagedata[@align][1]/@align"/>
397     </xsl:if>
398   </xsl:variable>
399
400   <xsl:variable name="example">
401     <xsl:choose>
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"/>
407             </xsl:attribute>
408           </xsl:if>
409           <xsl:call-template name="formal.object">
410             <xsl:with-param name="placement" select="$placement"/>
411           </xsl:call-template>
412         </fo:block>
413       </xsl:when>
414       <xsl:otherwise>
415         <fo:block>
416           <xsl:if test="$align != ''">
417             <xsl:attribute name="text-align">
418               <xsl:value-of select="$align"/>
419             </xsl:attribute>
420           </xsl:if>
421           <xsl:call-template name="formal.object">
422             <xsl:with-param name="placement" select="$placement"/>
423           </xsl:call-template>
424         </fo:block>
425       </xsl:otherwise>
426     </xsl:choose>
427   </xsl:variable>
428
429   <xsl:variable name="floatstyle">
430     <xsl:call-template name="floatstyle"/>
431   </xsl:variable>
432
433   <xsl:choose>
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"/>
438       </xsl:call-template>
439     </xsl:when>
440     <xsl:otherwise>
441       <xsl:copy-of select="$example"/>
442     </xsl:otherwise>
443   </xsl:choose>
444
445 </xsl:template>
446
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.
456 -->
457 <xsl:template match="table|informaltable">
458   <xsl:if test="tgroup/tbody/tr
459                 |tgroup/thead/tr
460                 |tgroup/tfoot/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:&#10;</xsl:text>
464       <xsl:value-of 
465                select="(tgroup//tr)[1]"/>
466     </xsl:message>
467   </xsl:if>
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:&#10;</xsl:text>
472       <xsl:value-of 
473                select=".//row[1]"/>
474     </xsl:message>
475   </xsl:if>
476
477   <!-- Contains fo:table, not title or footnotes -->
478   <xsl:variable name="table.content">
479     <xsl:call-template name="make.table.content"/>
480   </xsl:variable>
481
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"/>
486     </xsl:call-template>
487   </xsl:variable>
488
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"/>
493     </xsl:call-template>
494   </xsl:variable>
495
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"/>
500     </xsl:call-template>
501   </xsl:variable>
502
503   <!-- float or not -->
504   <xsl:variable name="floatstyle">
505     <xsl:call-template name="floatstyle"/>
506   </xsl:variable>
507
508   <xsl:choose>
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"/>
513       </xsl:call-template>
514     </xsl:when>
515     <xsl:otherwise>
516       <xsl:copy-of select="$table.container"/>
517     </xsl:otherwise>
518   </xsl:choose>
519 </xsl:template>
520
521
522 <xsl:template match="equation">
523   <xsl:variable name="param.placement"
524               select="substring-after(normalize-space($formal.title.placement),
525                                       concat(local-name(.), ' '))"/>
526
527   <xsl:variable name="placement">
528     <xsl:choose>
529       <xsl:when test="contains($param.placement, ' ')">
530         <xsl:value-of select="substring-before($param.placement, ' ')"/>
531       </xsl:when>
532       <xsl:when test="$param.placement = ''">before</xsl:when>
533       <xsl:otherwise>
534         <xsl:value-of select="$param.placement"/>
535       </xsl:otherwise>
536     </xsl:choose>
537   </xsl:variable>
538
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"/>
542   </xsl:variable>
543
544   <xsl:variable name="equation">
545     <xsl:choose>
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"/>
550           </xsl:call-template>
551         </fo:block>
552       </xsl:when>
553       <xsl:otherwise>
554         <xsl:call-template name="semiformal.object">
555           <xsl:with-param name="placement" select="$placement"/>
556         </xsl:call-template>
557       </xsl:otherwise>
558     </xsl:choose>
559   </xsl:variable>
560
561   <xsl:variable name="floatstyle">
562     <xsl:call-template name="floatstyle"/>
563   </xsl:variable>
564
565   <xsl:choose>
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"/>
570       </xsl:call-template>
571     </xsl:when>
572     <xsl:otherwise>
573       <xsl:copy-of select="$equation"/>
574     </xsl:otherwise>
575   </xsl:choose>
576 </xsl:template>
577
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>
587
588 <xsl:template match="informalfigure">
589   <xsl:call-template name="informal.object"/>
590 </xsl:template>
591
592 <xsl:template match="informalexample">
593   <xsl:call-template name="informal.object"/>
594 </xsl:template>
595
596 <xsl:template match="informaltable/textobject"></xsl:template>
597
598 <xsl:template match="informalequation">
599   <xsl:call-template name="informal.object"/>
600 </xsl:template>
601
602 <xsl:template name="floatstyle">
603   <xsl:if test="(@float and @float != '0') or @floatstyle != ''">
604     <xsl:choose>
605       <xsl:when test="@floatstyle != ''">
606         <xsl:value-of select="@floatstyle"/>
607       </xsl:when>
608       <xsl:when test="@float = '1'">
609         <xsl:value-of select="$default.float.class"/>
610       </xsl:when>
611       <xsl:otherwise>
612         <xsl:value-of select="@float"/>
613       </xsl:otherwise>
614     </xsl:choose>
615   </xsl:if>
616 </xsl:template>
617
618 </xsl:stylesheet>