Project

General

Profile

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
                xmlns:exsl="http://exslt.org/common"
5
                exclude-result-prefixes="doc exsl"
6
                version='1.0'>
7

    
8
<!-- ********************************************************************
9
     $Id: targets.xsl 8366 2009-03-21 07:49:16Z bobstayton $
10
     ********************************************************************
11

    
12
     This file is part of the XSL DocBook Stylesheet distribution.
13
     See ../README or http://docbook.sf.net/release/xsl/current/ for
14
     copyright and other information.
15

    
16
     ******************************************************************** -->
17

    
18
<!-- ==================================================================== -->
19

    
20
<!-- cross reference target collection  -->
21

    
22
<doc:mode mode="collect.targets" xmlns="">
23
<refpurpose>Collects information for potential cross reference targets</refpurpose>
24
<refdescription id="collect.targets-desc">
25
<para>Processing the root element in the
26
<literal role="mode">collect.targets</literal> mode produces 
27
a set of target database elements that can be used by
28
the olink mechanism to resolve external cross references.
29
The collection process is controlled by the <literal>
30
collect.xref.targets</literal> parameter, which can be
31
<literal>yes</literal> to collect targets and process
32
the document for output, <literal>only</literal> to
33
only collect the targets, and <literal>no</literal>
34
(default) to not collect the targets and only process the document.
35
</para>
36
<para>
37
A <literal>targets.filename</literal> parameter must be
38
specified to receive the output if 
39
<literal>collect.xref.targets</literal> is
40
set to <literal>yes</literal> so as to
41
redirect the target data to a file separate from the
42
document output.
43
</para>
44
</refdescription>
45
</doc:mode>
46

    
47
<!-- ============================================================ -->
48

    
49
<xsl:template match="*" mode="collect.targets">
50
  <xsl:choose>
51
    <xsl:when test="$collect.xref.targets = 'yes' and $targets.filename = ''">
52
      <xsl:message>
53
        Must specify a $targets.filename parameter when
54
        $collect.xref.targets is set to 'yes'.
55
        The xref targets were not collected.
56
      </xsl:message>
57
    </xsl:when> 
58
    <xsl:otherwise>
59
      <xsl:choose>
60
        <xsl:when test="$targets.filename">
61
          <xsl:call-template name="write.chunk">
62
            <xsl:with-param name="filename" select="$targets.filename"/>
63
            <xsl:with-param name="method" select="'xml'"/>
64
            <xsl:with-param name="encoding" select="'utf-8'"/>
65
            <xsl:with-param name="omit-xml-declaration" select="'yes'"/>
66
            <xsl:with-param name="doctype-public" select="''"/>
67
            <xsl:with-param name="doctype-system" select="''"/>
68
            <xsl:with-param name="indent" select="'no'"/>
69
            <xsl:with-param name="quiet" select="0"/>
70
            <xsl:with-param name="content">
71
              <xsl:apply-templates select="." mode="olink.mode"/>
72
            </xsl:with-param>
73
          </xsl:call-template>
74
        </xsl:when>
75
        <xsl:otherwise>
76
          <!-- Else write to standard output -->
77
          <xsl:apply-templates select="." mode="olink.mode"/>
78
        </xsl:otherwise>
79
      </xsl:choose>
80
    </xsl:otherwise>
81
  </xsl:choose>
82
</xsl:template>
83

    
84
<xsl:template name="olink.href.target">
85
  <xsl:param name="nd" select="."/>
86

    
87
  <xsl:value-of select="$olink.base.uri"/>
88
  <xsl:call-template name="href.target">
89
    <xsl:with-param name="object" select="$nd"/>
90
    <xsl:with-param name="context" select="NOTANODE"/>
91
  </xsl:call-template>
92
</xsl:template>
93

    
94
<!-- Templates for extracting cross reference information
95
     from a document for use in an xref database.
96
-->
97

    
98
<xsl:template name="attrs">
99
  <xsl:param name="nd" select="."/>
100

    
101
  <xsl:attribute name="element">
102
    <xsl:value-of select="local-name(.)"/>
103
  </xsl:attribute>
104

    
105
  <xsl:attribute name="href">
106
    <xsl:call-template name="olink.href.target">
107
      <xsl:with-param name="nd" select="$nd"/>
108
    </xsl:call-template>
109
  </xsl:attribute>
110

    
111
  <xsl:variable name="num">
112
    <xsl:apply-templates select="$nd" mode="label.markup">
113
      <xsl:with-param name="verbose" select="0"/>
114
    </xsl:apply-templates>
115
  </xsl:variable>
116

    
117
  <xsl:if test="$num">
118
    <xsl:attribute name="number">
119
      <xsl:value-of select="$num"/>
120
    </xsl:attribute>
121
  </xsl:if>
122

    
123
  <xsl:choose>
124
    <xsl:when test="$nd/@id">
125
      <xsl:attribute name="targetptr">
126
        <xsl:value-of select="$nd/@id"/>
127
      </xsl:attribute>
128
    </xsl:when>
129
    <xsl:when test="$nd/@xml:id">
130
      <xsl:attribute name="targetptr">
131
        <xsl:value-of select="$nd/@xml:id"/>
132
      </xsl:attribute>
133
    </xsl:when>
134
  </xsl:choose>
135

    
136
  <xsl:if test="$nd/@lang">
137
    <xsl:attribute name="lang">
138
      <xsl:value-of select="$nd/@lang"/>
139
    </xsl:attribute>
140
  </xsl:if>
141

    
142
</xsl:template>
143

    
144
<xsl:template name="div">
145
  <xsl:param name="nd" select="."/>
146

    
147
  <div>
148
    <xsl:call-template name="attrs">
149
      <xsl:with-param name="nd" select="$nd"/>
150
    </xsl:call-template>
151
    <ttl>
152
      <xsl:apply-templates select="$nd" mode="title.markup">
153
        <xsl:with-param name="verbose" select="0"/>
154
      </xsl:apply-templates>
155
    </ttl>
156
    <xreftext>
157
      <xsl:choose>
158
        <xsl:when test="$nd/@xreflabel">
159
          <xsl:call-template name="xref.xreflabel">
160
            <xsl:with-param name="target" select="$nd"/>
161
          </xsl:call-template>
162
        </xsl:when>
163
        <xsl:otherwise>
164
          <xsl:apply-templates select="$nd" mode="xref-to">
165
            <xsl:with-param name="verbose" select="0"/>
166
          </xsl:apply-templates>
167
        </xsl:otherwise>
168
      </xsl:choose>
169
    </xreftext>
170
    <xsl:apply-templates mode="olink.mode"/>
171
  </div>
172
</xsl:template>
173

    
174
<xsl:template name="obj">
175
  <xsl:param name="nd" select="."/>
176

    
177
  <obj>
178
    <xsl:call-template name="attrs">
179
      <xsl:with-param name="nd" select="$nd"/>
180
    </xsl:call-template>
181
    <ttl>
182
      <xsl:apply-templates select="$nd" mode="title.markup">
183
        <xsl:with-param name="verbose" select="0"/>
184
      </xsl:apply-templates>
185
    </ttl>
186
    <xreftext>
187
      <xsl:choose>
188
        <xsl:when test="$nd/@xreflabel">
189
          <xsl:call-template name="xref.xreflabel">
190
            <xsl:with-param name="target" select="$nd"/>
191
          </xsl:call-template>
192
        </xsl:when>
193
        <xsl:otherwise>
194
          <xsl:apply-templates select="$nd" mode="xref-to">
195
            <xsl:with-param name="verbose" select="0"/>
196
          </xsl:apply-templates>
197
        </xsl:otherwise>
198
      </xsl:choose>
199
    </xreftext>
200
  </obj>
201
</xsl:template>
202

    
203
<xsl:template match="text()|processing-instruction()|comment()"
204
              mode="olink.mode">
205
  <!-- nop -->
206
</xsl:template>
207

    
208
<!--
209
<xsl:template match="*" mode="olink.mode">
210
</xsl:template>
211
-->
212

    
213
<xsl:template match="set" mode="olink.mode">
214
  <xsl:call-template name="div"/>
215
</xsl:template>
216

    
217
<xsl:template match="book" mode="olink.mode">
218
  <xsl:call-template name="div"/>
219
</xsl:template>
220

    
221
<xsl:template match="preface|chapter|appendix" mode="olink.mode">
222
  <xsl:call-template name="div"/>
223
</xsl:template>
224

    
225
<xsl:template match="part|reference" mode="olink.mode">
226
  <xsl:call-template name="div"/>
227
</xsl:template>
228

    
229
<xsl:template match="article" mode="olink.mode">
230
  <xsl:call-template name="div"/>
231
</xsl:template>
232

    
233
<xsl:template match="bibliography|bibliodiv" mode="olink.mode">
234
  <xsl:call-template name="div"/>
235
</xsl:template>
236

    
237
<xsl:template match="biblioentry|bibliomixed" mode="olink.mode">
238
  <xsl:call-template name="obj"/>
239
</xsl:template>
240

    
241
<xsl:template match="refentry" mode="olink.mode">
242
  <xsl:call-template name="div"/>
243
</xsl:template>
244

    
245
<xsl:template match="section|sect1|sect2|sect3|sect4|sect5" mode="olink.mode">
246
  <xsl:call-template name="div"/>
247
</xsl:template>
248

    
249
<xsl:template match="refsection|refsect1|refsect2|refsect3" mode="olink.mode">
250
  <xsl:call-template name="div"/>
251
</xsl:template>
252

    
253
<xsl:template match="figure|example|table" mode="olink.mode">
254
  <xsl:call-template name="obj"/>
255
  <xsl:apply-templates mode="olink.mode"/>
256
</xsl:template>
257

    
258
<xsl:template match="equation[title or info/title]" mode="olink.mode">
259
  <xsl:call-template name="obj"/>
260
</xsl:template>
261

    
262
<xsl:template match="qandaset|qandaentry" mode="olink.mode">
263
  <xsl:call-template name="div"/>
264
</xsl:template>
265

    
266
<!-- handle an glossary collection -->
267
<xsl:template match="glossary[@role='auto']" mode="olink.mode" priority="2">
268
  <xsl:variable name="collection" select="document($glossary.collection, .)"/>
269
  <xsl:if test="$glossary.collection = ''">
270
    <xsl:message>
271
      <xsl:text>Warning: processing automatic glossary </xsl:text>
272
      <xsl:text>without a glossary.collection file.</xsl:text>
273
    </xsl:message>
274
  </xsl:if>
275

    
276
  <xsl:if test="not($collection) and $glossary.collection != ''">
277
    <xsl:message>
278
      <xsl:text>Warning: processing automatic glossary but unable to </xsl:text>
279
      <xsl:text>open glossary.collection file '</xsl:text>
280
      <xsl:value-of select="$glossary.collection"/>
281
      <xsl:text>'</xsl:text>
282
    </xsl:message>
283
  </xsl:if>
284

    
285

    
286
  <xsl:if test="$exsl.node.set.available != 0">
287
    <xsl:variable name="auto.glossary">
288
      <xsl:apply-templates select="." mode="assemble.auto.glossary"/>
289
    </xsl:variable>
290
    <xsl:variable name="auto.glossary.nodeset" select="exsl:node-set($auto.glossary)"/>
291
    <xsl:apply-templates select="$auto.glossary.nodeset/*" mode="olink.mode"/>
292
  </xsl:if>
293

    
294
</xsl:template>
295

    
296
<!-- construct a glossary in memory -->
297
<xsl:template match="glossary" mode="assemble.auto.glossary">
298
  <xsl:copy>
299
    <xsl:copy-of select="@*[not(local-name() = 'role')]"/>
300
    <xsl:apply-templates select="node()" mode="assemble.auto.glossary"/>
301
    <xsl:call-template name="select.glossentries"/>
302
  </xsl:copy>
303
</xsl:template>
304

    
305
<xsl:template name="select.glossentries">
306
  <xsl:param name="collection" select="document($glossary.collection, .)"/>
307
  <xsl:param name="terms" select="//glossterm[not(parent::glossdef)]|//firstterm"/>
308

    
309
  <xsl:for-each select="$collection//glossentry">
310
    <xsl:variable name="cterm" select="glossterm"/>
311
    <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
312
      <xsl:copy-of select="."/>
313
    </xsl:if>
314
  </xsl:for-each>
315
</xsl:template>
316

    
317
<xsl:template match="glossentry" mode="assemble.auto.glossary">
318
  <!-- skip the dummy entries -->
319
</xsl:template>
320

    
321
<xsl:template match="*" mode="assemble.auto.glossary">
322
  <!-- pass through any titles and intro stuff -->
323
  <xsl:copy-of select="."/>
324
</xsl:template>
325

    
326
<xsl:template match="*" mode="olink.mode">
327
  <xsl:if test="@id or @xml:id">
328
    <xsl:call-template name="obj"/>
329
  </xsl:if> 
330
  <xsl:apply-templates mode="olink.mode"/>
331
</xsl:template>
332

    
333
</xsl:stylesheet>
(67-67/78)