2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4 exclude-result-prefixes="doc"
7 <!-- ********************************************************************
8 $Id: titles.xsl 8469 2009-07-09 21:49:16Z bobstayton $
9 ********************************************************************
11 This file is part of the XSL DocBook Stylesheet distribution.
12 See ../README or http://docbook.sf.net/release/xsl/current/ for
13 copyright and other information.
15 ******************************************************************** -->
17 <!-- ==================================================================== -->
21 <doc:mode mode="title.markup" xmlns="">
22 <refpurpose>Provides access to element titles</refpurpose>
23 <refdescription id="title.markup-desc">
24 <para>Processing an element in the
25 <literal role="mode">title.markup</literal> mode produces the
26 title of the element. This does not include the label.
31 <xsl:template match="*" mode="title.markup">
32 <xsl:param name="allow-anchors" select="0"/>
33 <xsl:param name="verbose" select="1"/>
35 <!-- * FIXME: this should handle other *info elements as well -->
36 <!-- * but this is good enough for now. -->
37 <xsl:when test="title|info/title">
38 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
39 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
40 </xsl:apply-templates>
42 <xsl:when test="local-name(.) = 'partintro'">
43 <!-- partintro's don't have titles, use the parent (part or reference)
45 <xsl:apply-templates select="parent::*" mode="title.markup"/>
48 <xsl:if test="$verbose != 0">
50 <xsl:text>Request for title of element with no title: </xsl:text>
51 <xsl:value-of select="local-name(.)"/>
54 <xsl:text> (id="</xsl:text>
55 <xsl:value-of select="@id"/>
56 <xsl:text>")</xsl:text>
58 <xsl:when test="@xml:id">
59 <xsl:text> (xml:id="</xsl:text>
60 <xsl:value-of select="@xml:id"/>
61 <xsl:text>")</xsl:text>
66 <xsl:text>???TITLE???</xsl:text>
71 <xsl:template match="title" mode="title.markup">
72 <xsl:param name="allow-anchors" select="0"/>
75 <xsl:when test="$allow-anchors != 0">
76 <xsl:apply-templates/>
79 <xsl:apply-templates mode="no.anchor.mode"/>
84 <!-- only occurs in HTML Tables! -->
85 <xsl:template match="caption" mode="title.markup">
86 <xsl:param name="allow-anchors" select="0"/>
89 <xsl:when test="$allow-anchors != 0">
90 <xsl:apply-templates/>
93 <xsl:apply-templates mode="no.anchor.mode"/>
98 <xsl:template match="set" mode="title.markup">
99 <xsl:param name="allow-anchors" select="0"/>
100 <xsl:apply-templates select="(setinfo/title|info/title|title)[1]"
102 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
103 </xsl:apply-templates>
106 <xsl:template match="book" mode="title.markup">
107 <xsl:param name="allow-anchors" select="0"/>
108 <xsl:apply-templates select="(bookinfo/title|info/title|title)[1]"
110 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
111 </xsl:apply-templates>
114 <xsl:template match="part" mode="title.markup">
115 <xsl:param name="allow-anchors" select="0"/>
116 <xsl:apply-templates select="(partinfo/title|info/title|docinfo/title|title)[1]"
118 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
119 </xsl:apply-templates>
122 <xsl:template match="preface|chapter|appendix" mode="title.markup">
123 <xsl:param name="allow-anchors" select="0"/>
127 <xsl:value-of select="local-name(.)"/>
128 <xsl:text> </xsl:text>
129 <xsl:value-of select="$allow-anchors"/>
133 <xsl:variable name="title" select="(docinfo/title
139 <xsl:apply-templates select="$title" mode="title.markup">
140 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
141 </xsl:apply-templates>
144 <xsl:template match="dedication" mode="title.markup">
145 <xsl:param name="allow-anchors" select="0"/>
147 <xsl:when test="title|info/title">
148 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
149 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
150 </xsl:apply-templates>
153 <xsl:call-template name="gentext">
154 <xsl:with-param name="key" select="'Dedication'"/>
160 <xsl:template match="acknowledgements" mode="title.markup">
161 <xsl:param name="allow-anchors" select="0"/>
163 <xsl:when test="title|info/title">
164 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
165 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
166 </xsl:apply-templates>
169 <xsl:call-template name="gentext">
170 <xsl:with-param name="key" select="'Acknowledgements'"/>
176 <xsl:template match="colophon" mode="title.markup">
177 <xsl:param name="allow-anchors" select="0"/>
179 <xsl:when test="title|info/title">
180 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
181 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
182 </xsl:apply-templates>
185 <xsl:call-template name="gentext">
186 <xsl:with-param name="key" select="'Colophon'"/>
192 <xsl:template match="article" mode="title.markup">
193 <xsl:param name="allow-anchors" select="0"/>
194 <xsl:variable name="title" select="(artheader/title
199 <xsl:apply-templates select="$title" mode="title.markup">
200 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
201 </xsl:apply-templates>
204 <xsl:template match="reference" mode="title.markup">
205 <xsl:param name="allow-anchors" select="0"/>
206 <xsl:apply-templates select="(referenceinfo/title|docinfo/title|info/title|title)[1]"
208 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
209 </xsl:apply-templates>
212 <xsl:template match="refentry" mode="title.markup">
213 <xsl:param name="allow-anchors" select="0"/>
214 <xsl:variable name="refmeta" select=".//refmeta"/>
215 <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
216 <xsl:variable name="refnamediv" select=".//refnamediv"/>
217 <xsl:variable name="refname" select="$refnamediv//refname"/>
218 <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
220 <xsl:variable name="title">
222 <xsl:when test="$refentrytitle">
223 <xsl:apply-templates select="$refentrytitle[1]" mode="title.markup"/>
225 <xsl:when test="$refdesc">
226 <xsl:apply-templates select="$refdesc" mode="title.markup"/>
228 <xsl:when test="$refname">
229 <xsl:apply-templates select="$refname[1]" mode="title.markup"/>
231 <xsl:otherwise>REFENTRY WITHOUT TITLE???</xsl:otherwise>
235 <xsl:copy-of select="$title"/>
238 <xsl:template match="refentrytitle|refname|refdescriptor" mode="title.markup">
239 <xsl:param name="allow-anchors" select="0"/>
241 <xsl:when test="$allow-anchors != 0">
242 <xsl:apply-templates/>
245 <xsl:apply-templates mode="no.anchor.mode"/>
250 <xsl:template match="section
251 |sect1|sect2|sect3|sect4|sect5
252 |refsect1|refsect2|refsect3|refsection
255 <xsl:param name="allow-anchors" select="0"/>
256 <xsl:variable name="title" select="(info/title
266 |refsectioninfo/title
269 <xsl:apply-templates select="$title" mode="title.markup">
270 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
271 </xsl:apply-templates>
274 <xsl:template match="bridgehead" mode="title.markup">
275 <xsl:apply-templates mode="title.markup"/>
278 <xsl:template match="refsynopsisdiv" mode="title.markup">
279 <xsl:param name="allow-anchors" select="0"/>
281 <xsl:when test="title|info/title">
282 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
283 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
284 </xsl:apply-templates>
287 <xsl:call-template name="gentext">
288 <xsl:with-param name="key" select="'RefSynopsisDiv'"/>
294 <xsl:template match="bibliography" mode="title.markup">
295 <xsl:param name="allow-anchors" select="0"/>
296 <xsl:variable name="title" select="(bibliographyinfo/title|info/title|title)[1]"/>
298 <xsl:when test="$title">
299 <xsl:apply-templates select="$title" mode="title.markup">
300 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
301 </xsl:apply-templates>
304 <xsl:call-template name="gentext">
305 <xsl:with-param name="key" select="'Bibliography'"/>
311 <xsl:template match="glossary" mode="title.markup">
312 <xsl:param name="allow-anchors" select="0"/>
313 <xsl:variable name="title" select="(glossaryinfo/title|info/title|title)[1]"/>
315 <xsl:when test="$title">
316 <xsl:apply-templates select="$title" mode="title.markup">
317 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
318 </xsl:apply-templates>
321 <xsl:call-template name="gentext.element.name">
322 <xsl:with-param name="element.name" select="local-name(.)"/>
328 <xsl:template match="glossdiv" mode="title.markup">
329 <xsl:param name="allow-anchors" select="0"/>
330 <xsl:variable name="title" select="(info/title|title)[1]"/>
332 <xsl:when test="$title">
333 <xsl:apply-templates select="$title" mode="title.markup">
334 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
335 </xsl:apply-templates>
338 <xsl:message>ERROR: glossdiv missing its required title</xsl:message>
343 <xsl:template match="glossentry" mode="title.markup">
344 <xsl:param name="allow-anchors" select="0"/>
345 <xsl:apply-templates select="glossterm" mode="title.markup">
346 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
347 </xsl:apply-templates>
350 <xsl:template match="glossterm|firstterm" mode="title.markup">
351 <xsl:param name="allow-anchors" select="0"/>
354 <xsl:when test="$allow-anchors != 0">
355 <xsl:apply-templates/>
358 <xsl:apply-templates mode="no.anchor.mode"/>
363 <xsl:template match="index" mode="title.markup">
364 <xsl:param name="allow-anchors" select="0"/>
365 <xsl:variable name="title" select="(indexinfo/title|info/title|title)[1]"/>
367 <xsl:when test="$title">
368 <xsl:apply-templates select="$title" mode="title.markup">
369 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
370 </xsl:apply-templates>
373 <xsl:call-template name="gentext">
374 <xsl:with-param name="key" select="'Index'"/>
380 <xsl:template match="setindex" mode="title.markup">
381 <xsl:param name="allow-anchors" select="0"/>
382 <xsl:variable name="title" select="(setindexinfo/title|info/title|title)[1]"/>
384 <xsl:when test="$title">
385 <xsl:apply-templates select="$title" mode="title.markup">
386 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
387 </xsl:apply-templates>
390 <xsl:call-template name="gentext">
391 <xsl:with-param name="key" select="'SetIndex'"/>
397 <xsl:template match="figure|example|equation" mode="title.markup">
398 <xsl:param name="allow-anchors" select="0"/>
399 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
400 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
401 </xsl:apply-templates>
404 <xsl:template match="table" mode="title.markup">
405 <xsl:param name="allow-anchors" select="0"/>
406 <xsl:apply-templates select="(title|info/title|caption)[1]" mode="title.markup">
407 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
408 </xsl:apply-templates>
411 <xsl:template match="procedure" mode="title.markup">
412 <xsl:param name="allow-anchors" select="0"/>
413 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
414 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
415 </xsl:apply-templates>
418 <xsl:template match="task" mode="title.markup">
419 <xsl:param name="allow-anchors" select="0"/>
420 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
421 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
422 </xsl:apply-templates>
425 <xsl:template match="sidebar" mode="title.markup">
426 <xsl:param name="allow-anchors" select="0"/>
427 <xsl:apply-templates select="(info/title|sidebarinfo/title|title)[1]"
429 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
430 </xsl:apply-templates>
433 <xsl:template match="abstract" mode="title.markup">
434 <xsl:param name="allow-anchors" select="0"/>
436 <xsl:when test="title|info/title">
437 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
438 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
439 </xsl:apply-templates>
442 <xsl:call-template name="gentext">
443 <xsl:with-param name="key" select="'Abstract'"/>
449 <xsl:template match="caution|tip|warning|important|note" mode="title.markup">
450 <xsl:param name="allow-anchors" select="0"/>
451 <xsl:variable name="title" select="(title|info/title)[1]"/>
453 <xsl:when test="$title">
454 <xsl:apply-templates select="$title" mode="title.markup">
455 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
456 </xsl:apply-templates>
459 <xsl:call-template name="gentext">
460 <xsl:with-param name="key">
462 <xsl:when test="local-name(.)='note'">Note</xsl:when>
463 <xsl:when test="local-name(.)='important'">Important</xsl:when>
464 <xsl:when test="local-name(.)='caution'">Caution</xsl:when>
465 <xsl:when test="local-name(.)='warning'">Warning</xsl:when>
466 <xsl:when test="local-name(.)='tip'">Tip</xsl:when>
474 <xsl:template match="question" mode="title.markup">
475 <!-- questions don't have titles -->
476 <xsl:text>Question</xsl:text>
479 <xsl:template match="answer" mode="title.markup">
480 <!-- answers don't have titles -->
481 <xsl:text>Answer</xsl:text>
484 <xsl:template match="qandaentry" mode="title.markup">
485 <!-- qandaentrys are represented by the first question in them -->
486 <xsl:text>Question</xsl:text>
489 <xsl:template match="qandaset" mode="title.markup">
490 <xsl:param name="allow-anchors" select="0"/>
491 <xsl:variable name="title" select="(info/title|
495 <xsl:when test="$title">
496 <xsl:apply-templates select="$title" mode="title.markup">
497 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
498 </xsl:apply-templates>
501 <xsl:call-template name="gentext">
502 <xsl:with-param name="key" select="'QandASet'"/>
508 <xsl:template match="legalnotice" mode="title.markup">
509 <xsl:param name="allow-anchors" select="0"/>
511 <xsl:when test="title|info/title">
512 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
513 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
514 </xsl:apply-templates>
517 <xsl:call-template name="gentext">
518 <xsl:with-param name="key" select="'LegalNotice'"/>
524 <!-- ============================================================ -->
526 <xsl:template match="*" mode="titleabbrev.markup">
527 <xsl:param name="allow-anchors" select="0"/>
528 <xsl:param name="verbose" select="1"/>
531 <xsl:when test="titleabbrev">
532 <xsl:apply-templates select="titleabbrev[1]" mode="title.markup">
533 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
534 </xsl:apply-templates>
536 <xsl:when test="info/titleabbrev">
537 <xsl:apply-templates select="info/titleabbrev[1]" mode="title.markup">
538 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
539 </xsl:apply-templates>
542 <xsl:apply-templates select="." mode="title.markup">
543 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
544 <xsl:with-param name="verbose" select="$verbose"/>
545 </xsl:apply-templates>
550 <xsl:template match="book|preface|chapter|appendix" mode="titleabbrev.markup">
551 <xsl:param name="allow-anchors" select="0"/>
552 <xsl:param name="verbose" select="1"/>
554 <xsl:variable name="titleabbrev" select="(docinfo/titleabbrev
555 |bookinfo/titleabbrev
557 |prefaceinfo/titleabbrev
558 |chapterinfo/titleabbrev
559 |appendixinfo/titleabbrev
563 <xsl:when test="$titleabbrev">
564 <xsl:apply-templates select="$titleabbrev" mode="title.markup">
565 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
566 </xsl:apply-templates>
569 <xsl:apply-templates select="." mode="title.markup">
570 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
571 <xsl:with-param name="verbose" select="$verbose"/>
572 </xsl:apply-templates>
577 <xsl:template match="article" mode="titleabbrev.markup">
578 <xsl:param name="allow-anchors" select="0"/>
579 <xsl:param name="verbose" select="1"/>
581 <xsl:variable name="titleabbrev" select="(artheader/titleabbrev
582 |articleinfo/titleabbrev
587 <xsl:when test="$titleabbrev">
588 <xsl:apply-templates select="$titleabbrev" mode="title.markup">
589 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
590 </xsl:apply-templates>
593 <xsl:apply-templates select="." mode="title.markup">
594 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
595 <xsl:with-param name="verbose" select="$verbose"/>
596 </xsl:apply-templates>
601 <xsl:template match="section
602 |sect1|sect2|sect3|sect4|sect5
603 |refsect1|refsect2|refsect3
605 mode="titleabbrev.markup">
606 <xsl:param name="allow-anchors" select="0"/>
607 <xsl:param name="verbose" select="1"/>
609 <xsl:variable name="titleabbrev" select="(info/titleabbrev
610 |sectioninfo/titleabbrev
611 |sect1info/titleabbrev
612 |sect2info/titleabbrev
613 |sect3info/titleabbrev
614 |sect4info/titleabbrev
615 |sect5info/titleabbrev
616 |refsect1info/titleabbrev
617 |refsect2info/titleabbrev
618 |refsect3info/titleabbrev
622 <xsl:when test="$titleabbrev">
623 <xsl:apply-templates select="$titleabbrev" mode="title.markup">
624 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
625 </xsl:apply-templates>
628 <xsl:apply-templates select="." mode="title.markup">
629 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
630 <xsl:with-param name="verbose" select="$verbose"/>
631 </xsl:apply-templates>
636 <xsl:template match="titleabbrev" mode="title.markup">
637 <xsl:param name="allow-anchors" select="0"/>
640 <xsl:when test="$allow-anchors != 0">
641 <xsl:apply-templates/>
644 <xsl:apply-templates mode="no.anchor.mode"/>
649 <!-- ============================================================ -->
651 <xsl:template match="*" mode="no.anchor.mode">
652 <!-- Switch to normal mode if no links -->
654 <xsl:when test="descendant-or-self::footnote or
655 descendant-or-self::anchor or
656 descendant-or-self::ulink or
657 descendant-or-self::link or
658 descendant-or-self::olink or
659 descendant-or-self::xref or
660 descendant-or-self::indexterm or
661 (ancestor::title and (@id or @xml:id))">
663 <xsl:apply-templates mode="no.anchor.mode"/>
666 <xsl:apply-templates select="."/>
671 <xsl:template match="footnote" mode="no.anchor.mode">
672 <!-- nop, suppressed -->
675 <xsl:template match="anchor" mode="no.anchor.mode">
676 <!-- nop, suppressed -->
679 <xsl:template match="ulink" mode="no.anchor.mode">
680 <xsl:apply-templates/>
683 <xsl:template match="link" mode="no.anchor.mode">
685 <xsl:when test="count(child::node()) > 0">
686 <!-- If it has content, use it -->
687 <xsl:apply-templates/>
689 <!-- look for an endterm -->
690 <xsl:when test="@endterm">
691 <xsl:variable name="etargets" select="key('id',@endterm)"/>
692 <xsl:variable name="etarget" select="$etargets[1]"/>
694 <xsl:when test="count($etarget) = 0">
696 <xsl:value-of select="count($etargets)"/>
697 <xsl:text>Endterm points to nonexistent ID: </xsl:text>
698 <xsl:value-of select="@endterm"/>
700 <xsl:text>???</xsl:text>
703 <xsl:apply-templates select="$etarget" mode="endterm"/>
708 <xsl:apply-templates/>
713 <xsl:template match="olink" mode="no.anchor.mode">
714 <xsl:apply-templates/>
717 <xsl:template match="indexterm" mode="no.anchor.mode">
718 <!-- nop, suppressed -->
721 <xsl:template match="xref" mode="no.anchor.mode">
722 <xsl:variable name="targets" select="key('id',@linkend)"/>
723 <xsl:variable name="target" select="$targets[1]"/>
724 <xsl:variable name="refelem" select="local-name($target)"/>
726 <xsl:call-template name="check.id.unique">
727 <xsl:with-param name="linkend" select="@linkend"/>
731 <xsl:when test="count($target) = 0">
733 <xsl:text>XRef to nonexistent id: </xsl:text>
734 <xsl:value-of select="@linkend"/>
736 <xsl:text>???</xsl:text>
739 <xsl:when test="@endterm">
740 <xsl:variable name="etargets" select="key('id',@endterm)"/>
741 <xsl:variable name="etarget" select="$etargets[1]"/>
743 <xsl:when test="count($etarget) = 0">
745 <xsl:value-of select="count($etargets)"/>
746 <xsl:text>Endterm points to nonexistent ID: </xsl:text>
747 <xsl:value-of select="@endterm"/>
749 <xsl:text>???</xsl:text>
752 <xsl:apply-templates select="$etarget" mode="endterm"/>
757 <xsl:when test="$target/@xreflabel">
758 <xsl:call-template name="xref.xreflabel">
759 <xsl:with-param name="target" select="$target"/>
766 <!-- Watch out for the case when there is a xref or link inside
767 a title. See bugs #1811721 and #1838136. -->
768 <xsl:when test="not(ancestor::*[@id = $target/@id] or ancestor::*[@xml:id = $target/@xml:id])">
770 <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
772 <xsl:apply-templates select="$target" mode="xref-to">
774 <xsl:with-param name="referrer" select="."/>
775 <xsl:with-param name="xrefstyle">
777 <xsl:when test="@role and not(@xrefstyle) and $use.role.as.xrefstyle != 0">
778 <xsl:value-of select="@role"/>
781 <xsl:value-of select="@xrefstyle"/>
785 </xsl:apply-templates>
787 <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
791 <xsl:apply-templates/>
800 <!-- ============================================================ -->