]> git.stg.codes - stg.git/blob - doc/xslt/common/gentext.xsl
Set output encoding to utf-8.
[stg.git] / doc / xslt / common / gentext.xsl
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      $Id: gentext.xsl 8769 2010-07-26 17:38:32Z mzjn $
9      ********************************************************************
10
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.
14
15      ******************************************************************** -->
16
17 <!-- ==================================================================== -->
18
19
20 <xsl:template match="*" mode="object.title.template">
21   <xsl:call-template name="gentext.template">
22     <xsl:with-param name="context" select="'title'"/>
23     <xsl:with-param name="name">
24       <xsl:call-template name="xpath.location"/>
25     </xsl:with-param>
26   </xsl:call-template>
27 </xsl:template>
28
29 <xsl:template match="chapter" mode="object.title.template">
30   <xsl:choose>
31     <xsl:when test="string($chapter.autolabel) != 0">
32       <xsl:call-template name="gentext.template">
33         <xsl:with-param name="context" select="'title-numbered'"/>
34         <xsl:with-param name="name">
35           <xsl:call-template name="xpath.location"/>
36         </xsl:with-param>
37       </xsl:call-template>
38     </xsl:when>
39     <xsl:otherwise>
40       <xsl:call-template name="gentext.template">
41         <xsl:with-param name="context" select="'title-unnumbered'"/>
42         <xsl:with-param name="name">
43           <xsl:call-template name="xpath.location"/>
44         </xsl:with-param>
45       </xsl:call-template>
46     </xsl:otherwise>
47   </xsl:choose>
48 </xsl:template>
49
50 <xsl:template match="appendix" mode="object.title.template">
51   <xsl:choose>
52     <xsl:when test="string($appendix.autolabel) != 0">
53       <xsl:call-template name="gentext.template">
54         <xsl:with-param name="context" select="'title-numbered'"/>
55         <xsl:with-param name="name">
56           <xsl:call-template name="xpath.location"/>
57         </xsl:with-param>
58       </xsl:call-template>
59     </xsl:when>
60     <xsl:otherwise>
61       <xsl:call-template name="gentext.template">
62         <xsl:with-param name="context" select="'title-unnumbered'"/>
63         <xsl:with-param name="name">
64           <xsl:call-template name="xpath.location"/>
65         </xsl:with-param>
66       </xsl:call-template>
67     </xsl:otherwise>
68   </xsl:choose>
69 </xsl:template>
70
71 <xsl:template match="part" mode="object.title.template">
72   <xsl:choose>
73     <xsl:when test="string($part.autolabel) != 0">
74       <xsl:call-template name="gentext.template">
75         <xsl:with-param name="context" select="'title-numbered'"/>
76         <xsl:with-param name="name">
77           <xsl:call-template name="xpath.location"/>
78         </xsl:with-param>
79       </xsl:call-template>
80     </xsl:when>
81     <xsl:otherwise>
82       <xsl:call-template name="gentext.template">
83         <xsl:with-param name="context" select="'title-unnumbered'"/>
84         <xsl:with-param name="name">
85           <xsl:call-template name="xpath.location"/>
86         </xsl:with-param>
87       </xsl:call-template>
88     </xsl:otherwise>
89   </xsl:choose>
90 </xsl:template>
91
92 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect
93                      |bridgehead"
94               mode="object.title.template">
95   <xsl:variable name="is.numbered">
96     <xsl:call-template name="label.this.section"/>
97   </xsl:variable>
98   <xsl:choose>
99     <xsl:when test="$is.numbered != 0">
100       <xsl:call-template name="gentext.template">
101         <xsl:with-param name="context" select="'title-numbered'"/>
102         <xsl:with-param name="name">
103           <xsl:call-template name="xpath.location"/>
104         </xsl:with-param>
105       </xsl:call-template>
106     </xsl:when>
107     <xsl:otherwise>
108       <xsl:call-template name="gentext.template">
109         <xsl:with-param name="context" select="'title-unnumbered'"/>
110         <xsl:with-param name="name">
111           <xsl:call-template name="xpath.location"/>
112         </xsl:with-param>
113       </xsl:call-template>
114     </xsl:otherwise>
115   </xsl:choose>
116 </xsl:template>
117
118 <xsl:template match="procedure" mode="object.title.template">
119   <xsl:choose>
120     <xsl:when test="$formal.procedures != 0 and title">
121       <xsl:call-template name="gentext.template">
122         <xsl:with-param name="context" select="'title'"/>
123         <xsl:with-param name="name">
124           <xsl:call-template name="xpath.location"/>
125           <xsl:text>.formal</xsl:text>
126         </xsl:with-param>
127       </xsl:call-template>
128     </xsl:when>
129     <xsl:otherwise>
130       <xsl:call-template name="gentext.template">
131         <xsl:with-param name="context" select="'title'"/>
132         <xsl:with-param name="name">
133           <xsl:call-template name="xpath.location"/>
134         </xsl:with-param>
135       </xsl:call-template>
136     </xsl:otherwise>
137   </xsl:choose>
138 </xsl:template>
139
140 <!-- ============================================================ -->
141
142 <xsl:template match="*" mode="object.subtitle.template">
143   <xsl:call-template name="gentext.template">
144     <xsl:with-param name="context" select="'subtitle'"/>
145     <xsl:with-param name="name">
146       <xsl:call-template name="xpath.location"/>
147     </xsl:with-param>
148   </xsl:call-template>
149 </xsl:template>
150
151 <!-- ============================================================ -->
152
153 <xsl:template match="*" mode="is.autonumber">
154   <xsl:value-of select="'0'"/>
155 </xsl:template>
156
157 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5" 
158               mode="is.autonumber">
159   <xsl:call-template name="label.this.section"/>
160 </xsl:template>
161
162 <xsl:template match="figure|example|table|equation" mode="is.autonumber">
163   <xsl:value-of select="'1'"/>
164 </xsl:template>
165
166 <xsl:template match="appendix" mode="is.autonumber">
167   <xsl:value-of select="$appendix.autolabel"/>
168 </xsl:template>
169
170 <xsl:template match="chapter" mode="is.autonumber">
171   <xsl:value-of select="$chapter.autolabel"/>
172 </xsl:template>
173
174 <xsl:template match="part" mode="is.autonumber">
175   <xsl:value-of select="$part.autolabel"/>
176 </xsl:template>
177
178 <xsl:template match="preface" mode="is.autonumber">
179   <xsl:value-of select="$preface.autolabel"/>
180 </xsl:template>
181
182 <xsl:template match="question|answer" mode="is.autonumber">
183   <xsl:choose>
184     <xsl:when test="$qanda.defaultlabel = 'number'
185                     and not(label)">
186       <xsl:value-of select="'1'"/>
187     </xsl:when>
188     <xsl:otherwise>
189       <xsl:value-of select="'0'"/>
190     </xsl:otherwise>
191   </xsl:choose>
192 </xsl:template>
193
194 <xsl:template match="qandadiv" mode="is.autonumber">
195   <xsl:value-of select="$qandadiv.autolabel"/>
196 </xsl:template>
197
198 <xsl:template match="bridgehead" mode="is.autonumber">
199   <xsl:value-of select="$section.autolabel"/>
200 </xsl:template>
201
202 <xsl:template match="procedure" mode="is.autonumber">
203   <xsl:value-of select="$formal.procedures"/>
204 </xsl:template>
205
206
207 <xsl:template match="*" mode="object.xref.template">
208   <xsl:param name="purpose"/>
209   <xsl:param name="xrefstyle"/>
210   <xsl:param name="referrer"/>
211
212   <!-- Is autonumbering on? -->
213   <xsl:variable name="autonumber">
214     <xsl:apply-templates select="." mode="is.autonumber"/>
215   </xsl:variable>
216
217   <xsl:variable name="number-and-title-template">
218     <xsl:call-template name="gentext.template.exists">
219       <xsl:with-param name="context" select="'xref-number-and-title'"/>
220       <xsl:with-param name="name">
221         <xsl:call-template name="xpath.location"/>
222       </xsl:with-param>
223     </xsl:call-template>
224   </xsl:variable>
225
226   <xsl:variable name="number-template">
227     <xsl:call-template name="gentext.template.exists">
228       <xsl:with-param name="context" select="'xref-number'"/>
229       <xsl:with-param name="name">
230         <xsl:call-template name="xpath.location"/>
231       </xsl:with-param>
232     </xsl:call-template>
233   </xsl:variable>
234
235   <xsl:variable name="context">
236     <xsl:choose>
237       <xsl:when test="self::equation and not(title) and not(info/title)">
238          <xsl:value-of select="'xref-number'"/>
239       </xsl:when>
240       <xsl:when test="string($autonumber) != 0 
241                       and $number-and-title-template != 0
242                       and $xref.with.number.and.title != 0">
243          <xsl:value-of select="'xref-number-and-title'"/>
244       </xsl:when>
245       <xsl:when test="string($autonumber) != 0 
246                       and $number-template != 0">
247          <xsl:value-of select="'xref-number'"/>
248       </xsl:when>
249       <xsl:otherwise>
250          <xsl:value-of select="'xref'"/>
251       </xsl:otherwise>
252     </xsl:choose>
253   </xsl:variable>
254
255   <xsl:call-template name="gentext.template">
256     <xsl:with-param name="context" select="$context"/>
257     <xsl:with-param name="name">
258       <xsl:call-template name="xpath.location"/>
259     </xsl:with-param>
260     <xsl:with-param name="purpose" select="$purpose"/>
261     <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
262     <xsl:with-param name="referrer" select="$referrer"/>
263   </xsl:call-template>
264
265 </xsl:template>
266
267
268 <!-- ============================================================ -->
269
270 <xsl:template match="*" mode="object.title.markup">
271   <xsl:param name="allow-anchors" select="0"/>
272   <xsl:variable name="template">
273     <xsl:apply-templates select="." mode="object.title.template"/>
274   </xsl:variable>
275
276 <!--
277   <xsl:message>
278     <xsl:text>object.title.markup: </xsl:text>
279     <xsl:value-of select="local-name(.)"/>
280     <xsl:text>: </xsl:text>
281     <xsl:value-of select="$template"/>
282   </xsl:message>
283 -->
284
285   <xsl:call-template name="substitute-markup">
286     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
287     <xsl:with-param name="template" select="$template"/>
288   </xsl:call-template>
289 </xsl:template>
290
291 <xsl:template match="*" mode="object.title.markup.textonly">
292   <xsl:variable name="title">
293     <xsl:apply-templates select="." mode="object.title.markup"/>
294   </xsl:variable>
295   <xsl:value-of select="normalize-space($title)"/>
296 </xsl:template>
297
298 <!-- ============================================================ -->
299
300 <xsl:template match="*" mode="object.titleabbrev.markup">
301   <xsl:param name="allow-anchors" select="0"/>
302
303   <!-- Just for consistency in template naming -->
304
305   <xsl:apply-templates select="." mode="titleabbrev.markup">
306     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
307   </xsl:apply-templates>
308 </xsl:template>
309
310 <!-- ============================================================ -->
311
312 <xsl:template match="*" mode="object.subtitle.markup">
313   <xsl:variable name="template">
314     <xsl:apply-templates select="." mode="object.subtitle.template"/>
315   </xsl:variable>
316
317   <xsl:call-template name="substitute-markup">
318     <xsl:with-param name="template" select="$template"/>
319   </xsl:call-template>
320 </xsl:template>
321
322 <!-- ============================================================ -->
323
324 <xsl:template match="*" mode="object.xref.markup">
325   <xsl:param name="purpose"/>
326   <xsl:param name="xrefstyle"/>
327   <xsl:param name="referrer"/>
328   <xsl:param name="verbose" select="1"/>
329
330   <xsl:variable name="template">
331     <xsl:choose>
332       <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
333         <xsl:call-template name="make.gentext.template">
334           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
335           <xsl:with-param name="purpose" select="$purpose"/>
336           <xsl:with-param name="referrer" select="$referrer"/>
337         </xsl:call-template>
338       </xsl:when>
339       <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
340         <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
341       </xsl:when>
342       <xsl:otherwise>
343         <xsl:apply-templates select="." mode="object.xref.template">
344           <xsl:with-param name="purpose" select="$purpose"/>
345           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
346           <xsl:with-param name="referrer" select="$referrer"/>
347         </xsl:apply-templates>
348       </xsl:otherwise>
349     </xsl:choose>
350   </xsl:variable>
351
352 <!-- 
353   <xsl:message>
354     <xsl:text>object.xref.markup: </xsl:text>
355     <xsl:value-of select="local-name(.)"/>
356     <xsl:text>(</xsl:text>
357     <xsl:value-of select="$xrefstyle"/>
358     <xsl:text>, </xsl:text>
359     <xsl:value-of select="$purpose"/>
360     <xsl:text>)</xsl:text>
361     <xsl:text>: [</xsl:text>
362     <xsl:value-of select="$template"/>
363     <xsl:text>]</xsl:text>
364   </xsl:message>
365 -->
366
367   <xsl:if test="$template = '' and $verbose != 0">
368     <xsl:message>
369       <xsl:text>object.xref.markup: empty xref template</xsl:text>
370       <xsl:text> for linkend="</xsl:text>
371       <xsl:value-of select="@id|@xml:id"/>
372       <xsl:text>" and @xrefstyle="</xsl:text>
373       <xsl:value-of select="$xrefstyle"/>
374       <xsl:text>"</xsl:text>
375     </xsl:message>
376   </xsl:if>
377
378   <xsl:call-template name="substitute-markup">
379     <xsl:with-param name="purpose" select="$purpose"/>
380     <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
381     <xsl:with-param name="referrer" select="$referrer"/>
382     <xsl:with-param name="template" select="$template"/>
383     <xsl:with-param name="verbose" select="$verbose"/>
384   </xsl:call-template>
385 </xsl:template>
386
387 <xsl:template match="listitem" mode="object.xref.markup">
388   <xsl:param name="verbose" select="1"/>
389
390   <xsl:choose>
391     <xsl:when test="parent::orderedlist">
392       <xsl:variable name="template">
393         <xsl:apply-templates select="." mode="object.xref.template"/>
394       </xsl:variable>
395       <xsl:call-template name="substitute-markup">
396         <xsl:with-param name="template" select="$template"/>
397       </xsl:call-template>
398     </xsl:when>
399     <xsl:when test="$verbose != 0">
400       <xsl:message>
401         <xsl:text>Xref is only supported to listitems in an</xsl:text>
402         <xsl:text> orderedlist: </xsl:text>
403         <xsl:value-of select=".//@id|.//@xml:id"/>
404       </xsl:message>
405       <xsl:text>???</xsl:text>
406     </xsl:when>
407   </xsl:choose>
408 </xsl:template>
409
410 <xsl:template match="question" mode="object.xref.markup">
411   <xsl:param name="purpose"/>
412   <xsl:param name="xrefstyle"/>
413   <xsl:param name="referrer"/>
414
415   <xsl:variable name="deflabel">
416     <xsl:choose>
417       <xsl:when test="ancestor-or-self::*[@defaultlabel]">
418         <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
419                               /@defaultlabel"/>
420       </xsl:when>
421       <xsl:otherwise>
422         <xsl:value-of select="$qanda.defaultlabel"/>
423       </xsl:otherwise>
424     </xsl:choose>
425   </xsl:variable>
426
427   <xsl:variable name="template">
428     <xsl:choose>
429       <!-- This avoids double Q: Q: in xref when defaultlabel=qanda -->
430       <xsl:when test="$deflabel = 'qanda' and not(label)">%n</xsl:when>
431       <xsl:otherwise>
432         <xsl:apply-templates select="." mode="object.xref.template">
433           <xsl:with-param name="purpose" select="$purpose"/>
434           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
435           <xsl:with-param name="referrer" select="$referrer"/>
436         </xsl:apply-templates>
437       </xsl:otherwise>
438     </xsl:choose>
439   </xsl:variable>
440
441   <xsl:call-template name="substitute-markup">
442     <xsl:with-param name="purpose" select="$purpose"/>
443     <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
444     <xsl:with-param name="referrer" select="$referrer"/>
445     <xsl:with-param name="template" select="$template"/>
446   </xsl:call-template>
447 </xsl:template>
448
449 <!-- ============================================================ -->
450
451 <xsl:template name="substitute-markup">
452   <xsl:param name="template" select="''"/>
453   <xsl:param name="allow-anchors" select="'0'"/>
454   <xsl:param name="title" select="''"/>
455   <xsl:param name="subtitle" select="''"/>
456   <xsl:param name="docname" select="''"/>
457   <xsl:param name="label" select="''"/>
458   <xsl:param name="pagenumber" select="''"/>
459   <xsl:param name="purpose"/>
460   <xsl:param name="xrefstyle"/>
461   <xsl:param name="referrer"/>
462   <xsl:param name="verbose"/>
463
464   <xsl:choose>
465     <xsl:when test="contains($template, '%')">
466       <xsl:value-of select="substring-before($template, '%')"/>
467       <xsl:variable name="candidate"
468              select="substring(substring-after($template, '%'), 1, 1)"/>
469       <xsl:choose>
470         <xsl:when test="$candidate = 't'">
471           <xsl:apply-templates select="." mode="insert.title.markup">
472             <xsl:with-param name="purpose" select="$purpose"/>
473             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
474             <xsl:with-param name="title">
475               <xsl:choose>
476                 <xsl:when test="$title != ''">
477                   <xsl:copy-of select="$title"/>
478                 </xsl:when>
479                 <xsl:otherwise>
480                   <xsl:apply-templates select="." mode="title.markup">
481                     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
482                     <xsl:with-param name="verbose" select="$verbose"/>
483                   </xsl:apply-templates>
484                 </xsl:otherwise>
485               </xsl:choose>
486             </xsl:with-param>
487           </xsl:apply-templates>
488         </xsl:when>
489         <xsl:when test="$candidate = 's'">
490           <xsl:apply-templates select="." mode="insert.subtitle.markup">
491             <xsl:with-param name="purpose" select="$purpose"/>
492             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
493             <xsl:with-param name="subtitle">
494               <xsl:choose>
495                 <xsl:when test="$subtitle != ''">
496                   <xsl:copy-of select="$subtitle"/>
497                 </xsl:when>
498                 <xsl:otherwise>
499                   <xsl:apply-templates select="." mode="subtitle.markup">
500                     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
501                   </xsl:apply-templates>
502                 </xsl:otherwise>
503               </xsl:choose>
504             </xsl:with-param>
505           </xsl:apply-templates>
506         </xsl:when>
507         <xsl:when test="$candidate = 'n'">
508           <xsl:apply-templates select="." mode="insert.label.markup">
509             <xsl:with-param name="purpose" select="$purpose"/>
510             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
511             <xsl:with-param name="label">
512               <xsl:choose>
513                 <xsl:when test="$label != ''">
514                   <xsl:copy-of select="$label"/>
515                 </xsl:when>
516                 <xsl:otherwise>
517                   <xsl:apply-templates select="." mode="label.markup"/>
518                 </xsl:otherwise>
519               </xsl:choose>
520             </xsl:with-param>
521           </xsl:apply-templates>
522         </xsl:when>
523         <xsl:when test="$candidate = 'p'">
524           <xsl:apply-templates select="." mode="insert.pagenumber.markup">
525             <xsl:with-param name="purpose" select="$purpose"/>
526             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
527             <xsl:with-param name="pagenumber">
528               <xsl:choose>
529                 <xsl:when test="$pagenumber != ''">
530                   <xsl:copy-of select="$pagenumber"/>
531                 </xsl:when>
532                 <xsl:otherwise>
533                   <xsl:apply-templates select="." mode="pagenumber.markup"/>
534                 </xsl:otherwise>
535               </xsl:choose>
536             </xsl:with-param>
537           </xsl:apply-templates>
538         </xsl:when>
539         <xsl:when test="$candidate = 'o'">
540           <!-- olink target document title -->
541           <xsl:apply-templates select="." mode="insert.olink.docname.markup">
542             <xsl:with-param name="purpose" select="$purpose"/>
543             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
544             <xsl:with-param name="docname">
545               <xsl:choose>
546                 <xsl:when test="$docname != ''">
547                   <xsl:copy-of select="$docname"/>
548                 </xsl:when>
549                 <xsl:otherwise>
550                   <xsl:apply-templates select="." mode="olink.docname.markup"/>
551                 </xsl:otherwise>
552               </xsl:choose>
553             </xsl:with-param>
554           </xsl:apply-templates>
555         </xsl:when>
556         <xsl:when test="$candidate = 'd'">
557           <xsl:apply-templates select="." mode="insert.direction.markup">
558             <xsl:with-param name="purpose" select="$purpose"/>
559             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
560             <xsl:with-param name="direction">
561               <xsl:choose>
562                 <xsl:when test="$referrer">
563                   <xsl:variable name="referent-is-below">
564                     <xsl:for-each select="preceding::xref">
565                       <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
566                     </xsl:for-each>
567                   </xsl:variable>
568                   <xsl:choose>
569                     <xsl:when test="$referent-is-below = ''">
570                       <xsl:call-template name="gentext">
571                         <xsl:with-param name="key" select="'above'"/>
572                       </xsl:call-template>
573                     </xsl:when>
574                     <xsl:otherwise>
575                       <xsl:call-template name="gentext">
576                         <xsl:with-param name="key" select="'below'"/>
577                       </xsl:call-template>
578                     </xsl:otherwise>
579                   </xsl:choose>
580                 </xsl:when>
581                 <xsl:otherwise>
582                   <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
583                 </xsl:otherwise>
584               </xsl:choose>
585             </xsl:with-param>
586           </xsl:apply-templates>
587         </xsl:when>
588         <xsl:when test="$candidate = '%' ">
589           <xsl:text>%</xsl:text>
590         </xsl:when>
591         <xsl:otherwise>
592           <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
593         </xsl:otherwise>
594       </xsl:choose>
595       <!-- recurse with the rest of the template string -->
596       <xsl:variable name="rest"
597             select="substring($template,
598             string-length(substring-before($template, '%'))+3)"/>
599       <xsl:call-template name="substitute-markup">
600         <xsl:with-param name="template" select="$rest"/>
601         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
602         <xsl:with-param name="title" select="$title"/>
603         <xsl:with-param name="subtitle" select="$subtitle"/>
604         <xsl:with-param name="docname" select="$docname"/>
605         <xsl:with-param name="label" select="$label"/>
606         <xsl:with-param name="pagenumber" select="$pagenumber"/>
607         <xsl:with-param name="purpose" select="$purpose"/>
608         <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
609         <xsl:with-param name="referrer" select="$referrer"/>
610         <xsl:with-param name="verbose" select="$verbose"/>
611       </xsl:call-template>
612     </xsl:when>
613     <xsl:otherwise>
614       <xsl:value-of select="$template"/>
615     </xsl:otherwise>
616   </xsl:choose>
617 </xsl:template>
618
619 <!-- ============================================================ -->
620
621 <xsl:template name="make.gentext.template">
622   <xsl:param name="xrefstyle" select="''"/>
623   <xsl:param name="purpose"/>
624   <xsl:param name="referrer"/>
625   <xsl:param name="lang">
626     <xsl:call-template name="l10n.language"/>
627   </xsl:param>
628   <xsl:param name="target.elem" select="local-name(.)"/>
629
630   <!-- parse xrefstyle to get parts -->
631   <xsl:variable name="parts"
632       select="substring-after(normalize-space($xrefstyle), 'select:')"/>
633
634   <xsl:variable name="labeltype">
635     <xsl:choose>
636       <xsl:when test="contains($parts, 'labelnumber')">
637          <xsl:text>labelnumber</xsl:text>
638       </xsl:when>
639       <xsl:when test="contains($parts, 'labelname')">
640          <xsl:text>labelname</xsl:text>
641       </xsl:when>
642       <xsl:when test="contains($parts, 'label')">
643          <xsl:text>label</xsl:text>
644       </xsl:when>
645     </xsl:choose>
646   </xsl:variable>
647
648   <xsl:variable name="titletype">
649     <xsl:choose>
650       <xsl:when test="contains($parts, 'quotedtitle')">
651          <xsl:text>quotedtitle</xsl:text>
652       </xsl:when>
653       <xsl:when test="contains($parts, 'title')">
654          <xsl:text>title</xsl:text>
655       </xsl:when>
656     </xsl:choose>
657   </xsl:variable>
658
659   <xsl:variable name="pagetype">
660     <xsl:choose>
661       <xsl:when test="$insert.olink.page.number = 'no' and
662                       local-name($referrer) = 'olink'">
663         <!-- suppress page numbers -->
664       </xsl:when>
665       <xsl:when test="$insert.xref.page.number = 'no' and
666                       local-name($referrer) != 'olink'">
667         <!-- suppress page numbers -->
668       </xsl:when>
669       <xsl:when test="contains($parts, 'nopage')">
670          <xsl:text>nopage</xsl:text>
671       </xsl:when>
672       <xsl:when test="contains($parts, 'pagenumber')">
673          <xsl:text>pagenumber</xsl:text>
674       </xsl:when>
675       <xsl:when test="contains($parts, 'pageabbrev')">
676          <xsl:text>pageabbrev</xsl:text>
677       </xsl:when>
678       <xsl:when test="contains($parts, 'Page')">
679          <xsl:text>Page</xsl:text>
680       </xsl:when>
681       <xsl:when test="contains($parts, 'page')">
682          <xsl:text>page</xsl:text>
683       </xsl:when>
684     </xsl:choose>
685   </xsl:variable>
686
687   <xsl:variable name="docnametype">
688     <xsl:choose>
689       <xsl:when test="($olink.doctitle = 0 or
690                        $olink.doctitle = 'no') and
691                       local-name($referrer) = 'olink'">
692         <!-- suppress docname -->
693       </xsl:when>
694       <xsl:when test="contains($parts, 'nodocname')">
695          <xsl:text>nodocname</xsl:text>
696       </xsl:when>
697       <xsl:when test="contains($parts, 'docnamelong')">
698          <xsl:text>docnamelong</xsl:text>
699       </xsl:when>
700       <xsl:when test="contains($parts, 'docname')">
701          <xsl:text>docname</xsl:text>
702       </xsl:when>
703     </xsl:choose>
704   </xsl:variable>
705
706   <xsl:if test="$labeltype != ''">
707     <xsl:choose>
708       <xsl:when test="$labeltype = 'labelname'">
709         <xsl:call-template name="gentext">
710           <xsl:with-param name="key">
711             <xsl:choose>
712               <xsl:when test="local-name($referrer) = 'olink'">
713                 <xsl:value-of select="$target.elem"/>
714               </xsl:when>
715               <xsl:otherwise>
716                 <xsl:value-of select="local-name(.)"/>
717               </xsl:otherwise>
718             </xsl:choose>
719           </xsl:with-param>
720         </xsl:call-template>
721       </xsl:when>
722       <xsl:when test="$labeltype = 'labelnumber'">
723         <xsl:text>%n</xsl:text>
724       </xsl:when>
725       <xsl:when test="$labeltype = 'label'">
726         <xsl:call-template name="gentext.template">
727           <xsl:with-param name="context" select="'xref-number'"/>
728           <xsl:with-param name="name">
729             <xsl:choose>
730               <xsl:when test="local-name($referrer) = 'olink'">
731                 <xsl:value-of select="$target.elem"/>
732               </xsl:when>
733               <xsl:otherwise>
734                 <xsl:call-template name="xpath.location"/>
735               </xsl:otherwise>
736             </xsl:choose>
737           </xsl:with-param>
738           <xsl:with-param name="purpose" select="$purpose"/>
739           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
740           <xsl:with-param name="referrer" select="$referrer"/>
741         </xsl:call-template>
742       </xsl:when>
743     </xsl:choose>
744
745     <xsl:choose>
746       <xsl:when test="$titletype != ''">
747         <xsl:value-of select="$xref.label-title.separator"/>
748       </xsl:when>
749       <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
750         <xsl:value-of select="$xref.label-page.separator"/>
751       </xsl:when>
752     </xsl:choose>
753   </xsl:if>
754
755   <xsl:if test="$titletype != ''">
756     <xsl:choose>
757       <xsl:when test="$titletype = 'title'">
758         <xsl:text>%t</xsl:text>
759       </xsl:when>
760       <xsl:when test="$titletype = 'quotedtitle'">
761         <xsl:call-template name="gentext.dingbat">
762           <xsl:with-param name="dingbat" select="'startquote'"/>
763         </xsl:call-template>
764         <xsl:text>%t</xsl:text>
765         <xsl:call-template name="gentext.dingbat">
766           <xsl:with-param name="dingbat" select="'endquote'"/>
767         </xsl:call-template>
768       </xsl:when>
769     </xsl:choose>
770
771     <xsl:choose>
772       <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
773         <xsl:value-of select="$xref.title-page.separator"/>
774       </xsl:when>
775     </xsl:choose>
776   </xsl:if>
777   
778   <!-- special case: use regular xref template if just turning off page -->
779   <xsl:if test="($pagetype = 'nopage' or $docnametype = 'nodocname')
780                   and local-name($referrer) != 'olink'
781                   and $labeltype = '' 
782                   and $titletype = ''">
783     <xsl:apply-templates select="." mode="object.xref.template">
784       <xsl:with-param name="purpose" select="$purpose"/>
785       <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
786       <xsl:with-param name="referrer" select="$referrer"/>
787     </xsl:apply-templates>
788   </xsl:if>
789
790   <xsl:if test="$pagetype != ''">
791     <xsl:choose>
792       <xsl:when test="$pagetype = 'page'">
793         <xsl:call-template name="gentext.template">
794           <xsl:with-param name="context" select="'xref'"/>
795           <xsl:with-param name="name" select="'page'"/>
796         </xsl:call-template>
797       </xsl:when>
798       <xsl:when test="$pagetype = 'Page'">
799         <xsl:call-template name="gentext.template">
800           <xsl:with-param name="context" select="'xref'"/>
801           <xsl:with-param name="name" select="'Page'"/>
802         </xsl:call-template>
803       </xsl:when>
804       <xsl:when test="$pagetype = 'pageabbrev'">
805         <xsl:call-template name="gentext.template">
806           <xsl:with-param name="context" select="'xref'"/>
807           <xsl:with-param name="name" select="'pageabbrev'"/>
808         </xsl:call-template>
809       </xsl:when>
810       <xsl:when test="$pagetype = 'pagenumber'">
811         <xsl:text>%p</xsl:text>
812       </xsl:when>
813     </xsl:choose>
814
815   </xsl:if>
816
817   <!-- Add reference to other document title -->
818   <xsl:if test="$docnametype != '' and local-name($referrer) = 'olink'">
819     <!-- Any separator should be in the gentext template -->
820     <xsl:choose>
821       <xsl:when test="$docnametype = 'docnamelong'">
822         <xsl:call-template name="gentext.template">
823           <xsl:with-param name="context" select="'xref'"/>
824           <xsl:with-param name="name" select="'docnamelong'"/>
825         </xsl:call-template>
826       </xsl:when>
827       <xsl:when test="$docnametype = 'docname'">
828         <xsl:call-template name="gentext.template">
829           <xsl:with-param name="context" select="'xref'"/>
830           <xsl:with-param name="name" select="'docname'"/>
831         </xsl:call-template>
832       </xsl:when>
833     </xsl:choose>
834
835   </xsl:if>
836   
837 </xsl:template>
838
839 </xsl:stylesheet>