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