]> git.stg.codes - stg.git/blob - doc/xslt/html/docbook.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / html / docbook.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:ng="http://docbook.org/docbook-ng"
4                 xmlns:db="http://docbook.org/ns/docbook"
5                 xmlns:exsl="http://exslt.org/common"
6                 xmlns:exslt="http://exslt.org/common"
7                 exclude-result-prefixes="db ng exsl exslt"
8                 version='1.0'>
9
10 <xsl:output method="html"
11             encoding="ISO-8859-1"
12             indent="no"/>
13
14 <!-- ********************************************************************
15      $Id: docbook.xsl 8783 2010-07-28 10:59:39Z mzjn $
16      ********************************************************************
17
18      This file is part of the XSL DocBook Stylesheet distribution.
19      See ../README or http://docbook.sf.net/release/xsl/current/ for
20      copyright and other information.
21
22      ******************************************************************** -->
23
24 <!-- ==================================================================== -->
25
26 <xsl:include href="../VERSION"/>
27 <xsl:include href="param.xsl"/>
28 <xsl:include href="../lib/lib.xsl"/>
29 <xsl:include href="../common/l10n.xsl"/>
30 <xsl:include href="../common/common.xsl"/>
31 <xsl:include href="../common/utility.xsl"/>
32 <xsl:include href="../common/labels.xsl"/>
33 <xsl:include href="../common/titles.xsl"/>
34 <xsl:include href="../common/subtitles.xsl"/>
35 <xsl:include href="../common/gentext.xsl"/>
36 <xsl:include href="../common/targets.xsl"/>
37 <xsl:include href="../common/olink.xsl"/>
38 <xsl:include href="../common/pi.xsl"/>
39 <xsl:include href="autotoc.xsl"/>
40 <xsl:include href="autoidx.xsl"/>
41 <xsl:include href="lists.xsl"/>
42 <xsl:include href="callout.xsl"/>
43 <xsl:include href="verbatim.xsl"/>
44 <xsl:include href="graphics.xsl"/>
45 <xsl:include href="xref.xsl"/>
46 <xsl:include href="formal.xsl"/>
47 <xsl:include href="table.xsl"/>
48 <xsl:include href="htmltbl.xsl"/>
49 <xsl:include href="sections.xsl"/>
50 <xsl:include href="inline.xsl"/>
51 <xsl:include href="footnote.xsl"/>
52 <xsl:include href="html.xsl"/>
53 <xsl:include href="info.xsl"/>
54 <xsl:include href="keywords.xsl"/>
55 <xsl:include href="division.xsl"/>
56 <xsl:include href="toc.xsl"/>
57 <xsl:include href="index.xsl"/>
58 <xsl:include href="refentry.xsl"/>
59 <xsl:include href="math.xsl"/>
60 <xsl:include href="admon.xsl"/>
61 <xsl:include href="component.xsl"/>
62 <xsl:include href="biblio.xsl"/>
63 <xsl:include href="biblio-iso690.xsl"/>
64 <xsl:include href="glossary.xsl"/>
65 <xsl:include href="block.xsl"/>
66 <xsl:include href="task.xsl"/>
67 <xsl:include href="qandaset.xsl"/>
68 <xsl:include href="synop.xsl"/>
69 <xsl:include href="titlepage.xsl"/>
70 <xsl:include href="titlepage.templates.xsl"/>
71 <xsl:include href="pi.xsl"/>
72 <xsl:include href="ebnf.xsl"/>
73 <xsl:include href="chunker.xsl"/>
74 <xsl:include href="html-rtf.xsl"/>
75 <xsl:include href="annotations.xsl"/>
76 <xsl:include href="../common/stripns.xsl"/>
77
78 <xsl:param name="stylesheet.result.type" select="'html'"/>
79 <xsl:param name="htmlhelp.output" select="0"/>
80
81 <!-- ==================================================================== -->
82
83 <xsl:key name="id" match="*" use="@id|@xml:id"/>
84 <xsl:key name="gid" match="*" use="generate-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   <span style="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   </span>
111 </xsl:template>
112
113 <xsl:template match="text()">
114   <xsl:value-of select="."/>
115 </xsl:template>
116
117 <xsl:template name="body.attributes">
118   <xsl:attribute name="bgcolor">white</xsl:attribute>
119   <xsl:attribute name="text">black</xsl:attribute>
120   <xsl:attribute name="link">#0000FF</xsl:attribute>
121   <xsl:attribute name="vlink">#840084</xsl:attribute>
122   <xsl:attribute name="alink">#0000FF</xsl:attribute>
123   <xsl:if test="starts-with($writing.mode, 'rl')">
124     <xsl:attribute name="dir">rtl</xsl:attribute>
125   </xsl:if>
126 </xsl:template>
127
128 <xsl:template name="head.content">
129   <xsl:param name="node" select="."/>
130   <xsl:param name="title">
131     <xsl:apply-templates select="$node" mode="object.title.markup.textonly"/>
132   </xsl:param>
133
134   <title>
135     <xsl:copy-of select="$title"/>
136   </title>
137
138   <xsl:if test="$html.base != ''">
139     <base href="{$html.base}"/>
140   </xsl:if>
141
142   <!-- Insert links to CSS files or insert literal style elements -->
143   <xsl:call-template name="generate.css"/>
144
145   <xsl:if test="$html.stylesheet != ''">
146     <xsl:call-template name="output.html.stylesheets">
147       <xsl:with-param name="stylesheets" select="normalize-space($html.stylesheet)"/>
148     </xsl:call-template>
149   </xsl:if>
150
151   <xsl:if test="$link.mailto.url != ''">
152     <link rev="made"
153           href="{$link.mailto.url}"/>
154   </xsl:if>
155
156   <meta name="generator" content="DocBook {$DistroTitle} V{$VERSION}"/>
157
158   <xsl:if test="$generate.meta.abstract != 0">
159     <xsl:variable name="info" select="(articleinfo
160                                       |bookinfo
161                                       |prefaceinfo
162                                       |chapterinfo
163                                       |appendixinfo
164                                       |sectioninfo
165                                       |sect1info
166                                       |sect2info
167                                       |sect3info
168                                       |sect4info
169                                       |sect5info
170                                       |referenceinfo
171                                       |refentryinfo
172                                       |partinfo
173                                       |info
174                                       |docinfo)[1]"/>
175     <xsl:if test="$info and $info/abstract">
176       <meta name="description">
177         <xsl:attribute name="content">
178           <xsl:for-each select="$info/abstract[1]/*">
179             <xsl:value-of select="normalize-space(.)"/>
180             <xsl:if test="position() &lt; last()">
181               <xsl:text> </xsl:text>
182             </xsl:if>
183           </xsl:for-each>
184         </xsl:attribute>
185       </meta>
186     </xsl:if>
187   </xsl:if>
188
189   <xsl:if test="($draft.mode = 'yes' or
190                 ($draft.mode = 'maybe' and
191                 ancestor-or-self::*[@status][1]/@status = 'draft'))
192                 and $draft.watermark.image != ''">
193     <style type="text/css"><xsl:text>
194 body { background-image: url('</xsl:text>
195 <xsl:value-of select="$draft.watermark.image"/><xsl:text>');
196        background-repeat: no-repeat;
197        background-position: top left;
198        /* The following properties make the watermark "fixed" on the page. */
199        /* I think that's just a bit too distracting for the reader... */
200        /* background-attachment: fixed; */
201        /* background-position: center center; */
202      }</xsl:text>
203     </style>
204   </xsl:if>
205   <xsl:apply-templates select="." mode="head.keywords.content"/>
206 </xsl:template>
207
208 <xsl:template name="output.html.stylesheets">
209   <xsl:param name="stylesheets" select="''"/>
210
211   <xsl:choose>
212     <xsl:when test="contains($stylesheets, ' ')">
213       <xsl:variable name="css.filename" select="substring-before($stylesheets, ' ')"/>
214
215       <xsl:call-template name="make.css.link">
216         <xsl:with-param name="css.filename" select="$css.filename"/>
217       </xsl:call-template>
218
219       <xsl:call-template name="output.html.stylesheets">
220         <xsl:with-param name="stylesheets" select="substring-after($stylesheets, ' ')"/>
221       </xsl:call-template>
222     </xsl:when>
223     <xsl:when test="$stylesheets != ''">
224       <xsl:call-template name="make.css.link">
225         <xsl:with-param name="css.filename" select="$stylesheets"/>
226       </xsl:call-template>
227     </xsl:when>
228   </xsl:choose>
229 </xsl:template>
230
231 <!-- ============================================================ -->
232
233 <xsl:template match="*" mode="head.keywords.content">
234   <xsl:apply-templates select="chapterinfo/keywordset" mode="html.header"/>
235   <xsl:apply-templates select="appendixinfo/keywordset" mode="html.header"/>
236   <xsl:apply-templates select="prefaceinfo/keywordset" mode="html.header"/>
237   <xsl:apply-templates select="bookinfo/keywordset" mode="html.header"/>
238   <xsl:apply-templates select="setinfo/keywordset" mode="html.header"/>
239   <xsl:apply-templates select="articleinfo/keywordset" mode="html.header"/>
240   <xsl:apply-templates select="artheader/keywordset" mode="html.header"/>
241   <xsl:apply-templates select="sect1info/keywordset" mode="html.header"/>
242   <xsl:apply-templates select="sect2info/keywordset" mode="html.header"/>
243   <xsl:apply-templates select="sect3info/keywordset" mode="html.header"/>
244   <xsl:apply-templates select="sect4info/keywordset" mode="html.header"/>
245   <xsl:apply-templates select="sect5info/keywordset" mode="html.header"/>
246   <xsl:apply-templates select="sectioninfo/keywordset" mode="html.header"/>
247   <xsl:apply-templates select="refsect1info/keywordset" mode="html.header"/>
248   <xsl:apply-templates select="refsect2info/keywordset" mode="html.header"/>
249   <xsl:apply-templates select="refsect3info/keywordset" mode="html.header"/>
250   <xsl:apply-templates select="bibliographyinfo/keywordset" mode="html.header"/>
251   <xsl:apply-templates select="glossaryinfo/keywordset" mode="html.header"/>
252   <xsl:apply-templates select="indexinfo/keywordset" mode="html.header"/>
253   <xsl:apply-templates select="refentryinfo/keywordset" mode="html.header"/>
254   <xsl:apply-templates select="partinfo/keywordset" mode="html.header"/>
255   <xsl:apply-templates select="referenceinfo/keywordset" mode="html.header"/>
256   <xsl:apply-templates select="docinfo/keywordset" mode="html.header"/>
257   <xsl:apply-templates select="info/keywordset" mode="html.header"/>
258
259   <xsl:if test="$inherit.keywords != 0
260                 and parent::*">
261     <xsl:apply-templates select="parent::*" mode="head.keywords.content"/>
262   </xsl:if>
263 </xsl:template>
264
265 <!-- ============================================================ -->
266
267 <xsl:template name="system.head.content">
268   <xsl:param name="node" select="."/>
269
270   <!-- FIXME: When chunking, only the annotations actually used
271               in this chunk should be referenced. I don't think it
272               does any harm to reference them all, but it adds
273               unnecessary bloat to each chunk. -->
274   <xsl:if test="$annotation.support != 0 and //annotation">
275     <xsl:call-template name="add.annotation.links"/>
276     <script type="text/javascript">
277       <xsl:text>&#10;// Create PopupWindow objects</xsl:text>
278       <xsl:for-each select="//annotation">
279         <xsl:text>&#10;var popup_</xsl:text>
280         <xsl:value-of select="generate-id(.)"/>
281         <xsl:text> = new PopupWindow("popup-</xsl:text>
282         <xsl:value-of select="generate-id(.)"/>
283         <xsl:text>");&#10;</xsl:text>
284         <xsl:text>popup_</xsl:text>
285         <xsl:value-of select="generate-id(.)"/>
286         <xsl:text>.offsetY = 15;&#10;</xsl:text>
287         <xsl:text>popup_</xsl:text>
288         <xsl:value-of select="generate-id(.)"/>
289         <xsl:text>.autoHide();&#10;</xsl:text>
290       </xsl:for-each>
291     </script>
292
293     <style type="text/css">
294       <xsl:value-of select="$annotation.css"/>
295     </style>
296   </xsl:if>
297
298   <!-- system.head.content is like user.head.content, except that
299        it is called before head.content. This is important because it
300        means, for example, that <style> elements output by system.head.content
301        have a lower CSS precedence than the users stylesheet. -->
302 </xsl:template>
303
304 <!-- ============================================================ -->
305
306 <xsl:template name="user.preroot">
307   <!-- Pre-root output, can be used to output comments and PIs. -->
308   <!-- This must not output any element content! -->
309 </xsl:template>
310
311 <xsl:template name="user.head.content">
312   <xsl:param name="node" select="."/>
313 </xsl:template>
314
315 <xsl:template name="user.header.navigation">
316   <xsl:param name="node" select="."/>
317 </xsl:template>
318
319 <xsl:template name="user.header.content">
320   <xsl:param name="node" select="."/>
321 </xsl:template>
322
323 <xsl:template name="user.footer.content">
324   <xsl:param name="node" select="."/>
325 </xsl:template>
326
327 <xsl:template name="user.footer.navigation">
328   <xsl:param name="node" select="."/>
329 </xsl:template>
330
331 <xsl:template match="/">
332   <!-- * Get a title for current doc so that we let the user -->
333   <!-- * know what document we are processing at this point. -->
334   <xsl:variable name="doc.title">
335     <xsl:call-template name="get.doc.title"/>
336   </xsl:variable>
337   <xsl:choose>
338     <!-- Hack! If someone hands us a DocBook V5.x or DocBook NG document,
339          toss the namespace and continue.  Use the docbook5 namespaced
340          stylesheets for DocBook5 if you don't want to use this feature.-->
341     <!-- include extra test for Xalan quirk -->
342     <xsl:when test="$exsl.node.set.available != 0
343                     and (*/self::ng:* or */self::db:*)">
344       <xsl:call-template name="log.message">
345         <xsl:with-param name="level">Note</xsl:with-param>
346         <xsl:with-param name="source" select="$doc.title"/>
347         <xsl:with-param name="context-desc">
348           <xsl:text>namesp. cut</xsl:text>
349         </xsl:with-param>
350         <xsl:with-param name="message">
351           <xsl:text>stripped namespace before processing</xsl:text>
352         </xsl:with-param>
353       </xsl:call-template>
354       <xsl:variable name="nons">
355         <xsl:apply-templates mode="stripNS"/>
356       </xsl:variable>
357       <!--
358       <xsl:message>Saving stripped document.</xsl:message>
359       <xsl:call-template name="write.chunk">
360         <xsl:with-param name="filename" select="'/tmp/stripped.xml'"/>
361         <xsl:with-param name="method" select="'xml'"/>
362         <xsl:with-param name="content">
363           <xsl:copy-of select="exsl:node-set($nons)"/>
364         </xsl:with-param>
365       </xsl:call-template>
366       -->
367       <xsl:call-template name="log.message">
368         <xsl:with-param name="level">Note</xsl:with-param>
369         <xsl:with-param name="source" select="$doc.title"/>
370         <xsl:with-param name="context-desc">
371           <xsl:text>namesp. cut</xsl:text>
372         </xsl:with-param>
373         <xsl:with-param name="message">
374           <xsl:text>processing stripped document</xsl:text>
375         </xsl:with-param>
376       </xsl:call-template>
377       <xsl:apply-templates select="exsl:node-set($nons)"/>
378     </xsl:when>
379     <!-- Can't process unless namespace removed -->
380     <xsl:when test="*/self::ng:* or */self::db:*">
381       <xsl:message terminate="yes">
382         <xsl:text>Unable to strip the namespace from DB5 document,</xsl:text>
383         <xsl:text> cannot proceed.</xsl:text>
384       </xsl:message>
385     </xsl:when>
386     <xsl:otherwise>
387       <xsl:choose>
388         <xsl:when test="$rootid != ''">
389           <xsl:choose>
390             <xsl:when test="count(key('id',$rootid)) = 0">
391               <xsl:message terminate="yes">
392                 <xsl:text>ID '</xsl:text>
393                 <xsl:value-of select="$rootid"/>
394                 <xsl:text>' not found in document.</xsl:text>
395               </xsl:message>
396             </xsl:when>
397             <xsl:otherwise>
398               <xsl:if test="$collect.xref.targets = 'yes' or
399                             $collect.xref.targets = 'only'">
400                 <xsl:apply-templates select="key('id', $rootid)"
401                                      mode="collect.targets"/>
402               </xsl:if>
403               <xsl:if test="$collect.xref.targets != 'only'">
404                 <xsl:apply-templates select="key('id',$rootid)"
405                                      mode="process.root"/>
406                 <xsl:if test="$tex.math.in.alt != ''">
407                   <xsl:apply-templates select="key('id',$rootid)"
408                                        mode="collect.tex.math"/>
409                 </xsl:if>
410               </xsl:if>
411             </xsl:otherwise>
412           </xsl:choose>
413         </xsl:when>
414         <xsl:otherwise>
415           <xsl:if test="$collect.xref.targets = 'yes' or
416                         $collect.xref.targets = 'only'">
417             <xsl:apply-templates select="/" mode="collect.targets"/>
418           </xsl:if>
419           <xsl:if test="$collect.xref.targets != 'only'">
420             <xsl:apply-templates select="/" mode="process.root"/>
421             <xsl:if test="$tex.math.in.alt != ''">
422               <xsl:apply-templates select="/" mode="collect.tex.math"/>
423             </xsl:if>
424           </xsl:if>
425         </xsl:otherwise>
426       </xsl:choose>
427     </xsl:otherwise>
428   </xsl:choose>
429 </xsl:template>
430
431 <xsl:template match="*" mode="process.root">
432   <xsl:variable name="doc" select="self::*"/>
433
434   <xsl:call-template name="user.preroot"/>
435   <xsl:call-template name="root.messages"/>
436
437   <html>
438     <head>
439       <xsl:call-template name="system.head.content">
440         <xsl:with-param name="node" select="$doc"/>
441       </xsl:call-template>
442       <xsl:call-template name="head.content">
443         <xsl:with-param name="node" select="$doc"/>
444       </xsl:call-template>
445       <xsl:call-template name="user.head.content">
446         <xsl:with-param name="node" select="$doc"/>
447       </xsl:call-template>
448     </head>
449     <body>
450       <xsl:call-template name="body.attributes"/>
451       <xsl:call-template name="user.header.content">
452         <xsl:with-param name="node" select="$doc"/>
453       </xsl:call-template>
454       <xsl:apply-templates select="."/>
455       <xsl:call-template name="user.footer.content">
456         <xsl:with-param name="node" select="$doc"/>
457       </xsl:call-template>
458     </body>
459   </html>
460   <xsl:value-of select="$html.append"/>
461   
462   <!-- Generate any css files only once, not once per chunk -->
463   <xsl:call-template name="generate.css.files"/>
464 </xsl:template>
465
466 <xsl:template name="root.messages">
467   <!-- redefine this any way you'd like to output messages -->
468   <!-- DO NOT OUTPUT ANYTHING FROM THIS TEMPLATE -->
469 </xsl:template>
470
471 <!-- ==================================================================== -->
472
473 <xsl:template name="chunk">
474   <xsl:param name="node" select="."/>
475
476   <!-- The default is that we are not chunking... -->
477   <xsl:text>0</xsl:text>
478 </xsl:template>
479
480 </xsl:stylesheet>