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"
8 <!-- ********************************************************************
9 $Id: targets.xsl 8366 2009-03-21 07:49:16Z bobstayton $
10 ********************************************************************
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.
16 ******************************************************************** -->
18 <!-- ==================================================================== -->
20 <!-- cross reference target collection -->
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.
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
47 <!-- ============================================================ -->
49 <xsl:template match="*" mode="collect.targets">
51 <xsl:when test="$collect.xref.targets = 'yes' and $targets.filename = ''">
53 Must specify a $targets.filename parameter when
54 $collect.xref.targets is set to 'yes'.
55 The xref targets were not collected.
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"/>
76 <!-- Else write to standard output -->
77 <xsl:apply-templates select="." mode="olink.mode"/>
84 <xsl:template name="olink.href.target">
85 <xsl:param name="nd" select="."/>
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"/>
94 <!-- Templates for extracting cross reference information
95 from a document for use in an xref database.
98 <xsl:template name="attrs">
99 <xsl:param name="nd" select="."/>
101 <xsl:attribute name="element">
102 <xsl:value-of select="local-name(.)"/>
105 <xsl:attribute name="href">
106 <xsl:call-template name="olink.href.target">
107 <xsl:with-param name="nd" select="$nd"/>
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>
118 <xsl:attribute name="number">
119 <xsl:value-of select="$num"/>
124 <xsl:when test="$nd/@id">
125 <xsl:attribute name="targetptr">
126 <xsl:value-of select="$nd/@id"/>
129 <xsl:when test="$nd/@xml:id">
130 <xsl:attribute name="targetptr">
131 <xsl:value-of select="$nd/@xml:id"/>
136 <xsl:if test="$nd/@lang">
137 <xsl:attribute name="lang">
138 <xsl:value-of select="$nd/@lang"/>
144 <xsl:template name="div">
145 <xsl:param name="nd" select="."/>
148 <xsl:call-template name="attrs">
149 <xsl:with-param name="nd" select="$nd"/>
152 <xsl:apply-templates select="$nd" mode="title.markup">
153 <xsl:with-param name="verbose" select="0"/>
154 </xsl:apply-templates>
158 <xsl:when test="$nd/@xreflabel">
159 <xsl:call-template name="xref.xreflabel">
160 <xsl:with-param name="target" select="$nd"/>
164 <xsl:apply-templates select="$nd" mode="xref-to">
165 <xsl:with-param name="verbose" select="0"/>
166 </xsl:apply-templates>
170 <xsl:apply-templates mode="olink.mode"/>
174 <xsl:template name="obj">
175 <xsl:param name="nd" select="."/>
178 <xsl:call-template name="attrs">
179 <xsl:with-param name="nd" select="$nd"/>
182 <xsl:apply-templates select="$nd" mode="title.markup">
183 <xsl:with-param name="verbose" select="0"/>
184 </xsl:apply-templates>
188 <xsl:when test="$nd/@xreflabel">
189 <xsl:call-template name="xref.xreflabel">
190 <xsl:with-param name="target" select="$nd"/>
194 <xsl:apply-templates select="$nd" mode="xref-to">
195 <xsl:with-param name="verbose" select="0"/>
196 </xsl:apply-templates>
203 <xsl:template match="text()|processing-instruction()|comment()"
209 <xsl:template match="*" mode="olink.mode">
213 <xsl:template match="set" mode="olink.mode">
214 <xsl:call-template name="div"/>
217 <xsl:template match="book" mode="olink.mode">
218 <xsl:call-template name="div"/>
221 <xsl:template match="preface|chapter|appendix" mode="olink.mode">
222 <xsl:call-template name="div"/>
225 <xsl:template match="part|reference" mode="olink.mode">
226 <xsl:call-template name="div"/>
229 <xsl:template match="article" mode="olink.mode">
230 <xsl:call-template name="div"/>
233 <xsl:template match="bibliography|bibliodiv" mode="olink.mode">
234 <xsl:call-template name="div"/>
237 <xsl:template match="biblioentry|bibliomixed" mode="olink.mode">
238 <xsl:call-template name="obj"/>
241 <xsl:template match="refentry" mode="olink.mode">
242 <xsl:call-template name="div"/>
245 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5" mode="olink.mode">
246 <xsl:call-template name="div"/>
249 <xsl:template match="refsection|refsect1|refsect2|refsect3" mode="olink.mode">
250 <xsl:call-template name="div"/>
253 <xsl:template match="figure|example|table" mode="olink.mode">
254 <xsl:call-template name="obj"/>
255 <xsl:apply-templates mode="olink.mode"/>
258 <xsl:template match="equation[title or info/title]" mode="olink.mode">
259 <xsl:call-template name="obj"/>
262 <xsl:template match="qandaset|qandaentry" mode="olink.mode">
263 <xsl:call-template name="div"/>
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 = ''">
271 <xsl:text>Warning: processing automatic glossary </xsl:text>
272 <xsl:text>without a glossary.collection file.</xsl:text>
276 <xsl:if test="not($collection) and $glossary.collection != ''">
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>
286 <xsl:if test="$exsl.node.set.available != 0">
287 <xsl:variable name="auto.glossary">
288 <xsl:apply-templates select="." mode="assemble.auto.glossary"/>
290 <xsl:variable name="auto.glossary.nodeset" select="exsl:node-set($auto.glossary)"/>
291 <xsl:apply-templates select="$auto.glossary.nodeset/*" mode="olink.mode"/>
296 <!-- construct a glossary in memory -->
297 <xsl:template match="glossary" mode="assemble.auto.glossary">
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"/>
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"/>
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="."/>
317 <xsl:template match="glossentry" mode="assemble.auto.glossary">
318 <!-- skip the dummy entries -->
321 <xsl:template match="*" mode="assemble.auto.glossary">
322 <!-- pass through any titles and intro stuff -->
323 <xsl:copy-of select="."/>
326 <xsl:template match="*" mode="olink.mode">
327 <xsl:if test="@id or @xml:id">
328 <xsl:call-template name="obj"/>
330 <xsl:apply-templates mode="olink.mode"/>