]> git.lyx.org Git - lyx.git/blob - lib/docbook/common/titles.xsl
Use same find-dialogs as other bind-files also for x?emacs
[lyx.git] / lib / docbook / common / titles.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:d="http://docbook.org/ns/docbook"
4                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
5                 xmlns:xlink="http://www.w3.org/1999/xlink"
6                 exclude-result-prefixes="doc d"
7                 version='1.0'>
8
9 <!-- ********************************************************************
10
11      This file is part of the XSL DocBook Stylesheet distribution.
12      See ../README or http://cdn.docbook.org/release/xsl/current/ for
13      copyright and other information.
14
15      ******************************************************************** -->
16
17 <!-- ==================================================================== -->
18
19 <!-- title markup -->
20
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.
27 </para>
28 </refdescription>
29 </doc:mode>
30
31 <xsl:template match="*" mode="title.markup">
32   <xsl:param name="allow-anchors" select="0"/>
33   <xsl:param name="verbose" select="1"/>
34   <xsl:choose>
35     <!-- * FIXME: this should handle other *info elements as well -->
36     <!-- * but this is good enough for now. -->
37     <xsl:when test="d:title|d:info/d:title">
38       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
39         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
40       </xsl:apply-templates>
41     </xsl:when>
42     <xsl:when test="local-name(.) = 'partintro'">
43       <!-- partintro's don't have titles, use the parent (part or reference)
44            title instead. -->
45       <xsl:apply-templates select="parent::*" mode="title.markup"/>
46     </xsl:when>
47     <xsl:otherwise>
48       <xsl:if test="$verbose != 0">
49         <xsl:message>
50           <xsl:text>Request for title of element with no title: </xsl:text>
51           <xsl:value-of select="local-name(.)"/>
52           <xsl:choose>
53             <xsl:when test="@id">
54               <xsl:text> (id="</xsl:text>
55               <xsl:value-of select="@id"/>
56               <xsl:text>")</xsl:text>
57             </xsl:when>
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>
62             </xsl:when>
63             <xsl:otherwise>
64               <xsl:text> (contained in </xsl:text>
65               <xsl:value-of select="local-name(..)"/>
66               <xsl:if test="../@id or ../@xml:id">
67                 <xsl:text> with id </xsl:text>
68                 <xsl:value-of select="../@id | ../@xml:id"/>
69               </xsl:if>
70               <xsl:text>)</xsl:text>
71             </xsl:otherwise>
72           </xsl:choose>
73         </xsl:message>
74       </xsl:if>
75       <xsl:text>???TITLE???</xsl:text>
76     </xsl:otherwise>
77   </xsl:choose>
78 </xsl:template>
79
80 <xsl:template match="d:title" mode="title.markup">
81   <xsl:param name="allow-anchors" select="0"/>
82
83   <xsl:choose>
84     <xsl:when test="$allow-anchors != 0">
85       <xsl:apply-templates/>
86     </xsl:when>
87     <xsl:otherwise>
88       <xsl:apply-templates mode="no.anchor.mode"/>
89     </xsl:otherwise>
90   </xsl:choose>
91 </xsl:template>
92
93 <!-- only occurs in HTML Tables! -->
94 <xsl:template match="d:caption" mode="title.markup">
95   <xsl:param name="allow-anchors" select="0"/>
96
97   <xsl:choose>
98     <xsl:when test="$allow-anchors != 0">
99       <xsl:apply-templates/>
100     </xsl:when>
101     <xsl:otherwise>
102       <xsl:apply-templates mode="no.anchor.mode"/>
103     </xsl:otherwise>
104   </xsl:choose>
105 </xsl:template>
106
107 <xsl:template match="d:set" mode="title.markup">
108   <xsl:param name="allow-anchors" select="0"/>
109   <xsl:apply-templates select="(d:setinfo/d:title|d:info/d:title|d:title)[1]"
110                        mode="title.markup">
111     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
112   </xsl:apply-templates>
113 </xsl:template>
114
115 <xsl:template match="d:book" mode="title.markup">
116   <xsl:param name="allow-anchors" select="0"/>
117   <xsl:apply-templates select="(d:bookinfo/d:title|d:info/d:title|d:title)[1]"
118                        mode="title.markup">
119     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
120   </xsl:apply-templates>
121 </xsl:template>
122
123 <xsl:template match="d:part" mode="title.markup">
124   <xsl:param name="allow-anchors" select="0"/>
125   <xsl:apply-templates select="(d:partinfo/d:title|d:info/d:title|d:docinfo/d:title|d:title)[1]"
126                        mode="title.markup">
127     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
128   </xsl:apply-templates>
129 </xsl:template>
130
131 <xsl:template match="d:preface|d:chapter|d:appendix" mode="title.markup">
132   <xsl:param name="allow-anchors" select="0"/>
133
134 <!--
135   <xsl:message>
136     <xsl:value-of select="local-name(.)"/>
137     <xsl:text> </xsl:text>
138     <xsl:value-of select="$allow-anchors"/>
139   </xsl:message>
140 -->
141
142   <xsl:variable name="title" select="(d:docinfo/d:title
143                                       |d:info/d:title
144                                       |d:prefaceinfo/d:title
145                                       |d:chapterinfo/d:title
146                                       |d:appendixinfo/d:title
147                                       |d:title)[1]"/>
148   <xsl:apply-templates select="$title" mode="title.markup">
149     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
150   </xsl:apply-templates>
151 </xsl:template>
152
153 <xsl:template match="d:dedication" mode="title.markup">
154   <xsl:param name="allow-anchors" select="0"/>
155   <xsl:choose>
156     <xsl:when test="d:title|d:info/d:title">
157       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
158         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
159       </xsl:apply-templates>
160     </xsl:when>
161     <xsl:otherwise>
162       <xsl:call-template name="gentext">
163         <xsl:with-param name="key" select="'Dedication'"/>
164       </xsl:call-template>
165     </xsl:otherwise>
166   </xsl:choose>
167 </xsl:template>
168
169 <xsl:template match="d:acknowledgements" mode="title.markup">
170   <xsl:param name="allow-anchors" select="0"/>
171   <xsl:choose>
172     <xsl:when test="d:title|d:info/d:title">
173       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
174         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
175       </xsl:apply-templates>
176     </xsl:when>
177     <xsl:otherwise>
178       <xsl:call-template name="gentext">
179         <xsl:with-param name="key" select="'Acknowledgements'"/>
180       </xsl:call-template>
181     </xsl:otherwise>
182   </xsl:choose>
183 </xsl:template>
184
185 <xsl:template match="d:colophon" mode="title.markup">
186   <xsl:param name="allow-anchors" select="0"/>
187   <xsl:choose>
188     <xsl:when test="d:title|d:info/d:title">
189       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
190         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
191       </xsl:apply-templates>
192     </xsl:when>
193     <xsl:otherwise>
194       <xsl:call-template name="gentext">
195         <xsl:with-param name="key" select="'Colophon'"/>
196       </xsl:call-template>
197     </xsl:otherwise>
198   </xsl:choose>
199 </xsl:template>
200
201 <xsl:template match="d:article" mode="title.markup">
202   <xsl:param name="allow-anchors" select="0"/>
203   <xsl:variable name="title" select="(d:artheader/d:title
204                                       |d:articleinfo/d:title
205                                       |d:info/d:title
206                                       |d:title)[1]"/>
207
208   <xsl:apply-templates select="$title" mode="title.markup">
209     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
210   </xsl:apply-templates>
211 </xsl:template>
212
213 <xsl:template match="d:reference" mode="title.markup">
214   <xsl:param name="allow-anchors" select="0"/>
215   <xsl:apply-templates select="(d:referenceinfo/d:title|d:docinfo/d:title|d:info/d:title|d:title)[1]"
216                        mode="title.markup">
217     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
218   </xsl:apply-templates>
219 </xsl:template>
220
221 <xsl:template match="d:refentry" mode="title.markup">
222   <xsl:param name="allow-anchors" select="0"/>
223   <xsl:variable name="refmeta" select=".//d:refmeta"/>
224   <xsl:variable name="refentrytitle" select="$refmeta//d:refentrytitle"/>
225   <xsl:variable name="refnamediv" select=".//d:refnamediv"/>
226   <xsl:variable name="refname" select="$refnamediv//d:refname"/>
227   <xsl:variable name="refdesc" select="$refnamediv//d:refdescriptor"/>
228
229   <xsl:variable name="title">
230     <xsl:choose>
231       <xsl:when test="$refentrytitle">
232         <xsl:apply-templates select="$refentrytitle[1]" mode="title.markup"/>
233       </xsl:when>
234       <xsl:when test="$refdesc">
235         <xsl:apply-templates select="$refdesc" mode="title.markup"/>
236       </xsl:when>
237       <xsl:when test="$refname">
238         <xsl:apply-templates select="$refname[1]" mode="title.markup"/>
239       </xsl:when>
240       <xsl:otherwise>REFENTRY WITHOUT TITLE???</xsl:otherwise>
241     </xsl:choose>
242   </xsl:variable>
243
244   <xsl:copy-of select="$title"/>
245 </xsl:template>
246
247 <xsl:template match="d:refentrytitle|d:refname|d:refdescriptor" mode="title.markup">
248   <xsl:param name="allow-anchors" select="0"/>
249   <xsl:choose>
250     <xsl:when test="$allow-anchors != 0">
251       <xsl:apply-templates/>
252     </xsl:when>
253     <xsl:otherwise>
254       <xsl:apply-templates mode="no.anchor.mode"/>
255     </xsl:otherwise>
256   </xsl:choose>
257 </xsl:template>
258
259 <xsl:template match="d:section
260                      |d:sect1|d:sect2|d:sect3|d:sect4|d:sect5
261                      |d:refsect1|d:refsect2|d:refsect3|d:refsection
262                      |d:topic
263                      |d:simplesect"
264               mode="title.markup">
265   <xsl:param name="allow-anchors" select="0"/>
266   <xsl:variable name="title" select="(d:info/d:title
267                                       |d:sectioninfo/d:title
268                                       |d:sect1info/d:title
269                                       |d:sect2info/d:title
270                                       |d:sect3info/d:title
271                                       |d:sect4info/d:title
272                                       |d:sect5info/d:title
273                                       |d:refsect1info/d:title
274                                       |d:refsect2info/d:title
275                                       |d:refsect3info/d:title
276                                       |d:refsectioninfo/d:title
277                                       |d:title)[1]"/>
278
279   <xsl:apply-templates select="$title" mode="title.markup">
280     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
281   </xsl:apply-templates>
282 </xsl:template>
283
284 <xsl:template match="d:bridgehead" mode="title.markup">
285   <xsl:apply-templates/> 
286 </xsl:template>
287
288 <xsl:template match="d:refsynopsisdiv" mode="title.markup">
289   <xsl:param name="allow-anchors" select="0"/>
290   <xsl:choose>
291     <xsl:when test="d:title|d:info/d:title">
292       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
293         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
294       </xsl:apply-templates>
295     </xsl:when>
296     <xsl:otherwise>
297       <xsl:call-template name="gentext">
298         <xsl:with-param name="key" select="'RefSynopsisDiv'"/>
299       </xsl:call-template>
300     </xsl:otherwise>
301   </xsl:choose>
302 </xsl:template>
303
304 <xsl:template match="d:bibliography" mode="title.markup">
305   <xsl:param name="allow-anchors" select="0"/>
306   <xsl:variable name="title" select="(d:bibliographyinfo/d:title|d:info/d:title|d:title)[1]"/>
307   <xsl:choose>
308     <xsl:when test="$title">
309       <xsl:apply-templates select="$title" mode="title.markup">
310         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
311       </xsl:apply-templates>
312     </xsl:when>
313     <xsl:otherwise>
314       <xsl:call-template name="gentext">
315         <xsl:with-param name="key" select="'Bibliography'"/>
316       </xsl:call-template>
317     </xsl:otherwise>
318   </xsl:choose>
319 </xsl:template>
320
321 <xsl:template match="d:glossary" mode="title.markup">
322   <xsl:param name="allow-anchors" select="0"/>
323   <xsl:variable name="title" select="(d:glossaryinfo/d:title|d:info/d:title|d:title)[1]"/>
324   <xsl:choose>
325     <xsl:when test="$title">
326       <xsl:apply-templates select="$title" mode="title.markup">
327         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
328       </xsl:apply-templates>
329     </xsl:when>
330     <xsl:otherwise>
331       <xsl:call-template name="gentext.element.name">
332         <xsl:with-param name="element.name" select="local-name(.)"/>
333       </xsl:call-template>
334     </xsl:otherwise>
335   </xsl:choose>
336 </xsl:template>
337
338 <xsl:template match="d:glossdiv" mode="title.markup">
339   <xsl:param name="allow-anchors" select="0"/>
340   <xsl:variable name="title" select="(d:info/d:title|d:title)[1]"/>
341   <xsl:choose>
342     <xsl:when test="$title">
343       <xsl:apply-templates select="$title" mode="title.markup">
344         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
345       </xsl:apply-templates>
346     </xsl:when>
347     <xsl:otherwise>
348       <xsl:message>ERROR: glossdiv missing its required title</xsl:message>
349     </xsl:otherwise>
350   </xsl:choose>
351 </xsl:template>
352
353 <xsl:template match="d:glossentry" mode="title.markup">
354   <xsl:param name="allow-anchors" select="0"/>
355   <xsl:apply-templates select="d:glossterm" mode="title.markup">
356     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
357   </xsl:apply-templates>
358 </xsl:template>
359
360 <xsl:template match="d:glossterm|d:firstterm" mode="title.markup">
361   <xsl:param name="allow-anchors" select="0"/>
362
363   <xsl:choose>
364     <xsl:when test="$allow-anchors != 0">
365       <xsl:apply-templates/>
366     </xsl:when>
367     <xsl:otherwise>
368       <xsl:apply-templates mode="no.anchor.mode"/>
369     </xsl:otherwise>
370   </xsl:choose>
371 </xsl:template>
372
373 <xsl:template match="d:index" mode="title.markup">
374   <xsl:param name="allow-anchors" select="0"/>
375   <xsl:variable name="title" select="(d:indexinfo/d:title|d:info/d:title|d:title)[1]"/>
376   <xsl:choose>
377     <xsl:when test="$title">
378       <xsl:apply-templates select="$title" mode="title.markup">
379         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
380       </xsl:apply-templates>
381     </xsl:when>
382     <xsl:otherwise>
383       <xsl:call-template name="gentext">
384         <xsl:with-param name="key" select="'Index'"/>
385       </xsl:call-template>
386     </xsl:otherwise>
387   </xsl:choose>
388 </xsl:template>
389
390 <xsl:template match="d:setindex" mode="title.markup">
391   <xsl:param name="allow-anchors" select="0"/>
392   <xsl:variable name="title" select="(d:setindexinfo/d:title|d:info/d:title|d:title)[1]"/>
393   <xsl:choose>
394     <xsl:when test="$title">
395       <xsl:apply-templates select="$title" mode="title.markup">
396         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
397       </xsl:apply-templates>
398     </xsl:when>
399     <xsl:otherwise>
400       <xsl:call-template name="gentext">
401         <xsl:with-param name="key" select="'SetIndex'"/>
402       </xsl:call-template>
403     </xsl:otherwise>
404   </xsl:choose>
405 </xsl:template>
406
407 <xsl:template match="d:figure|d:example|d:equation" mode="title.markup">
408   <xsl:param name="allow-anchors" select="0"/>
409   <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
410     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
411   </xsl:apply-templates>
412 </xsl:template>
413
414 <xsl:template match="d:table" mode="title.markup">
415   <xsl:param name="allow-anchors" select="0"/>
416   <xsl:apply-templates select="(d:title|d:info/d:title|d:caption)[1]" mode="title.markup">
417     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
418   </xsl:apply-templates>
419 </xsl:template>
420
421 <xsl:template match="d:procedure" mode="title.markup">
422   <xsl:param name="allow-anchors" select="0"/>
423   <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
424     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
425   </xsl:apply-templates>
426 </xsl:template>
427
428 <xsl:template match="d:task" mode="title.markup">
429   <xsl:param name="allow-anchors" select="0"/>
430   <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
431     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
432   </xsl:apply-templates>
433 </xsl:template>
434
435 <xsl:template match="d:sidebar" mode="title.markup">
436   <xsl:param name="allow-anchors" select="0"/>
437   <xsl:apply-templates select="(d:info/d:title|d:sidebarinfo/d:title|d:title)[1]"
438                        mode="title.markup">
439     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
440   </xsl:apply-templates>
441 </xsl:template>
442
443 <xsl:template match="d:abstract" mode="title.markup">
444   <xsl:param name="allow-anchors" select="0"/>
445   <xsl:choose>
446     <xsl:when test="d:title|d:info/d:title">
447       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
448         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
449       </xsl:apply-templates>
450     </xsl:when>
451     <xsl:otherwise>
452       <xsl:call-template name="gentext">
453         <xsl:with-param name="key" select="'Abstract'"/>
454       </xsl:call-template>
455     </xsl:otherwise>
456   </xsl:choose>
457 </xsl:template>
458
459 <xsl:template match="d:caution|d:tip|d:warning|d:important|d:note" mode="title.markup">
460   <xsl:param name="allow-anchors" select="0"/>
461   <xsl:variable name="title" select="(d:title|d:info/d:title)[1]"/>
462   <xsl:choose>
463     <xsl:when test="$title">
464       <xsl:apply-templates select="$title" mode="title.markup">
465         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
466       </xsl:apply-templates>
467     </xsl:when>
468     <xsl:otherwise>
469       <xsl:call-template name="gentext">
470         <xsl:with-param name="key">
471           <xsl:choose>
472             <xsl:when test="local-name(.)='note'">Note</xsl:when>
473             <xsl:when test="local-name(.)='important'">Important</xsl:when>
474             <xsl:when test="local-name(.)='caution'">Caution</xsl:when>
475             <xsl:when test="local-name(.)='warning'">Warning</xsl:when>
476             <xsl:when test="local-name(.)='tip'">Tip</xsl:when>
477           </xsl:choose>
478         </xsl:with-param>
479       </xsl:call-template>
480     </xsl:otherwise>
481   </xsl:choose>
482 </xsl:template>
483
484 <xsl:template match="d:question" mode="title.markup">
485   <!-- questions don't have titles -->
486   <xsl:call-template name="gentext">
487     <xsl:with-param name="key">question</xsl:with-param>
488   </xsl:call-template>
489 </xsl:template>
490
491 <xsl:template match="d:answer" mode="title.markup">
492   <!-- answers don't have titles -->
493   <xsl:call-template name="gentext">
494     <xsl:with-param name="key">answer</xsl:with-param>
495   </xsl:call-template>
496 </xsl:template>
497
498 <xsl:template match="d:qandaentry" mode="title.markup">
499   <!-- qandaentrys are represented by the first question in them -->
500   <xsl:apply-templates select="d:question" mode="title.markup"/>
501 </xsl:template>
502
503 <xsl:template match="d:qandaset" mode="title.markup">
504   <xsl:param name="allow-anchors" select="0"/>
505   <xsl:variable name="title" select="(d:info/d:title|
506                                       d:blockinfo/d:title|
507                                       d:title)[1]"/>
508   <xsl:choose>
509     <xsl:when test="$title">
510       <xsl:apply-templates select="$title" mode="title.markup">
511         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
512       </xsl:apply-templates>
513     </xsl:when>
514     <xsl:otherwise>
515       <xsl:call-template name="gentext">
516         <xsl:with-param name="key" select="'QandASet'"/>
517       </xsl:call-template>
518     </xsl:otherwise>
519   </xsl:choose>
520 </xsl:template>
521
522 <xsl:template match="d:legalnotice" mode="title.markup">
523   <xsl:param name="allow-anchors" select="0"/>
524   <xsl:choose>
525     <xsl:when test="d:title|d:info/d:title">
526       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
527         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
528       </xsl:apply-templates>
529     </xsl:when>
530     <xsl:otherwise>
531       <xsl:call-template name="gentext">
532         <xsl:with-param name="key" select="'LegalNotice'"/>
533       </xsl:call-template>
534     </xsl:otherwise>
535   </xsl:choose>
536 </xsl:template>
537
538 <!-- ============================================================ -->
539
540 <!-- titleabbrev is always processed in a mode -->
541 <xsl:template match="d:titleabbrev"/>
542
543 <xsl:template match="*" mode="titleabbrev.markup">
544   <xsl:param name="allow-anchors" select="0"/>
545   <xsl:param name="verbose" select="1"/>
546
547   <xsl:choose>
548     <xsl:when test="d:titleabbrev">
549       <xsl:apply-templates select="d:titleabbrev[1]" mode="title.markup">
550         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
551       </xsl:apply-templates>
552     </xsl:when>
553     <xsl:when test="d:info/d:titleabbrev">
554       <xsl:apply-templates select="d:info/d:titleabbrev[1]" mode="title.markup">
555         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
556       </xsl:apply-templates>
557     </xsl:when>
558     <xsl:otherwise>
559       <xsl:apply-templates select="." mode="title.markup">
560         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
561         <xsl:with-param name="verbose" select="$verbose"/>
562       </xsl:apply-templates>
563     </xsl:otherwise>
564   </xsl:choose>
565 </xsl:template>
566
567 <xsl:template match="d:book|d:part|d:set|d:preface|d:chapter|d:appendix" mode="titleabbrev.markup">
568   <xsl:param name="allow-anchors" select="0"/>
569   <xsl:param name="verbose" select="1"/>
570
571   <xsl:variable name="titleabbrev" select="(d:docinfo/d:titleabbrev
572                                            |d:bookinfo/d:titleabbrev
573                                            |d:info/d:titleabbrev
574                                            |d:prefaceinfo/d:titleabbrev
575                                            |d:setinfo/d:titleabbrev
576                                            |d:partinfo/d:titleabbrev
577                                            |d:chapterinfo/d:titleabbrev
578                                            |d:appendixinfo/d:titleabbrev
579                                            |d:titleabbrev)[1]"/>
580
581   <xsl:choose>
582     <xsl:when test="$titleabbrev">
583       <xsl:apply-templates select="$titleabbrev" mode="title.markup">
584         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
585       </xsl:apply-templates>
586     </xsl:when>
587     <xsl:otherwise>
588       <xsl:apply-templates select="." mode="title.markup">
589         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
590         <xsl:with-param name="verbose" select="$verbose"/>
591       </xsl:apply-templates>
592     </xsl:otherwise>
593   </xsl:choose>
594 </xsl:template>
595
596 <xsl:template match="d:article" mode="titleabbrev.markup">
597   <xsl:param name="allow-anchors" select="0"/>
598   <xsl:param name="verbose" select="1"/>
599
600   <xsl:variable name="titleabbrev" select="(d:artheader/d:titleabbrev
601                                            |d:articleinfo/d:titleabbrev
602                                            |d:info/d:titleabbrev
603                                            |d:titleabbrev)[1]"/>
604
605   <xsl:choose>
606     <xsl:when test="$titleabbrev">
607       <xsl:apply-templates select="$titleabbrev" mode="title.markup">
608         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
609       </xsl:apply-templates>
610     </xsl:when>
611     <xsl:otherwise>
612       <xsl:apply-templates select="." mode="title.markup">
613         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
614         <xsl:with-param name="verbose" select="$verbose"/>
615       </xsl:apply-templates>
616     </xsl:otherwise>
617   </xsl:choose>
618 </xsl:template>
619
620 <xsl:template match="d:section
621                      |d:sect1|d:sect2|d:sect3|d:sect4|d:sect5
622                      |d:refsect1|d:refsect2|d:refsect3
623                      |d:topic
624                      |d:simplesect"
625               mode="titleabbrev.markup">
626   <xsl:param name="allow-anchors" select="0"/>
627   <xsl:param name="verbose" select="1"/>
628
629   <xsl:variable name="titleabbrev" select="(d:info/d:titleabbrev
630                                             |d:sectioninfo/d:titleabbrev
631                                             |d:sect1info/d:titleabbrev
632                                             |d:sect2info/d:titleabbrev
633                                             |d:sect3info/d:titleabbrev
634                                             |d:sect4info/d:titleabbrev
635                                             |d:sect5info/d:titleabbrev
636                                             |d:refsect1info/d:titleabbrev
637                                             |d:refsect2info/d:titleabbrev
638                                             |d:refsect3info/d:titleabbrev
639                                             |d:titleabbrev)[1]"/>
640
641   <xsl:choose>
642     <xsl:when test="$titleabbrev">
643       <xsl:apply-templates select="$titleabbrev" mode="title.markup">
644         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
645       </xsl:apply-templates>
646     </xsl:when>
647     <xsl:otherwise>
648       <xsl:apply-templates select="." mode="title.markup">
649         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
650         <xsl:with-param name="verbose" select="$verbose"/>
651       </xsl:apply-templates>
652     </xsl:otherwise>
653   </xsl:choose>
654 </xsl:template>
655
656 <xsl:template match="d:titleabbrev" mode="title.markup">
657   <xsl:param name="allow-anchors" select="0"/>
658
659   <xsl:choose>
660     <xsl:when test="$allow-anchors != 0">
661       <xsl:apply-templates/>
662     </xsl:when>
663     <xsl:otherwise>
664       <xsl:apply-templates mode="no.anchor.mode"/>
665     </xsl:otherwise>
666   </xsl:choose>
667 </xsl:template>
668
669 <!-- ============================================================ -->
670
671 <xsl:template match="*" mode="no.anchor.mode">
672   <!-- Switch to normal mode if no links -->
673   <xsl:choose>
674     <xsl:when test="descendant-or-self::d:footnote or
675                     descendant-or-self::d:anchor or
676                     descendant-or-self::d:ulink or
677                     descendant-or-self::d:link or
678                     descendant-or-self::d:olink or
679                     descendant-or-self::d:xref or
680                     descendant-or-self::d:indexterm or
681                     (ancestor::d:title and (@id or @xml:id))">
682
683       <xsl:apply-templates mode="no.anchor.mode"/>
684     </xsl:when>
685     <xsl:otherwise>
686       <xsl:apply-templates select="."/>
687     </xsl:otherwise>
688   </xsl:choose>
689 </xsl:template>
690
691 <xsl:template match="d:footnote" mode="no.anchor.mode">
692   <!-- nop, suppressed -->
693 </xsl:template>
694
695 <xsl:template match="d:anchor" mode="no.anchor.mode">
696   <!-- nop, suppressed -->
697 </xsl:template>
698
699 <xsl:template match="d:ulink" mode="no.anchor.mode">
700   <xsl:param name="url" select="@url"/>
701   <xsl:choose>
702     <xsl:when test="count(child::node())=0">
703       <xsl:value-of select="$url"/>
704     </xsl:when>
705     <xsl:otherwise>
706       <xsl:apply-templates/>
707     </xsl:otherwise>
708   </xsl:choose>
709 </xsl:template>
710
711 <xsl:template match="d:link" mode="no.anchor.mode">
712   <xsl:choose>
713     <xsl:when test="count(child::node()) &gt; 0">
714       <!-- If it has content, use it -->
715       <xsl:apply-templates/>
716     </xsl:when>
717         <!-- look for an endterm -->
718     <xsl:when test="@endterm">
719       <xsl:variable name="etargets" select="key('id',@endterm)"/>
720       <xsl:variable name="etarget" select="$etargets[1]"/>
721       <xsl:choose>
722         <xsl:when test="count($etarget) = 0">
723           <xsl:message>
724             <xsl:value-of select="count($etargets)"/>
725             <xsl:text>Endterm points to nonexistent ID: </xsl:text>
726             <xsl:value-of select="@endterm"/>
727           </xsl:message>
728           <xsl:text>???</xsl:text>
729         </xsl:when>
730         <xsl:otherwise>
731           <xsl:apply-templates select="$etarget" mode="endterm"/>
732         </xsl:otherwise>
733       </xsl:choose>
734     </xsl:when>
735     <xsl:otherwise>
736       <xsl:apply-templates/>
737     </xsl:otherwise>
738   </xsl:choose>
739 </xsl:template>
740
741 <xsl:template match="d:olink" mode="no.anchor.mode">
742   <xsl:apply-templates/>
743 </xsl:template>
744
745 <xsl:template match="d:indexterm" mode="no.anchor.mode">
746   <!-- nop, suppressed -->
747 </xsl:template>
748
749 <xsl:template match="d:xref" mode="no.anchor.mode">
750   <xsl:variable name="referrer" select="."/>
751   <xsl:variable name="targets" select="key('id',@linkend)|key('id',substring-after(@xlink:href,'#'))"/>
752   <xsl:variable name="target" select="$targets[1]"/>
753   <xsl:variable name="refelem" select="local-name($target)"/>
754   <xsl:variable name="xrefstyle">
755     <xsl:apply-templates select="." mode="xrefstyle">
756       <xsl:with-param name="target" select="$target"/>
757       <xsl:with-param name="referrer" select="$referrer"/>
758     </xsl:apply-templates>
759   </xsl:variable>
760   
761   <xsl:call-template name="check.id.unique">
762     <xsl:with-param name="linkend" select="@linkend"/>
763   </xsl:call-template>
764
765   <xsl:choose>
766     <xsl:when test="count($target) = 0">
767       <xsl:message>
768         <xsl:text>XRef to nonexistent id: </xsl:text>
769         <xsl:value-of select="@linkend"/> 
770         <xsl:value-of select="@xlink:href"/>
771       </xsl:message>
772       <xsl:text>???</xsl:text>
773     </xsl:when>
774
775     <xsl:when test="@endterm">
776       <xsl:variable name="etargets" select="key('id',@endterm)"/>
777       <xsl:variable name="etarget" select="$etargets[1]"/>
778       <xsl:choose>
779         <xsl:when test="count($etarget) = 0">
780           <xsl:message>
781             <xsl:value-of select="count($etargets)"/>
782             <xsl:text>Endterm points to nonexistent ID: </xsl:text>
783             <xsl:value-of select="@endterm"/>
784           </xsl:message>
785           <xsl:text>???</xsl:text>
786         </xsl:when>
787         <xsl:otherwise>
788           <xsl:apply-templates select="$etarget" mode="endterm"/>
789         </xsl:otherwise>
790       </xsl:choose>
791     </xsl:when>
792
793     <xsl:when test="$target/@xreflabel">
794       <xsl:call-template name="xref.xreflabel">
795         <xsl:with-param name="target" select="$target"/>
796       </xsl:call-template>
797     </xsl:when>
798
799     <xsl:otherwise>
800    
801       <xsl:choose>
802         <!-- Watch out for the case when there is a xref or link inside 
803              a title. See bugs #1811721 and #1838136. -->
804         <xsl:when test="not(ancestor::*[@id = $target/@id] or ancestor::*[@xml:id = $target/@xml:id])">
805
806           <xsl:apply-templates select="$target" mode="xref-to-prefix">
807             <xsl:with-param name="referrer" select="."/>
808             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
809           </xsl:apply-templates>
810           
811           <xsl:apply-templates select="$target" mode="xref-to">
812             <xsl:with-param name="referrer" select="."/>
813             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
814           </xsl:apply-templates>
815           
816           <xsl:apply-templates select="$target" mode="xref-to-suffix">
817             <xsl:with-param name="referrer" select="."/>
818             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
819           </xsl:apply-templates>
820         </xsl:when>
821         
822         <xsl:otherwise>
823           <xsl:apply-templates/>
824         </xsl:otherwise>
825       
826       </xsl:choose>
827     </xsl:otherwise>
828   </xsl:choose>
829
830 </xsl:template>
831
832 <!-- ============================================================ -->
833
834 <xsl:template mode="title.markup" match="d:toc">
835   <xsl:param name="allow-anchors" select="0"/>
836   <xsl:param name="verbose" select="1"/>
837   <xsl:choose>
838     <xsl:when test="d:title|d:info/d:title">
839       <xsl:apply-templates select="(d:title|d:info/d:title)[1]" mode="title.markup">
840         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
841       </xsl:apply-templates>
842     </xsl:when>
843     <xsl:otherwise>
844       <xsl:call-template name="gentext">
845         <xsl:with-param name="key" select="'TableofContents'"/>
846       </xsl:call-template>
847     </xsl:otherwise>
848   </xsl:choose>
849 </xsl:template>
850
851 </xsl:stylesheet>
852