]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/styleguide/docbook-xsl-1.75.2/common/gentext.xsl
stylesheet changes.
[working/Evergreen.git] / stylesheets / styleguide / docbook-xsl-1.75.2 / 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 8396 2009-04-07 07:41:35Z 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"
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="string($autonumber) != 0 
238                       and $number-and-title-template != 0
239                       and $xref.with.number.and.title != 0">
240          <xsl:value-of select="'xref-number-and-title'"/>
241       </xsl:when>
242       <xsl:when test="string($autonumber) != 0 
243                       and $number-template != 0">
244          <xsl:value-of select="'xref-number'"/>
245       </xsl:when>
246       <xsl:otherwise>
247          <xsl:value-of select="'xref'"/>
248       </xsl:otherwise>
249     </xsl:choose>
250   </xsl:variable>
251
252   <xsl:call-template name="gentext.template">
253     <xsl:with-param name="context" select="$context"/>
254     <xsl:with-param name="name">
255       <xsl:call-template name="xpath.location"/>
256     </xsl:with-param>
257     <xsl:with-param name="purpose" select="$purpose"/>
258     <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
259     <xsl:with-param name="referrer" select="$referrer"/>
260   </xsl:call-template>
261
262 </xsl:template>
263
264
265 <!-- ============================================================ -->
266
267 <xsl:template match="*" mode="object.title.markup">
268   <xsl:param name="allow-anchors" select="0"/>
269   <xsl:variable name="template">
270     <xsl:apply-templates select="." mode="object.title.template"/>
271   </xsl:variable>
272
273 <!--
274   <xsl:message>
275     <xsl:text>object.title.markup: </xsl:text>
276     <xsl:value-of select="local-name(.)"/>
277     <xsl:text>: </xsl:text>
278     <xsl:value-of select="$template"/>
279   </xsl:message>
280 -->
281
282   <xsl:call-template name="substitute-markup">
283     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
284     <xsl:with-param name="template" select="$template"/>
285   </xsl:call-template>
286 </xsl:template>
287
288 <xsl:template match="*" mode="object.title.markup.textonly">
289   <xsl:variable name="title">
290     <xsl:apply-templates select="." mode="object.title.markup"/>
291   </xsl:variable>
292   <xsl:value-of select="normalize-space($title)"/>
293 </xsl:template>
294
295 <!-- ============================================================ -->
296
297 <xsl:template match="*" mode="object.titleabbrev.markup">
298   <xsl:param name="allow-anchors" select="0"/>
299
300   <!-- Just for consistency in template naming -->
301
302   <xsl:apply-templates select="." mode="titleabbrev.markup">
303     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
304   </xsl:apply-templates>
305 </xsl:template>
306
307 <!-- ============================================================ -->
308
309 <xsl:template match="*" mode="object.subtitle.markup">
310   <xsl:variable name="template">
311     <xsl:apply-templates select="." mode="object.subtitle.template"/>
312   </xsl:variable>
313
314   <xsl:call-template name="substitute-markup">
315     <xsl:with-param name="template" select="$template"/>
316   </xsl:call-template>
317 </xsl:template>
318
319 <!-- ============================================================ -->
320
321 <xsl:template match="*" mode="object.xref.markup">
322   <xsl:param name="purpose"/>
323   <xsl:param name="xrefstyle"/>
324   <xsl:param name="referrer"/>
325   <xsl:param name="verbose" select="1"/>
326
327   <xsl:variable name="template">
328     <xsl:choose>
329       <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')">
330         <xsl:call-template name="make.gentext.template">
331           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
332           <xsl:with-param name="purpose" select="$purpose"/>
333           <xsl:with-param name="referrer" select="$referrer"/>
334         </xsl:call-template>
335       </xsl:when>
336       <xsl:when test="starts-with(normalize-space($xrefstyle), 'template:')">
337         <xsl:value-of select="substring-after(normalize-space($xrefstyle), 'template:')"/>
338       </xsl:when>
339       <xsl:otherwise>
340         <xsl:apply-templates select="." mode="object.xref.template">
341           <xsl:with-param name="purpose" select="$purpose"/>
342           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
343           <xsl:with-param name="referrer" select="$referrer"/>
344         </xsl:apply-templates>
345       </xsl:otherwise>
346     </xsl:choose>
347   </xsl:variable>
348
349 <!-- 
350   <xsl:message>
351     <xsl:text>object.xref.markup: </xsl:text>
352     <xsl:value-of select="local-name(.)"/>
353     <xsl:text>(</xsl:text>
354     <xsl:value-of select="$xrefstyle"/>
355     <xsl:text>, </xsl:text>
356     <xsl:value-of select="$purpose"/>
357     <xsl:text>)</xsl:text>
358     <xsl:text>: [</xsl:text>
359     <xsl:value-of select="$template"/>
360     <xsl:text>]</xsl:text>
361   </xsl:message>
362 -->
363
364   <xsl:if test="$template = '' and $verbose != 0">
365     <xsl:message>
366       <xsl:text>object.xref.markup: empty xref template</xsl:text>
367       <xsl:text> for linkend="</xsl:text>
368       <xsl:value-of select="@id|@xml:id"/>
369       <xsl:text>" and @xrefstyle="</xsl:text>
370       <xsl:value-of select="$xrefstyle"/>
371       <xsl:text>"</xsl:text>
372     </xsl:message>
373   </xsl:if>
374
375   <xsl:call-template name="substitute-markup">
376     <xsl:with-param name="purpose" select="$purpose"/>
377     <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
378     <xsl:with-param name="referrer" select="$referrer"/>
379     <xsl:with-param name="template" select="$template"/>
380     <xsl:with-param name="verbose" select="$verbose"/>
381   </xsl:call-template>
382 </xsl:template>
383
384 <xsl:template match="listitem" mode="object.xref.markup">
385   <xsl:param name="verbose" select="1"/>
386
387   <xsl:choose>
388     <xsl:when test="parent::orderedlist">
389       <xsl:variable name="template">
390         <xsl:apply-templates select="." mode="object.xref.template"/>
391       </xsl:variable>
392       <xsl:call-template name="substitute-markup">
393         <xsl:with-param name="template" select="$template"/>
394       </xsl:call-template>
395     </xsl:when>
396     <xsl:when test="$verbose != 0">
397       <xsl:message>
398         <xsl:text>Xref is only supported to listitems in an</xsl:text>
399         <xsl:text> orderedlist: </xsl:text>
400         <xsl:value-of select="@id|@xml:id"/>
401       </xsl:message>
402       <xsl:text>???</xsl:text>
403     </xsl:when>
404   </xsl:choose>
405 </xsl:template>
406
407 <xsl:template match="question" mode="object.xref.markup">
408   <xsl:param name="purpose"/>
409   <xsl:param name="xrefstyle"/>
410   <xsl:param name="referrer"/>
411
412   <xsl:variable name="deflabel">
413     <xsl:choose>
414       <xsl:when test="ancestor-or-self::*[@defaultlabel]">
415         <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
416                               /@defaultlabel"/>
417       </xsl:when>
418       <xsl:otherwise>
419         <xsl:value-of select="$qanda.defaultlabel"/>
420       </xsl:otherwise>
421     </xsl:choose>
422   </xsl:variable>
423
424   <xsl:variable name="template">
425     <xsl:choose>
426       <!-- This avoids double Q: Q: in xref when defaultlabel=qanda -->
427       <xsl:when test="$deflabel = 'qanda' and not(label)">%n</xsl:when>
428       <xsl:otherwise>
429         <xsl:apply-templates select="." mode="object.xref.template">
430           <xsl:with-param name="purpose" select="$purpose"/>
431           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
432           <xsl:with-param name="referrer" select="$referrer"/>
433         </xsl:apply-templates>
434       </xsl:otherwise>
435     </xsl:choose>
436   </xsl:variable>
437
438   <xsl:call-template name="substitute-markup">
439     <xsl:with-param name="purpose" select="$purpose"/>
440     <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
441     <xsl:with-param name="referrer" select="$referrer"/>
442     <xsl:with-param name="template" select="$template"/>
443   </xsl:call-template>
444 </xsl:template>
445
446 <!-- ============================================================ -->
447
448 <xsl:template name="substitute-markup">
449   <xsl:param name="template" select="''"/>
450   <xsl:param name="allow-anchors" select="'0'"/>
451   <xsl:param name="title" select="''"/>
452   <xsl:param name="subtitle" select="''"/>
453   <xsl:param name="docname" select="''"/>
454   <xsl:param name="label" select="''"/>
455   <xsl:param name="pagenumber" select="''"/>
456   <xsl:param name="purpose"/>
457   <xsl:param name="xrefstyle"/>
458   <xsl:param name="referrer"/>
459   <xsl:param name="verbose"/>
460
461   <xsl:choose>
462     <xsl:when test="contains($template, '%')">
463       <xsl:value-of select="substring-before($template, '%')"/>
464       <xsl:variable name="candidate"
465              select="substring(substring-after($template, '%'), 1, 1)"/>
466       <xsl:choose>
467         <xsl:when test="$candidate = 't'">
468           <xsl:apply-templates select="." mode="insert.title.markup">
469             <xsl:with-param name="purpose" select="$purpose"/>
470             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
471             <xsl:with-param name="title">
472               <xsl:choose>
473                 <xsl:when test="$title != ''">
474                   <xsl:copy-of select="$title"/>
475                 </xsl:when>
476                 <xsl:otherwise>
477                   <xsl:apply-templates select="." mode="title.markup">
478                     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
479                     <xsl:with-param name="verbose" select="$verbose"/>
480                   </xsl:apply-templates>
481                 </xsl:otherwise>
482               </xsl:choose>
483             </xsl:with-param>
484           </xsl:apply-templates>
485         </xsl:when>
486         <xsl:when test="$candidate = 's'">
487           <xsl:apply-templates select="." mode="insert.subtitle.markup">
488             <xsl:with-param name="purpose" select="$purpose"/>
489             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
490             <xsl:with-param name="subtitle">
491               <xsl:choose>
492                 <xsl:when test="$subtitle != ''">
493                   <xsl:copy-of select="$subtitle"/>
494                 </xsl:when>
495                 <xsl:otherwise>
496                   <xsl:apply-templates select="." mode="subtitle.markup">
497                     <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
498                   </xsl:apply-templates>
499                 </xsl:otherwise>
500               </xsl:choose>
501             </xsl:with-param>
502           </xsl:apply-templates>
503         </xsl:when>
504         <xsl:when test="$candidate = 'n'">
505           <xsl:apply-templates select="." mode="insert.label.markup">
506             <xsl:with-param name="purpose" select="$purpose"/>
507             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
508             <xsl:with-param name="label">
509               <xsl:choose>
510                 <xsl:when test="$label != ''">
511                   <xsl:copy-of select="$label"/>
512                 </xsl:when>
513                 <xsl:otherwise>
514                   <xsl:apply-templates select="." mode="label.markup"/>
515                 </xsl:otherwise>
516               </xsl:choose>
517             </xsl:with-param>
518           </xsl:apply-templates>
519         </xsl:when>
520         <xsl:when test="$candidate = 'p'">
521           <xsl:apply-templates select="." mode="insert.pagenumber.markup">
522             <xsl:with-param name="purpose" select="$purpose"/>
523             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
524             <xsl:with-param name="pagenumber">
525               <xsl:choose>
526                 <xsl:when test="$pagenumber != ''">
527                   <xsl:copy-of select="$pagenumber"/>
528                 </xsl:when>
529                 <xsl:otherwise>
530                   <xsl:apply-templates select="." mode="pagenumber.markup"/>
531                 </xsl:otherwise>
532               </xsl:choose>
533             </xsl:with-param>
534           </xsl:apply-templates>
535         </xsl:when>
536         <xsl:when test="$candidate = 'o'">
537           <!-- olink target document title -->
538           <xsl:apply-templates select="." mode="insert.olink.docname.markup">
539             <xsl:with-param name="purpose" select="$purpose"/>
540             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
541             <xsl:with-param name="docname">
542               <xsl:choose>
543                 <xsl:when test="$docname != ''">
544                   <xsl:copy-of select="$docname"/>
545                 </xsl:when>
546                 <xsl:otherwise>
547                   <xsl:apply-templates select="." mode="olink.docname.markup"/>
548                 </xsl:otherwise>
549               </xsl:choose>
550             </xsl:with-param>
551           </xsl:apply-templates>
552         </xsl:when>
553         <xsl:when test="$candidate = 'd'">
554           <xsl:apply-templates select="." mode="insert.direction.markup">
555             <xsl:with-param name="purpose" select="$purpose"/>
556             <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
557             <xsl:with-param name="direction">
558               <xsl:choose>
559                 <xsl:when test="$referrer">
560                   <xsl:variable name="referent-is-below">
561                     <xsl:for-each select="preceding::xref">
562                       <xsl:if test="generate-id(.) = generate-id($referrer)">1</xsl:if>
563                     </xsl:for-each>
564                   </xsl:variable>
565                   <xsl:choose>
566                     <xsl:when test="$referent-is-below = ''">
567                       <xsl:call-template name="gentext">
568                         <xsl:with-param name="key" select="'above'"/>
569                       </xsl:call-template>
570                     </xsl:when>
571                     <xsl:otherwise>
572                       <xsl:call-template name="gentext">
573                         <xsl:with-param name="key" select="'below'"/>
574                       </xsl:call-template>
575                     </xsl:otherwise>
576                   </xsl:choose>
577                 </xsl:when>
578                 <xsl:otherwise>
579                   <xsl:message>Attempt to use %d in gentext with no referrer!</xsl:message>
580                 </xsl:otherwise>
581               </xsl:choose>
582             </xsl:with-param>
583           </xsl:apply-templates>
584         </xsl:when>
585         <xsl:when test="$candidate = '%' ">
586           <xsl:text>%</xsl:text>
587         </xsl:when>
588         <xsl:otherwise>
589           <xsl:text>%</xsl:text><xsl:value-of select="$candidate"/>
590         </xsl:otherwise>
591       </xsl:choose>
592       <!-- recurse with the rest of the template string -->
593       <xsl:variable name="rest"
594             select="substring($template,
595             string-length(substring-before($template, '%'))+3)"/>
596       <xsl:call-template name="substitute-markup">
597         <xsl:with-param name="template" select="$rest"/>
598         <xsl:with-param name="allow-anchors" select="$allow-anchors"/>
599         <xsl:with-param name="title" select="$title"/>
600         <xsl:with-param name="subtitle" select="$subtitle"/>
601         <xsl:with-param name="docname" select="$docname"/>
602         <xsl:with-param name="label" select="$label"/>
603         <xsl:with-param name="pagenumber" select="$pagenumber"/>
604         <xsl:with-param name="purpose" select="$purpose"/>
605         <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
606         <xsl:with-param name="referrer" select="$referrer"/>
607         <xsl:with-param name="verbose" select="$verbose"/>
608       </xsl:call-template>
609     </xsl:when>
610     <xsl:otherwise>
611       <xsl:value-of select="$template"/>
612     </xsl:otherwise>
613   </xsl:choose>
614 </xsl:template>
615
616 <!-- ============================================================ -->
617
618 <xsl:template name="make.gentext.template">
619   <xsl:param name="xrefstyle" select="''"/>
620   <xsl:param name="purpose"/>
621   <xsl:param name="referrer"/>
622   <xsl:param name="lang">
623     <xsl:call-template name="l10n.language"/>
624   </xsl:param>
625   <xsl:param name="target.elem" select="local-name(.)"/>
626
627   <!-- parse xrefstyle to get parts -->
628   <xsl:variable name="parts"
629       select="substring-after(normalize-space($xrefstyle), 'select:')"/>
630
631   <xsl:variable name="labeltype">
632     <xsl:choose>
633       <xsl:when test="contains($parts, 'labelnumber')">
634          <xsl:text>labelnumber</xsl:text>
635       </xsl:when>
636       <xsl:when test="contains($parts, 'labelname')">
637          <xsl:text>labelname</xsl:text>
638       </xsl:when>
639       <xsl:when test="contains($parts, 'label')">
640          <xsl:text>label</xsl:text>
641       </xsl:when>
642     </xsl:choose>
643   </xsl:variable>
644
645   <xsl:variable name="titletype">
646     <xsl:choose>
647       <xsl:when test="contains($parts, 'quotedtitle')">
648          <xsl:text>quotedtitle</xsl:text>
649       </xsl:when>
650       <xsl:when test="contains($parts, 'title')">
651          <xsl:text>title</xsl:text>
652       </xsl:when>
653     </xsl:choose>
654   </xsl:variable>
655
656   <xsl:variable name="pagetype">
657     <xsl:choose>
658       <xsl:when test="$insert.olink.page.number = 'no' and
659                       local-name($referrer) = 'olink'">
660         <!-- suppress page numbers -->
661       </xsl:when>
662       <xsl:when test="$insert.xref.page.number = 'no' and
663                       local-name($referrer) != 'olink'">
664         <!-- suppress page numbers -->
665       </xsl:when>
666       <xsl:when test="contains($parts, 'nopage')">
667          <xsl:text>nopage</xsl:text>
668       </xsl:when>
669       <xsl:when test="contains($parts, 'pagenumber')">
670          <xsl:text>pagenumber</xsl:text>
671       </xsl:when>
672       <xsl:when test="contains($parts, 'pageabbrev')">
673          <xsl:text>pageabbrev</xsl:text>
674       </xsl:when>
675       <xsl:when test="contains($parts, 'Page')">
676          <xsl:text>Page</xsl:text>
677       </xsl:when>
678       <xsl:when test="contains($parts, 'page')">
679          <xsl:text>page</xsl:text>
680       </xsl:when>
681     </xsl:choose>
682   </xsl:variable>
683
684   <xsl:variable name="docnametype">
685     <xsl:choose>
686       <xsl:when test="($olink.doctitle = 0 or
687                        $olink.doctitle = 'no') and
688                       local-name($referrer) = 'olink'">
689         <!-- suppress docname -->
690       </xsl:when>
691       <xsl:when test="contains($parts, 'nodocname')">
692          <xsl:text>nodocname</xsl:text>
693       </xsl:when>
694       <xsl:when test="contains($parts, 'docnamelong')">
695          <xsl:text>docnamelong</xsl:text>
696       </xsl:when>
697       <xsl:when test="contains($parts, 'docname')">
698          <xsl:text>docname</xsl:text>
699       </xsl:when>
700     </xsl:choose>
701   </xsl:variable>
702
703   <xsl:if test="$labeltype != ''">
704     <xsl:choose>
705       <xsl:when test="$labeltype = 'labelname'">
706         <xsl:call-template name="gentext">
707           <xsl:with-param name="key">
708             <xsl:choose>
709               <xsl:when test="local-name($referrer) = 'olink'">
710                 <xsl:value-of select="$target.elem"/>
711               </xsl:when>
712               <xsl:otherwise>
713                 <xsl:value-of select="local-name(.)"/>
714               </xsl:otherwise>
715             </xsl:choose>
716           </xsl:with-param>
717         </xsl:call-template>
718       </xsl:when>
719       <xsl:when test="$labeltype = 'labelnumber'">
720         <xsl:text>%n</xsl:text>
721       </xsl:when>
722       <xsl:when test="$labeltype = 'label'">
723         <xsl:call-template name="gentext.template">
724           <xsl:with-param name="context" select="'xref-number'"/>
725           <xsl:with-param name="name">
726             <xsl:choose>
727               <xsl:when test="local-name($referrer) = 'olink'">
728                 <xsl:value-of select="$target.elem"/>
729               </xsl:when>
730               <xsl:otherwise>
731                 <xsl:call-template name="xpath.location"/>
732               </xsl:otherwise>
733             </xsl:choose>
734           </xsl:with-param>
735           <xsl:with-param name="purpose" select="$purpose"/>
736           <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
737           <xsl:with-param name="referrer" select="$referrer"/>
738         </xsl:call-template>
739       </xsl:when>
740     </xsl:choose>
741
742     <xsl:choose>
743       <xsl:when test="$titletype != ''">
744         <xsl:value-of select="$xref.label-title.separator"/>
745       </xsl:when>
746       <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
747         <xsl:value-of select="$xref.label-page.separator"/>
748       </xsl:when>
749     </xsl:choose>
750   </xsl:if>
751
752   <xsl:if test="$titletype != ''">
753     <xsl:choose>
754       <xsl:when test="$titletype = 'title'">
755         <xsl:text>%t</xsl:text>
756       </xsl:when>
757       <xsl:when test="$titletype = 'quotedtitle'">
758         <xsl:call-template name="gentext.dingbat">
759           <xsl:with-param name="dingbat" select="'startquote'"/>
760         </xsl:call-template>
761         <xsl:text>%t</xsl:text>
762         <xsl:call-template name="gentext.dingbat">
763           <xsl:with-param name="dingbat" select="'endquote'"/>
764         </xsl:call-template>
765       </xsl:when>
766     </xsl:choose>
767
768     <xsl:choose>
769       <xsl:when test="$pagetype != '' and $pagetype != 'nopage'">
770         <xsl:value-of select="$xref.title-page.separator"/>
771       </xsl:when>
772     </xsl:choose>
773   </xsl:if>
774   
775   <!-- special case: use regular xref template if just turning off page -->
776   <xsl:if test="($pagetype = 'nopage' or $docnametype = 'nodocname')
777                   and local-name($referrer) != 'olink'
778                   and $labeltype = '' 
779                   and $titletype = ''">
780     <xsl:apply-templates select="." mode="object.xref.template">
781       <xsl:with-param name="purpose" select="$purpose"/>
782       <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
783       <xsl:with-param name="referrer" select="$referrer"/>
784     </xsl:apply-templates>
785   </xsl:if>
786
787   <xsl:if test="$pagetype != ''">
788     <xsl:choose>
789       <xsl:when test="$pagetype = 'page'">
790         <xsl:call-template name="gentext.template">
791           <xsl:with-param name="context" select="'xref'"/>
792           <xsl:with-param name="name" select="'page'"/>
793         </xsl:call-template>
794       </xsl:when>
795       <xsl:when test="$pagetype = 'Page'">
796         <xsl:call-template name="gentext.template">
797           <xsl:with-param name="context" select="'xref'"/>
798           <xsl:with-param name="name" select="'Page'"/>
799         </xsl:call-template>
800       </xsl:when>
801       <xsl:when test="$pagetype = 'pageabbrev'">
802         <xsl:call-template name="gentext.template">
803           <xsl:with-param name="context" select="'xref'"/>
804           <xsl:with-param name="name" select="'pageabbrev'"/>
805         </xsl:call-template>
806       </xsl:when>
807       <xsl:when test="$pagetype = 'pagenumber'">
808         <xsl:text>%p</xsl:text>
809       </xsl:when>
810     </xsl:choose>
811
812   </xsl:if>
813
814   <!-- Add reference to other document title -->
815   <xsl:if test="$docnametype != '' and local-name($referrer) = 'olink'">
816     <!-- Any separator should be in the gentext template -->
817     <xsl:choose>
818       <xsl:when test="$docnametype = 'docnamelong'">
819         <xsl:call-template name="gentext.template">
820           <xsl:with-param name="context" select="'xref'"/>
821           <xsl:with-param name="name" select="'docnamelong'"/>
822         </xsl:call-template>
823       </xsl:when>
824       <xsl:when test="$docnametype = 'docname'">
825         <xsl:call-template name="gentext.template">
826           <xsl:with-param name="context" select="'xref'"/>
827           <xsl:with-param name="name" select="'docname'"/>
828         </xsl:call-template>
829       </xsl:when>
830     </xsl:choose>
831
832   </xsl:if>
833   
834 </xsl:template>
835
836 </xsl:stylesheet>