pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / src / site / src / documentation / skins / common / xslt / fo / document-to-fo.xsl
1 <?xml version="1.0"?>
2 <!--
3   Licensed to the Apache Software Foundation (ASF) under one or more
4   contributor license agreements.  See the NOTICE file distributed with
5   this work for additional information regarding copyright ownership.
6   The ASF licenses this file to You under the Apache License, Version 2.0
7   (the "License"); you may not use this file except in compliance with
8   the License.  You may obtain a copy of the License at
9
10       http://www.apache.org/licenses/LICENSE-2.0
11
12   Unless required by applicable law or agreed to in writing, software
13   distributed under the License is distributed on an "AS IS" BASIS,
14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   See the License for the specific language governing permissions and
16   limitations under the License.
17 -->
18 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
19                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
20                 version="1.0">
21 <!-- left, justify, right -->
22   <xsl:variable name="text-align" select="string(//skinconfig/pdf/page/@text-align)"/>
23 <!-- print URL of external links -->
24   <xsl:variable name="show-external-urls" select="//skinconfig/pdf/show-external-urls"/>
25 <!-- Get the section depth to use when generating the minitoc (default is 2) -->
26   <xsl:variable name="toc-max-depth" select="number(//skinconfig/toc/@max-depth)"/>
27 <!-- The page size to be used -->
28   <xsl:variable name="pagesize"
29                 select="string(//skinconfig/pdf/page/@size)"/>
30 <!-- The page orientation ("portrait" or "landscape") -->
31   <xsl:variable name="pageorientation"
32                 select="string(//skinconfig/pdf/page/@orientation)"/>
33 <!-- Double-sided printing toggle -->
34   <xsl:variable name="doublesided"
35                 select="string(//skinconfig/pdf/margins/@double-sided)"/>
36 <!-- The top page margin -->
37   <xsl:variable name="topmargin"
38                 select="string(//skinconfig/pdf/margins/top)"/>
39 <!-- The bottom page margin -->
40   <xsl:variable name="bottommargin"
41                 select="string(//skinconfig/pdf/margins/bottom)"/>
42 <!-- The inner page margin (always the left margin if
43   double-sided printing is off, alternating between left and right if
44   it's on) -->
45   <xsl:variable name="innermargin"
46                 select="string(//skinconfig/pdf/margins/inner)"/>
47 <!-- The outer page margin (always the right margin if
48   double-sided printing is off, alternating between right and left if
49   it's on)-->
50   <xsl:variable name="outermargin"
51                 select="string(//skinconfig/pdf/margins/outer)"/>
52   <xsl:param name="numbersections" select="'true'"/>
53 <!-- page breaks after TOC and each page if an aggregate document -->
54   <xsl:variable name="page-break-top-sections" select="'true'"/>
55 <!-- page numbering format -->
56   <xsl:variable name="page-numbering-format" select="string(//skinconfig/pdf/page-numbering-format)"/>
57 <!-- Section depth at which we stop numbering and just indent -->
58   <xsl:param name="numbering-max-depth" select="'3'"/>
59   <xsl:param name="imagesdir" select="."/>
60   <xsl:param name="xmlbasedir"/>
61   <xsl:include href="pdfoutline.xsl"/>
62   <xsl:include href="footerinfo.xsl"/>
63 <!-- Determine page height for various page sizes (US Letter portrait
64   is the default) -->
65 <!-- FIXME: JJP:would this be better of a file? -->
66   <xsl:variable name="pageheight">
67     <xsl:choose>
68       <xsl:when test="$pageorientation = 'landscape'">
69         <xsl:choose>
70           <xsl:when test="$pagesize = 'a0'">841mm</xsl:when>
71           <xsl:when test="$pagesize = 'a1'">594mm</xsl:when>
72           <xsl:when test="$pagesize = 'a2'">420mm</xsl:when>
73           <xsl:when test="$pagesize = 'a3'">297mm</xsl:when>
74           <xsl:when test="$pagesize = 'a4'">210mm</xsl:when>
75           <xsl:when test="$pagesize = 'a5'">148mm</xsl:when>
76           <xsl:when test="$pagesize = 'executive'">7.25in</xsl:when>
77           <xsl:when test="$pagesize = 'folio'">8.5in</xsl:when>
78           <xsl:when test="$pagesize = 'ledger'">11in</xsl:when>
79           <xsl:when test="$pagesize = 'legal'">8.5in</xsl:when>
80           <xsl:when test="$pagesize = 'letter'">8.5in</xsl:when>
81           <xsl:when test="$pagesize = 'quarto'">8.5in</xsl:when>
82           <xsl:when test="$pagesize = 'tabloid'">11in</xsl:when>
83           <xsl:otherwise>8.5in</xsl:otherwise>
84         </xsl:choose>
85       </xsl:when>
86       <xsl:otherwise>
87         <xsl:choose>
88           <xsl:when test="$pagesize = 'a0'">1189mm</xsl:when>
89           <xsl:when test="$pagesize = 'a1'">841mm</xsl:when>
90           <xsl:when test="$pagesize = 'a2'">594mm</xsl:when>
91           <xsl:when test="$pagesize = 'a3'">420mm</xsl:when>
92           <xsl:when test="$pagesize = 'a4'">297mm</xsl:when>
93           <xsl:when test="$pagesize = 'a5'">210mm</xsl:when>
94           <xsl:when test="$pagesize = 'executive'">10.5in</xsl:when>
95           <xsl:when test="$pagesize = 'folio'">13in</xsl:when>
96           <xsl:when test="$pagesize = 'ledger'">17in</xsl:when>
97           <xsl:when test="$pagesize = 'legal'">14in</xsl:when>
98           <xsl:when test="$pagesize = 'quarto'">10.83in</xsl:when>
99           <xsl:when test="$pagesize = 'tabloid'">17in</xsl:when>
100           <xsl:otherwise>11in</xsl:otherwise>
101         </xsl:choose>
102       </xsl:otherwise>
103     </xsl:choose>
104   </xsl:variable>
105 <!-- Determine page width for various page sizes (US Letter portrait
106   is the default) -->
107   <xsl:variable name="pagewidth">
108     <xsl:choose>
109       <xsl:when test="$pageorientation = 'landscape'">
110         <xsl:choose>
111           <xsl:when test="$pagesize = 'a0'">1189mm</xsl:when>
112           <xsl:when test="$pagesize = 'a1'">841mm</xsl:when>
113           <xsl:when test="$pagesize = 'a2'">594mm</xsl:when>
114           <xsl:when test="$pagesize = 'a3'">420mm</xsl:when>
115           <xsl:when test="$pagesize = 'a4'">297mm</xsl:when>
116           <xsl:when test="$pagesize = 'a5'">210mm</xsl:when>
117           <xsl:when test="$pagesize = 'executive'">10.5in</xsl:when>
118           <xsl:when test="$pagesize = 'folio'">13in</xsl:when>
119           <xsl:when test="$pagesize = 'ledger'">17in</xsl:when>
120           <xsl:when test="$pagesize = 'legal'">14in</xsl:when>
121           <xsl:when test="$pagesize = 'quarto'">10.83in</xsl:when>
122           <xsl:when test="$pagesize = 'tabloid'">17in</xsl:when>
123           <xsl:otherwise>11in</xsl:otherwise>
124         </xsl:choose>
125       </xsl:when>
126       <xsl:otherwise>
127         <xsl:choose>
128           <xsl:when test="$pagesize = 'a0'">841mm</xsl:when>
129           <xsl:when test="$pagesize = 'a1'">594mm</xsl:when>
130           <xsl:when test="$pagesize = 'a2'">420mm</xsl:when>
131           <xsl:when test="$pagesize = 'a3'">297mm</xsl:when>
132           <xsl:when test="$pagesize = 'a4'">210mm</xsl:when>
133           <xsl:when test="$pagesize = 'a5'">148mm</xsl:when>
134           <xsl:when test="$pagesize = 'executive'">7.25in</xsl:when>
135           <xsl:when test="$pagesize = 'folio'">8.5in</xsl:when>
136           <xsl:when test="$pagesize = 'ledger'">11in</xsl:when>
137           <xsl:when test="$pagesize = 'legal'">8.5in</xsl:when>
138           <xsl:when test="$pagesize = 'letter'">8.5in</xsl:when>
139           <xsl:when test="$pagesize = 'quarto'">8.5in</xsl:when>
140           <xsl:when test="$pagesize = 'tabloid'">11in</xsl:when>
141           <xsl:otherwise>8.5in</xsl:otherwise>
142         </xsl:choose>
143       </xsl:otherwise>
144     </xsl:choose>
145   </xsl:variable>
146   <xsl:template match="/">
147     <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
148       <fo:layout-master-set>
149         <fo:simple-page-master master-name="first-page"
150           page-height="{$pageheight}"
151           page-width="{$pagewidth}"
152           margin-top="{$topmargin}"
153           margin-bottom="{$bottommargin}"
154           margin-left="{$innermargin}"
155           margin-right="{$outermargin}">
156           <fo:region-body
157             margin-top="0.5in"
158             margin-bottom=".5in"/>
159           <fo:region-after
160             region-name="first-footer"
161             extent=".5in"
162             display-align="before"/>
163         </fo:simple-page-master>
164         <fo:simple-page-master master-name="even-page"
165           page-height="{$pageheight}"
166           page-width="{$pagewidth}"
167           margin-top="{$topmargin}"
168           margin-bottom="{$bottommargin}">
169           <xsl:choose>
170             <xsl:when test="$doublesided = 'true'">
171               <xsl:attribute name="margin-left">
172                 <xsl:value-of select="$outermargin"/>
173               </xsl:attribute>
174               <xsl:attribute name="margin-right">
175                 <xsl:value-of select="$innermargin"/>
176               </xsl:attribute>
177             </xsl:when>
178             <xsl:otherwise>
179               <xsl:attribute name="margin-left">
180                 <xsl:value-of select="$innermargin"/>
181               </xsl:attribute>
182               <xsl:attribute name="margin-right">
183                 <xsl:value-of select="$outermargin"/>
184               </xsl:attribute>
185             </xsl:otherwise>
186           </xsl:choose>
187           <fo:region-before
188             region-name="even-header"
189             extent="0.5in"
190             border-bottom="0.5pt solid"/>
191           <fo:region-body
192             margin-top="0.5in"
193             margin-bottom=".5in"/>
194           <fo:region-after
195             region-name="even-footer"
196             extent=".5in"
197             display-align="before"/>
198         </fo:simple-page-master>
199         <fo:simple-page-master master-name="odd-page"
200           page-height="{$pageheight}"
201           page-width="{$pagewidth}"
202           margin-top="{$topmargin}"
203           margin-bottom="{$bottommargin}"
204           margin-left="{$innermargin}"
205           margin-right="{$outermargin}">
206           <fo:region-before
207             region-name="odd-header"
208             extent="0.5in"
209             border-bottom="0.5pt solid"/>
210           <fo:region-body
211             margin-top="0.5in"
212             margin-bottom=".5in"/>
213           <fo:region-after
214             region-name="odd-footer"
215             extent=".5in"
216             display-align="before"/>
217         </fo:simple-page-master>
218         <fo:page-sequence-master master-name="book">
219           <fo:repeatable-page-master-alternatives>
220             <fo:conditional-page-master-reference
221               page-position="first"
222               master-reference="first-page"/>
223             <fo:conditional-page-master-reference
224               odd-or-even="odd"
225               master-reference="odd-page"/>
226             <fo:conditional-page-master-reference
227               odd-or-even="even"
228               master-reference="even-page"/>
229           </fo:repeatable-page-master-alternatives>
230         </fo:page-sequence-master>
231       </fo:layout-master-set>
232       <xsl:apply-templates select="/site/document" mode="outline"/>
233       <fo:page-sequence master-reference="book">
234         <xsl:apply-templates select="/site/document"/>
235       </fo:page-sequence>
236     </fo:root>
237   </xsl:template>
238   <xsl:template match="document">
239     <fo:title>
240       <xsl:value-of select="header/title"/>
241     </fo:title>
242     <fo:static-content flow-name="first-footer">
243       <fo:block
244         border-top="0.25pt solid"
245         padding-before="6pt"
246         text-align="center">
247         <xsl:apply-templates select="footer"/>
248       </fo:block>
249 <!-- don't list page number on first page if it's contents is just the TOC -->
250       <xsl:if test="not($toc-max-depth > 0 and $page-break-top-sections)">
251         <xsl:call-template name="insertPageNumber">
252           <xsl:with-param name="text-align">start</xsl:with-param>
253         </xsl:call-template>
254       </xsl:if>
255       <xsl:call-template name="info"/>
256     </fo:static-content>
257     <fo:static-content flow-name="even-header">
258       <fo:block
259         font-size="70%"
260         text-align="end"
261         font-style="italic">
262         <xsl:value-of select="header/title"/>
263       </fo:block>
264     </fo:static-content>
265     <fo:static-content flow-name="even-footer">
266       <fo:block
267         border-top="0.25pt solid"
268         padding-before="6pt"
269         text-align="center">
270         <xsl:apply-templates select="footer"/>
271       </fo:block>
272       <xsl:call-template name="insertPageNumber">
273         <xsl:with-param name="text-align">end</xsl:with-param>
274       </xsl:call-template>
275       <xsl:call-template name="info"/>
276     </fo:static-content>
277     <fo:static-content flow-name="odd-header">
278       <fo:block
279         font-size="70%"
280         text-align="start"
281         font-style="italic">
282         <xsl:value-of select="header/title"/>
283       </fo:block>
284     </fo:static-content>
285     <fo:static-content flow-name="odd-footer">
286       <fo:block
287         border-top="0.25pt solid"
288         padding-before="6pt"
289         text-align="center">
290         <xsl:apply-templates select="footer"/>
291       </fo:block>
292       <xsl:call-template name="insertPageNumber">
293         <xsl:with-param name="text-align">start</xsl:with-param>
294       </xsl:call-template>
295       <xsl:call-template name="info"/>
296     </fo:static-content>
297     <fo:flow flow-name="xsl-region-body">
298       <fo:block
299         padding-before="24pt"
300         padding-after="24pt"
301         font-size="24pt"
302         font-weight="bold"
303         id="{generate-id()}">
304         <xsl:value-of select="header/title"/>
305       </fo:block>
306       <fo:block
307         text-align="{$text-align}"
308         padding-before="18pt"
309         padding-after="18pt">
310         <xsl:apply-templates/>
311       </fo:block>
312 <!-- Total number of pages calculation... -->
313       <fo:block id="term"/>
314     </fo:flow>
315   </xsl:template>
316   <xsl:template match="abstract">
317     <fo:block
318       font-size="12pt"
319       text-align="center"
320       space-before="20pt"
321       space-after="25pt"
322       width="7.5in"
323       font-family="serif"
324       font-style="italic">
325       <xsl:call-template name="insertPageBreaks"/>
326       <xsl:apply-templates/>
327     </fo:block>
328   </xsl:template>
329   <xsl:template match="notice">
330     <fo:block
331       font-size="10pt"
332       text-align="left"
333       space-before="20pt"
334       width="7.5in"
335       font-family="serif"
336       border-top="0.25pt solid"
337       border-bottom="0.25pt solid"
338       padding-before="6pt"
339       padding-after="6pt">
340       <xsl:call-template name="insertPageBreaks"/>
341 <!-- insert i18n stuff here -->
342       NOTICE: <xsl:apply-templates/>
343     </fo:block>
344   </xsl:template>
345   <xsl:template match="anchor">
346     <fo:block id="{@id}"/>
347     <xsl:apply-templates/>
348   </xsl:template>
349   <xsl:template match="section">
350     <xsl:param name="level">0</xsl:param>
351     <xsl:variable name="size">
352 <!-- 14pt for level 1 12pt for level 2 -->
353       <xsl:value-of select="14-number($level)"/>
354     </xsl:variable>
355     <xsl:variable name="background-color" select="//skinconfig/colors/color[@name='body']/@value"/>
356     <xsl:variable name="heading-color" select="//skinconfig/colors/color[@name='subheading']/@value"/>
357     <xsl:variable name="heading-type" select="//skinconfig/headings/@type"/>
358     <fo:block
359       font-family="serif"
360       font-size="{$size}pt"
361       font-weight="bold"
362       space-before="12pt"
363       space-after="4pt">
364       <xsl:call-template name="insertPageBreaks"/>
365       <xsl:if test="$heading-type = 'boxed'">
366         <xsl:attribute name="background-color">
367           <xsl:value-of select="$heading-color"/>
368         </xsl:attribute>
369       </xsl:if>
370       <xsl:attribute name="id">
371         <xsl:choose>
372           <xsl:when test="normalize-space(@id)!=''">
373             <xsl:value-of select="@id"/>
374           </xsl:when>
375           <xsl:otherwise>
376             <xsl:value-of select="generate-id()"/>
377           </xsl:otherwise>
378         </xsl:choose>
379       </xsl:attribute>
380       <xsl:if test="$numbersections = 'true' and number($level) &lt; $numbering-max-depth+1">
381         <xsl:number format="1.1.1.1.1.1.1" count="section" level="multiple"/>
382 <xsl:text>. </xsl:text>
383       </xsl:if>
384 <!-- For sections 4  or more nestings deep, indent instead of number -->
385       <xsl:if test="number($level) &gt; $numbering-max-depth+1">
386         <xsl:attribute name="start-indent">
387           <xsl:value-of select="4+number($level)"/>
388 <xsl:text>pt</xsl:text>
389         </xsl:attribute>
390       </xsl:if>
391       <xsl:value-of select="title"/>
392     </fo:block>
393     <xsl:if test="$heading-type = 'underlined'">
394 <!-- The non-breaking space in this block is required, otherwise
395       the block won't be rendered at all. -->
396       <fo:block
397         font-family="serif"
398         font-size="{10 div (number($level) +1 )}pt"
399         background-color="{$heading-color}">&#160;</fo:block>
400     </xsl:if>
401     <fo:block
402         background-color="{$background-color}">
403       <xsl:apply-templates>
404         <xsl:with-param name="level" select="number($level)+1"/>
405       </xsl:apply-templates>
406     </fo:block>
407   </xsl:template>
408   <xsl:template match="title">
409 <!-- do nothing as titles are handled in their parent templates -->
410   </xsl:template>
411   <xsl:template match="subtitle">
412     <xsl:param name="level">0</xsl:param>
413     <xsl:variable name="size" select="16-(number($level)*1.5)"/>
414     <fo:block
415       font-weight="bold"
416       font-size="{$size}pt">
417       <xsl:call-template name="insertPageBreaks"/>
418       <xsl:apply-templates/>
419     </fo:block>
420   </xsl:template>
421   <xsl:template match="authors">
422     <fo:block
423       space-before="20pt"
424       font-weight="bold"
425       font-size="9pt">
426       <xsl:call-template name="insertPageBreaks"/>
427 <!-- insert i18n stuff here -->
428       by
429       <xsl:for-each select="person">
430         <xsl:value-of select="@name"/>
431         <xsl:if test="not(position() = last())">, </xsl:if>
432       </xsl:for-each>
433     </fo:block>
434   </xsl:template>
435   <xsl:template match="p">
436     <xsl:choose>
437       <xsl:when test="ancestor::li and not(preceding-sibling::*)">
438         <fo:block
439           space-after="4pt"
440           font-family="serif">
441           <xsl:call-template name="insertPageBreaks"/>
442           <xsl:apply-templates/>
443         </fo:block>
444       </xsl:when>
445       <xsl:otherwise>
446         <fo:block
447           space-before="4pt"
448           space-after="4pt"
449           font-family="serif">
450           <xsl:call-template name="insertPageBreaks"/>
451           <xsl:apply-templates/>
452         </fo:block>
453       </xsl:otherwise>
454     </xsl:choose>
455   </xsl:template>
456   <xsl:template match="source">
457     <xsl:variable name="color" select="//skinconfig/colors/color[@name='code']/@value"/>
458     <fo:block
459       font-family="monospace"
460       font-size="10pt"
461       background-color="{$color}"
462       white-space-collapse="false"
463       linefeed-treatment="preserve"
464       white-space-treatment="preserve"
465       wrap-option="wrap"
466       text-align="start">
467       <xsl:call-template name="insertPageBreaks"/>
468       <xsl:apply-templates/>
469     </fo:block>
470   </xsl:template>
471   <xsl:template match="ol|ul">
472     <fo:list-block
473       provisional-distance-between-starts="18pt"
474       provisional-label-separation="3pt"
475       text-align="start">
476       <xsl:apply-templates/>
477     </fo:list-block>
478   </xsl:template>
479   <xsl:template match="ol/li">
480     <fo:list-item>
481       <xsl:if test="not(following-sibling::li[1])">
482         <xsl:attribute name="space-after">6pt"</xsl:attribute>
483       </xsl:if>
484       <fo:list-item-label
485         end-indent="label-end()">
486         <fo:block>
487           <xsl:number format="1."/>
488         </fo:block>
489       </fo:list-item-label>
490       <fo:list-item-body
491         start-indent="body-start()">
492         <fo:block
493           font-family="serif">
494           <xsl:apply-templates/>
495         </fo:block>
496       </fo:list-item-body>
497     </fo:list-item>
498   </xsl:template>
499 <!-- Emulate browser handling of these invalid combinations that our DTD
500   unfortunately allows -->
501   <xsl:template match="ul/ul | ul/ol | ol/ul | ol/ol">
502     <fo:list-item>
503       <fo:list-item-label end-indent="label-end()">
504         <fo:block></fo:block>
505       </fo:list-item-label>
506       <fo:list-item-body start-indent="body-start()">
507         <fo:block font-family="serif">
508           <xsl:apply-templates/>
509         </fo:block>
510       </fo:list-item-body>
511     </fo:list-item>
512   </xsl:template>
513   <xsl:template match="ul/li">
514     <fo:list-item>
515       <xsl:if test="not(following-sibling::li[1])">
516         <xsl:attribute name="space-after">6pt</xsl:attribute>
517       </xsl:if>
518       <fo:list-item-label end-indent="label-end()">
519         <fo:block>&#x2022;</fo:block>
520       </fo:list-item-label>
521       <fo:list-item-body start-indent="body-start()">
522         <fo:block
523           font-family="serif">
524           <xsl:apply-templates/>
525         </fo:block>
526       </fo:list-item-body>
527     </fo:list-item>
528   </xsl:template>
529   <xsl:template match="dl">
530     <fo:list-block
531       provisional-distance-between-starts="18pt"
532       provisional-label-separation="3pt"
533       text-align="start">
534       <xsl:apply-templates/>
535     </fo:list-block>
536   </xsl:template>
537   <xsl:template match="dt">
538     <fo:list-item>
539       <fo:list-item-label end-indent="label-end()">
540         <fo:block></fo:block>
541       </fo:list-item-label>
542       <fo:list-item-body start-indent="body-start()">
543         <fo:block
544           font-weight="bold">
545           <xsl:apply-templates/>
546         </fo:block>
547       </fo:list-item-body>
548     </fo:list-item>
549   </xsl:template>
550   <xsl:template match="dd">
551     <fo:list-item>
552       <fo:list-item-label end-indent="label-end()">
553         <fo:block></fo:block>
554       </fo:list-item-label>
555       <fo:list-item-body start-indent="body-start()">
556         <fo:block>
557           <xsl:apply-templates/>
558         </fo:block>
559       </fo:list-item-body>
560     </fo:list-item>
561   </xsl:template>
562   <xsl:template match="strong">
563     <fo:inline font-weight="bold">
564       <xsl:apply-templates/>
565     </fo:inline>
566   </xsl:template>
567   <xsl:template match="em">
568     <fo:inline font-style="italic">
569       <xsl:apply-templates/>
570     </fo:inline>
571   </xsl:template>
572   <xsl:template match="code">
573     <fo:inline font-family="monospace">
574       <xsl:apply-templates/>
575     </fo:inline>
576   </xsl:template>
577   <xsl:template match="warning">
578     <xsl:variable name="color" select="//skinconfig/colors/color[@name='warning']/@value"/>
579     <fo:block
580       margin-left="0.25in"
581       margin-right="0.25in"
582       font-weight="bold"
583       font-size="10pt"
584       font-family="serif"
585       space-before="10pt"
586       border-before-style="solid"
587       border-start-style="solid"
588       border-end-style="solid"
589       border-color="{$color}"
590       background-color="{$color}"
591       color="#ffffff">
592       <xsl:call-template name="insertPageBreaks"/>
593       <xsl:choose>
594         <xsl:when test="@label">
595           <xsl:value-of select="@label"/>
596         </xsl:when>
597         <xsl:otherwise>Warning: </xsl:otherwise>
598       </xsl:choose>
599       <xsl:value-of select="title"/>
600     </fo:block>
601     <fo:block
602       margin-left="0.25in"
603       margin-right="0.25in"
604       font-family="serif"
605       font-size="8pt"
606       border-after-style="solid"
607       border-start-style="solid"
608       border-end-style="solid"
609       border-color="{$color}"
610       background-color="#fff0f0"
611       padding-start="3pt"
612       padding-end="3pt"
613       padding-before="3pt"
614       padding-after="3pt"
615       space-after="10pt">
616       <xsl:apply-templates/>
617     </fo:block>
618   </xsl:template>
619   <xsl:template match="note">
620     <xsl:variable name="color" select="//skinconfig/colors/color[@name='note']/@value"/>
621     <fo:block
622       margin-left="0.25in"
623       margin-right="0.25in"
624       font-weight="bold"
625       font-size="10pt"
626       color="#ffffff"
627       font-family="serif"
628       space-before="10pt"
629       border-before-style="solid"
630       border-start-style="solid"
631       border-end-style="solid"
632       border-color="{$color}"
633       background-color="{$color}">
634       <xsl:call-template name="insertPageBreaks"/>
635       <xsl:choose>
636         <xsl:when test="@label">
637           <xsl:value-of select="@label"/>
638         </xsl:when>
639 <!-- insert i18n stuff here -->
640         <xsl:otherwise>Note: </xsl:otherwise>
641       </xsl:choose>
642       <xsl:value-of select="title"/>
643     </fo:block>
644     <fo:block
645       margin-left="0.25in"
646       margin-right="0.25in"
647       font-family="serif"
648       font-size="8pt"
649       space-after="10pt"
650       border-after-style="solid"
651       border-start-style="solid"
652       border-end-style="solid"
653       border-color="{$color}"
654       background-color="#F0F0FF"
655       padding-start="3pt"
656       padding-end="3pt"
657       padding-before="3pt"
658       padding-after="3pt">
659       <xsl:apply-templates/>
660     </fo:block>
661   </xsl:template>
662   <xsl:template match="fixme">
663     <xsl:variable name="color" select="//skinconfig/colors/color[@name='fixme']/@value"/>
664     <fo:block
665       margin-left="0.25in"
666       margin-right="0.25in"
667       font-weight="bold"
668       font-size="10pt"
669       color="#FFFFFF"
670       font-family="serif"
671       space-before="10pt"
672       border-before-style="solid"
673       border-start-style="solid"
674       border-end-style="solid"
675       border-color="{$color}"
676       background-color="{$color}">
677       <xsl:call-template name="insertPageBreaks"/>
678 <!-- insert i18n stuff here -->
679       FIXME (<xsl:value-of select="@author"/>): <xsl:value-of select="title"/>
680     </fo:block>
681     <fo:block
682       margin-left="0.25in"
683       margin-right="0.25in"
684       font-family="serif"
685       font-size="8pt"
686       space-after="10pt"
687       border-after-style="solid"
688       border-start-style="solid"
689       border-end-style="solid"
690       border-color="{$color}"
691       background-color="#FFF0F0"
692       padding-start="3pt"
693       padding-end="3pt"
694       padding-before="3pt"
695       padding-after="3pt">
696       <xsl:apply-templates/>
697     </fo:block>
698   </xsl:template>
699   <xsl:template match="link|fork|jump">
700     <xsl:variable name="color" select="//skinconfig/colors/color[@name = 'body']/@link"/>
701     <xsl:choose>
702       <xsl:when test="starts-with(@href, '#')">
703         <fo:basic-link color="{$color}" text-decoration="underline" internal-destination="{substring(@href,2)}">
704           <xsl:apply-templates/>
705         </fo:basic-link>
706       </xsl:when>
707       <xsl:otherwise>
708         <fo:basic-link color="{$color}" text-decoration="underline" external-destination="{@href}">
709           <xsl:apply-templates/>
710         </fo:basic-link>
711         <xsl:if test="$show-external-urls = 'true' and @href != string(.)">
712           (<xsl:value-of select="@href"/>)
713         </xsl:if>
714       </xsl:otherwise>
715     </xsl:choose>
716   </xsl:template>
717   <xsl:template match="figure|img">
718     <fo:block text-align="center">
719       <xsl:call-template name="insertPageBreaks"/>
720       <xsl:if test="normalize-space(@id)!=''">
721         <xsl:attribute name="id">
722           <xsl:value-of select="@id"/>
723         </xsl:attribute>
724       </xsl:if>
725 <!-- Make relative paths absolute -->
726       <xsl:variable name="imgpath">
727         <xsl:choose>
728 <!-- resources image dir -->
729           <xsl:when test="starts-with(string(@src),'images/')">
730             <xsl:value-of select="concat($imagesdir,substring-after(@src,'images'))"/>
731           </xsl:when>
732           <xsl:when test="contains(string(@src),'/images/')">
733             <xsl:value-of select="concat($imagesdir,substring-after(@src,'/images'))"/>
734           </xsl:when>
735 <!-- already absolute -->
736           <xsl:when test="contains(string(@src),':') or starts-with(string(@src),'/')">
737             <xsl:value-of select="@src"/>
738           </xsl:when>
739 <!-- relative to document -->
740           <xsl:otherwise>
741             <xsl:value-of select="concat($xmlbasedir,@src)"/>
742           </xsl:otherwise>
743         </xsl:choose>
744       </xsl:variable>
745       <fo:external-graphic src="{$imgpath}">
746         <xsl:if test="@height">
747           <xsl:attribute name="height">
748             <xsl:value-of select="@height"/>
749           </xsl:attribute>
750         </xsl:if>
751         <xsl:if test="@width">
752           <xsl:attribute name="width">
753             <xsl:value-of select="@width"/>
754           </xsl:attribute>
755         </xsl:if>
756       </fo:external-graphic>
757 <!-- alt text -->
758       <xsl:if test="//skinconfig/pdf/show-image-alt-text='true'">
759         <xsl:if test="normalize-space(@alt)!=''">
760           <fo:block>
761             <xsl:value-of select="@alt"/>
762           </fo:block>
763         </xsl:if>
764       </xsl:if>
765     </fo:block>
766   </xsl:template>
767   <xsl:template match="table">
768 <!-- FIXME: Apache FOP must have column widths specified at present,
769          this section can be removed when this limitation is removed from Fop.
770          Unfortunately, this means that each column is a fixed width,
771          but at least the table displays! -->
772     <xsl:variable name="max-number-columns-td">
773       <xsl:for-each select="tr">
774         <xsl:sort select="count(td|th)" data-type="number"
775           order="descending"/>
776         <xsl:if test="position() = 1">
777           <xsl:value-of select="count(td|th)"/>
778         </xsl:if>
779       </xsl:for-each>
780     </xsl:variable>
781     <xsl:variable name="max-number-columns-colspan">
782       <xsl:for-each select="tr">
783         <xsl:sort select="count(td|th)" data-type="number"
784           order="descending"/>
785         <xsl:if test="position() = 1">
786           <xsl:value-of
787             select="sum(td/@colspan|th/@colspan)"/>
788         </xsl:if>
789       </xsl:for-each>
790     </xsl:variable>
791     <xsl:variable name="max-number-columns">
792       <xsl:choose>
793         <xsl:when
794           test="$max-number-columns-colspan&gt;$max-number-columns-td">
795           <xsl:value-of
796             select="$max-number-columns-colspan"/>
797         </xsl:when>
798         <xsl:otherwise>
799           <xsl:value-of select="$max-number-columns-td"/>
800         </xsl:otherwise>
801       </xsl:choose>
802     </xsl:variable>
803     <xsl:variable name="column-width">
804       <xsl:value-of select="6.25 div number($max-number-columns)"/>in
805     </xsl:variable>
806     <fo:table>
807       <fo:table-column>
808         <xsl:attribute name="column-width">
809           <xsl:value-of select="$column-width"/>
810         </xsl:attribute>
811         <xsl:attribute name="number-columns-repeated">
812           <xsl:value-of select="number($max-number-columns)"/>
813         </xsl:attribute>
814       </fo:table-column>
815 <!-- End of hack for Fop support (if removing this hack, remember
816            you need the <fo:table> element) -->
817       <fo:table-body
818         font-size="10pt"
819         font-family="sans-serif">
820         <xsl:apply-templates select="tr"/>
821       </fo:table-body>
822     </fo:table>
823 <!-- FIXME: Apache Fop does not support the caption element yet.
824          This hack will display the table caption accordingly. -->
825     <xsl:if test="caption">
826       <fo:block
827         text-align="center"
828         font-weight="bold">
829 <!-- insert i18n stuff here -->
830         Table
831         <xsl:text> </xsl:text>
832         <xsl:number count="table" level="multiple"/>
833 <xsl:text>: </xsl:text>
834         <xsl:value-of select="caption"/>
835       </fo:block>
836     </xsl:if>
837   </xsl:template>
838   <xsl:template match="tr">
839     <fo:table-row>
840       <xsl:apply-templates/>
841     </fo:table-row>
842   </xsl:template>
843   <xsl:template match="th">
844     <xsl:variable name="border-color" select="//skinconfig/colors/color[@name = 'table']/@value"/>
845     <xsl:variable name="background-color" select="$border-color"/>
846     <fo:table-cell
847         padding-before="4pt"
848         padding-after="4pt"
849         padding-start="4pt"
850         padding-end="4pt"
851         color="#FFFFFF"
852         background-color="{$background-color}"
853         border="1pt solid {$border-color}">
854       <xsl:attribute name="number-columns-spanned">
855         <xsl:value-of select="@colspan"/>
856       </xsl:attribute>
857       <xsl:attribute name="number-rows-spanned">
858         <xsl:value-of select="@rowspan"/>
859       </xsl:attribute>
860       <fo:block
861           text-align="center">
862         <xsl:apply-templates/>
863       </fo:block>
864     </fo:table-cell>
865   </xsl:template>
866   <xsl:template match="td">
867     <xsl:variable name="border-color" select="//skinconfig/colors/color[@name = 'table']/@value"/>
868     <xsl:variable name="background-color" select="//skinconfig/colors/color[@name = 'table-cell']/@value"/>
869     <fo:table-cell
870       padding-before="4pt"
871       padding-after="4pt"
872       padding-start="4pt"
873       padding-end="4pt"
874       background-color="{$background-color}"
875       border="1pt solid {$border-color}">
876       <xsl:attribute name="number-columns-spanned">
877         <xsl:value-of select="@colspan"/>
878       </xsl:attribute>
879       <xsl:attribute name="number-rows-spanned">
880         <xsl:value-of select="@rowspan"/>
881       </xsl:attribute>
882       <fo:block>
883         <xsl:apply-templates/>
884       </fo:block>
885     </fo:table-cell>
886   </xsl:template>
887   <xsl:template match="br">
888     <fo:block></fo:block>
889   </xsl:template>
890   <xsl:template match="legal">
891     <fo:inline
892       font-size="8pt">
893       <xsl:apply-templates/>
894     </fo:inline>
895   </xsl:template>
896   <xsl:template match="body[count(//section) != 0]">
897     <xsl:if test="$toc-max-depth > 0">
898       <fo:block font-family="serif" font-size="14pt" font-weight="bold"
899       space-after="5pt" space-before="5pt" text-align="justify" width="7.5in">
900         <xsl:call-template name="insertPageBreaks"/>
901 <!-- insert i18n stuff here -->
902 <xsl:text>Table of contents</xsl:text>
903       </fo:block>
904       <fo:block font-family="sans" font-size="12pt" space-after="5pt"
905       space-before="0pt" text-align="justify" width="7.5in">
906         <xsl:if test="$page-break-top-sections">
907           <xsl:attribute name="break-after">page</xsl:attribute>
908         </xsl:if>
909         <xsl:apply-templates select="section" mode="toc" />
910       </fo:block>
911     </xsl:if>
912     <xsl:apply-templates />
913   </xsl:template>
914   <xsl:template match="section" mode="toc">
915 <!-- FIXME: see bug FOR-640 -->
916     <xsl:param name="depth" select="'1'"/>
917     <fo:block space-before="5pt" text-align-last="justify" start-indent=".5em" text-indent=".5em">
918       <fo:inline>
919         <xsl:variable name="id">
920           <xsl:choose>
921             <xsl:when test="normalize-space(@id)!=''">
922               <xsl:value-of select="@id"/>
923             </xsl:when>
924             <xsl:otherwise>
925               <xsl:value-of select="generate-id()"/>
926             </xsl:otherwise>
927           </xsl:choose>
928         </xsl:variable>
929         <fo:basic-link internal-destination="{$id}">
930           <xsl:value-of select="substring('&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;', 0, 2 * $depth - 1)" />
931           <fo:inline font-size="10pt">
932             <xsl:number count="section" format="1.1.1.1.1.1.1" level="multiple" />
933           </fo:inline>
934 <xsl:text> </xsl:text>
935           <xsl:value-of select="title" />
936           <fo:leader leader-pattern="dots" />
937           <fo:page-number-citation ref-id="{$id}" />
938         </fo:basic-link>
939       </fo:inline>
940       <xsl:if test="$toc-max-depth > $depth">
941         <xsl:apply-templates select="section" mode="toc">
942           <xsl:with-param name="depth" select="$depth + 1"/>
943         </xsl:apply-templates>
944       </xsl:if>
945     </fo:block>
946   </xsl:template>
947 <!-- ====================================================================== -->
948 <!-- Local Extensions section -->
949 <!-- ====================================================================== -->
950   <xsl:template match="citation">
951     <fo:inline>
952      [<xsl:value-of select="@def"/>]
953    </fo:inline>
954   </xsl:template>
955   <xsl:template match="p[@class='quote']">
956     <fo:block start-indent="1em"
957      space-before="4pt"
958      space-after="4pt"
959      background-color="#f0f0f0"
960      font-family="monospace">
961       <xsl:call-template name="insertPageBreaks"/>
962       <xsl:apply-templates/>
963     </fo:block>
964   </xsl:template>
965   <xsl:template name="insertPageBreaks">
966 <!-- if marked as a 'pageBreakBefore', and we're breaking on pages, and were not the first node -->
967     <xsl:if test="contains(@class, 'pageBreakBefore') and preceding-sibling::node()">
968       <xsl:attribute name="break-before">page</xsl:attribute>
969     </xsl:if>
970 <!-- if marked as a 'pageBreakAfter', and we're breaking on pages, and were not the last node -->
971     <xsl:if test="contains(@class, 'pageBreakAfter') and following-sibling::node()">
972       <xsl:attribute name="break-after">page</xsl:attribute>
973     </xsl:if>
974   </xsl:template>
975 <!-- Display the document numerotation -->
976   <xsl:template name="insertPageNumber">
977     <xsl:param name="text-align" select="'start'"/>
978     <xsl:variable name="prefixe" select="substring-before($page-numbering-format,'1')"/>
979     <xsl:variable name="sep" select="substring-before(substring-after($page-numbering-format,'1'),'1')"/>
980     <xsl:variable name="postfixe">
981       <xsl:choose>
982         <xsl:when test="contains(substring-after($page-numbering-format,'1'),'1')">
983           <xsl:value-of select="substring-after(substring-after($page-numbering-format,'1'),'1')"/>
984         </xsl:when>
985         <xsl:otherwise>
986           <xsl:value-of select="substring-after($page-numbering-format,'1')"/>
987         </xsl:otherwise>
988       </xsl:choose>
989     </xsl:variable>
990 <!-- if 'page-numbering-format' contains 1 digits, the page number is displayed in the footer -->
991     <xsl:if test="contains($page-numbering-format,'1')">
992       <fo:block font-size="70%" text-align="{$text-align}">
993 <!-- if the separator is not found, the total page number is skipped -->
994         <xsl:value-of select="$prefixe"/>
995         <fo:page-number/>
996         <xsl:if test="$sep != ''">
997           <xsl:value-of select="$sep"/>
998           <fo:page-number-citation ref-id="term"/>
999         </xsl:if>
1000         <xsl:value-of select="$postfixe"/>
1001       </fo:block>
1002     </xsl:if>
1003   </xsl:template>
1004 <!-- ====================================================================== -->
1005 <!-- Temporary section - subject to change on short notice  -->
1006 <!-- ====================================================================== -->
1007   <xsl:template match="//style">
1008 <!-- HACK: The OpenOffice.org input plugin currently produces
1009    intermediate documents that contain a style element, invalid per
1010    the Forrest Document DTD. This style element must be ignored
1011    here. To find out why this is done this way, read the comments
1012    attached to issue FOR-433. -->
1013   </xsl:template>
1014 </xsl:stylesheet>