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