OLD | NEW |
| (Empty) |
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 9286 2012-04-19 10:10:58Z 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</refpurpo
se> | |
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="topic" mode="olink.mode"> | |
234 <xsl:call-template name="div"/> | |
235 </xsl:template> | |
236 | |
237 <xsl:template match="bibliography|bibliodiv" mode="olink.mode"> | |
238 <xsl:call-template name="div"/> | |
239 </xsl:template> | |
240 | |
241 <xsl:template match="biblioentry|bibliomixed" mode="olink.mode"> | |
242 <xsl:call-template name="obj"/> | |
243 </xsl:template> | |
244 | |
245 <xsl:template match="refentry" mode="olink.mode"> | |
246 <xsl:call-template name="div"/> | |
247 </xsl:template> | |
248 | |
249 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5" mode="olink.mode"> | |
250 <xsl:call-template name="div"/> | |
251 </xsl:template> | |
252 | |
253 <xsl:template match="refsection|refsect1|refsect2|refsect3" mode="olink.mode"> | |
254 <xsl:call-template name="div"/> | |
255 </xsl:template> | |
256 | |
257 <xsl:template match="figure|example|table" mode="olink.mode"> | |
258 <xsl:call-template name="obj"/> | |
259 <xsl:apply-templates mode="olink.mode"/> | |
260 </xsl:template> | |
261 | |
262 <xsl:template match="equation[title or info/title]" mode="olink.mode"> | |
263 <xsl:call-template name="obj"/> | |
264 </xsl:template> | |
265 | |
266 <xsl:template match="qandaset|qandaentry" mode="olink.mode"> | |
267 <xsl:call-template name="div"/> | |
268 </xsl:template> | |
269 | |
270 <!-- handle an glossary collection --> | |
271 <xsl:template match="glossary[@role='auto']" mode="olink.mode" priority="2"> | |
272 <xsl:variable name="collection" select="document($glossary.collection, .)"/> | |
273 <xsl:if test="$glossary.collection = ''"> | |
274 <xsl:message> | |
275 <xsl:text>Warning: processing automatic glossary </xsl:text> | |
276 <xsl:text>without a glossary.collection file.</xsl:text> | |
277 </xsl:message> | |
278 </xsl:if> | |
279 | |
280 <xsl:if test="not($collection) and $glossary.collection != ''"> | |
281 <xsl:message> | |
282 <xsl:text>Warning: processing automatic glossary but unable to </xsl:text> | |
283 <xsl:text>open glossary.collection file '</xsl:text> | |
284 <xsl:value-of select="$glossary.collection"/> | |
285 <xsl:text>'</xsl:text> | |
286 </xsl:message> | |
287 </xsl:if> | |
288 | |
289 | |
290 <xsl:if test="$exsl.node.set.available != 0"> | |
291 <xsl:variable name="auto.glossary"> | |
292 <xsl:apply-templates select="." mode="assemble.auto.glossary"/> | |
293 </xsl:variable> | |
294 <xsl:variable name="auto.glossary.nodeset" select="exsl:node-set($auto.gloss
ary)"/> | |
295 <xsl:apply-templates select="$auto.glossary.nodeset/*" mode="olink.mode"/> | |
296 </xsl:if> | |
297 | |
298 </xsl:template> | |
299 | |
300 <!-- construct a glossary in memory --> | |
301 <xsl:template match="glossary" mode="assemble.auto.glossary"> | |
302 <xsl:copy> | |
303 <xsl:copy-of select="@*[not(local-name() = 'role')]"/> | |
304 <xsl:apply-templates select="node()" mode="assemble.auto.glossary"/> | |
305 <xsl:call-template name="select.glossentries"/> | |
306 </xsl:copy> | |
307 </xsl:template> | |
308 | |
309 <xsl:template name="select.glossentries"> | |
310 <xsl:param name="collection" select="document($glossary.collection, .)"/> | |
311 <xsl:param name="terms" select="//glossterm[not(parent::glossdef)]|//firstterm
"/> | |
312 | |
313 <xsl:for-each select="$collection//glossentry"> | |
314 <xsl:variable name="cterm" select="glossterm"/> | |
315 <xsl:if test="$terms[@baseform = $cterm or . = $cterm]"> | |
316 <xsl:copy-of select="."/> | |
317 </xsl:if> | |
318 </xsl:for-each> | |
319 </xsl:template> | |
320 | |
321 <xsl:template match="glossentry" mode="assemble.auto.glossary"> | |
322 <!-- skip the dummy entries --> | |
323 </xsl:template> | |
324 | |
325 <xsl:template match="*" mode="assemble.auto.glossary"> | |
326 <!-- pass through any titles and intro stuff --> | |
327 <xsl:copy-of select="."/> | |
328 </xsl:template> | |
329 | |
330 <xsl:template match="*" mode="olink.mode"> | |
331 <xsl:if test="@id or @xml:id"> | |
332 <xsl:call-template name="obj"/> | |
333 </xsl:if> | |
334 <xsl:apply-templates mode="olink.mode"/> | |
335 </xsl:template> | |
336 | |
337 </xsl:stylesheet> | |
OLD | NEW |