Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/tools/boostbook/xsl/annotation.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  <xsl:key name="classes" match="class|struct|union" use="@name"/>
12  <xsl:key name="methods" match="method|overloaded-method" use="@name"/>
13  <xsl:key name="functions" match="function|overloaded-function" use="@name"/>
14  <xsl:key name="enums" match="enum" use="@name"/>
15  <xsl:key name="concepts" match="concept" use="@name"/>
16  <xsl:key name="libraries" match="library" use="@name"/>
17  <xsl:key name="macros" match="macro" use="@name"/>
18  <xsl:key name="headers" match="header" use="@name"/>
19  <xsl:key name="named-entities" match="class|struct|union|concept|function|overloaded-function|macro|library|namespace/data-member|header/data-member|*[attribute::id]" use="@name|@id"/>
20
21  <xsl:template match="function|overloaded-function" mode="generate.id">
22    <xsl:variable name="name" select="normalize-space(@name)"/>
23    <xsl:variable name="translated-name"
24                  select="translate($name,
25                                    '~!%^&amp;*()[].,&lt;&gt;|/ +-=',
26                                    'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')"/>
27                     
28    <xsl:choose>
29      <xsl:when test="count(key('named-entities', $name))=1
30                      and ($translated-name=$name)">
31        <xsl:call-template name="fully-qualified-name">
32          <xsl:with-param name="node" select="."/>
33          <xsl:with-param name="separator" select="'.'"/>
34        </xsl:call-template>
35      </xsl:when>
36      <xsl:otherwise>
37        <xsl:value-of select="generate-id(.)"/>
38        <xsl:text>-bb</xsl:text>
39      </xsl:otherwise>
40    </xsl:choose>
41  </xsl:template>
42
43  <xsl:template match="classname" mode="annotation">
44    <!-- Determine the (possibly qualified) class name we are looking for -->
45    <xsl:variable name="fullname">
46      <xsl:choose>
47        <xsl:when test="@alt">
48          <xsl:value-of select="@alt"/>
49        </xsl:when>
50        <xsl:otherwise>
51          <xsl:value-of select="string(.)"/>
52        </xsl:otherwise>
53      </xsl:choose>
54    </xsl:variable>
55
56    <!-- Strip off any instantiation -->
57    <xsl:variable name="name">
58      <xsl:choose>
59        <xsl:when test="contains($fullname, '&lt;')">
60          <xsl:value-of select="substring-before($fullname, '&lt;')"/>
61        </xsl:when>
62        <xsl:otherwise>
63          <xsl:value-of select="$fullname"/>
64        </xsl:otherwise>
65      </xsl:choose>
66    </xsl:variable>
67
68    <!-- Determine the unqualified name -->
69    <xsl:variable name="unqualified-name">
70      <xsl:call-template name="strip-qualifiers">
71        <xsl:with-param name="name" select="$name"/>
72      </xsl:call-template>
73    </xsl:variable>
74
75    <xsl:call-template name="cxx-link-name">
76      <xsl:with-param name="lookup" select="."/>
77      <xsl:with-param name="type" select="'class'"/>
78      <xsl:with-param name="name" select="$name"/>
79      <xsl:with-param name="display-name" select="string(.)"/>
80      <xsl:with-param name="unqualified-name" select="$unqualified-name"/>
81      <xsl:with-param name="nodes" select="key('classes', $unqualified-name)"/>
82    </xsl:call-template>
83  </xsl:template>
84
85  <xsl:template match="methodname" mode="annotation">
86    <!-- Determine the (possibly qualified) method name we are looking for -->
87    <xsl:variable name="fullname">
88      <xsl:choose>
89        <xsl:when test="@alt">
90          <xsl:value-of select="@alt"/>
91        </xsl:when>
92        <xsl:otherwise>
93          <xsl:value-of select="string(.)"/>
94        </xsl:otherwise>
95      </xsl:choose>
96    </xsl:variable>
97
98    <!-- Strip off any call -->
99    <xsl:variable name="name">
100      <xsl:choose>
101        <xsl:when test="contains($fullname, '(')">
102          <xsl:value-of select="substring-before($fullname, '(')"/>
103        </xsl:when>
104        <xsl:otherwise>
105          <xsl:value-of select="$fullname"/>
106        </xsl:otherwise>
107      </xsl:choose>
108    </xsl:variable>
109
110    <!-- Determine the unqualified name -->
111    <xsl:variable name="unqualified-name">
112      <xsl:call-template name="strip-qualifiers">
113        <xsl:with-param name="name" select="$name"/>
114      </xsl:call-template>
115    </xsl:variable>
116
117    <xsl:call-template name="cxx-link-name">
118      <xsl:with-param name="lookup" select="."/>
119      <xsl:with-param name="type" select="'method'"/>
120      <xsl:with-param name="name" select="$name"/>
121      <xsl:with-param name="display-name" select="string(.)"/>
122      <xsl:with-param name="unqualified-name" select="$unqualified-name"/>
123      <xsl:with-param name="nodes" select="key('methods', $unqualified-name)"/>
124    </xsl:call-template>
125  </xsl:template>
126
127  <xsl:template match="functionname" mode="annotation">
128    <!-- Determine the (possibly qualified) function name we are
129         looking for -->
130    <xsl:variable name="fullname">
131      <xsl:choose>
132        <xsl:when test="@alt">
133          <xsl:value-of select="@alt"/>
134        </xsl:when>
135        <xsl:otherwise>
136          <xsl:value-of select="string(.)"/>
137        </xsl:otherwise>
138      </xsl:choose>
139    </xsl:variable>
140
141    <!-- Strip off any call -->
142    <xsl:variable name="name">
143      <xsl:choose>
144        <xsl:when test="contains($fullname, '(')">
145          <xsl:value-of select="substring-before($fullname, '(')"/>
146        </xsl:when>
147        <xsl:otherwise>
148          <xsl:value-of select="$fullname"/>
149        </xsl:otherwise>
150      </xsl:choose>
151    </xsl:variable>
152
153    <!-- Determine the unqualified name -->
154    <xsl:variable name="unqualified-name">
155      <xsl:call-template name="strip-qualifiers">
156        <xsl:with-param name="name" select="$name"/>
157      </xsl:call-template>
158    </xsl:variable>
159
160    <xsl:call-template name="cxx-link-name">
161      <xsl:with-param name="lookup" select="."/>
162      <xsl:with-param name="type" select="'function'"/>
163      <xsl:with-param name="name" select="$name"/>
164      <xsl:with-param name="display-name" select="string(.)"/>
165      <xsl:with-param name="unqualified-name" select="$unqualified-name"/>
166      <xsl:with-param name="nodes" 
167        select="key('functions', $unqualified-name)"/>
168    </xsl:call-template>
169  </xsl:template>
170
171  <xsl:template match="enumname" mode="annotation">
172    <!-- Determine the (possibly qualified) enum name we are
173         looking for -->
174    <xsl:variable name="fullname">
175      <xsl:choose>
176        <xsl:when test="@alt">
177          <xsl:value-of select="@alt"/>
178        </xsl:when>
179        <xsl:otherwise>
180          <xsl:value-of select="string(.)"/>
181        </xsl:otherwise>
182      </xsl:choose>
183    </xsl:variable>
184
185    <!-- Strip off any call -->
186    <xsl:variable name="name">
187      <xsl:choose>
188        <xsl:when test="contains($fullname, '(')">
189          <xsl:value-of select="substring-before($fullname, '(')"/>
190        </xsl:when>
191        <xsl:otherwise>
192          <xsl:value-of select="$fullname"/>
193        </xsl:otherwise>
194      </xsl:choose>
195    </xsl:variable>
196
197    <!-- Determine the unqualified name -->
198    <xsl:variable name="unqualified-name">
199      <xsl:call-template name="strip-qualifiers">
200        <xsl:with-param name="name" select="$name"/>
201      </xsl:call-template>
202    </xsl:variable>
203
204    <xsl:call-template name="cxx-link-name">
205      <xsl:with-param name="lookup" select="."/>
206      <xsl:with-param name="type" select="'enum'"/>
207      <xsl:with-param name="name" select="$name"/>
208      <xsl:with-param name="display-name" select="string(.)"/>
209      <xsl:with-param name="unqualified-name" select="$unqualified-name"/>
210      <xsl:with-param name="nodes" 
211        select="key('enums', $unqualified-name)"/>
212    </xsl:call-template>
213  </xsl:template>
214
215  <xsl:template match="libraryname" mode="annotation">
216    <xsl:variable name="name">
217      <xsl:choose>
218        <xsl:when test="@alt">
219          <xsl:value-of select="@alt"/>
220        </xsl:when>
221        <xsl:otherwise>
222          <xsl:value-of select="text()"/>
223        </xsl:otherwise>
224      </xsl:choose>
225    </xsl:variable>
226
227    <xsl:variable name="node" select="key('libraries', $name)"/>
228   
229    <xsl:choose>
230      <xsl:when test="count($node)=0">
231        <xsl:message>
232          <xsl:text>warning: Cannot find library '</xsl:text>
233          <xsl:value-of select="$name"/>
234          <xsl:text>'</xsl:text>
235        </xsl:message>
236        <xsl:value-of select="$name"/>
237      </xsl:when>
238      <xsl:otherwise>
239        <xsl:call-template name="library.link">
240          <xsl:with-param name="node" select="$node"/>
241          <xsl:with-param name="name" select="text()"/>
242        </xsl:call-template>
243      </xsl:otherwise>
244    </xsl:choose>
245  </xsl:template>
246
247  <xsl:template match="conceptname" mode="annotation">
248    <xsl:param name="name" select="text()"/>
249
250    <xsl:call-template name="concept.link">
251      <xsl:with-param name="name" select="$name"/>
252    </xsl:call-template>
253  </xsl:template>
254
255  <xsl:template match="macroname" mode="annotation">
256    <xsl:param name="name" select="text()"/>
257   
258    <xsl:variable name="node" select="key('macros', $name)"/>
259    <xsl:choose>
260      <xsl:when test="count($node) = 0">
261        <xsl:message>
262          <xsl:text>warning: cannot find macro `</xsl:text>
263          <xsl:value-of select="$name"/>
264          <xsl:text>'</xsl:text>
265        </xsl:message>
266        <xsl:value-of select="$name"/>
267      </xsl:when>
268
269      <xsl:when test="count($node) = 1">
270        <xsl:call-template name="internal-link">
271          <xsl:with-param name="to">
272            <xsl:call-template name="generate.id">
273              <xsl:with-param name="node" select="$node"/>
274            </xsl:call-template>
275          </xsl:with-param>
276          <xsl:with-param name="text" select="$name"/>
277        </xsl:call-template>
278      </xsl:when>
279
280      <xsl:otherwise>
281        <xsl:message>
282          <xsl:text>error: macro `</xsl:text>
283          <xsl:value-of select="$name"/>
284          <xsl:text>' is multiply defined.</xsl:text>
285        </xsl:message>
286        <xsl:value-of select="$node"/>
287      </xsl:otherwise>
288    </xsl:choose>
289  </xsl:template>
290
291  <xsl:template match="headername" mode="annotation">
292    <xsl:param name="name" select="text()"/>
293   
294    <xsl:variable name="node" select="key('headers', $name)"/>
295    <xsl:choose>
296      <xsl:when test="count($node) = 0">
297        <xsl:message>
298          <xsl:text>warning: cannot find header `</xsl:text>
299          <xsl:value-of select="$name"/>
300          <xsl:text>'</xsl:text>
301        </xsl:message>
302        <xsl:value-of select="$name"/>
303      </xsl:when>
304
305      <xsl:when test="count($node) = 1">
306        <xsl:call-template name="internal-link">
307          <xsl:with-param name="to">
308            <xsl:call-template name="generate.id">
309              <xsl:with-param name="node" select="$node"/>
310            </xsl:call-template>
311          </xsl:with-param>
312          <xsl:with-param name="text" select="$name"/>
313        </xsl:call-template>
314      </xsl:when>
315
316      <xsl:otherwise>
317        <xsl:message>
318          <xsl:text>error: header `</xsl:text>
319          <xsl:value-of select="$name"/>
320          <xsl:text>' is multiply defined.</xsl:text>
321        </xsl:message>
322        <xsl:value-of select="$node"/>
323      </xsl:otherwise>
324    </xsl:choose>
325  </xsl:template>
326
327  <xsl:template match="text()" mode="annotation">
328    <xsl:param name="highlight" select="false()"/>
329    <xsl:choose>
330      <xsl:when test="$highlight">
331        <xsl:call-template name="source-highlight">
332          <xsl:with-param name="text" select="."/>
333        </xsl:call-template>
334      </xsl:when>
335      <xsl:otherwise>
336        <xsl:copy-of select="."/>
337      </xsl:otherwise>
338    </xsl:choose>
339  </xsl:template>
340
341  <xsl:template match="code" mode="annotation">
342    <computeroutput>
343      <xsl:apply-templates mode="annotation"/>
344    </computeroutput>
345  </xsl:template>
346
347  <xsl:template match="bold" mode="annotation">
348    <emphasis role="bold">
349      <xsl:apply-templates mode="annotation"/>
350    </emphasis>
351  </xsl:template>
352
353  <xsl:template match="comment()" mode="annotation">
354    <xsl:copy/>
355  </xsl:template>
356
357  <xsl:template match="node()" mode="annotation">
358    <xsl:param name="highlight" select="false()"/>
359
360    <xsl:element name="{name(.)}">
361      <xsl:for-each select="./@*">
362        <xsl:attribute name="{name(.)}">
363          <xsl:value-of select="."/>
364        </xsl:attribute>
365      </xsl:for-each>
366      <xsl:apply-templates select="./*|./text()" mode="annotation">
367        <xsl:with-param name="highlight" select="$highlight"/>
368      </xsl:apply-templates>
369    </xsl:element>
370  </xsl:template>
371
372  <!-- The "purpose" mode strips simpara/para elements so that we can
373       place the resulting text into a comment in the synopsis. -->
374  <xsl:template match="para|simpara" mode="purpose">
375    <xsl:apply-templates mode="annotation"/>
376  </xsl:template>
377
378  <xsl:template match="*" mode="purpose">
379    <xsl:apply-templates select="." mode="annotation"/>
380  </xsl:template>
381
382  <xsl:template match="text()" mode="purpose">
383    <xsl:apply-templates select="." mode="annotation"/>
384  </xsl:template>
385</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.