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