Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/boostbook/xsl/lookup.xsl @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 12.9 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!--
3   Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
4 
5   Distributed under the Boost Software License, Version 1.0.
6   (See accompanying file LICENSE_1_0.txt or copy at
7   http://www.boost.org/LICENSE_1_0.txt)
8  -->
9<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10                version="1.0">
11
12  <xsl:param name="boost.max.id.length">26</xsl:param>
13
14  <!-- Generate an ID for the entity referenced -->
15  <xsl:template name="generate.id">
16    <xsl:param name="node" select="."/>
17    <xsl:apply-templates select="$node" mode="generate.id"/>
18  </xsl:template>
19
20  <xsl:template match="*" mode="generate.id">
21    <xsl:value-of select="generate-id(.)"/>
22    <xsl:text>-bb</xsl:text>
23  </xsl:template>
24
25  <!-- Strip the qualifiers off a qualified name and return the unqualified
26       name. For instance, "boost::python::function" would become just
27       "function". -->
28  <xsl:template name="strip-qualifiers">
29    <xsl:param name="name"/>
30    <xsl:choose>
31      <xsl:when test="contains($name, '::') and not(contains(substring-before($name, '::'), '&lt;'))">
32        <xsl:call-template name="strip-qualifiers">
33          <xsl:with-param name="name" select="substring-after($name, '::')"/>
34        </xsl:call-template>
35      </xsl:when>
36      <xsl:otherwise>
37        <xsl:value-of select="$name"/>
38      </xsl:otherwise>
39    </xsl:choose>
40  </xsl:template>
41
42  <!-- Build the fully-qualified name of the given node -->
43  <xsl:template name="fully-qualified-name">
44    <xsl:param name="node"/>
45    <xsl:param name="separator" select="'::'"/>
46    <xsl:apply-templates select="$node" mode="fully-qualified-name">
47      <xsl:with-param name="separator" select="$separator"/>
48    </xsl:apply-templates>
49  </xsl:template>
50
51  <!-- Hack to make the node we are building the current node so that the
52       ancestor:: syntax will work -->
53  <xsl:template match="*" mode="fully-qualified-name">
54    <xsl:param name="separator" select="'::'"/>
55    <xsl:call-template name="build-fully-qualified-name">
56      <xsl:with-param name="separator" select="$separator"/>
57    </xsl:call-template>
58  </xsl:template>
59
60  <!-- The real routine that builds a fully-qualified name for the current
61       node. -->
62  <xsl:template name="build-fully-qualified-name">
63    <xsl:param name="separator" select="'::'"/>
64
65    <!-- The depth of qualified name element that we will print now-->
66    <xsl:param name="depth" select="1"/>
67
68    <!-- Determine the set of ancestor namespaces -->
69    <xsl:variable name="ancestors" 
70      select="ancestor::namespace|ancestor::class|ancestor::struct|ancestor::union"/>
71
72    <xsl:choose>
73      <xsl:when test="$depth &gt; count($ancestors)">
74        <xsl:apply-templates select="." mode="print-name"/>
75      </xsl:when>
76      <xsl:otherwise>
77        <xsl:if test="name($ancestors[$depth])='namespace' or
78                      count(ancestor::free-function-group)=0">
79          <xsl:apply-templates select="$ancestors[$depth]" mode="print-name"/>
80          <xsl:value-of select="$separator"/>
81        </xsl:if>
82        <xsl:call-template name="build-fully-qualified-name">
83          <xsl:with-param name="separator" select="$separator"/>
84          <xsl:with-param name="depth" select="$depth + 1"/>
85        </xsl:call-template>
86      </xsl:otherwise>
87    </xsl:choose>
88  </xsl:template>
89
90  <!-- Print the name of the current node -->
91  <xsl:template match="*" mode="print-name">
92    <xsl:value-of select="@name"/>
93  </xsl:template>
94
95  <xsl:template name="name-matches-node">
96    <!-- The name we are looking for -->
97    <xsl:param name="name"/>
98
99    <!-- The name to display -->
100    <xsl:param name="display-name" select="$name"/>
101
102    <!-- The context in which this name occurs -->
103    <xsl:param name="context"/>
104
105    <!-- The node that we are checking against -->
106    <xsl:param name="node"/>
107
108    <!-- The mode we are in. Can be one of:
109           matches: emits the matches as they are found (for debugging)
110           link: link to the node that was found
111         -->
112    <xsl:param name="mode" select="'matches'"/>
113
114    <!-- The index into the list of using directives for the context node -->
115    <xsl:param name="index" select="1"/>
116
117    <!-- The prefix we should append to the name when checking this node -->
118    <xsl:param name="prefix" select="''"/>
119
120    <xsl:choose>
121      <xsl:when test="count($node) &gt; 1">
122        <xsl:variable name="matches">
123          <xsl:call-template name="count-matches">
124            <xsl:with-param name="name" select="$name"/>
125            <xsl:with-param name="context" select="$context"/>
126            <xsl:with-param name="nodes" select="$node[position() = 1]"/>
127          </xsl:call-template>
128        </xsl:variable>
129
130        <xsl:choose>
131          <xsl:when test="$matches = 0">
132            <xsl:call-template name="name-matches-node">
133              <xsl:with-param name="name" select="$name"/>
134              <xsl:with-param name="display-name" select="$display-name"/>
135              <xsl:with-param name="context" select="$context"/>
136              <xsl:with-param name="node" select="$node[position() &gt; 1]"/>
137              <xsl:with-param name="mode" select="$mode"/>
138            </xsl:call-template>
139          </xsl:when>
140          <xsl:otherwise>
141            <xsl:call-template name="name-matches-node">
142              <xsl:with-param name="name" select="$name"/>
143              <xsl:with-param name="display-name" select="$display-name"/>
144              <xsl:with-param name="context" select="$context"/>
145              <xsl:with-param name="node" select="$node[position() = 1]"/>
146              <xsl:with-param name="mode" select="$mode"/>
147            </xsl:call-template>
148          </xsl:otherwise>
149        </xsl:choose>
150      </xsl:when>
151      <xsl:when test="count($node) = 1">
152        <!-- The fully-qualified name of the node we are checking against -->
153        <xsl:variable name="fully-qualified-name">
154          <xsl:call-template name="fully-qualified-name">
155            <xsl:with-param name="node" select="$node"/>
156          </xsl:call-template>
157        </xsl:variable>
158       
159        <!-- The set of using directives for this context node -->
160        <xsl:variable name="directives"
161          select="$context/ancestor::*/using-namespace |
162                  $context/ancestor::namespace |
163                  $context/ancestor::*/using-class |
164                  $context/ancestor::class"/>
165       
166        <!-- The name of the current directive -->
167        <xsl:variable name="this-context">
168          <xsl:apply-templates select="$directives[$index]" mode="print-name"/>
169        </xsl:variable>
170       
171        <!-- Check if we have a match -->
172        <xsl:variable name="have-match" 
173          select="$fully-qualified-name = concat($prefix, $name)"/>
174       
175        <xsl:if test="$have-match">
176          <xsl:choose>
177            <xsl:when test="$mode='matches'">
178              Match in namespace ::<xsl:value-of select="$prefix"/>
179            </xsl:when>
180            <xsl:when test="$mode='link'">
181              <xsl:call-template name="internal-link">
182                <xsl:with-param name="to">
183                  <xsl:call-template name="generate.id">
184                    <xsl:with-param name="node" select="$node"/>
185                  </xsl:call-template>
186                </xsl:with-param>
187                <xsl:with-param name="text" select="$display-name"/>
188              </xsl:call-template>
189            </xsl:when>
190          </xsl:choose>
191        </xsl:if>
192       
193        <xsl:if test="(not($index &gt; count($directives))) and
194                      (not($have-match) or ($mode = 'matches'))">
195          <xsl:variable name="first-branch">
196            <xsl:if test="not ($prefix = '')">
197              <!-- Recurse and append the current context node to the prefix -->
198              <xsl:call-template name="name-matches-node">
199                <xsl:with-param name="name" select="$name"/>
200                <xsl:with-param name="display-name" select="$display-name"/>
201                <xsl:with-param name="context" select="$context"/>
202                <xsl:with-param name="node" select="$node"/>
203                <xsl:with-param name="mode" select="$mode"/>
204                <xsl:with-param name="index" select="$index + 1"/>
205                <xsl:with-param name="prefix"
206                  select="concat($prefix, $this-context, '::')"/>
207              </xsl:call-template>
208            </xsl:if>
209          </xsl:variable>
210         
211          <xsl:choose>
212            <xsl:when test="string($first-branch) != ''">
213              <xsl:copy-of select="$first-branch"/>
214            </xsl:when>
215            <xsl:otherwise>
216              <!-- Recurse with just the current context node -->
217              <xsl:call-template name="name-matches-node">
218                <xsl:with-param name="name" select="$name"/>
219                <xsl:with-param name="display-name" select="$display-name"/>
220                <xsl:with-param name="context" select="$context"/>
221                <xsl:with-param name="node" select="$node"/>
222                <xsl:with-param name="mode" select="$mode"/>
223                <xsl:with-param name="index" select="$index + 1"/>
224                <xsl:with-param name="prefix" 
225                  select="concat($this-context, '::')"/>
226              </xsl:call-template>
227            </xsl:otherwise>
228          </xsl:choose>
229        </xsl:if>       
230      </xsl:when>
231    </xsl:choose>
232  </xsl:template>
233
234  <!-- Count the number of nodes in the set that match the given name and
235       lookup context -->
236  <xsl:template name="count-matches">
237    <xsl:param name="name"/>
238    <xsl:param name="context"/>
239    <xsl:param name="nodes"/>
240
241    <xsl:variable name="match-string">
242      <xsl:for-each select="$nodes">
243        <xsl:variable name="does-match">
244          <xsl:call-template name="name-matches-node">
245            <xsl:with-param name="name" select="$name"/>
246            <xsl:with-param name="context" select="$context"/>
247            <xsl:with-param name="node" select="."/>
248          </xsl:call-template>
249        </xsl:variable>
250        <xsl:if test="not($does-match='')">X</xsl:if>
251      </xsl:for-each>
252    </xsl:variable>
253    <xsl:value-of select="string-length($match-string)"/>
254  </xsl:template>
255
256  <xsl:template name="cxx-link-name">
257    <!-- The actual lookup node -->
258    <xsl:param name="lookup"/> 
259
260    <!-- The type of name to lookup (e.g., class) -->
261    <xsl:param name="type"/> 
262
263    <!-- The name we are looking for -->
264    <xsl:param name="name"/> 
265
266    <!-- The name we will display  -->
267    <xsl:param name="display-name"/>
268
269    <!-- The name we are looking for (unqualified)-->
270    <xsl:param name="unqualified-name"/> 
271
272    <!-- The list of nodes that match the lookup node in both name and type -->
273    <xsl:param name="nodes"/>
274
275    <!-- Count the number of nodes that match -->
276    <xsl:variable name="matches">
277      <xsl:call-template name="count-matches">
278        <xsl:with-param name="name" select="$name"/>
279        <xsl:with-param name="context" select="$lookup"/>
280        <xsl:with-param name="nodes" select="$nodes"/>
281      </xsl:call-template>
282    </xsl:variable>
283
284    <xsl:choose>
285      <xsl:when test="$matches = 0">
286        <xsl:message>
287          <xsl:text>Cannot find </xsl:text>
288          <xsl:value-of select="$type"/>
289          <xsl:text> named '</xsl:text>
290          <xsl:value-of select="$name"/>
291          <xsl:text>'</xsl:text>
292        </xsl:message>
293        <xsl:value-of select="$display-name"/>
294      </xsl:when>
295      <xsl:when test="$matches = 1">
296        <xsl:for-each select="$nodes">
297          <xsl:call-template name="name-matches-node">
298            <xsl:with-param name="name" select="$name"/>
299            <xsl:with-param name="display-name" select="$display-name"/>
300            <xsl:with-param name="context" select="$lookup"/>
301            <xsl:with-param name="node" select="."/>
302            <xsl:with-param name="mode" select="'link'"/>
303          </xsl:call-template>
304        </xsl:for-each>
305      </xsl:when>
306      <xsl:otherwise>
307        <xsl:message>
308          <xsl:text>Reference to </xsl:text>
309          <xsl:value-of select="$type"/>
310          <xsl:text> '</xsl:text>
311          <xsl:value-of select="$name"/>
312          <xsl:text>' is ambiguous. Found:</xsl:text>
313          <xsl:for-each select="$nodes">
314            <xsl:call-template name="name-matches-node">
315              <xsl:with-param name="name" select="$name"/>
316              <xsl:with-param name="context" select="$lookup"/>
317              <xsl:with-param name="node" select="."/>
318              <xsl:with-param name="mode" select="'matches'"/>
319            </xsl:call-template>
320          </xsl:for-each>
321        </xsl:message>
322        <xsl:call-template name="name-matches-node">
323          <xsl:with-param name="name" select="$name"/>
324          <xsl:with-param name="display-name" select="$display-name"/>
325          <xsl:with-param name="context" select="$lookup"/>
326          <xsl:with-param name="node" select="$nodes"/>
327          <xsl:with-param name="mode" select="'link'"/>
328        </xsl:call-template>
329      </xsl:otherwise>
330    </xsl:choose>
331  </xsl:template>
332</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.