]> git.lyx.org Git - lyx.git/blob - lib/docbook/common/targets.xsl
Release notes
[lyx.git] / lib / docbook / common / targets.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:d="http://docbook.org/ns/docbook"
4                 xmlns:doc="http://nwalsh.com/xsl/documentation/1.0"
5                 xmlns:exsl="http://exslt.org/common"
6                 exclude-result-prefixes="doc exsl d"
7                 version='1.0'>
8
9 <!-- ********************************************************************
10
11      This file is part of the XSL DocBook Stylesheet distribution.
12      See ../README or http://cdn.docbook.org/release/xsl/current/ for
13      copyright 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 id="collect.targets-desc">
24 <para>Processing the root element in the
25 <literal role="mode">collect.targets</literal> mode produces 
26 a set of target database elements that can be used by
27 the olink mechanism to resolve external cross references.
28 The collection process is controlled by the <literal>
29 collect.xref.targets</literal> parameter, which can be
30 <literal>yes</literal> to collect targets and process
31 the document for output, <literal>only</literal> to
32 only collect the targets, and <literal>no</literal>
33 (default) to not collect the targets and only process the document.
34 </para>
35 <para>
36 A <literal>targets.filename</literal> parameter must be
37 specified to receive the output if 
38 <literal>collect.xref.targets</literal> is
39 set to <literal>yes</literal> so as to
40 redirect the target data to a file separate from the
41 document 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="'no'"/>
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:with-param name="context" select="NOTANODE"/>
90   </xsl:call-template>
91 </xsl:template>
92
93 <!-- Templates for extracting cross reference information
94      from a document for use in an xref database.
95 -->
96
97 <xsl:template name="attrs">
98   <xsl:param name="nd" select="."/>
99
100   <xsl:attribute name="element">
101     <xsl:value-of select="local-name(.)"/>
102   </xsl:attribute>
103
104   <xsl:attribute name="href">
105     <xsl:call-template name="olink.href.target">
106       <xsl:with-param name="nd" select="$nd"/>
107     </xsl:call-template>
108   </xsl:attribute>
109
110   <xsl:variable name="num">
111     <xsl:apply-templates select="$nd" mode="label.markup">
112       <xsl:with-param name="verbose" select="0"/>
113     </xsl:apply-templates>
114   </xsl:variable>
115
116   <xsl:if test="$num">
117     <xsl:attribute name="number">
118       <xsl:value-of select="$num"/>
119     </xsl:attribute>
120   </xsl:if>
121
122   <xsl:choose>
123     <xsl:when test="$nd/@id">
124       <xsl:attribute name="targetptr">
125         <xsl:value-of select="$nd/@id"/>
126       </xsl:attribute>
127     </xsl:when>
128     <xsl:when test="$nd/@xml:id">
129       <xsl:attribute name="targetptr">
130         <xsl:value-of select="$nd/@xml:id"/>
131       </xsl:attribute>
132     </xsl:when>
133   </xsl:choose>
134
135   <xsl:if test="$nd/@lang">
136     <xsl:attribute name="lang">
137       <xsl:value-of select="$nd/@lang"/>
138     </xsl:attribute>
139   </xsl:if>
140
141 </xsl:template>
142
143 <xsl:template name="div">
144   <xsl:param name="nd" select="."/>
145
146   <div>
147     <xsl:call-template name="attrs">
148       <xsl:with-param name="nd" select="$nd"/>
149     </xsl:call-template>
150     <ttl>
151       <xsl:apply-templates select="$nd" mode="title.markup">
152         <xsl:with-param name="verbose" select="0"/>
153       </xsl:apply-templates>
154     </ttl>
155     <xreftext>
156       <xsl:choose>
157         <xsl:when test="$nd/@xreflabel">
158           <xsl:call-template name="xref.xreflabel">
159             <xsl:with-param name="target" select="$nd"/>
160           </xsl:call-template>
161         </xsl:when>
162         <xsl:otherwise>
163           <xsl:apply-templates select="$nd" mode="xref-to">
164             <xsl:with-param name="verbose" select="0"/>
165           </xsl:apply-templates>
166         </xsl:otherwise>
167       </xsl:choose>
168     </xreftext>
169     <xsl:apply-templates mode="olink.mode"/>
170   </div>
171 </xsl:template>
172
173 <xsl:template name="obj">
174   <xsl:param name="nd" select="."/>
175
176   <obj>
177     <xsl:call-template name="attrs">
178       <xsl:with-param name="nd" select="$nd"/>
179     </xsl:call-template>
180     <ttl>
181       <xsl:apply-templates select="$nd" mode="title.markup">
182         <xsl:with-param name="verbose" select="0"/>
183       </xsl:apply-templates>
184     </ttl>
185     <xreftext>
186       <xsl:choose>
187         <xsl:when test="$nd/@xreflabel">
188           <xsl:call-template name="xref.xreflabel">
189             <xsl:with-param name="target" select="$nd"/>
190           </xsl:call-template>
191         </xsl:when>
192         <xsl:otherwise>
193           <xsl:apply-templates select="$nd" mode="xref-to">
194             <xsl:with-param name="verbose" select="0"/>
195           </xsl:apply-templates>
196         </xsl:otherwise>
197       </xsl:choose>
198     </xreftext>
199   </obj>
200 </xsl:template>
201
202 <xsl:template match="text()|processing-instruction()|comment()"
203               mode="olink.mode">
204   <!-- nop -->
205 </xsl:template>
206
207 <!--
208 <xsl:template match="*" mode="olink.mode">
209 </xsl:template>
210 -->
211
212 <xsl:template match="d:set" mode="olink.mode">
213   <xsl:call-template name="div"/>
214 </xsl:template>
215
216 <xsl:template match="d:book" mode="olink.mode">
217   <xsl:call-template name="div"/>
218 </xsl:template>
219
220 <xsl:template match="d:preface|d:chapter|d:appendix" mode="olink.mode">
221   <xsl:call-template name="div"/>
222 </xsl:template>
223
224 <xsl:template match="d:part|d:reference" mode="olink.mode">
225   <xsl:call-template name="div"/>
226 </xsl:template>
227
228 <xsl:template match="d:article" mode="olink.mode">
229   <xsl:call-template name="div"/>
230 </xsl:template>
231
232 <xsl:template match="d:topic" mode="olink.mode">
233   <xsl:call-template name="div"/>
234 </xsl:template>
235
236 <xsl:template match="d:bibliography|d:bibliodiv" mode="olink.mode">
237   <xsl:call-template name="div"/>
238 </xsl:template>
239
240 <xsl:template match="d:biblioentry|d:bibliomixed" mode="olink.mode">
241   <xsl:call-template name="obj"/>
242 </xsl:template>
243
244 <xsl:template match="d:refentry" mode="olink.mode">
245   <xsl:call-template name="div"/>
246 </xsl:template>
247
248 <xsl:template match="d:section|d:sect1|d:sect2|d:sect3|d:sect4|d:sect5" mode="olink.mode">
249   <xsl:call-template name="div"/>
250 </xsl:template>
251
252 <xsl:template match="d:refsection|d:refsect1|d:refsect2|d:refsect3" mode="olink.mode">
253   <xsl:call-template name="div"/>
254 </xsl:template>
255
256 <xsl:template match="d:figure|d:example|d:table" mode="olink.mode">
257   <xsl:call-template name="obj"/>
258   <xsl:apply-templates mode="olink.mode"/>
259 </xsl:template>
260
261 <xsl:template match="d:equation[d:title or d:info/d:title]" mode="olink.mode">
262   <xsl:call-template name="obj"/>
263 </xsl:template>
264
265 <xsl:template match="d:qandaset|d:qandaentry" mode="olink.mode">
266   <xsl:call-template name="div"/>
267 </xsl:template>
268
269 <!-- handle an glossary collection -->
270 <xsl:template match="d:glossary[@role='auto']" mode="olink.mode" priority="2">
271   <xsl:variable name="collection" select="document($glossary.collection, .)"/>
272   <xsl:if test="$glossary.collection = ''">
273     <xsl:message>
274       <xsl:text>Warning: processing automatic glossary </xsl:text>
275       <xsl:text>without a glossary.collection file.</xsl:text>
276     </xsl:message>
277   </xsl:if>
278
279   <xsl:if test="not($collection) and $glossary.collection != ''">
280     <xsl:message>
281       <xsl:text>Warning: processing automatic glossary but unable to </xsl:text>
282       <xsl:text>open glossary.collection file '</xsl:text>
283       <xsl:value-of select="$glossary.collection"/>
284       <xsl:text>'</xsl:text>
285     </xsl:message>
286   </xsl:if>
287
288
289   <xsl:if test="$exsl.node.set.available != 0">
290     <xsl:variable name="auto.glossary">
291       <xsl:apply-templates select="." mode="assemble.auto.glossary"/>
292     </xsl:variable>
293     <xsl:variable name="auto.glossary.nodeset" select="exsl:node-set($auto.glossary)"/>
294     <xsl:apply-templates select="$auto.glossary.nodeset/*" mode="olink.mode"/>
295   </xsl:if>
296
297 </xsl:template>
298
299 <!-- construct a glossary in memory -->
300 <xsl:template match="d:glossary" mode="assemble.auto.glossary">
301   <xsl:copy>
302     <xsl:copy-of select="@*[not(local-name() = 'role')]"/>
303     <xsl:apply-templates select="node()" mode="assemble.auto.glossary"/>
304     <xsl:call-template name="select.glossentries"/>
305   </xsl:copy>
306 </xsl:template>
307
308 <xsl:template name="select.glossentries">
309   <xsl:param name="collection" select="document($glossary.collection, .)"/>
310   <xsl:param name="terms" select="//d:glossterm[not(parent::d:glossdef)]|//d:firstterm"/>
311
312   <xsl:for-each select="$collection//d:glossentry">
313     <xsl:variable name="cterm" select="d:glossterm"/>
314     <xsl:if test="$terms[@baseform = $cterm or . = $cterm]">
315       <xsl:copy-of select="."/>
316     </xsl:if>
317   </xsl:for-each>
318 </xsl:template>
319
320 <xsl:template match="d:glossentry" mode="assemble.auto.glossary">
321   <!-- skip the dummy entries -->
322 </xsl:template>
323
324 <xsl:template match="*" mode="assemble.auto.glossary">
325   <!-- pass through any titles and intro stuff -->
326   <xsl:copy-of select="."/>
327 </xsl:template>
328
329 <xsl:template match="*" mode="olink.mode">
330   <xsl:if test="@id or @xml:id">
331     <xsl:call-template name="obj"/>
332   </xsl:if> 
333   <xsl:apply-templates mode="olink.mode"/>
334 </xsl:template>
335
336 </xsl:stylesheet>