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: targets.xsl,v 1.11 2005/12/29 19:27:24 bobstayton Exp $
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<!-- cross reference target collection  -->
20
21<doc:mode mode="collect.targets" xmlns="">
22<refpurpose>Collects information for potential cross reference targets</refpurpose>
23<refdescription>
24<para>Processing the root element in the
25<literal role="mode">collect.targets</literal> mode produces 
26a set of target database elements that can be used by
27the olink mechanism to resolve external cross references.
28The collection process is controlled by the <literal>
29collect.xref.targets</literal> parameter, which can be
30<literal>yes</literal> to collect targets and process
31the document for output, <literal>only</literal> to
32only collect the targets, and <literal>no</literal>
33(default) to not collect the targets and only process the document.
34</para>
35<para>
36A <literal>targets.filename</literal> parameter must be
37specified to receive the output if 
38<literal>collect.xref.targets</literal> is
39set to <literal>yes</literal> so as to
40redirect the target data to a file separate from the
41document output.
42</para>
43</refdescription>
44</doc:mode>
45
46<!-- ============================================================ -->
47
48<xsl:template match="*" mode="collect.targets">
49  <xsl:choose>
50    <xsl:when test="$collect.xref.targets = 'yes' and $targets.filename = ''">
51      <xsl:message>
52        Must specify a $targets.filename parameter when
53        $collect.xref.targets is set to 'yes'.
54        The xref targets were not collected.
55      </xsl:message>
56    </xsl:when> 
57    <xsl:otherwise>
58      <xsl:choose>
59        <xsl:when test="$targets.filename">
60          <xsl:call-template name="write.chunk">
61            <xsl:with-param name="filename" select="$targets.filename"/>
62            <xsl:with-param name="method" select="'xml'"/>
63            <xsl:with-param name="encoding" select="'utf-8'"/>
64            <xsl:with-param name="omit-xml-declaration" select="'yes'"/>
65            <xsl:with-param name="doctype-public" select="''"/>
66            <xsl:with-param name="doctype-system" select="''"/>
67            <xsl:with-param name="indent" select="'yes'"/>
68            <xsl:with-param name="quiet" select="0"/>
69            <xsl:with-param name="content">
70              <xsl:apply-templates select="." mode="olink.mode"/>
71            </xsl:with-param>
72          </xsl:call-template>
73        </xsl:when>
74        <xsl:otherwise>
75          <!-- Else write to standard output -->
76          <xsl:apply-templates select="." mode="olink.mode"/>
77        </xsl:otherwise>
78      </xsl:choose>
79    </xsl:otherwise>
80  </xsl:choose>
81</xsl:template>
82
83<xsl:template name="olink.href.target">
84  <xsl:param name="nd" select="."/>
85
86  <xsl:value-of select="$olink.base.uri"/>
87  <xsl:call-template name="href.target">
88    <xsl:with-param name="object" select="$nd"/>
89  </xsl:call-template>
90</xsl:template>
91
92<!-- Templates for extracting cross reference information
93     from a document for use in an xref database.
94-->
95
96<xsl:template name="attrs">
97  <xsl:param name="nd" select="."/>
98
99  <xsl:attribute name="element">
100    <xsl:value-of select="local-name(.)"/>
101  </xsl:attribute>
102
103  <xsl:attribute name="href">
104    <xsl:call-template name="olink.href.target">
105      <xsl:with-param name="nd" select="$nd"/>
106    </xsl:call-template>
107  </xsl:attribute>
108
109  <xsl:variable name="num">
110    <xsl:apply-templates select="$nd" mode="label.markup">
111      <xsl:with-param name="verbose" select="0"/>
112    </xsl:apply-templates>
113  </xsl:variable>
114
115  <xsl:if test="$num">
116    <xsl:attribute name="number">
117      <xsl:value-of select="$num"/>
118    </xsl:attribute>
119  </xsl:if>
120
121  <xsl:choose>
122    <xsl:when test="$nd/@id">
123      <xsl:attribute name="targetptr">
124        <xsl:value-of select="$nd/@id"/>
125      </xsl:attribute>
126    </xsl:when>
127    <xsl:when test="$nd/@xml:id">
128      <xsl:attribute name="targetptr">
129        <xsl:value-of select="$nd/@xml:id"/>
130      </xsl:attribute>
131    </xsl:when>
132  </xsl:choose>
133
134  <xsl:if test="$nd/@lang">
135    <xsl:attribute name="lang">
136      <xsl:value-of select="$nd/@lang"/>
137    </xsl:attribute>
138  </xsl:if>
139
140</xsl:template>
141
142<xsl:template name="div">
143  <xsl:param name="nd" select="."/>
144
145  <div>
146    <xsl:call-template name="attrs">
147      <xsl:with-param name="nd" select="$nd"/>
148    </xsl:call-template>
149    <ttl>
150      <xsl:apply-templates select="$nd" mode="title.markup">
151        <xsl:with-param name="verbose" select="0"/>
152      </xsl:apply-templates>
153    </ttl>
154    <xreftext>
155      <xsl:choose>
156        <xsl:when test="$nd/@xreflabel">
157          <xsl:call-template name="xref.xreflabel">
158            <xsl:with-param name="target" select="$nd"/>
159          </xsl:call-template>
160        </xsl:when>
161        <xsl:otherwise>
162          <xsl:apply-templates select="$nd" mode="xref-to">
163            <xsl:with-param name="verbose" select="0"/>
164          </xsl:apply-templates>
165        </xsl:otherwise>
166      </xsl:choose>
167    </xreftext>
168    <xsl:apply-templates mode="olink.mode"/>
169  </div>
170</xsl:template>
171
172<xsl:template name="obj">
173  <xsl:param name="nd" select="."/>
174
175  <obj>
176    <xsl:call-template name="attrs">
177      <xsl:with-param name="nd" select="$nd"/>
178    </xsl:call-template>
179    <ttl>
180      <xsl:apply-templates select="$nd" mode="title.markup">
181        <xsl:with-param name="verbose" select="0"/>
182      </xsl:apply-templates>
183    </ttl>
184    <xreftext>
185      <xsl:choose>
186        <xsl:when test="$nd/@xreflabel">
187          <xsl:call-template name="xref.xreflabel">
188            <xsl:with-param name="target" select="$nd"/>
189          </xsl:call-template>
190        </xsl:when>
191        <xsl:otherwise>
192          <xsl:apply-templates select="$nd" mode="xref-to">
193            <xsl:with-param name="verbose" select="0"/>
194          </xsl:apply-templates>
195        </xsl:otherwise>
196      </xsl:choose>
197    </xreftext>
198  </obj>
199</xsl:template>
200
201<xsl:template match="text()|processing-instruction()|comment()"
202              mode="olink.mode">
203  <!-- nop -->
204</xsl:template>
205
206<!--
207<xsl:template match="*" mode="olink.mode">
208</xsl:template>
209-->
210
211<xsl:template match="set" mode="olink.mode">
212  <xsl:call-template name="div"/>
213</xsl:template>
214
215<xsl:template match="book" mode="olink.mode">
216  <xsl:call-template name="div"/>
217</xsl:template>
218
219<xsl:template match="preface|chapter|appendix" mode="olink.mode">
220  <xsl:call-template name="div"/>
221</xsl:template>
222
223<xsl:template match="part|reference" mode="olink.mode">
224  <xsl:call-template name="div"/>
225</xsl:template>
226
227<xsl:template match="article" mode="olink.mode">
228  <xsl:call-template name="div"/>
229</xsl:template>
230
231<xsl:template match="bibliography|bibliodiv" mode="olink.mode">
232  <xsl:call-template name="div"/>
233</xsl:template>
234
235<xsl:template match="biblioentry|bibliomixed" mode="olink.mode">
236  <xsl:call-template name="obj"/>
237</xsl:template>
238
239<xsl:template match="refentry" mode="olink.mode">
240  <xsl:call-template name="div"/>
241</xsl:template>
242
243<xsl:template match="section|sect1|sect2|sect3|sect4|sect5" mode="olink.mode">
244  <xsl:call-template name="div"/>
245</xsl:template>
246
247<xsl:template match="refsection|refsect1|refsect2|refsect3" mode="olink.mode">
248  <xsl:call-template name="div"/>
249</xsl:template>
250
251<xsl:template match="figure|example|table" mode="olink.mode">
252  <xsl:call-template name="obj"/>
253  <xsl:apply-templates mode="olink.mode"/>
254</xsl:template>
255
256<xsl:template match="equation[title]" mode="olink.mode">
257  <xsl:call-template name="obj"/>
258</xsl:template>
259
260<xsl:template match="qandaset|qandaentry" mode="olink.mode">
261  <xsl:call-template name="div"/>
262</xsl:template>
263
264<xsl:template match="*" mode="olink.mode">
265  <xsl:if test="@id or @xml:id">
266    <xsl:call-template name="obj"/>
267  </xsl:if> 
268  <xsl:apply-templates mode="olink.mode"/>
269</xsl:template>
270
271</xsl:stylesheet>
272