1<?xml version='1.0'?>
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"
5                version='1.0'>
6
7<!-- ============================================================ -->
8<!-- title markup -->
9
10<doc:mode mode="title.markup" xmlns="">
11<refpurpose>Provides access to element titles</refpurpose>
12<refdescription>
13<para>Processing an element in the
14<literal role="mode">title.markup</literal> mode produces the
15title of the element. This does not include the label.
16</para>
17</refdescription>
18</doc:mode>
19
20<xsl:template match="*" mode="title.markup">
21  <xsl:param name="allow-anchors" select="'0'"/>
22  <xsl:choose>
23    <xsl:when test="title">
24      <xsl:apply-templates select="title[1]" mode="title.markup">
25	<xsl:with-param name="allow-anchors" select="$allow-anchors"/>
26      </xsl:apply-templates>
27    </xsl:when>
28    <xsl:when test="local-name(.) = 'partintro'">
29      <!-- partintro's don't have titles, use the parent (part or reference)
30           title instead. -->
31      <xsl:apply-templates select="parent::*" mode="title.markup"/>
32    </xsl:when>
33    <xsl:otherwise>
34      <xsl:message>
35	<xsl:text>Request for title of unexpected element: </xsl:text>
36	<xsl:value-of select="name(.)"/>
37      </xsl:message>
38      <xsl:text>???TITLE???</xsl:text>
39    </xsl:otherwise>
40  </xsl:choose>
41</xsl:template>
42
43<xsl:template match="title" mode="title.markup">
44  <xsl:param name="allow-anchors" select="'0'"/>
45  <xsl:choose>
46    <xsl:when test="$allow-anchors != 0">
47      <xsl:apply-templates/>
48    </xsl:when>
49    <xsl:otherwise>
50      <xsl:apply-templates mode="no.anchor.mode"/>
51    </xsl:otherwise>
52  </xsl:choose>
53</xsl:template>
54
55<xsl:template match="set" mode="title.markup">
56  <xsl:param name="allow-anchors" select="'0'"/>
57  <xsl:apply-templates select="(setinfo/title|title)[1]"
58                       mode="title.markup">
59    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
60  </xsl:apply-templates>
61</xsl:template>
62
63<xsl:template match="book" mode="title.markup">
64  <xsl:param name="allow-anchors" select="'0'"/>
65  <xsl:apply-templates select="(bookinfo/title|title)[1]"
66                       mode="title.markup">
67    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
68  </xsl:apply-templates>
69</xsl:template>
70
71<xsl:template match="part" mode="title.markup">
72  <xsl:param name="allow-anchors" select="'0'"/>
73  <xsl:apply-templates select="(partinfo/title|docinfo/title|title)[1]"
74                       mode="title.markup">
75    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
76  </xsl:apply-templates>
77</xsl:template>
78
79<xsl:template match="preface|chapter|appendix" mode="title.markup">
80  <xsl:param name="allow-anchors" select="'0'"/>
81
82<!--
83  <xsl:message>
84    <xsl:value-of select="name(.)"/>
85    <xsl:text> </xsl:text>
86    <xsl:value-of select="$allow-anchors"/>
87  </xsl:message>
88-->
89
90  <xsl:variable name="title" select="(docinfo/title
91                                      |prefaceinfo/title
92                                      |chapterinfo/title
93                                      |appendixinfo/title
94                                      |title)[1]"/>
95  <xsl:apply-templates select="$title" mode="title.markup">
96    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
97  </xsl:apply-templates>
98</xsl:template>
99
100<xsl:template match="dedication" mode="title.markup">
101  <xsl:param name="allow-anchors" select="'0'"/>
102  <xsl:choose>
103    <xsl:when test="title">
104      <xsl:apply-templates select="title" mode="title.markup">
105        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
106      </xsl:apply-templates>
107    </xsl:when>
108    <xsl:otherwise>
109      <xsl:call-template name="gentext">
110        <xsl:with-param name="key" select="'Dedication'"/>
111      </xsl:call-template>
112    </xsl:otherwise>
113  </xsl:choose>
114</xsl:template>
115
116<xsl:template match="colophon" mode="title.markup">
117  <xsl:param name="allow-anchors" select="'0'"/>
118  <xsl:choose>
119    <xsl:when test="title">
120      <xsl:apply-templates select="title" mode="title.markup">
121        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
122      </xsl:apply-templates>
123    </xsl:when>
124    <xsl:otherwise>
125      <xsl:call-template name="gentext">
126        <xsl:with-param name="key" select="'Colophon'"/>
127      </xsl:call-template>
128    </xsl:otherwise>
129  </xsl:choose>
130</xsl:template>
131
132<xsl:template match="article" mode="title.markup">
133  <xsl:param name="allow-anchors" select="'0'"/>
134  <xsl:variable name="title" select="(artheader/title
135                                      |articleinfo/title
136                                      |title)[1]"/>
137
138  <xsl:apply-templates select="$title" mode="title.markup">
139    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
140  </xsl:apply-templates>
141</xsl:template>
142
143<xsl:template match="reference" mode="title.markup">
144  <xsl:param name="allow-anchors" select="'0'"/>
145  <xsl:apply-templates select="(referenceinfo/title|docinfo/title|title)[1]"
146                       mode="title.markup">
147    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
148  </xsl:apply-templates>
149</xsl:template>
150
151<xsl:template match="refentry" mode="title.markup">
152  <xsl:param name="allow-anchors" select="'0'"/>
153  <xsl:variable name="refmeta" select=".//refmeta"/>
154  <xsl:variable name="refentrytitle" select="$refmeta//refentrytitle"/>
155  <xsl:variable name="refnamediv" select=".//refnamediv"/>
156  <xsl:variable name="refname" select="$refnamediv//refname"/>
157
158  <xsl:variable name="title">
159    <xsl:choose>
160      <xsl:when test="$refentrytitle">
161        <xsl:apply-templates select="$refentrytitle[1]" mode="title.markup"/>
162      </xsl:when>
163      <xsl:when test="$refname">
164        <xsl:apply-templates select="$refname[1]" mode="title.markup"/>
165      </xsl:when>
166      <xsl:otherwise>REFENTRY WITHOUT TITLE???</xsl:otherwise>
167    </xsl:choose>
168  </xsl:variable>
169
170  <xsl:copy-of select="$title"/>
171</xsl:template>
172
173<xsl:template match="refentrytitle|refname" mode="title.markup">
174  <xsl:apply-templates/>
175</xsl:template>
176
177<xsl:template match="section
178                     |sect1|sect2|sect3|sect4|sect5
179                     |refsect1|refsect2|refsect3
180                     |simplesect"
181              mode="title.markup">
182  <xsl:param name="allow-anchors" select="'0'"/>
183  <xsl:variable name="title" select="(sectioninfo/title
184                                      |sect1info/title
185                                      |sect2info/title
186                                      |sect3info/title
187                                      |sect4info/title
188                                      |sect5info/title
189                                      |refsect1info/title
190                                      |refsect2info/title
191                                      |refsect3info/title
192                                      |title)[1]"/>
193
194  <xsl:apply-templates select="$title" mode="title.markup">
195    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
196  </xsl:apply-templates>
197</xsl:template>
198
199<xsl:template match="bibliography" mode="title.markup">
200  <xsl:param name="allow-anchors" select="'0'"/>
201  <xsl:variable name="title" select="(bibliographyinfo/title|title)[1]"/>
202  <xsl:choose>
203    <xsl:when test="$title">
204      <xsl:apply-templates select="$title" mode="title.markup">
205        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
206      </xsl:apply-templates>
207    </xsl:when>
208    <xsl:otherwise>
209      <xsl:call-template name="gentext">
210        <xsl:with-param name="key" select="'Bibliography'"/>
211      </xsl:call-template>
212    </xsl:otherwise>
213  </xsl:choose>
214</xsl:template>
215
216<xsl:template match="glossary" mode="title.markup">
217  <xsl:param name="allow-anchors" select="'0'"/>
218  <xsl:variable name="title" select="(glossaryinfo/title|title)[1]"/>
219  <xsl:choose>
220    <xsl:when test="$title">
221      <xsl:apply-templates select="$title" mode="title.markup">
222        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
223      </xsl:apply-templates>
224    </xsl:when>
225    <xsl:otherwise>
226      <xsl:call-template name="gentext.element.name">
227        <xsl:with-param name="element.name" select="name(.)"/>
228      </xsl:call-template>
229    </xsl:otherwise>
230  </xsl:choose>
231</xsl:template>
232
233<xsl:template match="index" mode="title.markup">
234  <xsl:param name="allow-anchors" select="'0'"/>
235  <xsl:variable name="title" select="(indexinfo/title|title)[1]"/>
236  <xsl:choose>
237    <xsl:when test="$title">
238      <xsl:apply-templates select="$title" mode="title.markup">
239        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
240      </xsl:apply-templates>
241    </xsl:when>
242    <xsl:otherwise>
243      <xsl:call-template name="gentext">
244        <xsl:with-param name="key" select="'Index'"/>
245      </xsl:call-template>
246    </xsl:otherwise>
247  </xsl:choose>
248</xsl:template>
249
250<xsl:template match="figure|table|example|equation" mode="title.markup">
251  <xsl:param name="allow-anchors" select="'0'"/>
252  <xsl:apply-templates select="title" mode="title.markup">
253    <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
254  </xsl:apply-templates>
255</xsl:template>
256
257<xsl:template match="abstract" mode="title.markup">
258  <xsl:param name="allow-anchors" select="'0'"/>
259  <xsl:choose>
260    <xsl:when test="title">
261      <xsl:apply-templates select="title" mode="title.markup">
262        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
263      </xsl:apply-templates>
264    </xsl:when>
265    <xsl:otherwise>
266      <xsl:call-template name="gentext">
267        <xsl:with-param name="key" select="'Abstract'"/>
268      </xsl:call-template>
269    </xsl:otherwise>
270  </xsl:choose>
271</xsl:template>
272
273<xsl:template match="caution|tip|warning|important|note" mode="title.markup">
274  <xsl:param name="allow-anchors" select="'0'"/>
275  <xsl:variable name="title" select="title[1]"/>
276  <xsl:choose>
277    <xsl:when test="$title">
278      <xsl:apply-templates select="$title" mode="title.markup">
279        <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
280      </xsl:apply-templates>
281    </xsl:when>
282    <xsl:otherwise>
283      <xsl:call-template name="gentext">
284        <xsl:with-param name="key">
285          <xsl:choose>
286            <xsl:when test="local-name(.)='note'">Note</xsl:when>
287            <xsl:when test="local-name(.)='important'">Important</xsl:when>
288            <xsl:when test="local-name(.)='caution'">Caution</xsl:when>
289            <xsl:when test="local-name(.)='warning'">Warning</xsl:when>
290            <xsl:when test="local-name(.)='tip'">Tip</xsl:when>
291          </xsl:choose>
292        </xsl:with-param>
293      </xsl:call-template>
294    </xsl:otherwise>
295  </xsl:choose>
296</xsl:template>
297
298<!-- ============================================================ -->
299
300<xsl:template match="*" mode="no.anchor.mode">
301  <xsl:apply-templates select="."/>
302</xsl:template>
303
304<xsl:template match="footnote" mode="no.anchor.mode">
305  <!-- nop, suppressed -->
306</xsl:template>
307
308<xsl:template match="anchor" mode="no.anchor.mode">
309  <!-- nop, suppressed -->
310</xsl:template>
311
312<xsl:template match="ulink" mode="no.anchor.mode">
313  <xsl:apply-templates/>
314</xsl:template>
315
316<xsl:template match="link" mode="no.anchor.mode">
317  <xsl:apply-templates/>
318</xsl:template>
319
320<xsl:template match="olink" mode="no.anchor.mode">
321  <xsl:apply-templates/>
322</xsl:template>
323
324<xsl:template match="indexterm" mode="no.anchor.mode">
325  <!-- nop, suppressed -->
326</xsl:template>
327
328<xsl:template match="xref" mode="no.anchor.mode">
329  <!-- FIXME: this should generate the text without the link... -->
330</xsl:template>
331
332<!-- ============================================================ -->
333
334</xsl:stylesheet>
335
336