2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
4 xmlns:xlink="http://www.w3.org/1999/xlink"
5 exclude-result-prefixes="doc"
8 <!-- ********************************************************************
9 $Id: titles.xsl 8599 2010-03-20 10:47:36Z mzjn $
10 ********************************************************************
12 This file is part of the XSL DocBook Stylesheet distribution.
13 See ../README or http://docbook.sf.net/release/xsl/current/ for
14 copyright and other information.
16 ******************************************************************** -->
18 <!-- ==================================================================== -->
22 <doc:mode mode="title.markup" xmlns="">
23 <refpurpose>Provides access to element titles</refpurpose>
24 <refdescription id="title.markup-desc">
25 <para>Processing an element in the
26 <literal role="mode">title.markup</literal> mode produces the
27 title of the element. This does not include the label.
32 <xsl:template match="*" mode="title.markup">
33 <xsl:param name="allow-anchors" select="0"/>
34 <xsl:param name="verbose" select="1"/>
36 <!-- * FIXME: this should handle other *info elements as well -->
37 <!-- * but this is good enough for now. -->
38 <xsl:when test="title|info/title">
39 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
40 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
41 </xsl:apply-templates>
43 <xsl:when test="local-name(.) = 'partintro'">
44 <!-- partintro's don't have titles, use the parent (part or reference)
46 <xsl:apply-templates select="parent::*" mode="title.markup"/>
49 <xsl:if test="$verbose != 0">
51 <xsl:text>Request for title of element with no title: </xsl:text>
52 <xsl:value-of select="local-name(.)"/>
55 <xsl:text> (id="</xsl:text>
56 <xsl:value-of select="@id"/>
57 <xsl:text>")</xsl:text>
59 <xsl:when test="@xml:id">
60 <xsl:text> (xml:id="</xsl:text>
61 <xsl:value-of select="@xml:id"/>
62 <xsl:text>")</xsl:text>
67 <xsl:text>???TITLE???</xsl:text>
72 <xsl:template match="title" mode="title.markup">
73 <xsl:param name="allow-anchors" select="0"/>
76 <xsl:when test="$allow-anchors != 0">
77 <xsl:apply-templates/>
80 <xsl:apply-templates mode="no.anchor.mode"/>
85 <!-- only occurs in HTML Tables! -->
86 <xsl:template match="caption" mode="title.markup">
87 <xsl:param name="allow-anchors" select="0"/>
90 <xsl:when test="$allow-anchors != 0">
91 <xsl:apply-templates/>
94 <xsl:apply-templates mode="no.anchor.mode"/>
99 <xsl:template match="set" mode="title.markup">
100 <xsl:param name="allow-anchors" select="0"/>
101 <xsl:apply-templates select="(setinfo/title|info/title|title)[1]"
103 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
104 </xsl:apply-templates>
107 <xsl:template match="book" mode="title.markup">
108 <xsl:param name="allow-anchors" select="0"/>
109 <xsl:apply-templates select="(bookinfo/title|info/title|title)[1]"
111 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
112 </xsl:apply-templates>
115 <xsl:template match="part" mode="title.markup">
116 <xsl:param name="allow-anchors" select="0"/>
117 <xsl:apply-templates select="(partinfo/title|info/title|docinfo/title|title)[1]"
119 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
120 </xsl:apply-templates>
123 <xsl:template match="preface|chapter|appendix" mode="title.markup">
124 <xsl:param name="allow-anchors" select="0"/>
128 <xsl:value-of select="local-name(.)"/>
129 <xsl:text> </xsl:text>
130 <xsl:value-of select="$allow-anchors"/>
134 <xsl:variable name="title" select="(docinfo/title
140 <xsl:apply-templates select="$title" mode="title.markup">
141 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
142 </xsl:apply-templates>
145 <xsl:template match="dedication" mode="title.markup">
146 <xsl:param name="allow-anchors" select="0"/>
148 <xsl:when test="title|info/title">
149 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
150 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
151 </xsl:apply-templates>
154 <xsl:call-template name="gentext">
155 <xsl:with-param name="key" select="'Dedication'"/>
161 <xsl:template match="acknowledgements" mode="title.markup">
162 <xsl:param name="allow-anchors" select="0"/>
164 <xsl:when test="title|info/title">
165 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
166 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
167 </xsl:apply-templates>
170 <xsl:call-template name="gentext">
171 <xsl:with-param name="key" select="'Acknowledgements'"/>
177 <xsl:template match="colophon" mode="title.markup">
178 <xsl:param name="allow-anchors" select="0"/>
180 <xsl:when test="title|info/title">
181 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
182 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
183 </xsl:apply-templates>
186 <xsl:call-template name="gentext">
187 <xsl:with-param name="key" select="'Colophon'"/>
193 <xsl:template match="article" mode="title.markup">
194 <xsl:param name="allow-anchors" select="0"/>
195 <xsl:variable name="title" select="(artheader/title
200 <xsl:apply-templates select="$title" mode="title.markup">
201 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
202 </xsl:apply-templates>
205 <xsl:template match="reference" mode="title.markup">
206 <xsl:param name="allow-anchors" select="0"/>
207 <xsl:apply-templates select="(referenceinfo/title|docinfo/title|info/title|title)[1]"
209 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
210 </xsl:apply-templates>
213 <xsl:template match="refentry" mode="title.markup">
214 <xsl:param name="allow-anchors" select="0"/>
215 <xsl:variable name="refmeta" select=".//refmeta"/>
216 <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
217 <xsl:variable name="refnamediv" select=".//refnamediv"/>
218 <xsl:variable name="refname" select="$refnamediv//refname"/>
219 <xsl:variable name="refdesc" select="$refnamediv//refdescriptor"/>
221 <xsl:variable name="title">
223 <xsl:when test="$refentrytitle">
224 <xsl:apply-templates select="$refentrytitle[1]" mode="title.markup"/>
226 <xsl:when test="$refdesc">
227 <xsl:apply-templates select="$refdesc" mode="title.markup"/>
229 <xsl:when test="$refname">
230 <xsl:apply-templates select="$refname[1]" mode="title.markup"/>
232 <xsl:otherwise>REFENTRY WITHOUT TITLE???</xsl:otherwise>
236 <xsl:copy-of select="$title"/>
239 <xsl:template match="refentrytitle|refname|refdescriptor" mode="title.markup">
240 <xsl:param name="allow-anchors" select="0"/>
242 <xsl:when test="$allow-anchors != 0">
243 <xsl:apply-templates/>
246 <xsl:apply-templates mode="no.anchor.mode"/>
251 <xsl:template match="section
252 |sect1|sect2|sect3|sect4|sect5
253 |refsect1|refsect2|refsect3|refsection
256 <xsl:param name="allow-anchors" select="0"/>
257 <xsl:variable name="title" select="(info/title
267 |refsectioninfo/title
270 <xsl:apply-templates select="$title" mode="title.markup">
271 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
272 </xsl:apply-templates>
275 <xsl:template match="bridgehead" mode="title.markup">
276 <xsl:apply-templates mode="title.markup"/>
279 <xsl:template match="refsynopsisdiv" mode="title.markup">
280 <xsl:param name="allow-anchors" select="0"/>
282 <xsl:when test="title|info/title">
283 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
284 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
285 </xsl:apply-templates>
288 <xsl:call-template name="gentext">
289 <xsl:with-param name="key" select="'RefSynopsisDiv'"/>
295 <xsl:template match="bibliography" mode="title.markup">
296 <xsl:param name="allow-anchors" select="0"/>
297 <xsl:variable name="title" select="(bibliographyinfo/title|info/title|title)[1]"/>
299 <xsl:when test="$title">
300 <xsl:apply-templates select="$title" mode="title.markup">
301 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
302 </xsl:apply-templates>
305 <xsl:call-template name="gentext">
306 <xsl:with-param name="key" select="'Bibliography'"/>
312 <xsl:template match="glossary" mode="title.markup">
313 <xsl:param name="allow-anchors" select="0"/>
314 <xsl:variable name="title" select="(glossaryinfo/title|info/title|title)[1]"/>
316 <xsl:when test="$title">
317 <xsl:apply-templates select="$title" mode="title.markup">
318 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
319 </xsl:apply-templates>
322 <xsl:call-template name="gentext.element.name">
323 <xsl:with-param name="element.name" select="local-name(.)"/>
329 <xsl:template match="glossdiv" mode="title.markup">
330 <xsl:param name="allow-anchors" select="0"/>
331 <xsl:variable name="title" select="(info/title|title)[1]"/>
333 <xsl:when test="$title">
334 <xsl:apply-templates select="$title" mode="title.markup">
335 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
336 </xsl:apply-templates>
339 <xsl:message>ERROR: glossdiv missing its required title</xsl:message>
344 <xsl:template match="glossentry" mode="title.markup">
345 <xsl:param name="allow-anchors" select="0"/>
346 <xsl:apply-templates select="glossterm" mode="title.markup">
347 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
348 </xsl:apply-templates>
351 <xsl:template match="glossterm|firstterm" mode="title.markup">
352 <xsl:param name="allow-anchors" select="0"/>
355 <xsl:when test="$allow-anchors != 0">
356 <xsl:apply-templates/>
359 <xsl:apply-templates mode="no.anchor.mode"/>
364 <xsl:template match="index" mode="title.markup">
365 <xsl:param name="allow-anchors" select="0"/>
366 <xsl:variable name="title" select="(indexinfo/title|info/title|title)[1]"/>
368 <xsl:when test="$title">
369 <xsl:apply-templates select="$title" mode="title.markup">
370 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
371 </xsl:apply-templates>
374 <xsl:call-template name="gentext">
375 <xsl:with-param name="key" select="'Index'"/>
381 <xsl:template match="setindex" mode="title.markup">
382 <xsl:param name="allow-anchors" select="0"/>
383 <xsl:variable name="title" select="(setindexinfo/title|info/title|title)[1]"/>
385 <xsl:when test="$title">
386 <xsl:apply-templates select="$title" mode="title.markup">
387 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
388 </xsl:apply-templates>
391 <xsl:call-template name="gentext">
392 <xsl:with-param name="key" select="'SetIndex'"/>
398 <xsl:template match="figure|example|equation" mode="title.markup">
399 <xsl:param name="allow-anchors" select="0"/>
400 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
401 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
402 </xsl:apply-templates>
405 <xsl:template match="table" mode="title.markup">
406 <xsl:param name="allow-anchors" select="0"/>
407 <xsl:apply-templates select="(title|info/title|caption)[1]" mode="title.markup">
408 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
409 </xsl:apply-templates>
412 <xsl:template match="procedure" mode="title.markup">
413 <xsl:param name="allow-anchors" select="0"/>
414 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
415 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
416 </xsl:apply-templates>
419 <xsl:template match="task" mode="title.markup">
420 <xsl:param name="allow-anchors" select="0"/>
421 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
422 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
423 </xsl:apply-templates>
426 <xsl:template match="sidebar" mode="title.markup">
427 <xsl:param name="allow-anchors" select="0"/>
428 <xsl:apply-templates select="(info/title|sidebarinfo/title|title)[1]"
430 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
431 </xsl:apply-templates>
434 <xsl:template match="abstract" mode="title.markup">
435 <xsl:param name="allow-anchors" select="0"/>
437 <xsl:when test="title|info/title">
438 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
439 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
440 </xsl:apply-templates>
443 <xsl:call-template name="gentext">
444 <xsl:with-param name="key" select="'Abstract'"/>
450 <xsl:template match="caution|tip|warning|important|note" mode="title.markup">
451 <xsl:param name="allow-anchors" select="0"/>
452 <xsl:variable name="title" select="(title|info/title)[1]"/>
454 <xsl:when test="$title">
455 <xsl:apply-templates select="$title" mode="title.markup">
456 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
457 </xsl:apply-templates>
460 <xsl:call-template name="gentext">
461 <xsl:with-param name="key">
463 <xsl:when test="local-name(.)='note'">Note</xsl:when>
464 <xsl:when test="local-name(.)='important'">Important</xsl:when>
465 <xsl:when test="local-name(.)='caution'">Caution</xsl:when>
466 <xsl:when test="local-name(.)='warning'">Warning</xsl:when>
467 <xsl:when test="local-name(.)='tip'">Tip</xsl:when>
475 <xsl:template match="question" mode="title.markup">
476 <!-- questions don't have titles -->
477 <xsl:text>Question</xsl:text>
480 <xsl:template match="answer" mode="title.markup">
481 <!-- answers don't have titles -->
482 <xsl:text>Answer</xsl:text>
485 <xsl:template match="qandaentry" mode="title.markup">
486 <!-- qandaentrys are represented by the first question in them -->
487 <xsl:text>Question</xsl:text>
490 <xsl:template match="qandaset" mode="title.markup">
491 <xsl:param name="allow-anchors" select="0"/>
492 <xsl:variable name="title" select="(info/title|
496 <xsl:when test="$title">
497 <xsl:apply-templates select="$title" mode="title.markup">
498 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
499 </xsl:apply-templates>
502 <xsl:call-template name="gentext">
503 <xsl:with-param name="key" select="'QandASet'"/>
509 <xsl:template match="legalnotice" mode="title.markup">
510 <xsl:param name="allow-anchors" select="0"/>
512 <xsl:when test="title|info/title">
513 <xsl:apply-templates select="(title|info/title)[1]" mode="title.markup">
514 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
515 </xsl:apply-templates>
518 <xsl:call-template name="gentext">
519 <xsl:with-param name="key" select="'LegalNotice'"/>
525 <!-- ============================================================ -->
527 <xsl:template match="*" mode="titleabbrev.markup">
528 <xsl:param name="allow-anchors" select="0"/>
529 <xsl:param name="verbose" select="1"/>
532 <xsl:when test="titleabbrev">
533 <xsl:apply-templates select="titleabbrev[1]" mode="title.markup">
534 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
535 </xsl:apply-templates>
537 <xsl:when test="info/titleabbrev">
538 <xsl:apply-templates select="info/titleabbrev[1]" mode="title.markup">
539 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
540 </xsl:apply-templates>
543 <xsl:apply-templates select="." mode="title.markup">
544 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
545 <xsl:with-param name="verbose" select="$verbose"/>
546 </xsl:apply-templates>
551 <xsl:template match="book|preface|chapter|appendix" mode="titleabbrev.markup">
552 <xsl:param name="allow-anchors" select="0"/>
553 <xsl:param name="verbose" select="1"/>
555 <xsl:variable name="titleabbrev" select="(docinfo/titleabbrev
556 |bookinfo/titleabbrev
558 |prefaceinfo/titleabbrev
559 |chapterinfo/titleabbrev
560 |appendixinfo/titleabbrev
564 <xsl:when test="$titleabbrev">
565 <xsl:apply-templates select="$titleabbrev" mode="title.markup">
566 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
567 </xsl:apply-templates>
570 <xsl:apply-templates select="." mode="title.markup">
571 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
572 <xsl:with-param name="verbose" select="$verbose"/>
573 </xsl:apply-templates>
578 <xsl:template match="article" mode="titleabbrev.markup">
579 <xsl:param name="allow-anchors" select="0"/>
580 <xsl:param name="verbose" select="1"/>
582 <xsl:variable name="titleabbrev" select="(artheader/titleabbrev
583 |articleinfo/titleabbrev
588 <xsl:when test="$titleabbrev">
589 <xsl:apply-templates select="$titleabbrev" mode="title.markup">
590 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
591 </xsl:apply-templates>
594 <xsl:apply-templates select="." mode="title.markup">
595 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
596 <xsl:with-param name="verbose" select="$verbose"/>
597 </xsl:apply-templates>
602 <xsl:template match="section
603 |sect1|sect2|sect3|sect4|sect5
604 |refsect1|refsect2|refsect3
606 mode="titleabbrev.markup">
607 <xsl:param name="allow-anchors" select="0"/>
608 <xsl:param name="verbose" select="1"/>
610 <xsl:variable name="titleabbrev" select="(info/titleabbrev
611 |sectioninfo/titleabbrev
612 |sect1info/titleabbrev
613 |sect2info/titleabbrev
614 |sect3info/titleabbrev
615 |sect4info/titleabbrev
616 |sect5info/titleabbrev
617 |refsect1info/titleabbrev
618 |refsect2info/titleabbrev
619 |refsect3info/titleabbrev
623 <xsl:when test="$titleabbrev">
624 <xsl:apply-templates select="$titleabbrev" mode="title.markup">
625 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
626 </xsl:apply-templates>
629 <xsl:apply-templates select="." mode="title.markup">
630 <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
631 <xsl:with-param name="verbose" select="$verbose"/>
632 </xsl:apply-templates>
637 <xsl:template match="titleabbrev" mode="title.markup">
638 <xsl:param name="allow-anchors" select="0"/>
641 <xsl:when test="$allow-anchors != 0">
642 <xsl:apply-templates/>
645 <xsl:apply-templates mode="no.anchor.mode"/>
650 <!-- ============================================================ -->
652 <xsl:template match="*" mode="no.anchor.mode">
653 <!-- Switch to normal mode if no links -->
655 <xsl:when test="descendant-or-self::footnote or
656 descendant-or-self::anchor or
657 descendant-or-self::ulink or
658 descendant-or-self::link or
659 descendant-or-self::olink or
660 descendant-or-self::xref or
661 descendant-or-self::indexterm or
662 (ancestor::title and (@id or @xml:id))">
664 <xsl:apply-templates mode="no.anchor.mode"/>
667 <xsl:apply-templates select="."/>
672 <xsl:template match="footnote" mode="no.anchor.mode">
673 <!-- nop, suppressed -->
676 <xsl:template match="anchor" mode="no.anchor.mode">
677 <!-- nop, suppressed -->
680 <xsl:template match="ulink" mode="no.anchor.mode">
681 <xsl:apply-templates/>
684 <xsl:template match="link" mode="no.anchor.mode">
686 <xsl:when test="count(child::node()) > 0">
687 <!-- If it has content, use it -->
688 <xsl:apply-templates/>
690 <!-- look for an endterm -->
691 <xsl:when test="@endterm">
692 <xsl:variable name="etargets" select="key('id',@endterm)"/>
693 <xsl:variable name="etarget" select="$etargets[1]"/>
695 <xsl:when test="count($etarget) = 0">
697 <xsl:value-of select="count($etargets)"/>
698 <xsl:text>Endterm points to nonexistent ID: </xsl:text>
699 <xsl:value-of select="@endterm"/>
701 <xsl:text>???</xsl:text>
704 <xsl:apply-templates select="$etarget" mode="endterm"/>
709 <xsl:apply-templates/>
714 <xsl:template match="olink" mode="no.anchor.mode">
715 <xsl:apply-templates/>
718 <xsl:template match="indexterm" mode="no.anchor.mode">
719 <!-- nop, suppressed -->
722 <xsl:template match="xref" mode="no.anchor.mode">
723 <xsl:variable name="targets" select="key('id',@linkend)|key('id',substring-after(@xlink:href,'#'))"/>
724 <xsl:variable name="target" select="$targets[1]"/>
725 <xsl:variable name="refelem" select="local-name($target)"/>
727 <xsl:call-template name="check.id.unique">
728 <xsl:with-param name="linkend" select="@linkend"/>
732 <xsl:when test="count($target) = 0">
734 <xsl:text>XRef to nonexistent id: </xsl:text>
735 <xsl:value-of select="@linkend"/>
736 <xsl:value-of select="@xlink:href"/>
738 <xsl:text>???</xsl:text>
741 <xsl:when test="@endterm">
742 <xsl:variable name="etargets" select="key('id',@endterm)"/>
743 <xsl:variable name="etarget" select="$etargets[1]"/>
745 <xsl:when test="count($etarget) = 0">
747 <xsl:value-of select="count($etargets)"/>
748 <xsl:text>Endterm points to nonexistent ID: </xsl:text>
749 <xsl:value-of select="@endterm"/>
751 <xsl:text>???</xsl:text>
754 <xsl:apply-templates select="$etarget" mode="endterm"/>
759 <xsl:when test="$target/@xreflabel">
760 <xsl:call-template name="xref.xreflabel">
761 <xsl:with-param name="target" select="$target"/>
768 <!-- Watch out for the case when there is a xref or link inside
769 a title. See bugs #1811721 and #1838136. -->
770 <xsl:when test="not(ancestor::*[@id = $target/@id] or ancestor::*[@xml:id = $target/@xml:id])">
772 <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
774 <xsl:apply-templates select="$target" mode="xref-to">
776 <xsl:with-param name="referrer" select="."/>
777 <xsl:with-param name="xrefstyle">
779 <xsl:when test="@role and not(@xrefstyle) and $use.role.as.xrefstyle != 0">
780 <xsl:value-of select="@role"/>
783 <xsl:value-of select="@xrefstyle"/>
787 </xsl:apply-templates>
789 <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
793 <xsl:apply-templates/>
802 <!-- ============================================================ -->