Debian Codegraph @

docbook-xsl-ns/fo/docbook.xsl

raw symbols SCIP
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:d="http://docbook.org/ns/docbook"
4 xmlns:exsl="http://exslt.org/common"
5 xmlns:fo="http://www.w3.org/1999/XSL/Format"
6 xmlns:ng="http://docbook.org/docbook-ng"
7 xmlns:db="http://docbook.org/ns/docbook"
8 exclude-result-prefixes="db ng exsl d"
9 version='1.0'>
10
11 <!-- It is important to use indent="no" here, otherwise verbatim -->
12 <!-- environments get broken by indented tags...at least when the -->
13 <!-- callout extension is used...at least with some processors -->
14 <xsl:output method="xml" indent="no"/>
15
16 <!-- ********************************************************************
17
18 This file is part of the XSL DocBook Stylesheet distribution.
19 See ../README or http://cdn.docbook.org/release/xsl/current/ for
20 copyright and other information.
21
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="publishers.xsl"/>
80 <xsl:include href="../common/addns.xsl"/>
81
82 <xsl:include href="fop.xsl"/>
83 <xsl:include href="fop1.xsl"/>
84 <xsl:include href="xep.xsl"/>
85 <xsl:include href="axf.xsl"/>
86 <xsl:include href="ptc.xsl"/>
87
88 <xsl:param name="stylesheet.result.type" select="'fo'"/>
89
90 <!-- ==================================================================== -->
91
92 <xsl:key name="id" match="*" use="@id|@xml:id"/>
93
94 <!-- ==================================================================== -->
95
96 <xsl:template match="*">
97 <xsl:message>
98 <xsl:text>Element </xsl:text>
99 <xsl:value-of select="local-name(.)"/>
100 <xsl:text> in namespace '</xsl:text>
101 <xsl:value-of select="namespace-uri(.)"/>
102 <xsl:text>' encountered</xsl:text>
103 <xsl:if test="parent::*">
104 <xsl:text> in </xsl:text>
105 <xsl:value-of select="name(parent::*)"/>
106 </xsl:if>
107 <xsl:text>, but no template matches.</xsl:text>
108 </xsl:message>
109
110 <fo:block color="red">
111 <xsl:text>&lt;</xsl:text>
112 <xsl:value-of select="name(.)"/>
113 <xsl:text>&gt;</xsl:text>
114 <xsl:apply-templates/>
115 <xsl:text>&lt;/</xsl:text>
116 <xsl:value-of select="name(.)"/>
117 <xsl:text>&gt;</xsl:text>
118 </fo:block>
119 </xsl:template>
120
121 <!-- Update this list if new root elements supported -->
122 <xsl:variable name="root.elements" select="' appendix article bibliography book chapter colophon dedication glossary index part preface qandaset refentry reference sect1 section set setindex '"/>
123
124 <xsl:template match="/">
125 <!-- * Get a title for current doc so that we let the user -->
126 <!-- * know what document we are processing at this point. -->
127 <xsl:variable name="doc.title">
128 <xsl:call-template name="get.doc.title"/>
129 </xsl:variable>
130 <xsl:choose>
131 <!-- fix namespace if necessary -->
132 <xsl:when test="$exsl.node.set.available != 0 and
133 namespace-uri(/*) != 'http://docbook.org/ns/docbook'">
134 <xsl:variable name="with.namespace">
135 <xsl:apply-templates select="/*" mode="addNS"/>
136 </xsl:variable>
137
138 <xsl:call-template name="log.message">
139 <xsl:with-param name="level">Note</xsl:with-param>
140 <xsl:with-param name="source" select="$doc.title"/>
141 <xsl:with-param name="context-desc">
142 <xsl:text>namesp. add</xsl:text>
143 </xsl:with-param>
144 <xsl:with-param name="message">
145 <xsl:text>added namespace before processing</xsl:text>
146 </xsl:with-param>
147 </xsl:call-template>
148 <!-- DEBUG: uncomment to save namespace-fixed document.
149 <xsl:message>Saving namespace-fixed document.</xsl:message>
150 <xsl:call-template name="write.chunk">
151 <xsl:with-param name="filename" select="'namespace-fixed.debug.xml'"/>
152 <xsl:with-param name="method" select="'xml'"/>
153 <xsl:with-param name="content">
154 <xsl:copy-of select="exsl:node-set($with.namespace)"/>
155 </xsl:with-param>
156 </xsl:call-template>
157 -->
158 <xsl:apply-templates select="exsl:node-set($with.namespace)"/>
159 </xsl:when>
160 <!-- Can't process unless namespace fixed with exsl node-set()-->
161 <xsl:when test="namespace-uri(/*) != 'http://docbook.org/ns/docbook'">
162 <xsl:message terminate="yes">
163 <xsl:text>Unable to add the namespace from DB4 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/d:title | $document.element/d:info/d:title">
241 <xsl:value-of
242 select="($document.element/d:title | $document.element/d:info/d:title)[1]"/>
243 </xsl:when>
244 <xsl:otherwise>[could not find document title]</xsl:otherwise>
245 </xsl:choose>
246 </xsl:variable>
247
248 <!-- Include all id values in XEP output -->
249 <xsl:if test="$xep.extensions != 0">
250 <xsl:processing-instruction
251 name="xep-pdf-drop-unused-destinations">false</xsl:processing-instruction>
252 </xsl:if>
253
254 <fo:root xsl:use-attribute-sets="root.properties">
255 <xsl:attribute name="language">
256 <xsl:call-template name="l10n.language">
257 <xsl:with-param name="target" select="/*[1]"/>
258 </xsl:call-template>
259 </xsl:attribute>
260
261 <xsl:if test="$xep.extensions != 0">
262 <xsl:call-template name="xep-pis"/>
263 <xsl:call-template name="xep-document-information"/>
264 </xsl:if>
265 <xsl:if test="$axf.extensions != 0">
266 <xsl:call-template name="axf-document-information"/>
267 </xsl:if>
268
269 <xsl:call-template name="setup.pagemasters"/>
270
271 <xsl:if test="$fop1.extensions != 0">
272 <xsl:call-template name="fop1-document-information"/>
273 <xsl:apply-templates select="$document.element" mode="fop1.foxdest"/>
274 </xsl:if>
275
276 <!-- generate bookmark tree -->
277 <xsl:call-template name="generate.bookmarks"/>
278
279 <xsl:apply-templates select="$document.element"/>
280 </fo:root>
281 </xsl:template>
282
283 <xsl:template name="generate.bookmarks">
284 <xsl:variable name="document.element" select="self::*"/>
285 <xsl:choose>
286 <xsl:when test="$show.bookmarks = 0">
287 <!-- omit bookmarks -->
288 </xsl:when>
289 <xsl:when test="$xsl1.1.bookmarks != 0">
290 <!-- use standard bookmark elements -->
291 <xsl:variable name="bookmarks">
292 <xsl:apply-templates select="$document.element"
293 mode="bookmark"/>
294 </xsl:variable>
295 <xsl:if test="string($bookmarks) != ''">
296 <fo:bookmark-tree>
297 <xsl:copy-of select="$bookmarks"/>
298 </fo:bookmark-tree>
299 </xsl:if>
300 </xsl:when>
301 <xsl:otherwise>
302 <xsl:choose>
303 <!-- pre FOP 1.0 -->
304 <xsl:when test="$fop.extensions != 0">
305 <xsl:apply-templates select="$document.element" mode="fop.outline"/>
306 </xsl:when>
307
308 <!-- FOP 1.0 -->
309 <xsl:when test="$fop1.extensions != 0">
310 <xsl:variable name="bookmarks">
311 <xsl:apply-templates select="$document.element"
312 mode="fop1.outline"/>
313 </xsl:variable>
314 <xsl:if test="string($bookmarks) != ''">
315 <fo:bookmark-tree>
316 <xsl:copy-of select="$bookmarks"/>
317 </fo:bookmark-tree>
318 </xsl:if>
319 </xsl:when>
320
321 <!-- RenderX XEP 4.6 and earlier -->
322 <xsl:when test="$xep.extensions != 0">
323 <xsl:variable name="bookmarks">
324 <xsl:apply-templates select="$document.element" mode="xep.outline"/>
325 </xsl:variable>
326 <xsl:if test="string($bookmarks) != ''">
327 <rx:outline xmlns:rx="http://www.renderx.com/XSL/Extensions">
328 <xsl:copy-of select="$bookmarks"/>
329 </rx:outline>
330 </xsl:if>
331 </xsl:when>
332
333 <!-- PTC Arbortext -->
334 <xsl:when test="$arbortext.extensions != 0">
335 <xsl:variable name="bookmarks">
336 <xsl:apply-templates select="$document.element"
337 mode="ati.xsl11.bookmarks"/>
338 </xsl:variable>
339 <xsl:if test="string($bookmarks) != ''">
340 <fo:bookmark-tree>
341 <xsl:copy-of select="$bookmarks"/>
342 </fo:bookmark-tree>
343 </xsl:if>
344 </xsl:when>
345 </xsl:choose>
346 </xsl:otherwise>
347 </xsl:choose>
348 </xsl:template>
349
350 <xsl:variable name="bookmarks.state">
351 <xsl:choose>
352 <xsl:when test="$bookmarks.collapse != 0">hide</xsl:when>
353 <xsl:otherwise>show</xsl:otherwise>
354 </xsl:choose>
355 </xsl:variable>
356
357 <xsl:template match="*" mode="bookmark">
358 <xsl:apply-templates select="*" mode="bookmark"/>
359 </xsl:template>
360
361 <xsl:template match="d:set|d:book|d:part|d:reference|
362 d:preface|d:chapter|d:appendix|d:article|d:topic
363 |d:glossary|d:bibliography|d:index|d:setindex
364 |d:refentry
365 |d:sect1|d:sect2|d:sect3|d:sect4|d:sect5|d:section"
366 mode="bookmark">
367
368 <xsl:variable name="id">
369 <xsl:call-template name="object.id"/>
370 </xsl:variable>
371 <xsl:variable name="bookmark-label">
372 <xsl:apply-templates select="." mode="object.title.markup"/>
373 </xsl:variable>
374
375 <!-- Put the root element bookmark at the same level as its children -->
376 <!-- If the object is a set or book, generate a bookmark for the toc -->
377
378 <xsl:choose>
379 <xsl:when test="self::d:index and $generate.index = 0"/>
380 <xsl:when test="parent::*">
381 <fo:bookmark internal-destination="{$id}">
382 <xsl:attribute name="starting-state">
383 <xsl:value-of select="$bookmarks.state"/>
384 </xsl:attribute>
385 <fo:bookmark-title>
386 <xsl:value-of select="normalize-space($bookmark-label)"/>
387 </fo:bookmark-title>
388 <xsl:apply-templates select="*" mode="bookmark"/>
389 </fo:bookmark>
390 </xsl:when>
391 <xsl:otherwise>
392 <fo:bookmark internal-destination="{$id}">
393 <xsl:attribute name="starting-state">
394 <xsl:value-of select="$bookmarks.state"/>
395 </xsl:attribute>
396 <fo:bookmark-title>
397 <xsl:value-of select="normalize-space($bookmark-label)"/>
398 </fo:bookmark-title>
399 </fo:bookmark>
400
401 <xsl:variable name="toc.params">
402 <xsl:call-template name="find.path.params">
403 <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
404 </xsl:call-template>
405 </xsl:variable>
406
407 <xsl:if test="contains($toc.params, 'toc')
408 and (d:book|d:part|d:reference|d:preface|d:chapter|d:appendix|d:article|d:topic
409 |d:glossary|d:bibliography|d:index|d:setindex
410 |d:refentry
411 |d:sect1|d:sect2|d:sect3|d:sect4|d:sect5|d:section)">
412 <fo:bookmark internal-destination="toc...{$id}">
413 <fo:bookmark-title>
414 <xsl:call-template name="gentext">
415 <xsl:with-param name="key" select="'TableofContents'"/>
416 </xsl:call-template>
417 </fo:bookmark-title>
418 </fo:bookmark>
419 </xsl:if>
420 <xsl:apply-templates select="*" mode="bookmark"/>
421 </xsl:otherwise>
422 </xsl:choose>
423 </xsl:template>
424
425 <xsl:template name="root.messages">
426 <!-- redefine this any way you'd like to output messages -->
427 <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
428 <xsl:message>
429 <xsl:text>Making </xsl:text>
430 <xsl:value-of select="$page.orientation"/>
431 <xsl:text> pages on </xsl:text>
432 <xsl:value-of select="$paper.type"/>
433 <xsl:text> paper (</xsl:text>
434 <xsl:value-of select="$page.width"/>
435 <xsl:text>x</xsl:text>
436 <xsl:value-of select="$page.height"/>
437 <xsl:text>)</xsl:text>
438 </xsl:message>
439 </xsl:template>
440
441 <!-- ==================================================================== -->
442
443 </xsl:stylesheet>