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$
9     ********************************************************************
10
11     This file is part of the XSL DocBook Stylesheet distribution.
12     See /README or http://nwalsh.com/docbook/xsl/ for copyright
13     and other information.
14
15     ******************************************************************** -->
16
17<!-- ==================================================================== -->
18
19<xsl:template match="anchor">
20  <a>
21    <xsl:attribute name="name">
22      <xsl:call-template name="object.id"/>
23    </xsl:attribute>
24  </a>
25</xsl:template>
26
27<!-- ==================================================================== -->
28
29<xsl:template match="xref">
30  <xsl:variable name="targets" select="id(@linkend)"/>
31  <xsl:variable name="target" select="$targets[1]"/>
32  <xsl:variable name="refelem" select="local-name($target)"/>
33
34  <xsl:call-template name="check.id.unique">
35    <xsl:with-param name="linkend" select="@linkend"/>
36  </xsl:call-template>
37
38  <xsl:if test="@id">
39    <a name="{@id}"/>
40  </xsl:if>
41
42  <xsl:choose>
43    <xsl:when test="count($target) = 0">
44      <xsl:message>
45	<xsl:text>XRef to nonexistent id: </xsl:text>
46	<xsl:value-of select="@linkend"/>
47      </xsl:message>
48      <xsl:text>???</xsl:text>
49    </xsl:when>
50
51    <xsl:when test="$target/@xreflabel">
52      <a>
53        <xsl:attribute name="href">
54          <xsl:call-template name="href.target">
55            <xsl:with-param name="object" select="$target"/>
56          </xsl:call-template>
57        </xsl:attribute>
58        <xsl:call-template name="xref.xreflabel">
59          <xsl:with-param name="target" select="$target"/>
60        </xsl:call-template>
61      </a>
62    </xsl:when>
63
64    <xsl:otherwise>
65      <a>
66        <xsl:attribute name="href">
67          <xsl:call-template name="href.target">
68            <xsl:with-param name="object" select="$target"/>
69          </xsl:call-template>
70        </xsl:attribute>
71
72        <xsl:choose>
73	  <xsl:when test="@endterm">
74	    <xsl:variable name="etargets" select="id(@endterm)"/>
75	    <xsl:variable name="etarget" select="$etargets[1]"/>
76	    <xsl:choose>
77	      <xsl:when test="count($etarget) = 0">
78		<xsl:message>
79		  <xsl:value-of select="count($etargets)"/>
80		  <xsl:text>Endterm points to nonexistent ID: </xsl:text>
81		  <xsl:value-of select="@endterm"/>
82		</xsl:message>
83		<xsl:text>???</xsl:text>
84	      </xsl:when>
85	      <xsl:otherwise>
86		<xsl:apply-templates select="$etarget" mode="xref.text"/>
87	      </xsl:otherwise>
88	    </xsl:choose>
89	  </xsl:when>
90
91          <xsl:otherwise>
92            <xsl:attribute name="title">
93              <xsl:apply-templates select="$target" mode="xref-title"/>
94            </xsl:attribute>
95
96            <xsl:apply-templates select="$target" mode="xref-to"/>
97          </xsl:otherwise>
98        </xsl:choose>
99      </a>
100    </xsl:otherwise>
101  </xsl:choose>
102</xsl:template>
103
104<!-- ==================================================================== -->
105
106<xsl:template match="*" mode="xref-to">
107  <xsl:param name="target" select="."/>
108  <xsl:param name="refelem" select="local-name($target)"/>
109
110  <xsl:message>
111    <xsl:text>Don't know what gentext to create for xref to: "</xsl:text>
112    <xsl:value-of select="$refelem"/>
113    <xsl:text>"</xsl:text>
114  </xsl:message>
115  <xsl:text>???</xsl:text>
116</xsl:template>
117
118<xsl:template match="author" mode="xref-to">
119  <xsl:call-template name="person.name"/>
120</xsl:template>
121
122<xsl:template match="figure" mode="xref-to">
123  <xsl:apply-templates select="." mode="object.xref.markup"/>
124</xsl:template>
125
126<xsl:template match="example" mode="xref-to">
127  <xsl:apply-templates select="." mode="object.xref.markup"/>
128</xsl:template>
129
130<xsl:template match="table" mode="xref-to">
131  <xsl:apply-templates select="." mode="object.xref.markup"/>
132</xsl:template>
133
134<xsl:template match="equation" mode="xref-to">
135  <xsl:apply-templates select="." mode="object.xref.markup"/>
136</xsl:template>
137
138<xsl:template match="cmdsynopsis" mode="xref-to">
139  <xsl:apply-templates select="(.//command)[1]" mode="xref"/>
140</xsl:template>
141
142<xsl:template match="funcsynopsis" mode="xref-to">
143  <xsl:apply-templates select="(.//function)[1]" mode="xref"/>
144</xsl:template>
145
146<xsl:template match="dedication" mode="xref-to">
147  <xsl:apply-templates select="." mode="object.xref.markup"/>
148</xsl:template>
149
150<xsl:template match="preface" mode="xref-to">
151  <xsl:apply-templates select="." mode="object.xref.markup"/>
152</xsl:template>
153
154<xsl:template match="chapter" mode="xref-to">
155  <xsl:apply-templates select="." mode="object.xref.markup"/>
156</xsl:template>
157
158<xsl:template match="appendix" mode="xref-to">
159  <xsl:apply-templates select="." mode="object.xref.markup"/>
160</xsl:template>
161
162<xsl:template match="bibliography" mode="xref-to">
163  <xsl:apply-templates select="." mode="object.xref.markup"/>
164</xsl:template>
165
166<xsl:template match="biblioentry|bibliomixed" mode="xref-to">
167  <!-- handles both biblioentry and bibliomixed -->
168  <xsl:text>[</xsl:text>
169  <xsl:choose>
170    <xsl:when test="local-name(*[1]) = 'abbrev'">
171      <xsl:apply-templates select="*[1]"/>
172    </xsl:when>
173    <xsl:otherwise>
174      <xsl:value-of select="@id"/>
175    </xsl:otherwise>
176  </xsl:choose>
177  <xsl:text>]</xsl:text>
178</xsl:template>
179
180<xsl:template match="glossary" mode="xref-to">
181  <xsl:apply-templates select="." mode="object.xref.markup"/>
182</xsl:template>
183
184<xsl:template match="index" mode="xref-to">
185  <xsl:apply-templates select="." mode="object.xref.markup"/>
186</xsl:template>
187
188<xsl:template match="section|simplesect
189                     |sect1|sect2|sect3|sect4|sect5
190                     |refsect1|refsect2|refsect3" mode="xref-to">
191  <xsl:apply-templates select="." mode="object.xref.markup"/>
192  <!-- What about "in Chapter X"? -->
193</xsl:template>
194
195<xsl:template match="question" mode="xref-to">
196  <xsl:apply-templates select="." mode="object.xref.markup"/>
197</xsl:template>
198
199<xsl:template match="answer" mode="xref-to">
200  <xsl:apply-templates select="." mode="object.xref.markup"/>
201</xsl:template>
202
203<xsl:template match="part" mode="xref-to">
204  <xsl:apply-templates select="." mode="object.xref.markup"/>
205</xsl:template>
206
207<xsl:template match="reference" mode="xref-to">
208  <xsl:apply-templates select="." mode="object.xref.markup"/>
209</xsl:template>
210
211<xsl:template match="co" mode="xref-to">
212  <xsl:apply-templates select="." mode="callout-bug"/>
213</xsl:template>
214
215<xsl:template match="book" mode="xref-to">
216  <xsl:apply-templates select="." mode="object.xref.markup"/>
217</xsl:template>
218
219<!-- ==================================================================== -->
220
221<xsl:template match="*" mode="xref-title">
222  <xsl:variable name="title">
223    <xsl:apply-templates select="." mode="object.title.markup"/>
224  </xsl:variable>
225
226  <xsl:value-of select="$title"/>
227</xsl:template>
228
229<xsl:template match="author" mode="xref-title">
230  <xsl:variable name="title">
231    <xsl:call-template name="person.name"/>
232  </xsl:variable>
233
234  <xsl:value-of select="$title"/>
235</xsl:template>
236
237<xsl:template match="cmdsynopsis" mode="xref-title">
238  <xsl:variable name="title">
239    <xsl:apply-templates select="(.//command)[1]" mode="xref"/>
240  </xsl:variable>
241
242  <xsl:value-of select="$title"/>
243</xsl:template>
244
245<xsl:template match="funcsynopsis" mode="xref-title">
246  <xsl:variable name="title">
247    <xsl:apply-templates select="(.//function)[1]" mode="xref"/>
248  </xsl:variable>
249
250  <xsl:value-of select="$title"/>
251</xsl:template>
252
253<xsl:template match="biblioentry|bibliomixed" mode="xref-title">
254  <!-- handles both biblioentry and bibliomixed -->
255  <xsl:variable name="title">
256    <xsl:text>[</xsl:text>
257    <xsl:choose>
258      <xsl:when test="local-name(*[1]) = 'abbrev'">
259        <xsl:apply-templates select="*[1]"/>
260      </xsl:when>
261      <xsl:otherwise>
262        <xsl:value-of select="@id"/>
263      </xsl:otherwise>
264    </xsl:choose>
265    <xsl:text>]</xsl:text>
266  </xsl:variable>
267
268  <xsl:value-of select="$title"/>
269</xsl:template>
270
271<xsl:template match="co" mode="xref-title">
272  <xsl:variable name="title">
273    <xsl:apply-templates select="." mode="callout-bug"/>
274  </xsl:variable>
275
276  <xsl:value-of select="$title"/>
277</xsl:template>
278
279<!-- ==================================================================== -->
280
281<xsl:template match="link">
282  <xsl:variable name="targets" select="id(@linkend)"/>
283  <xsl:variable name="target" select="$targets[1]"/>
284
285  <xsl:call-template name="check.id.unique">
286    <xsl:with-param name="linkend" select="@linkend"/>
287  </xsl:call-template>
288
289  <a>
290    <xsl:if test="@id">
291      <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
292    </xsl:if>
293
294    <xsl:attribute name="href">
295      <xsl:call-template name="href.target">
296        <xsl:with-param name="object" select="$target"/>
297      </xsl:call-template>
298    </xsl:attribute>
299
300    <!-- FIXME: is there a better way to tell what elements have a title? -->
301    <xsl:if test="local-name($target) = 'book'
302                  or local-name($target) = 'set'
303                  or local-name($target) = 'chapter'
304                  or local-name($target) = 'preface'
305                  or local-name($target) = 'appendix'
306                  or local-name($target) = 'bibliography'
307                  or local-name($target) = 'glossary'
308                  or local-name($target) = 'index'
309                  or local-name($target) = 'part'
310                  or local-name($target) = 'refentry'
311                  or local-name($target) = 'reference'
312                  or local-name($target) = 'example'
313                  or local-name($target) = 'equation'
314                  or local-name($target) = 'table'
315                  or local-name($target) = 'figure'
316                  or local-name($target) = 'simplesect'
317                  or starts-with(local-name($target),'sect')
318                  or starts-with(local-name($target),'refsect')">
319      <xsl:attribute name="title">
320        <xsl:apply-templates select="$target"
321                             mode="object.title.markup.textonly"/>
322      </xsl:attribute>
323    </xsl:if>
324
325    <xsl:apply-templates/>
326  </a>
327</xsl:template>
328
329<xsl:template match="ulink">
330  <a>
331    <xsl:if test="@id">
332      <xsl:attribute name="name"><xsl:value-of select="@id"/></xsl:attribute>
333    </xsl:if>
334    <xsl:attribute name="href"><xsl:value-of select="@url"/></xsl:attribute>
335    <xsl:if test="$ulink.target != ''">
336      <xsl:attribute name="target">
337        <xsl:value-of select="$ulink.target"/>
338      </xsl:attribute>
339    </xsl:if>
340    <xsl:choose>
341      <xsl:when test="count(child::node())=0">
342	<xsl:value-of select="@url"/>
343      </xsl:when>
344      <xsl:otherwise>
345	<xsl:apply-templates/>
346      </xsl:otherwise>
347    </xsl:choose>
348  </a>
349</xsl:template>
350
351<xsl:template match="olink">
352  <xsl:if test="@id">
353    <a name="{@id}"/>
354  </xsl:if>
355  <xsl:apply-templates/>
356</xsl:template>
357
358<!-- ==================================================================== -->
359
360<xsl:template name="xref.xreflabel">
361  <!-- called to process an xreflabel...you might use this to make  -->
362  <!-- xreflabels come out in the right font for different targets, -->
363  <!-- for example. -->
364  <xsl:param name="target" select="."/>
365  <xsl:value-of select="$target/@xreflabel"/>
366</xsl:template>
367
368<!-- ==================================================================== -->
369
370<xsl:template match="title" mode="xref">
371  <xsl:apply-templates/>
372</xsl:template>
373
374<xsl:template match="command" mode="xref">
375  <xsl:call-template name="inline.boldseq"/>
376</xsl:template>
377
378<xsl:template match="function" mode="xref">
379  <xsl:call-template name="inline.monoseq"/>
380</xsl:template>
381
382</xsl:stylesheet>
383