1 <?xml version="1.0" encoding="ASCII"?>
2 <!--This file was created automatically by html2xhtml-->
3 <!--from the HTML stylesheets.-->
4 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
6 <!-- ********************************************************************
7 $Id: html.xsl 9772 2013-05-15 08:05:56Z kosek $
8 ********************************************************************
10 This file is part of the XSL DocBook Stylesheet distribution.
11 See ../README or http://docbook.sf.net/release/xsl/current/ for
12 copyright and other information.
14 ******************************************************************** -->
16 <!-- These variables set the align attribute value for HTML output based on
17 the writing-mode specified in the gentext file for the document's lang. -->
19 <xsl:variable name="direction.align.start">
21 <xsl:when test="starts-with($writing.mode, 'lr')">left</xsl:when>
22 <xsl:when test="starts-with($writing.mode, 'rl')">right</xsl:when>
23 <xsl:otherwise>left</xsl:otherwise>
27 <xsl:variable name="direction.align.end">
29 <xsl:when test="starts-with($writing.mode, 'lr')">right</xsl:when>
30 <xsl:when test="starts-with($writing.mode, 'rl')">left</xsl:when>
31 <xsl:otherwise>right</xsl:otherwise>
35 <xsl:variable name="direction.mode">
37 <xsl:when test="starts-with($writing.mode, 'lr')">ltr</xsl:when>
38 <xsl:when test="starts-with($writing.mode, 'rl')">rtl</xsl:when>
39 <xsl:otherwise>ltr</xsl:otherwise>
43 <!-- Support switching to <section> for HTML5 stylesheet -->
44 <!-- This is an internal variable that does not need to be set by a user -->
45 <xsl:variable name="div.element">div</xsl:variable>
46 <!-- Support turning off table border with border="" for HTML5 -->
47 <xsl:variable name="table.border.off">0</xsl:variable>
49 <!-- The generate.html.title template is currently used for generating HTML -->
50 <!-- "title" attributes for some inline elements only, but not for any -->
51 <!-- block elements. It is called in eleven places in the inline.xsl -->
52 <!-- file. But it's called by all the inline.* templates (e.g., -->
53 <!-- inline.boldseq), which in turn are called by other (element) -->
54 <!-- templates, so it results, currently, in supporting generation of the -->
55 <!-- HTML "title" attribute for a total of about 92 elements. -->
56 <!-- You can use mode="html.title.attribute" to get a title for -->
57 <!-- an element specified by a param, including targets of cross references. -->
58 <xsl:template name="generate.html.title">
59 <xsl:apply-templates select="." mode="html.title.attribute"/>
62 <xsl:template match="acronym|abbrev" mode="html.title.attribute">
64 <xsl:attribute name="title">
65 <xsl:value-of select="normalize-space(alt)"/>
70 <!-- Generate a title attribute for the context node -->
71 <!-- This may be the target of an xref -->
72 <xsl:template match="*" mode="html.title.attribute">
73 <xsl:variable name="is.title">
74 <xsl:call-template name="gentext.template.exists">
75 <xsl:with-param name="context" select="'title'"/>
76 <xsl:with-param name="name" select="local-name(.)"/>
77 <xsl:with-param name="lang">
78 <xsl:call-template name="l10n.language"/>
83 <xsl:variable name="is.title-numbered">
84 <xsl:call-template name="gentext.template.exists">
85 <xsl:with-param name="context" select="'title-numbered'"/>
86 <xsl:with-param name="name" select="local-name(.)"/>
87 <xsl:with-param name="lang">
88 <xsl:call-template name="l10n.language"/>
93 <xsl:variable name="is.title-unnumbered">
94 <xsl:call-template name="gentext.template.exists">
95 <xsl:with-param name="context" select="'title-unnumbered'"/>
96 <xsl:with-param name="name" select="local-name(.)"/>
97 <xsl:with-param name="lang">
98 <xsl:call-template name="l10n.language"/>
103 <xsl:variable name="has.title.markup">
104 <xsl:apply-templates select="." mode="title.markup">
105 <xsl:with-param name="verbose" select="0"/>
106 </xsl:apply-templates>
109 <xsl:variable name="gentext.title">
110 <xsl:if test="$has.title.markup != '???TITLE???' and ($is.title != 0 or $is.title-numbered != 0 or $is.title-unnumbered != 0)">
111 <xsl:apply-templates select="." mode="object.title.markup.textonly"/>
116 <xsl:when test="string-length($gentext.title) != 0">
117 <xsl:attribute name="title">
118 <xsl:value-of select="$gentext.title"/>
121 <!-- Fall back to alt if available -->
122 <xsl:when test="alt">
123 <xsl:attribute name="title">
124 <xsl:value-of select="normalize-space(alt)"/>
130 <xsl:template match="qandaentry" mode="html.title.attribute">
131 <xsl:apply-templates select="question" mode="html.title.attribute"/>
134 <xsl:template match="question" mode="html.title.attribute">
135 <xsl:variable name="label.text">
136 <xsl:apply-templates select="." mode="qanda.label"/>
140 <xsl:when test="string-length($label.text) != 0">
141 <xsl:attribute name="title">
142 <xsl:value-of select="$label.text"/>
145 <!-- Fall back to alt if available -->
146 <xsl:when test="alt">
147 <xsl:attribute name="title">
148 <xsl:value-of select="normalize-space(alt)"/>
154 <xsl:template name="dir">
155 <xsl:param name="inherit" select="0"/>
157 <xsl:variable name="dir">
159 <xsl:when test="@dir">
160 <xsl:value-of select="@dir"/>
162 <xsl:when test="$inherit != 0">
163 <xsl:value-of select="ancestor::*/@dir[1]"/>
168 <xsl:if test="$dir != ''">
169 <xsl:attribute name="dir">
170 <xsl:value-of select="$dir"/>
175 <xsl:template name="anchor">
176 <xsl:param name="node" select="."/>
177 <xsl:param name="conditional" select="1"/>
180 <xsl:when test="$generate.id.attributes != 0">
181 <!-- No named anchors output when this param is set -->
183 <xsl:when test="$conditional = 0 or $node/@id or $node/@xml:id">
185 <xsl:attribute name="id">
186 <xsl:call-template name="object.id">
187 <xsl:with-param name="object" select="$node"/>
195 <xsl:template name="id.attribute">
196 <xsl:param name="node" select="."/>
197 <xsl:param name="conditional" select="1"/>
199 <xsl:when test="$generate.id.attributes = 0">
200 <!-- No id attributes when this param is zero -->
202 <xsl:when test="$conditional = 0 or $node/@id or $node/@xml:id">
203 <xsl:attribute name="id">
204 <xsl:call-template name="object.id">
205 <xsl:with-param name="object" select="$node"/>
212 <xsl:template name="href.target.uri">
213 <xsl:param name="context" select="."/>
214 <xsl:param name="object" select="."/>
215 <xsl:text>#</xsl:text>
216 <xsl:call-template name="object.id">
217 <xsl:with-param name="object" select="$object"/>
221 <xsl:template name="href.target">
222 <xsl:param name="context" select="."/>
223 <xsl:param name="object" select="."/>
224 <xsl:text>#</xsl:text>
225 <xsl:call-template name="object.id">
226 <xsl:with-param name="object" select="$object"/>
230 <xsl:template name="href.target.with.base.dir">
231 <xsl:param name="context" select="."/>
232 <xsl:param name="object" select="."/>
233 <xsl:if test="$manifest.in.base.dir = 0">
234 <xsl:value-of select="$chunk.base.dir"/>
236 <xsl:call-template name="href.target">
237 <xsl:with-param name="context" select="$context"/>
238 <xsl:with-param name="object" select="$object"/>
242 <xsl:template name="dingbat">
243 <xsl:param name="dingbat">bullet</xsl:param>
244 <xsl:call-template name="dingbat.characters">
245 <xsl:with-param name="dingbat" select="$dingbat"/>
249 <xsl:template name="dingbat.characters">
250 <!-- now that I'm using the real serializer, all that dingbat malarky -->
251 <!-- isn't necessary anymore... -->
252 <xsl:param name="dingbat">bullet</xsl:param>
254 <xsl:when test="$dingbat='bullet'">•</xsl:when>
255 <xsl:when test="$dingbat='copyright'">©</xsl:when>
256 <xsl:when test="$dingbat='trademark'">™</xsl:when>
257 <xsl:when test="$dingbat='trade'">™</xsl:when>
258 <xsl:when test="$dingbat='registered'">®</xsl:when>
259 <xsl:when test="$dingbat='service'">(SM)</xsl:when>
260 <xsl:when test="$dingbat='nbsp'"> </xsl:when>
261 <xsl:when test="$dingbat='ldquo'">“</xsl:when>
262 <xsl:when test="$dingbat='rdquo'">”</xsl:when>
263 <xsl:when test="$dingbat='lsquo'">‘</xsl:when>
264 <xsl:when test="$dingbat='rsquo'">’</xsl:when>
265 <xsl:when test="$dingbat='em-dash'">—</xsl:when>
266 <xsl:when test="$dingbat='mdash'">—</xsl:when>
267 <xsl:when test="$dingbat='en-dash'">–</xsl:when>
268 <xsl:when test="$dingbat='ndash'">–</xsl:when>
270 <xsl:text>•</xsl:text>
275 <xsl:template name="id.warning">
276 <xsl:if test="$id.warnings != 0 and not(@id) and not(@xml:id) and parent::*">
277 <xsl:variable name="title">
279 <xsl:when test="title">
280 <xsl:value-of select="title[1]"/>
282 <xsl:when test="substring(local-name(*[1]), string-length(local-name(*[1])-3) = 'info') and *[1]/title">
283 <xsl:value-of select="*[1]/title[1]"/>
285 <xsl:when test="refmeta/refentrytitle">
286 <xsl:value-of select="refmeta/refentrytitle"/>
288 <xsl:when test="refnamediv/refname">
289 <xsl:value-of select="refnamediv/refname[1]"/>
295 <xsl:text>ID recommended on </xsl:text>
296 <xsl:value-of select="local-name(.)"/>
297 <xsl:if test="$title != ''">
298 <xsl:text>: </xsl:text>
300 <xsl:when test="string-length($title) > 40">
301 <xsl:value-of select="substring($title,1,40)"/>
302 <xsl:text>...</xsl:text>
305 <xsl:value-of select="$title"/>
313 <xsl:template name="generate.class.attribute">
314 <xsl:param name="class" select="local-name(.)"/>
315 <xsl:apply-templates select="." mode="class.attribute">
316 <xsl:with-param name="class" select="$class"/>
317 </xsl:apply-templates>
320 <xsl:template match="*" mode="class.attribute">
321 <xsl:param name="class" select="local-name(.)"/>
322 <!-- permit customization of class attributes -->
323 <!-- Use element name by default -->
324 <xsl:variable name="class.value">
325 <xsl:apply-templates select="." mode="class.value">
326 <xsl:with-param name="class" select="$class"/>
327 </xsl:apply-templates>
330 <xsl:if test="string-length(normalize-space($class.value)) != 0">
331 <xsl:attribute name="class">
332 <xsl:value-of select="$class.value"/>
337 <xsl:template match="*" mode="class.value">
338 <xsl:param name="class" select="local-name(.)"/>
339 <!-- permit customization of class value only -->
340 <!-- Use element name by default -->
341 <xsl:value-of select="$class"/>
344 <!-- Apply common attributes such as class, lang, dir -->
345 <xsl:template name="common.html.attributes">
346 <xsl:param name="inherit" select="0"/>
347 <xsl:param name="class" select="local-name(.)"/>
348 <xsl:apply-templates select="." mode="common.html.attributes">
349 <xsl:with-param name="class" select="$class"/>
350 <xsl:with-param name="inherit" select="$inherit"/>
351 </xsl:apply-templates>
354 <xsl:template match="*" mode="common.html.attributes">
355 <xsl:param name="class" select="local-name(.)"/>
356 <xsl:param name="inherit" select="0"/>
357 <xsl:call-template name="generate.html.lang"/>
358 <xsl:call-template name="dir">
359 <xsl:with-param name="inherit" select="$inherit"/>
361 <xsl:apply-templates select="." mode="class.attribute">
362 <xsl:with-param name="class" select="$class"/>
363 </xsl:apply-templates>
364 <xsl:call-template name="its.attributes">
365 <xsl:with-param name="inherit" select="$inherit"/>
369 <!-- Apply common attributes not including class -->
370 <xsl:template name="locale.html.attributes">
371 <xsl:apply-templates select="." mode="locale.html.attributes"/>
374 <xsl:template match="*" mode="locale.html.attributes">
375 <xsl:call-template name="generate.html.lang"/>
376 <xsl:call-template name="dir"/>
377 <xsl:call-template name="its.attributes"/>
380 <!-- Pass through any lang attributes -->
381 <xsl:template name="generate.html.lang">
382 <xsl:apply-templates select="." mode="html.lang.attribute"/>
385 <xsl:template match="*" mode="html.lang.attribute">
386 <!-- match the attribute name to the output type -->
388 <xsl:when test="@lang and $stylesheet.result.type = 'html'">
389 <xsl:attribute name="lang">
390 <xsl:value-of select="@lang"/>
393 <xsl:when test="@lang and $stylesheet.result.type = 'xhtml'">
394 <xsl:attribute name="xml:lang">
395 <xsl:value-of select="@lang"/>
398 <xsl:when test="@xml:lang and $stylesheet.result.type = 'html'">
399 <xsl:attribute name="lang">
400 <xsl:value-of select="@xml:lang"/>
403 <xsl:when test="@xml:lang and $stylesheet.result.type = 'xhtml'">
404 <xsl:attribute name="xml:lang">
405 <xsl:value-of select="@xml:lang"/>
411 <!-- ==================================================================== -->
412 <!-- Insert link to css or insert literal CSS in head element -->
413 <xsl:template name="generate.css">
415 <xsl:when test="$generate.css.header = 0">
416 <xsl:call-template name="generate.css.links"/>
419 <xsl:call-template name="generate.css.headers"/>
424 <xsl:template name="generate.css.headers">
425 <xsl:call-template name="generate.default.css.header"/>
426 <xsl:call-template name="generate.custom.css.header"/>
429 <xsl:template name="generate.default.css.header">
430 <xsl:if test="$make.clean.html != 0 and $docbook.css.source != ''">
431 <!-- Select default file relative to stylesheet -->
432 <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
434 <xsl:call-template name="output.css.header">
435 <xsl:with-param name="css.node" select="$css.node"/>
440 <xsl:template name="generate.custom.css.header">
441 <xsl:if test="$custom.css.source != ''">
442 <!-- Select custom file relative to document -->
443 <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
445 <xsl:call-template name="output.css.header">
446 <xsl:with-param name="css.node" select="$css.node"/>
451 <xsl:template name="output.css.header">
452 <xsl:param name="css.node"/>
455 <xsl:when test="count($css.node) = 0">
458 <style type="text/css">
459 <xsl:copy-of select="$css.node/text()"/>
465 <!-- ==================================================================== -->
466 <xsl:template name="generate.css.links">
467 <xsl:call-template name="generate.default.css.link"/>
468 <xsl:call-template name="generate.custom.css.link"/>
471 <xsl:template name="generate.default.css.link">
472 <xsl:if test="$make.clean.html != 0 and $docbook.css.link != 0 and $docbook.css.source != ''">
473 <xsl:variable name="filename">
474 <xsl:call-template name="css.output.filename">
475 <xsl:with-param name="src" select="$docbook.css.source"/>
479 <xsl:call-template name="make.css.link">
480 <xsl:with-param name="css.filename" select="$filename"/>
485 <xsl:template name="generate.custom.css.link">
486 <xsl:if test="$custom.css.source != ''">
487 <xsl:variable name="filename">
488 <xsl:call-template name="css.output.filename">
489 <xsl:with-param name="src" select="$custom.css.source"/>
493 <xsl:call-template name="make.css.link">
494 <xsl:with-param name="css.filename" select="$filename"/>
499 <!-- a CSS link reference must take into account the relative
500 path to a CSS file when chunked HTML is output to more than one directory -->
501 <xsl:template name="make.css.link">
502 <xsl:param name="css.filename" select="''"/>
504 <xsl:variable name="href">
505 <xsl:call-template name="relative.path.link">
506 <xsl:with-param name="target.pathname" select="$css.filename"/>
510 <xsl:if test="string-length($css.filename) != 0">
511 <link rel="stylesheet" type="text/css" href="{$href}"/>
515 <!-- And the same applies to script links -->
516 <xsl:template name="make.script.link">
517 <xsl:param name="script.filename" select="''"/>
519 <xsl:variable name="src">
520 <xsl:call-template name="relative.path.link">
521 <xsl:with-param name="target.pathname" select="$script.filename"/>
525 <xsl:if test="string-length($script.filename) != 0">
527 <xsl:attribute name="src">
528 <xsl:value-of select="$src"/>
530 <xsl:attribute name="type">
531 <xsl:value-of select="$html.script.type"/>
533 <xsl:call-template name="other.script.attributes">
534 <xsl:with-param name="script.filename" select="$script.filename"/>
540 <xsl:template name="other.script.attributes">
541 <xsl:param name="script.filename"/>
542 <!-- Placeholder template to allow customization to
543 insert additional script element attributes if needed -->
546 <xsl:template name="relative.path.link">
547 <xsl:param name="target.pathname"/>
549 <xsl:variable name="href.to.uri" select="$target.pathname"/>
551 <xsl:variable name="href.from.uri">
552 <xsl:call-template name="href.target.uri">
553 <xsl:with-param name="object" select="."/>
557 <xsl:variable name="href.to">
558 <xsl:call-template name="trim.common.uri.paths">
559 <xsl:with-param name="uriA" select="$href.to.uri"/>
560 <xsl:with-param name="uriB" select="$href.from.uri"/>
561 <xsl:with-param name="return" select="'A'"/>
565 <xsl:variable name="href.from">
566 <xsl:call-template name="trim.common.uri.paths">
567 <xsl:with-param name="uriA" select="$href.to.uri"/>
568 <xsl:with-param name="uriB" select="$href.from.uri"/>
569 <xsl:with-param name="return" select="'B'"/>
572 <xsl:variable name="depth">
573 <xsl:call-template name="count.uri.path.depth">
574 <xsl:with-param name="filename" select="$href.from"/>
577 <xsl:variable name="href">
578 <xsl:call-template name="copy-string">
579 <xsl:with-param name="string" select="'../'"/>
580 <xsl:with-param name="count" select="$depth"/>
582 <xsl:value-of select="$href.to"/>
585 <xsl:value-of select="$href"/>
588 <!-- ==================================================================== -->
590 <xsl:template name="generate.css.files">
591 <xsl:call-template name="generate.default.css.file"/>
592 <xsl:call-template name="generate.custom.css.file"/>
595 <xsl:template name="generate.default.css.file">
596 <xsl:if test="$make.clean.html != 0 and $generate.css.header = 0 and $docbook.css.source != ''">
597 <!-- Select default file relative to stylesheet -->
598 <xsl:variable name="css.node" select="document($docbook.css.source)/*[1]"/>
600 <xsl:call-template name="generate.css.file">
601 <xsl:with-param name="src" select="$docbook.css.source"/>
602 <xsl:with-param name="css.node" select="$css.node"/>
607 <xsl:template name="generate.custom.css.file">
608 <xsl:if test="$custom.css.source != '' and $generate.css.header = 0">
609 <!-- Select custom file relative to document -->
610 <xsl:variable name="css.node" select="document($custom.css.source,.)/*[1]"/>
612 <xsl:call-template name="generate.css.file">
613 <xsl:with-param name="src" select="$custom.css.source"/>
614 <xsl:with-param name="css.node" select="$css.node"/>
619 <xsl:template name="generate.css.file">
620 <xsl:param name="css.node"/>
621 <xsl:param name="src" select="''"/>
623 <xsl:variable name="css.text" select="$css.node/text()"/>
626 <xsl:when test="count($css.node) = 0">
628 <xsl:text>ERROR: no root element for CSS source file'</xsl:text>
629 <xsl:value-of select="$src"/>
630 <xsl:text>'.</xsl:text>
634 <xsl:variable name="filename">
635 <xsl:call-template name="css.output.pathname">
636 <xsl:with-param name="src" select="$src"/>
637 <xsl:with-param name="content" select="$css.node"/>
641 <xsl:call-template name="write.text.chunk">
642 <xsl:with-param name="filename" select="$filename"/>
643 <xsl:with-param name="content" select="$css.text"/>
650 <xsl:template name="css.output.filename">
651 <xsl:param name="content"/>
652 <xsl:param name="src" select="''"/>
654 <xsl:variable name="candidate">
656 <xsl:when test="string-length($src) = 0">
658 <xsl:text>ERROR: missing CSS input filename.</xsl:text>
661 <xsl:when test="substring($src,string-length($src)-3) = '.xml'">
662 <xsl:value-of select="substring($src, 1, string-length($src) - 4)"/>
665 <xsl:value-of select="$src"/>
669 <xsl:value-of select="$candidate"/>
672 <xsl:template name="css.output.pathname">
673 <xsl:param name="content"/>
674 <xsl:param name="src" select="''"/>
676 <xsl:variable name="file">
677 <xsl:call-template name="css.output.filename">
678 <xsl:with-param name="content" select="$content"/>
679 <xsl:with-param name="src" select="$src"/>
683 <xsl:variable name="path" select="concat($chunk.base.dir, $file)"/>
684 <xsl:value-of select="$path"/>