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"
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"/>
15 <!-- ********************************************************************
16 $Id: docbook.xsl 9988 2015-09-17 20:22:22Z bobstayton $
17 ********************************************************************
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.
23 ******************************************************************** -->
25 <!-- ==================================================================== -->
28 <xsl:include href="../VERSION.xsl"/>
29 <xsl:include href="param.xsl"/>
30 <xsl:include href="../lib/lib.xsl"/>
31 <xsl:include href="../common/l10n.xsl"/>
32 <xsl:include href="../common/common.xsl"/>
33 <xsl:include href="../common/utility.xsl"/>
34 <xsl:include href="../common/labels.xsl"/>
35 <xsl:include href="../common/titles.xsl"/>
36 <xsl:include href="../common/subtitles.xsl"/>
37 <xsl:include href="../common/gentext.xsl"/>
38 <xsl:include href="../common/olink.xsl"/>
39 <xsl:include href="../common/targets.xsl"/>
40 <xsl:include href="../common/pi.xsl"/>
41 <xsl:include href="autotoc.xsl"/>
42 <xsl:include href="autoidx.xsl"/>
43 <xsl:include href="lists.xsl"/>
44 <xsl:include href="callout.xsl"/>
45 <xsl:include href="verbatim.xsl"/>
46 <xsl:include href="graphics.xsl"/>
47 <xsl:include href="xref.xsl"/>
48 <xsl:include href="formal.xsl"/>
49 <xsl:include href="table.xsl"/>
50 <xsl:include href="htmltbl.xsl"/>
51 <xsl:include href="sections.xsl"/>
52 <xsl:include href="inline.xsl"/>
53 <xsl:include href="footnote.xsl"/>
54 <xsl:include href="fo.xsl"/>
55 <xsl:include href="fo-rtf.xsl"/>
56 <xsl:include href="info.xsl"/>
57 <xsl:include href="keywords.xsl"/>
58 <xsl:include href="division.xsl"/>
59 <xsl:include href="index.xsl"/>
60 <xsl:include href="toc.xsl"/>
61 <xsl:include href="refentry.xsl"/>
62 <xsl:include href="math.xsl"/>
63 <xsl:include href="admon.xsl"/>
64 <xsl:include href="component.xsl"/>
65 <xsl:include href="biblio.xsl"/>
66 <xsl:include href="biblio-iso690.xsl"/>
67 <xsl:include href="glossary.xsl"/>
68 <xsl:include href="block.xsl"/>
69 <xsl:include href="task.xsl"/>
70 <xsl:include href="qandaset.xsl"/>
71 <xsl:include href="synop.xsl"/>
72 <xsl:include href="titlepage.xsl"/>
73 <xsl:include href="titlepage.templates.xsl"/>
74 <xsl:include href="pagesetup.xsl"/>
75 <xsl:include href="pi.xsl"/>
76 <xsl:include href="spaces.xsl"/>
77 <xsl:include href="ebnf.xsl"/>
78 <xsl:include href="../html/chunker.xsl"/>
79 <xsl:include href="annotations.xsl"/>
80 <xsl:include href="publishers.xsl"/>
81 <xsl:include href="../common/stripns.xsl"/>
83 <xsl:include href="fop.xsl"/>
84 <xsl:include href="fop1.xsl"/>
85 <xsl:include href="xep.xsl"/>
86 <xsl:include href="axf.xsl"/>
87 <xsl:include href="ptc.xsl"/>
89 <xsl:param name="stylesheet.result.type" select="'fo'"/>
91 <!-- ==================================================================== -->
93 <xsl:key name="id" match="*" use="@id|@xml:id"/>
95 <!-- ==================================================================== -->
97 <xsl:template match="*">
99 <xsl:text>Element </xsl:text>
100 <xsl:value-of select="local-name(.)"/>
101 <xsl:text> in namespace '</xsl:text>
102 <xsl:value-of select="namespace-uri(.)"/>
103 <xsl:text>' encountered</xsl:text>
104 <xsl:if test="parent::*">
105 <xsl:text> in </xsl:text>
106 <xsl:value-of select="name(parent::*)"/>
108 <xsl:text>, but no template matches.</xsl:text>
111 <fo:block color="red">
112 <xsl:text><</xsl:text>
113 <xsl:value-of select="name(.)"/>
114 <xsl:text>></xsl:text>
115 <xsl:apply-templates/>
116 <xsl:text></</xsl:text>
117 <xsl:value-of select="name(.)"/>
118 <xsl:text>></xsl:text>
122 <!-- Update this list if new root elements supported -->
123 <xsl:variable name="root.elements" select="' appendix article bibliography book chapter colophon dedication glossary index part preface qandaset refentry reference sect1 section set setindex '"/>
125 <xsl:template match="/">
126 <!-- * Get a title for current doc so that we let the user -->
127 <!-- * know what document we are processing at this point. -->
128 <xsl:variable name="doc.title">
129 <xsl:call-template name="get.doc.title"/>
132 <!-- fix namespace if necessary -->
133 <xsl:when test="$exsl.node.set.available != 0 and
134 namespace-uri(/*) = 'http://docbook.org/ns/docbook'">
135 <xsl:variable name="no.namespace">
136 <xsl:apply-templates select="/*" mode="stripNS"/>
139 <xsl:call-template name="log.message">
140 <xsl:with-param name="level">Note</xsl:with-param>
141 <xsl:with-param name="source" select="$doc.title"/>
142 <xsl:with-param name="context-desc">
143 <xsl:text>namesp. cut</xsl:text>
145 <xsl:with-param name="message">
146 <xsl:text>stripped namespace before processing</xsl:text>
149 <!-- DEBUG: uncomment to save namespace-fixed document.
150 <xsl:message>Saving namespace-fixed document.</xsl:message>
151 <xsl:call-template name="write.chunk">
152 <xsl:with-param name="filename" select="'namespace-fixed.debug.xml'"/>
153 <xsl:with-param name="method" select="'xml'"/>
154 <xsl:with-param name="content">
155 <xsl:copy-of select="exsl:node-set($no.namespace)"/>
159 <xsl:apply-templates select="exsl:node-set($no.namespace)"/>
161 <!-- Can't process unless namespace fixed with exsl node-set()-->
162 <xsl:when test="namespace-uri(/*) = 'http://docbook.org/ns/docbook'">
163 <xsl:message terminate="yes">
164 <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
165 <xsl:text> cannot proceed.</xsl:text>
170 <xsl:when test="$rootid != ''">
171 <xsl:variable name="root.element" select="key('id', $rootid)"/>
173 <xsl:when test="count($root.element) = 0">
174 <xsl:message terminate="yes">
175 <xsl:text>ID '</xsl:text>
176 <xsl:value-of select="$rootid"/>
177 <xsl:text>' not found in document.</xsl:text>
180 <xsl:when test="not(contains($root.elements, concat(' ', local-name($root.element), ' ')))">
181 <xsl:message terminate="yes">
182 <xsl:text>ERROR: Document root element ($rootid=</xsl:text>
183 <xsl:value-of select="$rootid"/>
184 <xsl:text>) for FO output </xsl:text>
185 <xsl:text>must be one of the following elements:</xsl:text>
186 <xsl:value-of select="$root.elements"/>
189 <!-- Otherwise proceed -->
191 <xsl:if test="$collect.xref.targets = 'yes' or
192 $collect.xref.targets = 'only'">
193 <xsl:apply-templates select="$root.element"
194 mode="collect.targets"/>
196 <xsl:if test="$collect.xref.targets != 'only'">
197 <xsl:apply-templates select="$root.element"
198 mode="process.root"/>
203 <!-- Otherwise process the document root element -->
205 <xsl:variable name="document.element" select="*[1]"/>
207 <xsl:when test="not(contains($root.elements,
208 concat(' ', local-name($document.element), ' ')))">
209 <xsl:message terminate="yes">
210 <xsl:text>ERROR: Document root element for FO output </xsl:text>
211 <xsl:text>must be one of the following elements:</xsl:text>
212 <xsl:value-of select="$root.elements"/>
215 <!-- Otherwise proceed -->
217 <xsl:if test="$collect.xref.targets = 'yes' or
218 $collect.xref.targets = 'only'">
219 <xsl:apply-templates select="/"
220 mode="collect.targets"/>
222 <xsl:if test="$collect.xref.targets != 'only'">
223 <xsl:apply-templates select="/"
224 mode="process.root"/>
234 <xsl:template match="*" mode="process.root">
235 <xsl:variable name="document.element" select="self::*"/>
237 <xsl:call-template name="root.messages"/>
239 <xsl:variable name="title">
241 <xsl:when test="$document.element/title | $document.element/info/title">
243 select="($document.element/title | $document.element/info/title)[1]"/>
245 <xsl:otherwise>[could not find document title]</xsl:otherwise>
249 <!-- Include all id values in XEP output -->
250 <xsl:if test="$xep.extensions != 0">
251 <xsl:processing-instruction
252 name="xep-pdf-drop-unused-destinations">false</xsl:processing-instruction>
255 <fo:root xsl:use-attribute-sets="root.properties">
256 <xsl:attribute name="language">
257 <xsl:call-template name="l10n.language">
258 <xsl:with-param name="target" select="/*[1]"/>
262 <xsl:if test="$xep.extensions != 0">
263 <xsl:call-template name="xep-pis"/>
264 <xsl:call-template name="xep-document-information"/>
266 <xsl:if test="$axf.extensions != 0">
267 <xsl:call-template name="axf-document-information"/>
270 <xsl:call-template name="setup.pagemasters"/>
272 <xsl:if test="$fop1.extensions != 0">
273 <xsl:call-template name="fop1-document-information"/>
274 <xsl:apply-templates select="$document.element" mode="fop1.foxdest"/>
277 <!-- generate bookmark tree -->
278 <xsl:call-template name="generate.bookmarks"/>
280 <xsl:apply-templates select="$document.element"/>
284 <xsl:template name="generate.bookmarks">
285 <xsl:variable name="document.element" select="self::*"/>
287 <xsl:when test="$show.bookmarks = 0">
288 <!-- omit bookmarks -->
290 <xsl:when test="$xsl1.1.bookmarks != 0">
291 <!-- use standard bookmark elements -->
292 <xsl:variable name="bookmarks">
293 <xsl:apply-templates select="$document.element"
296 <xsl:if test="string($bookmarks) != ''">
298 <xsl:copy-of select="$bookmarks"/>
305 <xsl:when test="$fop.extensions != 0">
306 <xsl:apply-templates select="$document.element" mode="fop.outline"/>
310 <xsl:when test="$fop1.extensions != 0">
311 <xsl:variable name="bookmarks">
312 <xsl:apply-templates select="$document.element"
313 mode="fop1.outline"/>
315 <xsl:if test="string($bookmarks) != ''">
317 <xsl:copy-of select="$bookmarks"/>
322 <!-- RenderX XEP 4.6 and earlier -->
323 <xsl:when test="$xep.extensions != 0">
324 <xsl:variable name="bookmarks">
325 <xsl:apply-templates select="$document.element" mode="xep.outline"/>
327 <xsl:if test="string($bookmarks) != ''">
328 <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
329 <xsl:copy-of select="$bookmarks"/>
334 <!-- PTC Arbortext -->
335 <xsl:when test="$arbortext.extensions != 0">
336 <xsl:variable name="bookmarks">
337 <xsl:apply-templates select="$document.element"
338 mode="ati.xsl11.bookmarks"/>
340 <xsl:if test="string($bookmarks) != ''">
342 <xsl:copy-of select="$bookmarks"/>
351 <xsl:variable name="bookmarks.state">
353 <xsl:when test="$bookmarks.collapse != 0">hide</xsl:when>
354 <xsl:otherwise>show</xsl:otherwise>
358 <xsl:template match="*" mode="bookmark">
359 <xsl:apply-templates select="*" mode="bookmark"/>
362 <xsl:template match="set|book|part|reference|
363 preface|chapter|appendix|article|topic
364 |glossary|bibliography|index|setindex
366 |sect1|sect2|sect3|sect4|sect5|section"
369 <xsl:variable name="id">
370 <xsl:call-template name="object.id"/>
372 <xsl:variable name="bookmark-label">
373 <xsl:apply-templates select="." mode="object.title.markup"/>
376 <!-- Put the root element bookmark at the same level as its children -->
377 <!-- If the object is a set or book, generate a bookmark for the toc -->
380 <xsl:when test="self::index and $generate.index = 0"/>
381 <xsl:when test="parent::*">
382 <fo:bookmark internal-destination="{$id}">
383 <xsl:attribute name="starting-state">
384 <xsl:value-of select="$bookmarks.state"/>
387 <xsl:value-of select="normalize-space($bookmark-label)"/>
389 <xsl:apply-templates select="*" mode="bookmark"/>
393 <fo:bookmark internal-destination="{$id}">
394 <xsl:attribute name="starting-state">
395 <xsl:value-of select="$bookmarks.state"/>
398 <xsl:value-of select="normalize-space($bookmark-label)"/>
402 <xsl:variable name="toc.params">
403 <xsl:call-template name="find.path.params">
404 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
408 <xsl:if test="contains($toc.params, 'toc')
409 and (book|part|reference|preface|chapter|appendix|article|topic
410 |glossary|bibliography|index|setindex
412 |sect1|sect2|sect3|sect4|sect5|section)">
413 <fo:bookmark internal-destination="toc...{$id}">
415 <xsl:call-template name="gentext">
416 <xsl:with-param name="key" select="'TableofContents'"/>
421 <xsl:apply-templates select="*" mode="bookmark"/>
426 <xsl:template name="root.messages">
427 <!-- redefine this any way you'd like to output messages -->
428 <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
430 <xsl:text>Making </xsl:text>
431 <xsl:value-of select="$page.orientation"/>
432 <xsl:text> pages on </xsl:text>
433 <xsl:value-of select="$paper.type"/>
434 <xsl:text> paper (</xsl:text>
435 <xsl:value-of select="$page.width"/>
436 <xsl:text>x</xsl:text>
437 <xsl:value-of select="$page.height"/>
438 <xsl:text>)</xsl:text>
442 <!-- ==================================================================== -->