resetting manifest requested domain to floor
[platform/upstream/docbook-xsl-stylesheets.git] / fo / docbook.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:exsl="http://exslt.org/common"
4                 xmlns:fo="http://www.w3.org/1999/XSL/Format"
5                 xmlns:ng="http://docbook.org/docbook-ng"
6                 xmlns:db="http://docbook.org/ns/docbook"
7                 exclude-result-prefixes="db ng exsl"
8                 version='1.0'>
9
10 <!-- It is important to use indent="no" here, otherwise verbatim -->
11 <!-- environments get broken by indented tags...at least when the -->
12 <!-- callout extension is used...at least with some processors -->
13 <xsl:output method="xml" indent="no"/>
14
15 <!-- ********************************************************************
16      $Id: docbook.xsl 9647 2012-10-26 17:42:03Z bobstayton $
17      ********************************************************************
18
19      This file is part of the XSL DocBook Stylesheet distribution.
20      See ../README or http://docbook.sf.net/release/xsl/current/ for
21      copyright and other information.
22
23      ******************************************************************** -->
24
25 <!-- ==================================================================== -->
26
27 <xsl:include href="../VERSION.xsl"/>
28 <xsl:include href="param.xsl"/>
29 <xsl:include href="../lib/lib.xsl"/>
30 <xsl:include href="../common/l10n.xsl"/>
31 <xsl:include href="../common/common.xsl"/>
32 <xsl:include href="../common/utility.xsl"/>
33 <xsl:include href="../common/labels.xsl"/>
34 <xsl:include href="../common/titles.xsl"/>
35 <xsl:include href="../common/subtitles.xsl"/>
36 <xsl:include href="../common/gentext.xsl"/>
37 <xsl:include href="../common/olink.xsl"/>
38 <xsl:include href="../common/targets.xsl"/>
39 <xsl:include href="../common/pi.xsl"/>
40 <xsl:include href="autotoc.xsl"/>
41 <xsl:include href="autoidx.xsl"/>
42 <xsl:include href="lists.xsl"/>
43 <xsl:include href="callout.xsl"/>
44 <xsl:include href="verbatim.xsl"/>
45 <xsl:include href="graphics.xsl"/>
46 <xsl:include href="xref.xsl"/>
47 <xsl:include href="formal.xsl"/>
48 <xsl:include href="table.xsl"/>
49 <xsl:include href="htmltbl.xsl"/>
50 <xsl:include href="sections.xsl"/>
51 <xsl:include href="inline.xsl"/>
52 <xsl:include href="footnote.xsl"/>
53 <xsl:include href="fo.xsl"/>
54 <xsl:include href="fo-rtf.xsl"/>
55 <xsl:include href="info.xsl"/>
56 <xsl:include href="keywords.xsl"/>
57 <xsl:include href="division.xsl"/>
58 <xsl:include href="index.xsl"/>
59 <xsl:include href="toc.xsl"/>
60 <xsl:include href="refentry.xsl"/>
61 <xsl:include href="math.xsl"/>
62 <xsl:include href="admon.xsl"/>
63 <xsl:include href="component.xsl"/>
64 <xsl:include href="biblio.xsl"/>
65 <xsl:include href="biblio-iso690.xsl"/>
66 <xsl:include href="glossary.xsl"/>
67 <xsl:include href="block.xsl"/>
68 <xsl:include href="task.xsl"/>
69 <xsl:include href="qandaset.xsl"/>
70 <xsl:include href="synop.xsl"/>
71 <xsl:include href="titlepage.xsl"/>
72 <xsl:include href="titlepage.templates.xsl"/>
73 <xsl:include href="pagesetup.xsl"/>
74 <xsl:include href="pi.xsl"/>
75 <xsl:include href="spaces.xsl"/>
76 <xsl:include href="ebnf.xsl"/>
77 <xsl:include href="../html/chunker.xsl"/>
78 <xsl:include href="annotations.xsl"/>
79 <xsl:include href="../common/stripns.xsl"/>
80
81 <xsl:include href="fop.xsl"/>
82 <xsl:include href="fop1.xsl"/>
83 <xsl:include href="xep.xsl"/>
84 <xsl:include href="axf.xsl"/>
85 <xsl:include href="ptc.xsl"/>
86
87 <xsl:param name="stylesheet.result.type" select="'fo'"/>
88
89 <!-- ==================================================================== -->
90
91 <xsl:key name="id" match="*" use="@id|@xml:id"/>
92
93 <!-- ==================================================================== -->
94
95 <xsl:template match="*">
96   <xsl:message>
97     <xsl:text>Element </xsl:text>
98     <xsl:value-of select="local-name(.)"/>
99     <xsl:text> in namespace '</xsl:text>
100     <xsl:value-of select="namespace-uri(.)"/>
101     <xsl:text>' encountered</xsl:text>
102     <xsl:if test="parent::*">
103       <xsl:text> in </xsl:text>
104       <xsl:value-of select="name(parent::*)"/>
105     </xsl:if>
106     <xsl:text>, but no template matches.</xsl:text>
107   </xsl:message>
108   
109   <fo:block color="red">
110     <xsl:text>&lt;</xsl:text>
111     <xsl:value-of select="name(.)"/>
112     <xsl:text>&gt;</xsl:text>
113     <xsl:apply-templates/> 
114     <xsl:text>&lt;/</xsl:text>
115     <xsl:value-of select="name(.)"/>
116     <xsl:text>&gt;</xsl:text>
117   </fo:block>
118 </xsl:template>
119
120 <!-- Update this list if new root elements supported -->
121 <xsl:variable name="root.elements" select="' appendix article bibliography book chapter colophon dedication glossary index part preface qandaset refentry reference sect1 section set setindex '"/>
122
123 <xsl:template match="/">
124   <!-- * Get a title for current doc so that we let the user -->
125   <!-- * know what document we are processing at this point. -->
126   <xsl:variable name="doc.title">
127     <xsl:call-template name="get.doc.title"/>
128   </xsl:variable>
129   <xsl:choose>
130     <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
131          toss the namespace and continue.  Use the docbook5 namespaced
132          stylesheets for DocBook5 if you don't want to use this feature.-->
133     <xsl:when test="$exsl.node.set.available != 0
134                     and (*/self::ng:* or */self::db:*)">
135       <xsl:call-template name="log.message">
136         <xsl:with-param name="level">Note</xsl:with-param>
137         <xsl:with-param name="source" select="$doc.title"/>
138         <xsl:with-param name="context-desc">
139           <xsl:text>namesp. cut</xsl:text>
140         </xsl:with-param>
141         <xsl:with-param name="message">
142           <xsl:text>stripped namespace before processing</xsl:text>
143         </xsl:with-param>
144       </xsl:call-template>
145       <xsl:variable name="nons">
146         <xsl:apply-templates mode="stripNS"/>
147       </xsl:variable>
148       <xsl:call-template name="log.message">
149         <xsl:with-param name="level">Note</xsl:with-param>
150         <xsl:with-param name="source" select="$doc.title"/>
151         <xsl:with-param name="context-desc">
152           <xsl:text>namesp. cut</xsl:text>
153         </xsl:with-param>
154         <xsl:with-param name="message">
155           <xsl:text>processing stripped document</xsl:text>
156         </xsl:with-param>
157       </xsl:call-template>
158       <xsl:apply-templates select="exsl:node-set($nons)"/>
159     </xsl:when>
160     <!-- Can't process unless namespace removed -->
161     <xsl:when test="*/self::ng:* or */self::db:*">
162       <xsl:message terminate="yes">
163         <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
164         <xsl:text> cannot proceed.</xsl:text>
165       </xsl:message>
166     </xsl:when>
167     <xsl:otherwise>
168       <xsl:choose>
169         <xsl:when test="$rootid != ''">
170           <xsl:variable name="root.element" select="key('id', $rootid)"/>
171           <xsl:choose>
172             <xsl:when test="count($root.element) = 0">
173               <xsl:message terminate="yes">
174                 <xsl:text>ID '</xsl:text>
175                 <xsl:value-of select="$rootid"/>
176                 <xsl:text>' not found in document.</xsl:text>
177               </xsl:message>
178             </xsl:when>
179             <xsl:when test="not(contains($root.elements, concat(' ', local-name($root.element), ' ')))">
180               <xsl:message terminate="yes">
181                 <xsl:text>ERROR: Document root element ($rootid=</xsl:text>
182                 <xsl:value-of select="$rootid"/>
183                 <xsl:text>) for FO output </xsl:text>
184                 <xsl:text>must be one of the following elements:</xsl:text>
185                 <xsl:value-of select="$root.elements"/>
186               </xsl:message>
187             </xsl:when>
188             <!-- Otherwise proceed -->
189             <xsl:otherwise>
190               <xsl:if test="$collect.xref.targets = 'yes' or
191                             $collect.xref.targets = 'only'">
192                 <xsl:apply-templates select="$root.element"
193                                      mode="collect.targets"/>
194               </xsl:if>
195               <xsl:if test="$collect.xref.targets != 'only'">
196                 <xsl:apply-templates select="$root.element"
197                                      mode="process.root"/>
198               </xsl:if>
199             </xsl:otherwise>
200           </xsl:choose>
201         </xsl:when>
202         <!-- Otherwise process the document root element -->
203         <xsl:otherwise>
204           <xsl:variable name="document.element" select="*[1]"/>
205           <xsl:choose>
206             <xsl:when test="not(contains($root.elements,
207                      concat(' ', local-name($document.element), ' ')))">
208               <xsl:message terminate="yes">
209                 <xsl:text>ERROR: Document root element for FO output </xsl:text>
210                 <xsl:text>must be one of the following elements:</xsl:text>
211                 <xsl:value-of select="$root.elements"/>
212               </xsl:message>
213             </xsl:when>
214             <!-- Otherwise proceed -->
215             <xsl:otherwise>
216               <xsl:if test="$collect.xref.targets = 'yes' or
217                             $collect.xref.targets = 'only'">
218                 <xsl:apply-templates select="/"
219                                      mode="collect.targets"/>
220               </xsl:if>
221               <xsl:if test="$collect.xref.targets != 'only'">
222                 <xsl:apply-templates select="/"
223                                      mode="process.root"/>
224               </xsl:if>
225             </xsl:otherwise>
226           </xsl:choose>
227         </xsl:otherwise>
228       </xsl:choose>
229     </xsl:otherwise>
230   </xsl:choose>
231 </xsl:template>
232
233 <xsl:template match="*" mode="process.root">
234   <xsl:variable name="document.element" select="self::*"/>
235
236   <xsl:call-template name="root.messages"/>
237
238   <xsl:variable name="title">
239     <xsl:choose>
240       <xsl:when test="$document.element/title[1]">
241         <xsl:value-of select="$document.element/title[1]"/>
242       </xsl:when>
243       <xsl:otherwise>[could not find document title]</xsl:otherwise>
244     </xsl:choose>
245   </xsl:variable>
246   
247   <!-- Include all id values in XEP output -->
248   <xsl:if test="$xep.extensions != 0">
249     <xsl:processing-instruction 
250      name="xep-pdf-drop-unused-destinations">false</xsl:processing-instruction>
251   </xsl:if>
252
253   <fo:root xsl:use-attribute-sets="root.properties">
254     <xsl:attribute name="language">
255       <xsl:call-template name="l10n.language">
256         <xsl:with-param name="target" select="/*[1]"/>
257       </xsl:call-template>
258     </xsl:attribute>
259
260     <xsl:if test="$xep.extensions != 0">
261       <xsl:call-template name="xep-pis"/>
262       <xsl:call-template name="xep-document-information"/>
263     </xsl:if>
264     <xsl:if test="$axf.extensions != 0">
265       <xsl:call-template name="axf-document-information"/>
266     </xsl:if>
267
268     <xsl:call-template name="setup.pagemasters"/>
269
270     <xsl:if test="$fop.extensions != 0">
271       <xsl:apply-templates select="$document.element" mode="fop.outline"/>
272     </xsl:if>
273
274     <xsl:if test="$fop1.extensions != 0">
275       <xsl:call-template name="fop1-document-information"/>
276       <xsl:variable name="bookmarks">
277         <xsl:apply-templates select="$document.element" 
278                              mode="fop1.outline"/>
279       </xsl:variable>
280       <xsl:if test="string($bookmarks) != ''">
281         <fo:bookmark-tree>
282           <xsl:copy-of select="$bookmarks"/>
283         </fo:bookmark-tree>
284       </xsl:if>
285       <xsl:apply-templates select="$document.element" 
286                            mode="fop1.foxdest"/>
287     </xsl:if>
288
289     <xsl:if test="$xep.extensions != 0">
290       <xsl:variable name="bookmarks">
291         <xsl:apply-templates select="$document.element" mode="xep.outline"/>
292       </xsl:variable>
293       <xsl:if test="string($bookmarks) != ''">
294         <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
295           <xsl:copy-of select="$bookmarks"/>
296         </rx:outline>
297       </xsl:if>
298     </xsl:if>
299
300     <xsl:if test="$arbortext.extensions != 0 and $ati.xsl11.bookmarks != 0">
301       <xsl:variable name="bookmarks">
302         <xsl:apply-templates select="$document.element"
303                              mode="ati.xsl11.bookmarks"/>
304       </xsl:variable>
305       <xsl:if test="string($bookmarks) != ''">
306         <fo:bookmark-tree>
307           <xsl:copy-of select="$bookmarks"/>
308         </fo:bookmark-tree>
309       </xsl:if>
310     </xsl:if>
311
312     <xsl:apply-templates select="$document.element"/>
313   </fo:root>
314 </xsl:template>
315
316 <xsl:template name="root.messages">
317   <!-- redefine this any way you'd like to output messages -->
318   <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
319   <xsl:message>
320     <xsl:text>Making </xsl:text>
321     <xsl:value-of select="$page.orientation"/>
322     <xsl:text> pages on </xsl:text>
323     <xsl:value-of select="$paper.type"/>
324     <xsl:text> paper (</xsl:text>
325     <xsl:value-of select="$page.width"/>
326     <xsl:text>x</xsl:text>
327     <xsl:value-of select="$page.height"/>
328     <xsl:text>)</xsl:text>
329   </xsl:message>
330 </xsl:template>
331
332 <!-- ==================================================================== -->
333
334 </xsl:stylesheet>