You need to retrieve a title (or subtitle), but your current
node is not a title.
The DocBook XSL stylesheets offer the
title.markup mode for this purpose. Usually,
insert the following code into the appropriate place:
<xsl:apply-templates select="." mode="title.markup"/>
The xsl:apply-templates recursively finds the
correct title node, regardless where you are. It also looks
into an info element, if necessary.
DocBook contains three elements which are used for title markup:
titleThe main title. According to the TDG“it identifies the titles of documents and parts of documents, and is the required caption on formal objects.”
subtitleA optional subtitle is an alternative or explanatory title in addition to its main title. Usually a subtitle is printed below the main title on the same page.
titleabbrevThe optional, abbreviated title is used in case the main title is overly verbose. Usually this element is not printed with the main title on the same page. However, it is used in the table of contents, for example.
All of the above title elements contain a special mode to get the content of this node:
| Element | Mode |
|---|---|
title | title.markup |
subtitle | subtitle.markup |
titleabbrev | titleabbrev.markup |
To further elaborate why you should use one of the previous modes, let's assume you have this chapter title:
<chapter> <title>Programming in Python</title> <!-- further substructure pruned --> </chapter>
Let's further assume, you have a template where you need the title from the above chapter. One simple, yet unfavorable, solution could be coded like this:
<xsl:template name="..."> <xsl:value-of select="ancestor::d:title"/> </xsl:template>
This has several disadvantages:
The XPath does not consider a title inside an
info element.
The xsl:value-of returns the string
value. In most cases this is correct. However, if
you have a quote inside title, the
quote is not processed and you will not get any
quotation marks.
Replacing xsl:value-of with
xsl:apply-templates as shown in the solution section,
ensures correct processing of child elements inside
title.
The same is true for subtitle and
titleabbrev. Using the subtitle.markup or
titleabbrev.markup mode ensures that you always get the
correct content.
To see what combination results in what string, find an
overview in Table 2.2, “Different Combinations and Their Results on
*.markup Modes”.
*.markup Modes| Code | Results |
|---|---|
<title>Programming in Python</title> |
|
<title>Programming in Python</title> <subtitle>With an IDE</subtitle> |
|
<title>Programming in Python</title> <titleabbrev>Python</titleabbrev> |
|
<title>Programming in Python</title> <subtitle>With an IDE</subtitle> <titleabbrev>Python</titleabbrev> |
|
| Project@GitHub | Issue#7 |