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