1<?xml version='1.0'?>
2<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                xmlns:fo="http://www.w3.org/1999/XSL/Format"
4                version='1.0'>
5
6<!-- ********************************************************************
7     $Id$
8     ********************************************************************
9
10     This file is part of the XSL DocBook Stylesheet distribution.
11     See /README or http://nwalsh.com/docbook/xsl/ for copyright
12     and other information.
13
14     ******************************************************************** -->
15
16<!-- ==================================================================== -->
17
18<xsl:template match="anchor">
19  <!-- FIXME: should this output an empty element with an ID? -->
20  <!-- what element!? -->
21  <!-- suppress -->
22</xsl:template>
23
24<!-- ==================================================================== -->
25
26<xsl:template match="xref">
27  <xsl:variable name="targets" select="id(@linkend)"/>
28  <xsl:variable name="target" select="$targets[1]"/>
29  <xsl:variable name="refelem" select="name($target)"/>
30
31  <xsl:call-template name="check.id.unique">
32    <xsl:with-param name="linkend" select="@linkend"/>
33  </xsl:call-template>
34
35  <xsl:choose>
36    <xsl:when test="$refelem=''">
37      <xsl:message>
38	<xsl:text>XRef to nonexistent id: </xsl:text>
39	<xsl:value-of select="@linkend"/>
40      </xsl:message>
41      <xsl:text>???</xsl:text>
42    </xsl:when>
43
44    <xsl:when test="$target/@xreflabel">
45      <fo:basic-link internal-destination="{@linkend}"
46                     xsl:use-attribute-sets="xref.properties">
47	<xsl:call-template name="xref.xreflabel">
48	  <xsl:with-param name="target" select="$target"/>
49	</xsl:call-template>
50      </fo:basic-link>
51    </xsl:when>
52
53    <xsl:otherwise>
54      <fo:basic-link internal-destination="{@linkend}"
55                     xsl:use-attribute-sets="xref.properties">
56        <xsl:choose>
57	  <xsl:when test="@endterm">
58	    <xsl:variable name="etargets" select="id(@endterm)"/>
59	    <xsl:variable name="etarget" select="$etargets[1]"/>
60	    <xsl:choose>
61	      <xsl:when test="count($etarget) = 0">
62		<xsl:message>
63		  <xsl:value-of select="count($etargets)"/>
64		  <xsl:text>Endterm points to nonexistent ID: </xsl:text>
65		  <xsl:value-of select="@endterm"/>
66		</xsl:message>
67		<xsl:text>???</xsl:text>
68	      </xsl:when>
69	      <xsl:otherwise>
70		<xsl:apply-templates select="$etarget" mode="xref.text"/>
71	      </xsl:otherwise>
72	    </xsl:choose>
73	  </xsl:when>
74
75          <xsl:otherwise>
76            <xsl:apply-templates select="$target" mode="xref-to"/>
77          </xsl:otherwise>
78        </xsl:choose>
79      </fo:basic-link>
80    </xsl:otherwise>
81  </xsl:choose>
82</xsl:template>
83
84<!--- ==================================================================== -->
85
86<xsl:template match="*" mode="xref-to">
87  <xsl:param name="target" select="."/>
88  <xsl:param name="refelem" select="local-name($target)"/>
89
90  <xsl:message>
91    <xsl:text>Don't know what gentext to create for xref to: "</xsl:text>
92    <xsl:value-of select="$refelem"/>
93    <xsl:text>"</xsl:text>
94  </xsl:message>
95  <xsl:text>???</xsl:text>
96</xsl:template>
97
98<xsl:template match="author" mode="xref-to">
99  <xsl:call-template name="person.name"/>
100</xsl:template>
101
102<xsl:template match="figure" mode="xref-to">
103  <xsl:apply-templates select="." mode="object.xref.markup"/>
104</xsl:template>
105
106<xsl:template match="example" mode="xref-to">
107  <xsl:apply-templates select="." mode="object.xref.markup"/>
108</xsl:template>
109
110<xsl:template match="table" mode="xref-to">
111  <xsl:apply-templates select="." mode="object.xref.markup"/>
112</xsl:template>
113
114<xsl:template match="equation" mode="xref-to">
115  <xsl:apply-templates select="." mode="object.xref.markup"/>
116</xsl:template>
117
118<xsl:template match="cmdsynopsis" mode="xref-to">
119  <xsl:apply-templates select="(.//command)[1]" mode="xref"/>
120</xsl:template>
121
122<xsl:template match="funcsynopsis" mode="xref-to">
123  <xsl:apply-templates select="(.//function)[1]" mode="xref"/>
124</xsl:template>
125
126<xsl:template match="dedication" mode="xref-to">
127  <xsl:apply-templates select="." mode="object.xref.markup"/>
128</xsl:template>
129
130<xsl:template match="preface" mode="xref-to">
131  <xsl:apply-templates select="." mode="object.xref.markup"/>
132</xsl:template>
133
134<xsl:template match="chapter" mode="xref-to">
135  <xsl:apply-templates select="." mode="object.xref.markup"/>
136</xsl:template>
137
138<xsl:template match="appendix" mode="xref-to">
139  <xsl:apply-templates select="." mode="object.xref.markup"/>
140</xsl:template>
141
142<xsl:template match="bibliography" mode="xref-to">
143  <xsl:apply-templates select="." mode="object.xref.markup"/>
144</xsl:template>
145
146<xsl:template match="biblioentry|bibliomixed" mode="xref-to">
147  <!-- handles both biblioentry and bibliomixed -->
148  <xsl:text>[</xsl:text>
149  <xsl:choose>
150    <xsl:when test="local-name(*[1]) = 'abbrev'">
151      <xsl:apply-templates select="*[1]"/>
152    </xsl:when>
153    <xsl:otherwise>
154      <xsl:value-of select="@id"/>
155    </xsl:otherwise>
156  </xsl:choose>
157  <xsl:text>]</xsl:text>
158</xsl:template>
159
160<xsl:template match="glossary" mode="xref-to">
161  <xsl:apply-templates select="." mode="object.xref.markup"/>
162</xsl:template>
163
164<xsl:template match="index" mode="xref-to">
165  <xsl:apply-templates select="." mode="object.xref.markup"/>
166</xsl:template>
167
168<xsl:template match="section|simplesect
169                     |sect1|sect2|sect3|sect4|sect5
170                     |refsect1|refsect2|refsect3" mode="xref-to">
171  <xsl:apply-templates select="." mode="object.xref.markup"/>
172  <!-- What about "in Chapter X"? -->
173</xsl:template>
174
175<xsl:template match="question" mode="xref-to">
176  <xsl:apply-templates select="." mode="object.xref.markup"/>
177</xsl:template>
178
179<xsl:template match="answer" mode="xref-to">
180  <xsl:apply-templates select="." mode="object.xref.markup"/>
181</xsl:template>
182
183<xsl:template match="part" mode="xref-to">
184  <xsl:apply-templates select="." mode="object.xref.markup"/>
185</xsl:template>
186
187<xsl:template match="reference" mode="xref-to">
188  <xsl:apply-templates select="." mode="object.xref.markup"/>
189</xsl:template>
190
191<xsl:template match="co" mode="xref-to">
192  <xsl:apply-templates select="." mode="callout-bug"/>
193</xsl:template>
194
195<xsl:template match="book" mode="xref-to">
196  <xsl:apply-templates select="." mode="object.xref.markup"/>
197</xsl:template>
198
199<!-- ==================================================================== -->
200
201<xsl:template match="link">
202  <xsl:variable name="targets" select="id(@linkend)"/>
203  <xsl:variable name="target" select="$targets[1]"/>
204
205  <xsl:call-template name="check.id.unique">
206    <xsl:with-param name="linkend" select="@linkend"/>
207  </xsl:call-template>
208
209  <fo:basic-link internal-destination="{@linkend}"
210                 xsl:use-attribute-sets="xref.properties">
211    <xsl:apply-templates/>
212  </fo:basic-link>
213</xsl:template>
214
215<xsl:template match="ulink">
216  <fo:basic-link external-destination="{@url}"
217                 xsl:use-attribute-sets="xref.properties">
218    <xsl:choose>
219      <xsl:when test="count(child::node())=0">
220	<xsl:value-of select="@url"/>
221      </xsl:when>
222      <xsl:otherwise>
223	<xsl:apply-templates/>
224      </xsl:otherwise>
225    </xsl:choose>
226  </fo:basic-link>
227  <xsl:if test="count(child::node()) != 0">
228    <fo:inline hyphenate="false">
229      <xsl:text> [</xsl:text>
230      <xsl:value-of select="@url"/>
231      <xsl:text>]</xsl:text>
232    </fo:inline>
233  </xsl:if>
234</xsl:template>
235
236<xsl:template match="olink">
237  <xsl:apply-templates/>
238</xsl:template>
239
240<!-- ==================================================================== -->
241
242<xsl:template name="title.xref">
243  <xsl:param name="target" select="."/>
244  <xsl:choose>
245    <xsl:when test="local-name($target) = 'figure'
246                    or local-name($target) = 'example'
247                    or local-name($target) = 'equation'
248                    or local-name($target) = 'table'
249                    or local-name($target) = 'dedication'
250                    or local-name($target) = 'preface'
251                    or local-name($target) = 'bibliography'
252                    or local-name($target) = 'glossary'
253                    or local-name($target) = 'index'
254                    or local-name($target) = 'setindex'
255                    or local-name($target) = 'colophon'">
256      <xsl:call-template name="gentext.startquote"/>
257      <xsl:apply-templates select="$target" mode="title.markup"/>
258      <xsl:call-template name="gentext.endquote"/>
259    </xsl:when>
260    <xsl:otherwise>
261      <fo:inline font-style="italic">
262        <xsl:apply-templates select="$target" mode="title.markup"/>
263      </fo:inline>
264    </xsl:otherwise>
265  </xsl:choose>
266</xsl:template>
267
268<xsl:template name="number.xref">
269  <xsl:param name="target" select="."/>
270  <xsl:apply-templates select="$target" mode="label.markup"/>
271</xsl:template>
272
273<!-- ==================================================================== -->
274
275<xsl:template name="xref.xreflabel">
276  <!-- called to process an xreflabel...you might use this to make  -->
277  <!-- xreflabels come out in the right font for different targets, -->
278  <!-- for example. -->
279  <xsl:param name="target" select="."/>
280  <xsl:value-of select="$target/@xreflabel"/>
281</xsl:template>
282
283<!-- ==================================================================== -->
284
285<xsl:template match="title" mode="xref">
286  <xsl:apply-templates/>
287</xsl:template>
288
289<xsl:template match="command" mode="xref">
290  <xsl:call-template name="inline.boldseq"/>
291</xsl:template>
292
293<xsl:template match="function" mode="xref">
294  <xsl:call-template name="inline.monoseq"/>
295</xsl:template>
296
297<xsl:template name="insert.page.citation">
298  <xsl:param name="id" select="'???'"/>
299  <xsl:if test="$insert.xref.page.number">
300    <xsl:text> </xsl:text>
301    <fo:inline keep-together.within-line="always">
302      <xsl:text>[</xsl:text>
303      <xsl:call-template name="gentext">
304        <xsl:with-param name="key" select="'page.citation'"/>
305      </xsl:call-template>
306      <xsl:text> </xsl:text>
307      <fo:page-number-citation ref-id="{$id}"/>
308      <xsl:text>]</xsl:text>
309    </fo:inline>
310  </xsl:if>
311</xsl:template>
312
313</xsl:stylesheet>
314