VirtualBox

source: vbox/trunk/doc/manual/docbook2latex.xsl@ 56475

Last change on this file since 56475 was 56469, checked in by vboxsync, 10 years ago

docbook2latex.xsl: new section tricks.

File size: 37.5 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 docbook2latex.xslt:
5 translates a DocBook XML source into a LaTeX source file,
6 which can be processed with pdflatex to produce a
7 pretty PDF file.
8
9 Note: In the LaTeX output, this XSLT encodes all quotes
10 with \QUOTE{} commands, which are not defined in this
11 file. This is because XSLT does not support regular
12 expressions natively and therefore it is rather difficult
13 to implement proper "pretty quotes" (different glyphs for
14 opening and closing quotes) in XSLT. The doc/manual/
15 makefile solves this by running sed over the LaTeX source
16 once more, replacing all \QUOTE{} commands with
17 \OQ{} and \CQ{} commands, which _are_ defined to the
18 pretty quotes for English in the LaTeX output generated
19 by this XSLT (see below).
20
21 Copyright (C) 2006-2012 Oracle Corporation
22
23 This file is part of VirtualBox Open Source Edition (OSE), as
24 available from http://www.virtualbox.org. This file is free software;
25 you can redistribute it and/or modify it under the terms of the GNU
26 General Public License (GPL) as published by the Free Software
27 Foundation, in version 2 as it comes in the "COPYING" file of the
28 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
29 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
30 -->
31
32<xsl:stylesheet
33 version="1.0"
34 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
35 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
36 xmlns:str="http://xsltsl.org/string"
37>
38
39 <xsl:import href="string.xsl"/>
40
41 <xsl:variable name="g_nlsChapter">
42 <xsl:choose>
43 <xsl:when test="$TARGETLANG='de_DE'">Kapitel</xsl:when>
44 <xsl:when test="$TARGETLANG='fr_FR'">chapitre</xsl:when>
45 <xsl:when test="$TARGETLANG='en_US'">chapter</xsl:when>
46 <xsl:otherwise>
47 <xsl:message terminate="yes"><xsl:value-of select="concat('Invalid language ', $TARGETLANG)" /></xsl:message>
48 </xsl:otherwise>
49 </xsl:choose>
50 </xsl:variable>
51
52 <xsl:variable name="g_nlsPage">
53 <xsl:choose>
54 <xsl:when test="$TARGETLANG='de_DE'">auf Seite</xsl:when>
55 <xsl:when test="$TARGETLANG='fr_FR'">page</xsl:when>
56 <xsl:when test="$TARGETLANG='en_US'">page</xsl:when>
57 <xsl:otherwise>
58 <xsl:message terminate="yes"><xsl:value-of select="concat('Invalid language ', $TARGETLANG)" /></xsl:message>
59 </xsl:otherwise>
60 </xsl:choose>
61 </xsl:variable>
62
63 <xsl:variable name="g_nlsNote">
64 <xsl:choose>
65 <xsl:when test="$TARGETLANG='de_DE'">Hinweis</xsl:when>
66 <xsl:when test="$TARGETLANG='fr_FR'">Note</xsl:when>
67 <xsl:when test="$TARGETLANG='en_US'">Note</xsl:when>
68 <xsl:otherwise>
69 <xsl:message terminate="yes"><xsl:value-of select="concat('Invalid language ', $TARGETLANG)" /></xsl:message>
70 </xsl:otherwise>
71 </xsl:choose>
72 </xsl:variable>
73
74 <xsl:variable name="g_nlsWarning">
75 <xsl:choose>
76 <xsl:when test="$TARGETLANG='de_DE'">Warnung</xsl:when>
77 <xsl:when test="$TARGETLANG='fr_FR'">Avertissement</xsl:when>
78 <xsl:when test="$TARGETLANG='en_US'">Warning</xsl:when>
79 <xsl:otherwise>
80 <xsl:message terminate="yes"><xsl:value-of select="concat('Invalid language ', $TARGETLANG)" /></xsl:message>
81 </xsl:otherwise>
82 </xsl:choose>
83 </xsl:variable>
84
85 <xsl:output method="text"/>
86
87 <xsl:strip-space elements="*"/>
88 <xsl:preserve-space elements="para"/>
89
90 <xsl:template match="/book">
91 <xsl:text>
92\documentclass[oneside,a4paper,10pt,DIV10]{scrbook}
93\usepackage{geometry}
94\geometry{top=3cm,bottom=4cm}
95\usepackage{ucs}
96\usepackage[utf8x]{inputenc}
97\usepackage[T1]{fontenc}
98\usepackage{tabulary}
99\usepackage[pdftex,
100 a4paper,
101 colorlinks=true,
102 linkcolor=blue,
103 urlcolor=darkgreen,
104 bookmarksnumbered,
105 bookmarksopen=true,
106 bookmarksopenlevel=0,
107 hyperfootnotes=false,
108 plainpages=false,
109 pdfpagelabels
110 ]{hyperref}
111
112\usepackage{nameref}
113\usepackage{graphicx}
114\usepackage{hyperref}
115\usepackage{fancybox}
116\usepackage{fancyvrb}
117\usepackage{alltt}
118\usepackage{color}
119\usepackage{scrextend}
120\definecolor{darkgreen}{rgb}{0,0.6,0}
121
122</xsl:text>
123 <xsl:if test="$TARGETLANG='de_DE'">\usepackage[ngerman]{babel}&#10;\PrerenderUnicode{ü}</xsl:if>
124<!-- <xsl:if test="$TARGETLANG='fr_FR'">\usepackage[french]{babel}&#10;\FrenchItemizeSpacingfalse&#10;\renewcommand{\FrenchLabelItem}{\textbullet}</xsl:if>
125 this command is no longer understood by TexLive2008
126 -->
127 <xsl:text>
128
129% use Palatino as serif font:
130% \usepackage{mathpazo}
131\usepackage{charter}
132% use Helvetica as sans-serif font:
133\usepackage{helvet}
134
135% use Bera Mono (a variant of Bitstream Vera Mono) as typewriter font
136% (requires texlive-fontsextra)
137\usepackage[scaled]{beramono}
138% previously: use Courier as typewriter font:
139% \usepackage{courier}
140
141\definecolor{colNote}{rgb}{0,0,0}
142\definecolor{colWarning}{rgb}{0,0,0}
143\definecolor{colScreenFrame}{rgb}{0,0,0}
144\definecolor{colScreenText}{rgb}{0,0,0}
145
146% number headings down to this level
147\setcounter{secnumdepth}{3}
148% more space for the section numbers
149\makeatletter
150\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{2.9em}}
151\renewcommand*\l@subsection{\@dottedtocline{2}{4.4em}{3.8em}}
152\renewcommand*\l@subsubsection{\@dottedtocline{3}{8.2em}{3.8em}}
153\renewcommand*\@pnumwidth{1.7em}
154\renewcommand*\@tocrmarg{5.0em}
155\makeatother
156
157% more tolerance at 2nd wrap stage:
158\tolerance = 1000
159% allow 3rd wrap stage:
160\emergencystretch = 10pt
161% no Schusterjungen:
162\clubpenalty = 10000
163% no Hurenkinder:
164\widowpenalty = 10000
165\displaywidowpenalty = 10000
166% max pdf compression:
167\pdfcompresslevel9
168
169% opening and closing quotes: the OQ and CQ macros define this (and the makefile employs some sed magic also)
170</xsl:text>
171 <xsl:choose>
172 <xsl:when test="$TARGETLANG='de_DE'">
173 <xsl:text>\newcommand\OQ{\texorpdfstring{\glqq}{"}}&#10;\newcommand\CQ{\texorpdfstring{\grqq}{"}}&#10;</xsl:text>
174 </xsl:when>
175 <xsl:when test="$TARGETLANG='fr_FR'">
176 <xsl:text>\newcommand\OQ{\texorpdfstring{``}{"}}&#10;\newcommand\CQ{\texorpdfstring{''}{"}}&#10;</xsl:text>
177 </xsl:when>
178 <xsl:when test="$TARGETLANG='en_US'">
179 <xsl:text>\newcommand\OQ{\texorpdfstring{``}{"}}&#10;\newcommand\CQ{\texorpdfstring{''}{"}}&#10;</xsl:text>
180 </xsl:when>
181 <xsl:otherwise>
182 <xsl:message terminate="yes"><xsl:value-of select="concat('Invalid language ', $TARGETLANG)" /></xsl:message>
183 </xsl:otherwise>
184 </xsl:choose>
185
186 <xsl:apply-templates />
187
188 <xsl:text>
189\end{document}
190 </xsl:text>
191
192 </xsl:template>
193
194 <xsl:template match="bookinfo">
195 <xsl:apply-templates />
196 <xsl:text>&#x0a;\newcommand\docbookbookinfocopyright{\copyright{} \docbookbookinfocopyrightyear{} \docbookbookinfocopyrightholder{}}&#x0a;
197\author{ \docbooktitleedition \\ %
198\\ %
199</xsl:text>
200 <xsl:if test="//bookinfo/address">
201 <xsl:text>\docbookbookinfoaddress \\ %
202\\ %
203</xsl:text>
204 </xsl:if>
205 <xsl:text>\docbookbookinfocopyright \\ %
206}
207
208\title{\docbooktitle \\
209\docbooksubtitle}
210% \subtitle{\docbooksubtitle}
211\hypersetup{pdfauthor=\docbookcorpauthor}
212\hypersetup{pdftitle=\docbooktitle{} \docbooksubtitle{}}
213
214\hyphenation{da-ta-ba-ses}
215\hyphenation{deb-conf}
216\hyphenation{VirtualBox}
217
218\begin{document}
219% \maketitle
220%\begin{titlepage}
221\thispagestyle{empty}
222\begin{minipage}{\textwidth}
223\begin{center}
224\includegraphics[width=4cm]{images/vboxlogo.png}
225\end{center}%
226\vspace{10mm}
227
228{\fontsize{40pt}{40pt}\selectfont\rmfamily\bfseries%
229\begin{center}
230\docbooktitle
231\end{center}%
232\vspace{10mm}
233}
234
235{\fontsize{30pt}{30pt}\selectfont\rmfamily\bfseries%
236\begin{center}
237\docbooksubtitle
238\end{center}%
239\vspace{10mm}
240}
241
242{\fontsize{16pt}{20pt}\selectfont\rmfamily%
243\begin{center}
244</xsl:text>
245 <xsl:if test="//bookinfo/othercredit">
246 <xsl:text>\docbookbookinfoothercreditcontrib{}: \docbookbookinfoothercreditfirstname{} \docbookbookinfoothercreditsurname
247
248\vspace{8mm}
249</xsl:text>
250 </xsl:if>
251 <xsl:text>\docbooktitleedition
252
253\vspace{2mm}
254
255\docbookbookinfocopyright
256
257\vspace{2mm}
258
259\docbookbookinfoaddress
260\end{center}%
261}
262
263%\end{titlepage}
264\end{minipage}
265
266\tableofcontents
267 </xsl:text>
268 </xsl:template>
269
270 <xsl:template match="subtitle">
271 <xsl:choose>
272 <xsl:when test="name(..)='bookinfo'">
273 <xsl:text>\newcommand\docbooksubtitle{</xsl:text>
274 <xsl:apply-templates />
275 <xsl:text>}</xsl:text>
276 </xsl:when>
277 </xsl:choose>
278 </xsl:template>
279
280 <!--
281 Inserts \hypertarget{@id} that can be referenced via the /A "nameddest=@id"
282 command line or #nameddest=@id URL parameter.
283
284 TODO: The placement of the target could be improved on. The raisebox
285 stuff is a crude hack to make it a little more acceptable. -->
286 <xsl:template name="title-wrapper">
287 <xsl:param name="texcmd" select="concat('\',name(..))"/>
288 <xsl:param name="refid" select="../@id"/>
289
290 <xsl:call-template name="xsltprocNewlineOutputHack"/>
291 <xsl:choose>
292 <xsl:when test="$refid">
293 <xsl:text>&#x0a;</xsl:text>
294 <xsl:value-of select="$texcmd"/>
295 <xsl:if test="not(contains($texcmd, '*'))">
296 <xsl:text>[</xsl:text> <!-- for toc -->
297 <xsl:apply-templates />
298 <xsl:text>]</xsl:text>
299 </xsl:if>
300 <xsl:text>{</xsl:text> <!-- for doc -->
301 <xsl:text>\raisebox{\ht\strutbox}{\hypertarget{</xsl:text>
302 <xsl:value-of select="$refid"/>
303 <xsl:text>}{}}</xsl:text>
304 <xsl:apply-templates />
305 <xsl:text>}</xsl:text>
306 </xsl:when>
307 <xsl:otherwise>
308 <xsl:text>&#x0a;</xsl:text><xsl:value-of select="$texcmd"/><xsl:text>{</xsl:text>
309 <xsl:apply-templates />
310 <xsl:text>}</xsl:text>
311 </xsl:otherwise>
312 </xsl:choose>
313 </xsl:template>
314
315 <xsl:template match="title">
316 <xsl:variable name="refid" select="../@id" />
317 <xsl:choose>
318 <xsl:when test="name(..)='bookinfo'">
319 <xsl:text>\newcommand\docbooktitle{</xsl:text>
320 <xsl:apply-templates />
321 <xsl:text>}</xsl:text>
322 </xsl:when>
323 <xsl:when test="name(..)='chapter'">
324 <xsl:call-template name="title-wrapper"/>
325 </xsl:when>
326 <xsl:when test="name(..)='sect1'">
327 <xsl:call-template name="title-wrapper">
328 <xsl:with-param name="texcmd">\section</xsl:with-param>
329 </xsl:call-template>
330 </xsl:when>
331 <xsl:when test="parent::sect2[@condition='no-toc'] or parent::refsect1 or (parent::section and count(ancestor::section) = 2)">
332 <xsl:call-template name="title-wrapper">
333 <xsl:with-param name="texcmd">\subsection*</xsl:with-param>
334 </xsl:call-template>
335 </xsl:when>
336 <xsl:when test="name(..)='sect2'">
337 <xsl:call-template name="title-wrapper">
338 <xsl:with-param name="texcmd">\subsection</xsl:with-param>
339 </xsl:call-template>
340 </xsl:when>
341 <xsl:when test="parent::sect3[@condition='no-toc'] or parent::refsect2 or (parent::section and count(ancestor::section) = 3)">
342 <xsl:call-template name="title-wrapper">
343 <xsl:with-param name="texcmd">\subsubsection*</xsl:with-param>
344 </xsl:call-template>
345 </xsl:when>
346 <xsl:when test="name(..)='sect3'">
347 <xsl:call-template name="title-wrapper">
348 <xsl:with-param name="texcmd">\subsubsection</xsl:with-param>
349 </xsl:call-template>
350 </xsl:when>
351 <xsl:when test="parent::sect4[@condition='no-toc'] or parent::refsect3 or (parent::section and count(ancestor::section) = 4)">
352 <xsl:call-template name="title-wrapper">
353 <xsl:with-param name="texcmd">\paragraph*</xsl:with-param>
354 </xsl:call-template>
355 </xsl:when>
356 <xsl:when test="name(..)='sect4'">
357 <xsl:call-template name="title-wrapper">
358 <xsl:with-param name="texcmd">\paragraph</xsl:with-param>
359 </xsl:call-template>
360 </xsl:when>
361 <xsl:when test="parent::sect5[@condition='no-toc'] or parent::refsect4 or (parent::section and count(ancestor::section) = 5)">
362 <xsl:call-template name="title-wrapper">
363 <xsl:with-param name="texcmd">\subparagraph*</xsl:with-param>
364 </xsl:call-template>
365 </xsl:when>
366 <xsl:when test="name(..)='sect5'">
367 <xsl:call-template name="title-wrapper">
368 <xsl:with-param name="texcmd">\subparagraph</xsl:with-param>
369 </xsl:call-template>
370 </xsl:when>
371 <xsl:when test="name(..)='appendix'">
372 <xsl:call-template name="title-wrapper">
373 <xsl:with-param name="texcmd">\chapter</xsl:with-param>
374 </xsl:call-template>
375 </xsl:when>
376 <xsl:when test="name(..)='glossdiv'">
377 <xsl:call-template name="title-wrapper">
378 <xsl:with-param name="texcmd">\section*</xsl:with-param>
379 </xsl:call-template>
380 </xsl:when>
381 </xsl:choose>
382 <xsl:if test="$refid">
383 <xsl:value-of select="concat('&#x0a;\label{', $refid, '}')" />
384 </xsl:if>
385 <xsl:text>&#x0a;</xsl:text>
386 </xsl:template>
387
388 <xsl:template match="edition">
389 <xsl:choose>
390 <xsl:when test="name(..)='bookinfo'">
391 <xsl:text>\newcommand\docbooktitleedition{</xsl:text>
392 <xsl:apply-templates />
393 <xsl:text>}&#x0a;</xsl:text>
394 </xsl:when>
395 </xsl:choose>
396 </xsl:template>
397
398 <xsl:template match="corpauthor">
399 <xsl:choose>
400 <xsl:when test="name(..)='bookinfo'">
401 <xsl:text>\newcommand\docbookcorpauthor{</xsl:text>
402 <xsl:apply-templates />
403 <xsl:text>}&#x0a;</xsl:text>
404 </xsl:when>
405 </xsl:choose>
406 </xsl:template>
407
408 <xsl:template match="address">
409 <xsl:choose>
410 <xsl:when test="name(..)='bookinfo'">
411 <xsl:text>\newcommand\docbookbookinfoaddress{</xsl:text>
412 <xsl:apply-templates />
413 <xsl:text>}&#x0a;</xsl:text>
414 </xsl:when>
415 </xsl:choose>
416 </xsl:template>
417
418 <xsl:template match="year">
419 <xsl:choose>
420 <xsl:when test="name(..)='copyright'">
421 <xsl:text>\newcommand\docbookbookinfocopyrightyear{</xsl:text>
422 <xsl:apply-templates />
423 <xsl:text>}&#x0a;</xsl:text>
424 </xsl:when>
425 </xsl:choose>
426 </xsl:template>
427
428 <xsl:template match="holder">
429 <xsl:choose>
430 <xsl:when test="name(..)='copyright'">
431 <xsl:text>\newcommand\docbookbookinfocopyrightholder{</xsl:text>
432 <xsl:apply-templates />
433 <xsl:text>}&#x0a;</xsl:text>
434 </xsl:when>
435 </xsl:choose>
436 </xsl:template>
437
438 <xsl:template match="firstname">
439 <xsl:choose>
440 <xsl:when test="name(..)='othercredit'">
441 <xsl:text>\newcommand\docbookbookinfoothercreditfirstname{</xsl:text>
442 <xsl:apply-templates />
443 <xsl:text>}&#x0a;</xsl:text>
444 </xsl:when>
445 </xsl:choose>
446 </xsl:template>
447
448 <xsl:template match="surname">
449 <xsl:choose>
450 <xsl:when test="name(..)='othercredit'">
451 <xsl:text>\newcommand\docbookbookinfoothercreditsurname{</xsl:text>
452 <xsl:apply-templates />
453 <xsl:text>}&#x0a;</xsl:text>
454 </xsl:when>
455 </xsl:choose>
456 </xsl:template>
457
458 <xsl:template match="contrib">
459 <xsl:choose>
460 <xsl:when test="name(..)='othercredit'">
461 <xsl:text>\newcommand\docbookbookinfoothercreditcontrib{</xsl:text>
462 <xsl:apply-templates />
463 <xsl:text>}&#x0a;</xsl:text>
464 </xsl:when>
465 </xsl:choose>
466 </xsl:template>
467
468 <xsl:template match="glossary">
469 <xsl:text>&#x0a;&#x0a;\backmatter&#x0a;\chapter{Glossary}&#x0a;</xsl:text>
470 <xsl:apply-templates />
471 </xsl:template>
472
473 <xsl:template match="para">
474 <xsl:if test="not(name(..)='footnote' or name(..)='note' or name(..)='warning' or (name(../..)='varlistentry' and position()=1))">
475 <xsl:text>&#x0a;&#x0a;</xsl:text>
476 </xsl:if>
477 <xsl:apply-templates />
478 </xsl:template>
479
480 <xsl:template match="note">
481 <xsl:value-of select="concat('&#x0a;&#x0a;\vspace{.2cm}&#x0a;&#x0a;\begin{center}\fbox{\begin{minipage}[c]{0.9\textwidth}\color{colNote}\textbf{', $g_nlsNote, ':} ')" />
482 <xsl:apply-templates />
483 <xsl:text>\end{minipage}}\end{center}&#x0a;&#x0a;\vspace{.2cm}&#x0a;&#x0a;</xsl:text>
484 </xsl:template>
485
486 <xsl:template match="warning">
487 <xsl:value-of select="concat('&#x0a;&#x0a;\vspace{.2cm}&#x0a;&#x0a;\begin{center}\fbox{\begin{minipage}[c]{0.9\textwidth}\color{colWarning}\textbf{', $g_nlsWarning, ':} ')" />
488 <xsl:apply-templates />
489 <xsl:text>\end{minipage}}\end{center}&#x0a;&#x0a;\vspace{.2cm}&#x0a;&#x0a;</xsl:text>
490 </xsl:template>
491
492 <xsl:template match="screen">
493 <xsl:text>&#x0a;&#x0a;\begin{Verbatim}[fontsize=\footnotesize]&#x0a;</xsl:text>
494 <xsl:apply-templates />
495 <xsl:text>&#x0a;\end{Verbatim}&#x0a;</xsl:text>
496 </xsl:template>
497
498 <xsl:template match="programlisting">
499 <xsl:text>&#x0a;&#x0a;{\small\begin{alltt}&#x0a;</xsl:text>
500 <xsl:apply-templates />
501 <xsl:text>&#x0a;\end{alltt}}&#x0a;</xsl:text>
502 </xsl:template>
503
504 <xsl:template match="footnote">
505 <xsl:text>\footnote{</xsl:text>
506 <xsl:apply-templates />
507 <xsl:text>}</xsl:text>
508 </xsl:template>
509
510 <xsl:template match="tgroup">
511 <xsl:choose>
512 <xsl:when test="@style='verywide'">
513 <xsl:text>&#x0a;&#x0a;{\small\begin{center}&#x0a;\begin{tabulary}{1.1\textwidth}[]{|L|L|L|}&#x0a;\hline&#x0a;</xsl:text>
514 </xsl:when>
515 <xsl:otherwise>
516 <xsl:text>&#x0a;&#x0a;{\small\begin{center}&#x0a;\begin{tabulary}{.9\textwidth}[]{|L|L|L|}&#x0a;\hline&#x0a;</xsl:text>
517 </xsl:otherwise>
518 </xsl:choose>
519 <xsl:apply-templates />
520 <xsl:text>&#x0a;\end{tabulary}&#x0a;\end{center}}&#x0a;</xsl:text>
521 </xsl:template>
522
523 <xsl:template match="row">
524 <xsl:apply-templates />
525 <xsl:text>&#x0a;\\ \hline&#x0a;</xsl:text>
526 </xsl:template>
527
528 <xsl:template match="entry">
529 <xsl:if test="not(position()=1)">
530 <xsl:text> &amp; </xsl:text>
531 </xsl:if>
532 <xsl:apply-templates />
533 </xsl:template>
534
535 <xsl:template match="itemizedlist">
536 <xsl:call-template name="xsltprocNewlineOutputHack"/>
537 <xsl:text>&#x0a;\begin{itemize}&#x0a;</xsl:text>
538 <xsl:apply-templates />
539 <xsl:text>&#x0a;\end{itemize}&#x0a;</xsl:text>
540 </xsl:template>
541
542 <xsl:template match="orderedlist">
543 <xsl:call-template name="xsltprocNewlineOutputHack"/>
544 <xsl:text>&#x0a;\begin{enumerate}&#x0a;</xsl:text>
545 <xsl:apply-templates />
546 <xsl:text>&#x0a;\end{enumerate}&#x0a;</xsl:text>
547 </xsl:template>
548
549 <xsl:template match="variablelist">
550 <xsl:call-template name="xsltprocNewlineOutputHack"/>
551 <xsl:text>&#x0a;\begin{description}&#x0a;</xsl:text>
552 <xsl:apply-templates />
553 <xsl:text>&#x0a;\end{description}&#x0a;</xsl:text>
554 </xsl:template>
555
556 <xsl:template match="varlistentry">
557 <xsl:if test="not(./term) or not(./listitem) or count(*) != 2">
558 <xsl:message terminate="yes">Expected exactly one term and one listitem element in the varlistentry.</xsl:message>
559 </xsl:if>
560 <xsl:text>&#x0a;&#x0a;\item[</xsl:text>
561 <xsl:apply-templates select="term"/>
562 <xsl:text>] \hfill \\&#x0a;</xsl:text>
563 <xsl:apply-templates select="listitem/*"/>
564 </xsl:template>
565
566 <xsl:template match="listitem">
567 <xsl:text>&#x0a;&#x0a;\item </xsl:text>
568 <xsl:apply-templates />
569 <xsl:text>&#x0a;</xsl:text>
570 </xsl:template>
571
572 <xsl:template match="glossterm">
573 <xsl:variable name="refid" select="(@id)" />
574 <xsl:if test="$refid">
575 <xsl:value-of select="concat('&#x0a;\label{', $refid, '}')" />
576 </xsl:if>
577 <xsl:text>&#x0a;&#x0a;\item[</xsl:text>
578 <xsl:apply-templates />
579 <xsl:text>]</xsl:text>
580 </xsl:template>
581
582 <xsl:template match="glosslist | glossdiv">
583 <xsl:text>&#x0a;&#x0a;\begin{description}&#x0a;</xsl:text>
584 <xsl:apply-templates />
585 <xsl:text>&#x0a;\end{description}&#x0a;</xsl:text>
586 </xsl:template>
587
588 <xsl:template match="superscript">
589 <xsl:variable name="contents">
590 <xsl:apply-templates />
591 </xsl:variable>
592 <xsl:value-of select="concat('\texorpdfstring{\textsuperscript{', $contents, '}}{', $contents, '}')" />
593 </xsl:template>
594
595 <xsl:template match="emphasis">
596 <xsl:choose>
597 <xsl:when test="@role='bold'">
598 <xsl:text>\textbf{</xsl:text>
599 </xsl:when>
600 <xsl:otherwise>
601 <xsl:text>\textit{</xsl:text>
602 </xsl:otherwise>
603 </xsl:choose>
604 <xsl:apply-templates />
605 <xsl:text>}</xsl:text>
606 </xsl:template>
607
608 <xsl:template match="computeroutput | code">
609 <xsl:text>\texttt{</xsl:text>
610 <xsl:apply-templates />
611 <xsl:text>}</xsl:text>
612 </xsl:template>
613
614 <xsl:template match="ulink">
615 <xsl:text>\url{</xsl:text>
616 <xsl:apply-templates />
617 <xsl:text>}</xsl:text>
618 </xsl:template>
619
620 <xsl:template match="xref">
621 <xsl:choose>
622 <xsl:when test="@xreflabel">
623 <xsl:value-of select="concat('\hyperref[', @linkend, ']{\mbox{', @xreflabel, '}}')" />
624 </xsl:when>
625 <xsl:when test="@apiref='yes'">
626 <xsl:value-of select="concat('\hyperref[', @linkend, ']{\mbox{')" />
627 <xsl:apply-templates />
628 <xsl:value-of select="'}}'" />
629 </xsl:when>
630 <xsl:otherwise>
631 <xsl:value-of select="concat($g_nlsChapter, ' \ref{', @linkend, '}, \textit{\nameref{', @linkend, '}}, ', $g_nlsPage, ' \pageref{', @linkend, '}')" />
632 </xsl:otherwise>
633 </xsl:choose>
634 </xsl:template>
635
636 <!-- for some reason, DocBook insists of having image data nested this way always:
637 mediaobject -> imageobject -> imagedata
638 but only imagedata is interesting -->
639 <xsl:template match="imagedata">
640 <xsl:if test="@align='center'">
641 <xsl:text>\begin{center}</xsl:text>
642 </xsl:if>
643 <xsl:value-of select="concat('&#x0a;\includegraphics[width=', @width, ']{', @fileref, '}&#x0a;')" />
644 <xsl:apply-templates />
645 <xsl:if test="@align='center'">
646 <xsl:text>\end{center}</xsl:text>
647 </xsl:if>
648 </xsl:template>
649
650 <!--
651 Turn the refsynopsisdiv part of a manpage into a named & indented paragraph.
652 -->
653 <xsl:template match="refsynopsisdiv">
654 <xsl:if test="name(*[1]) != 'cmdsynopsis'"><xsl:message terminate="yes">Expected refsynopsisdiv to start with cmdsynopsis</xsl:message></xsl:if>
655 <xsl:if test="title"><xsl:message terminate="yes">No title element supported in refsynopsisdiv</xsl:message></xsl:if>
656 <xsl:call-template name="xsltprocNewlineOutputHack"/>
657 <xsl:text>&#x0a;\subsection*{Synopsis}</xsl:text>
658 <xsl:if test="name(*[1]) != 'cmdsynopsis'"> <!-- just in case -->
659 <xsl:text>\hfill \\&#x0a;</xsl:text>
660 </xsl:if>
661 <xsl:text>&#x0a;</xsl:text>
662 <xsl:apply-templates />
663 </xsl:template>
664
665 <!--
666 The refsect1 is used for 'Description' and such. Do same as with refsynopsisdiv
667 and turn it into a named & indented paragraph.
668 -->
669 <xsl:template match="refsect1">
670 <xsl:if test="name(*[1]) != 'title' or count(title) != 1">
671 <xsl:message terminate="yes">Expected exactly one title as the first refsect1 element (remarks goes after title!).</xsl:message>
672 </xsl:if>
673 <xsl:apply-templates/>
674 </xsl:template>
675
676 <!--
677 The refsect2 element will be turned into a subparagraph if it has a title,
678 however, that didn't work out when it didn't have a title and started with
679 a cmdsynopsis instead (subcommand docs). So, we're doing some trickery
680 here (HACK ALERT) for the non-title case to feign a paragraph.
681 -->
682 <xsl:template match="refsect2">
683 <xsl:if test="name(*[1]) != 'title' or count(title) != 1">
684 <xsl:message terminate="yes">Expected exactly one title as the first refsect2 element (remarks goes after title!).</xsl:message>
685 </xsl:if>
686 <xsl:apply-templates/>
687 <xsl:text>&#x0a;</xsl:text>
688 </xsl:template>
689
690
691 <!--
692 Command Synopsis elements.
693
694 We treat each command element inside a cmdsynopsis as the start of
695 a new paragraph. The DocBook HTML converter does so too, but the
696 manpage one doesn't.
697
698 sbr and linebreaks made by latex should be indented from the base
699 command level. This is done by the \hangindent3em\hangafter1 bits.
700
701 We exploit the default paragraph indentation to get each command
702 indented from the left margin. This, unfortunately, doesn't work
703 if we're the first paragraph in a (sub*)section. \noindent cannot
704 counter this due to when latex enforces first paragraph stuff. Since
705 it's tedious to figure out when we're in the first paragraph and when
706 not, we just do \noindent\hspace{1em} everywhere.
707 -->
708 <xsl:template match="sbr">
709 <xsl:if test="not(ancestor::cmdsynopsis)">
710 <xsl:message terminate="yes">sbr only supported inside cmdsynopsis (because of hangindent)</xsl:message>
711 </xsl:if>
712 <xsl:text>\linebreak</xsl:text>
713 </xsl:template>
714
715 <xsl:template match="refentry|refnamediv|refentryinfo|refmeta|refsect3|refsect4|refsect5|synopfragment|synopfragmentref|cmdsynopsis/info">
716 <xsl:message terminate="yes"><xsl:value-of select="name()"/> is not supported</xsl:message>
717 </xsl:template>
718
719 <xsl:template match="cmdsynopsis">
720 <xsl:if test="preceding-sibling::cmdsynopsis">
721 <xsl:text>\par%cmdsynopsis</xsl:text>
722 </xsl:if>
723 <xsl:text>&#x0a;</xsl:text>
724 <xsl:if test="parent::remark[@role='VBoxManage-overview']">
725 <!-- Overview fontsize trick -->
726 <xsl:text>{\footnotesize</xsl:text>
727 </xsl:if>
728 <xsl:text>\noindent\hspace{1em}</xsl:text>
729 <xsl:text>\hangindent3em\hangafter1\texttt{</xsl:text>
730 <xsl:apply-templates />
731 <xsl:text>}</xsl:text>
732 <xsl:if test="following-sibling::*">
733 </xsl:if>
734
735 <!-- For refsect2 subcommand descriptions. -->
736 <xsl:if test="not(following-sibling::cmdsynopsis) and position() != last()">
737 <xsl:text>\linebreak</xsl:text>
738 </xsl:if>
739 <!-- Special overview trick for the current VBoxManage command overview. -->
740 <xsl:if test="parent::remark[@role='VBoxManage-overview']">
741 <xsl:text>}\vspace{1em}</xsl:text>
742 </xsl:if>
743 </xsl:template>
744
745 <xsl:template match="command">
746 <xsl:choose>
747 <xsl:when test="ancestor::cmdsynopsis">
748 <!-- Trigger a line break if this isn't the first command in a the synopsis -->
749 <xsl:if test="preceding-sibling::command">
750 <xsl:text>}\par%command&#x0a;</xsl:text>
751 <xsl:text>\noindent\hspace{1em}</xsl:text>
752 <xsl:text>\hangindent3em\hangafter1\texttt{</xsl:text>
753 </xsl:if>
754 <xsl:apply-templates />
755 </xsl:when>
756 <xsl:otherwise>
757 <xsl:text>\texttt{</xsl:text>
758 <xsl:apply-templates />
759 <xsl:text>}</xsl:text>
760 </xsl:otherwise>
761 </xsl:choose>
762 </xsl:template>
763
764 <xsl:template match="option">
765 <xsl:choose>
766 <xsl:when test="ancestor::cmdsynopsis">
767 <xsl:apply-templates />
768 </xsl:when>
769 <xsl:otherwise>
770 <xsl:text>\texttt{</xsl:text>
771 <xsl:apply-templates />
772 <xsl:text>}</xsl:text>
773 </xsl:otherwise>
774 </xsl:choose>
775 </xsl:template>
776
777 <xsl:template match="arg|group">
778 <!-- separator char if we're not the first child -->
779 <xsl:if test="position() > 1">
780 <xsl:choose>
781 <xsl:when test="ancestor-or-self::*/@sepchar"><xsl:value-of select="ancestor-or-self::*/@sepchar"/></xsl:when>
782 <xsl:otherwise><xsl:text> </xsl:text></xsl:otherwise>
783 </xsl:choose>
784 </xsl:if>
785 <!-- open wrapping -->
786 <xsl:choose>
787 <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>[</xsl:text></xsl:when>
788 <xsl:when test="@choice = 'req'"> <xsl:text>{</xsl:text></xsl:when>
789 <xsl:when test="@choice = 'plain'"/>
790 <xsl:otherwise><xsl:message terminate="yes">Invalid arg choice: "<xsl:value-of select="@choice"/>"</xsl:message></xsl:otherwise>
791 </xsl:choose>
792 <!-- render the arg (TODO: may need to do more work here) -->
793 <xsl:apply-templates />
794 <!-- repeat wrapping -->
795 <xsl:choose>
796 <xsl:when test="@rep = 'norepeat' or not(@rep) or @rep = ''"/>
797 <xsl:when test="@rep = 'repeat'"> <xsl:text>...</xsl:text></xsl:when>
798 <xsl:otherwise><xsl:message terminate="yes">Invalid rep choice: "<xsl:value-of select="@rep"/>"</xsl:message></xsl:otherwise>
799 </xsl:choose>
800 <!-- close wrapping -->
801 <xsl:choose>
802 <xsl:when test="@choice = 'opt' or not(@choice) or @choice = ''"> <xsl:text>]</xsl:text></xsl:when>
803 <xsl:when test="@choice = 'req'"> <xsl:text>}</xsl:text></xsl:when>
804 </xsl:choose>
805 </xsl:template>
806
807 <xsl:template match="replaceable">
808 <xsl:choose>
809 <xsl:when test="not(ancestor::cmdsynopsis)">
810 <xsl:text>\texttt{\textit{</xsl:text>
811 <xsl:apply-templates />
812 <xsl:text>}}</xsl:text>
813 </xsl:when>
814 <xsl:otherwise>
815 <xsl:text>\textit{</xsl:text>
816 <xsl:apply-templates />
817 <xsl:text>}</xsl:text>
818 </xsl:otherwise>
819 </xsl:choose>
820 </xsl:template>
821
822
823 <!--
824 Generic element text magic.
825 -->
826 <xsl:template match="//text()">
827 <xsl:variable name="subst1">
828 <xsl:call-template name="str:subst">
829 <xsl:with-param name="text" select="." />
830 <xsl:with-param name="replace" select="'\'" />
831 <xsl:with-param name="with" select="'\textbackslash{}'" />
832 <xsl:with-param name="disable-output-escaping" select="no" />
833 </xsl:call-template>
834 </xsl:variable>
835 <xsl:choose>
836 <xsl:when test="(name(..)='screen') or (name(../..)='screen')">
837 <xsl:value-of select="." />
838 </xsl:when>
839 <xsl:when test="(name(..) = 'computeroutput') or (name(../..) = 'computeroutput')
840 or (name(..) = 'code') or (name(../..) = 'code')
841 or (name(..) = 'arg') or (name(../..) = 'arg')
842 or (name(..) = 'option') or (name(../..) = 'option')
843 or (name(..) = 'command') or (name(../..) = 'command')
844 or (name(..) = 'cmdsynopsis') or (name(../..) = 'cmdsynopsis')
845 or (name(..) = 'replaceable') or (name(../..) = 'replaceable')
846 ">
847 <xsl:variable name="subst2">
848 <xsl:call-template name="str:subst">
849 <xsl:with-param name="text" select="$subst1" />
850 <xsl:with-param name="replace" select="'--'" />
851 <xsl:with-param name="with" select="'-{}-'" />
852 <xsl:with-param name="disable-output-escaping" select="no" />
853 </xsl:call-template>
854 </xsl:variable>
855 <xsl:variable name="subst3">
856 <xsl:call-template name="str:subst">
857 <xsl:with-param name="text" select="$subst2" />
858 <xsl:with-param name="replace" select="'_'" />
859 <xsl:with-param name="with" select="'\_'" />
860 <xsl:with-param name="disable-output-escaping" select="no" />
861 </xsl:call-template>
862 </xsl:variable>
863 <xsl:variable name="subst4">
864 <xsl:call-template name="str:subst">
865 <xsl:with-param name="text" select="$subst3" />
866 <xsl:with-param name="replace" select="'$'" />
867 <xsl:with-param name="with" select="'\$'" />
868 <xsl:with-param name="disable-output-escaping" select="no" />
869 </xsl:call-template>
870 </xsl:variable>
871 <xsl:variable name="subst5">
872 <xsl:call-template name="str:subst">
873 <xsl:with-param name="text" select="$subst4" />
874 <xsl:with-param name="replace" select="'%'" />
875 <xsl:with-param name="with" select="'\%'" />
876 <xsl:with-param name="disable-output-escaping" select="no" />
877 </xsl:call-template>
878 </xsl:variable>
879 <xsl:variable name="subst6">
880 <xsl:call-template name="str:subst">
881 <xsl:with-param name="text" select="$subst5" />
882 <xsl:with-param name="replace" select="'#'" />
883 <xsl:with-param name="with" select="'\#'" />
884 <xsl:with-param name="disable-output-escaping" select="no" />
885 </xsl:call-template>
886 </xsl:variable>
887 <xsl:variable name="subst7">
888 <xsl:call-template name="str:subst">
889 <xsl:with-param name="text" select="$subst6" />
890 <xsl:with-param name="replace" select="'~'" />
891 <xsl:with-param name="with" select="'\textasciitilde '" />
892 <xsl:with-param name="disable-output-escaping" select="no" />
893 </xsl:call-template>
894 </xsl:variable>
895 <xsl:variable name="subst8">
896 <xsl:call-template name="str:subst">
897 <xsl:with-param name="text" select="$subst7" />
898 <xsl:with-param name="replace" select="'&amp;'" />
899 <xsl:with-param name="with" select="'\&amp;'" />
900 <xsl:with-param name="disable-output-escaping" select="no" />
901 </xsl:call-template>
902 </xsl:variable>
903 <xsl:value-of select="$subst8" />
904 </xsl:when>
905 <xsl:when test="(name(..)='address') or (name(../..)='address')">
906 <xsl:variable name="subst2">
907 <xsl:call-template name="str:subst">
908 <xsl:with-param name="text" select="$subst1" />
909 <xsl:with-param name="replace" select="'&#x0a;'" />
910 <xsl:with-param name="with" select="' \\'" />
911 <xsl:with-param name="disable-output-escaping" select="no" />
912 </xsl:call-template>
913 </xsl:variable>
914 <xsl:value-of select="$subst2" />
915 </xsl:when>
916 <xsl:otherwise>
917 <xsl:variable name="subst2">
918 <xsl:call-template name="str:subst">
919 <xsl:with-param name="text" select="$subst1" />
920 <xsl:with-param name="replace" select="'_'" />
921 <xsl:with-param name="with" select="'\_'" />
922 <xsl:with-param name="disable-output-escaping" select="no" />
923 </xsl:call-template>
924 </xsl:variable>
925 <xsl:variable name="subst3">
926 <xsl:call-template name="str:subst">
927 <xsl:with-param name="text" select="$subst2" />
928 <xsl:with-param name="replace" select="'$'" />
929 <xsl:with-param name="with" select="'\$'" />
930 <xsl:with-param name="disable-output-escaping" select="no" />
931 </xsl:call-template>
932 </xsl:variable>
933 <xsl:variable name="subst4">
934 <xsl:call-template name="str:subst">
935 <xsl:with-param name="text" select="$subst3" />
936 <xsl:with-param name="replace" select="'%'" />
937 <xsl:with-param name="with" select="'\%'" />
938 <xsl:with-param name="disable-output-escaping" select="no" />
939 </xsl:call-template>
940 </xsl:variable>
941 <xsl:variable name="subst5">
942 <xsl:call-template name="str:subst">
943 <xsl:with-param name="text" select="$subst4" />
944 <xsl:with-param name="replace" select="'#'" />
945 <xsl:with-param name="with" select="'\#'" />
946 <xsl:with-param name="disable-output-escaping" select="no" />
947 </xsl:call-template>
948 </xsl:variable>
949 <xsl:variable name="subst6">
950 <xsl:call-template name="str:subst">
951 <xsl:with-param name="text" select="$subst5" />
952 <xsl:with-param name="replace" select="'µ'" />
953 <xsl:with-param name="with" select="'$\mu$'" />
954 <xsl:with-param name="disable-output-escaping" select="no" />
955 </xsl:call-template>
956 </xsl:variable>
957 <xsl:variable name="subst7">
958 <xsl:call-template name="str:subst">
959 <xsl:with-param name="text" select="$subst6" />
960 <xsl:with-param name="replace" select="'®'" />
961 <xsl:with-param name="with" select="'\texorpdfstring{\textregistered}{}'" />
962 <xsl:with-param name="disable-output-escaping" select="no" />
963 </xsl:call-template>
964 </xsl:variable>
965 <xsl:variable name="quote">"</xsl:variable>
966 <!-- preparation for pretty quotes: replace all double quotes _outside_ screen
967 sections with "\QUOTE{}" strings, which the makefile will then replace
968 with pretty quotes by invoking sed a few times. Unfortunately there are
969 no regular expressions in XSLT so there's no other way. -->
970 <xsl:variable name="subst8">
971 <xsl:call-template name="str:subst">
972 <xsl:with-param name="text" select="$subst7" />
973 <xsl:with-param name="replace" select="$quote" />
974 <xsl:with-param name="with" select="'\QUOTE{}'" />
975 <xsl:with-param name="disable-output-escaping" select="no" />
976 </xsl:call-template>
977 </xsl:variable>
978 <xsl:variable name="subst9">
979 <xsl:call-template name="str:subst">
980 <xsl:with-param name="text" select="$subst8" />
981 <xsl:with-param name="replace" select="'~'" />
982 <xsl:with-param name="with" select="'\textasciitilde '" />
983 <xsl:with-param name="disable-output-escaping" select="no" />
984 </xsl:call-template>
985 </xsl:variable>
986 <xsl:variable name="subst10">
987 <xsl:call-template name="str:subst">
988 <xsl:with-param name="text" select="$subst9" />
989 <xsl:with-param name="replace" select="'&amp;'" />
990 <xsl:with-param name="with" select="'\&amp;'" />
991 <xsl:with-param name="disable-output-escaping" select="no" />
992 </xsl:call-template>
993 </xsl:variable>
994 <xsl:value-of select="$subst10" />
995 </xsl:otherwise>
996 </xsl:choose>
997 </xsl:template>
998
999 <!--
1000 xsltprocNewlineOutputHack - emits a single new line.
1001
1002 Hack Alert! This template helps xsltproc split up the output text elements
1003 and avoid reallocating them into the MB range. Calls to this
1004 template is made occationally while generating larger output
1005 file. It's not necessary for small stuff like header.
1006
1007 The trick we're playing on xsltproc has to do with CDATA
1008 and/or the escape setting of the xsl:text element. It forces
1009 xsltproc to allocate a new output element, thus preventing
1010 things from growing out of proportions and slowing us down.
1011
1012 This was successfully employed to reduce a 18+ seconds run to
1013 around one second (possibly less due to kmk overhead).
1014 -->
1015 <xsl:template name="xsltprocNewlineOutputHack">
1016 <xsl:text disable-output-escaping="yes"><![CDATA[
1017]]></xsl:text>
1018 </xsl:template>
1019
1020</xsl:stylesheet>
1021
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette