VirtualBox

source: vbox/trunk/doc/manual/xidl2docbook.xsl@ 56540

Last change on this file since 56540 was 56540, checked in by vboxsync, 9 years ago

xidl2docbook.xsl: Use keys for full document element searches - speeds up processing quite a bit.

File size: 19.9 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4 xidl2docbook.xsl:
5 XSLT stylesheet that generates docbook from
6 VirtualBox.xidl.
7
8 Copyright (C) 2006-2015 Oracle Corporation
9
10 This file is part of VirtualBox Open Source Edition (OSE), as
11 available from http://www.virtualbox.org. This file is free software;
12 you can redistribute it and/or modify it under the terms of the GNU
13 General Public License (GPL) as published by the Free Software
14 Foundation, in version 2 as it comes in the "COPYING" file of the
15 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17-->
18
19<xsl:stylesheet
20 version="1.0"
21 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22 xmlns:exsl="http://exslt.org/common"
23 extension-element-prefixes="exsl">
24
25 <xsl:output
26 method="xml"
27 version="1.0"
28 encoding="utf-8"
29 indent="yes"/>
30
31 <xsl:strip-space elements="*"/>
32
33 <!-- - - - - - - - - - - - - - - - - - - - - - -
34 Keys for more efficiently looking up of types.
35 - - - - - - - - - - - - - - - - - - - - - - -->
36
37<xsl:key name="G_keyEnumsByName" match="//enum[@name]" use="@name"/>
38<xsl:key name="G_keyInterfacesByName" match="//interface[@name]" use="@name"/>
39<xsl:key name="G_keyResultsByName" match="//result[@name]" use="@name"/>
40
41<!-- - - - - - - - - - - - - - - - - - - - - - -
42 global XSLT variables
43 - - - - - - - - - - - - - - - - - - - - - - -->
44
45<xsl:variable name="G_xsltFilename" select="'glue-jaxws.xsl'" />
46
47<!-- collect all interfaces with "wsmap='suppress'" in a global variable for
48 quick lookup -->
49<xsl:variable name="G_setSuppressedInterfaces"
50 select="//interface[@wsmap='suppress']" />
51
52<xsl:template name="makeLinkId">
53 <xsl:param name="ifname" />
54 <xsl:param name="member" />
55 <xsl:value-of select="concat($ifname, '__', $member)"/>
56</xsl:template>
57
58<xsl:template name="emitType">
59 <xsl:param name="type" />
60 <xsl:choose>
61 <xsl:when test="$type">
62 <xsl:choose>
63 <xsl:when test="count(key('G_keyInterfacesByName',$type)) > 0">
64 <link>
65 <xsl:attribute name="linkend">
66 <xsl:value-of select="translate($type, ':', '_')" />
67 </xsl:attribute>
68 <xsl:value-of select="$type" />
69 </link>
70 </xsl:when>
71 <xsl:when test="count(key('G_keyEnumsByName',$type)) > 0">
72 <link>
73 <xsl:attribute name="linkend">
74 <xsl:value-of select="translate($type, ':', '_')" />
75 </xsl:attribute>
76 <xsl:value-of select="$type" />
77 </link>
78 </xsl:when>
79 <xsl:otherwise>
80 <xsl:value-of select="$type" />
81 </xsl:otherwise>
82 </xsl:choose>
83 </xsl:when>
84 <xsl:otherwise>
85 <xsl:value-of select="'void'" />
86 </xsl:otherwise>
87 </xsl:choose>
88</xsl:template>
89
90<xsl:template name="isWebserviceOnly">
91 <xsl:for-each select="ancestor-or-self::*">
92 <xsl:if test="(name()='if') and (@target='wsdl')">
93 <xsl:text>yes</xsl:text>
94 </xsl:if>
95 </xsl:for-each>
96</xsl:template>
97
98
99<!-- - - - - - - - - - - - - - - - - - - - - - -
100 root match
101 - - - - - - - - - - - - - - - - - - - - - - -->
102
103<xsl:template match="/idl">
104 <chapter id="sdkref_classes">
105 <title>Classes (interfaces)</title>
106 <xsl:for-each select="//interface">
107 <xsl:sort select="@name"/>
108
109 <!-- ignore those interfaces within module sections; they don't have uuid -->
110 <xsl:if test="@uuid">
111 <xsl:variable name="ifname" select="@name" />
112 <xsl:variable name="wsmap" select="@wsmap" />
113 <xsl:variable name="wscpp" select="@wscpp" />
114 <xsl:variable name="wsonly"><xsl:call-template name="isWebserviceOnly" /></xsl:variable>
115 <xsl:variable name="extends" select="@extends" />
116 <xsl:variable name="reportExtends" select="not($extends='$unknown') and not($extends='$errorinfo')" />
117
118 <sect1>
119 <xsl:attribute name="id">
120 <xsl:value-of select="$ifname" />
121 </xsl:attribute>
122 <title><xsl:value-of select="$ifname" />
123 <xsl:if test="$reportExtends">
124 <xsl:value-of select="concat(' (', @extends, ')')" />
125 </xsl:if>
126 </title>
127
128 <xsl:choose>
129 <xsl:when test="$wsmap='suppress'">
130 <para><note><para>
131 This interface is not supported in the web service.
132 </para></note></para>
133 </xsl:when>
134 <xsl:when test="$wsmap='struct'">
135 <para><note><para>With the web service, this interface is mapped to a structure. Attributes that return this interface will not return an object, but a complete structure
136 containing the attributes listed below as structure members.</para></note></para>
137 </xsl:when>
138 <xsl:when test="$wsonly='yes'">
139 <para><note><para>This interface is supported in the web service only, not in COM/XPCOM.</para></note></para>
140 </xsl:when>
141 </xsl:choose>
142
143 <xsl:if test="$reportExtends">
144 <para><note><para>
145 This interface extends
146 <link>
147 <xsl:attribute name="linkend"><xsl:value-of select="$extends" /></xsl:attribute>
148 <xsl:value-of select="$extends" />
149 </link>
150 and therefore supports all its methods and attributes as well.
151 </para></note></para>
152 </xsl:if>
153
154 <xsl:apply-templates select="desc" />
155
156 <xsl:if test="attribute">
157 <sect2>
158 <title>Attributes</title>
159 <xsl:for-each select="attribute">
160 <xsl:variable name="attrtype" select="@type" />
161 <sect3>
162 <xsl:attribute name="id">
163 <xsl:call-template name="makeLinkId">
164 <xsl:with-param name="ifname" select="$ifname" />
165 <xsl:with-param name="member" select="@name" />
166 </xsl:call-template>
167 </xsl:attribute>
168 <title>
169 <xsl:choose>
170 <xsl:when test="@readonly='yes'">
171 <xsl:value-of select="concat(@name, ' (read-only)')" />
172 </xsl:when>
173 <xsl:otherwise>
174 <xsl:value-of select="concat(@name, ' (read/write)')" />
175 </xsl:otherwise>
176 </xsl:choose>
177 </title>
178 <programlisting>
179 <xsl:call-template name="emitType">
180 <xsl:with-param name="type" select="$attrtype" />
181 </xsl:call-template>
182 <xsl:value-of select="concat(' ', $ifname, '::', @name)" />
183 <xsl:if test="(@array='yes') or (@safearray='yes')">
184 <xsl:text>[]</xsl:text>
185 </xsl:if>
186 </programlisting>
187 <xsl:if test="( ($attrtype=($G_setSuppressedInterfaces/@name)) )">
188 <para><note><para>
189 This attribute is not supported in the web service.
190 </para></note></para>
191 </xsl:if>
192 <xsl:apply-templates select="desc" />
193 </sect3>
194 </xsl:for-each>
195 </sect2>
196 </xsl:if>
197
198 <xsl:if test="method">
199<!-- <sect2> -->
200<!-- <title>Methods</title> -->
201 <xsl:for-each select="method">
202 <xsl:sort select="@name" />
203 <xsl:variable name="returnidltype" select="param[@dir='return']/@type" />
204 <sect2>
205 <xsl:attribute name="id">
206 <xsl:call-template name="makeLinkId">
207 <xsl:with-param name="ifname" select="$ifname" />
208 <xsl:with-param name="member" select="@name" />
209 </xsl:call-template>
210 </xsl:attribute>
211 <title>
212 <xsl:value-of select="@name" />
213 </title>
214 <xsl:if test=" (param[@type=($G_setSuppressedInterfaces/@name)])
215 or (param[@mod='ptr'])" >
216 <para><note><para>
217 This method is not supported in the web service.
218 </para></note></para>
219 </xsl:if>
220 <!-- make a set of all parameters with in and out direction -->
221 <xsl:variable name="paramsinout" select="param[@dir='in' or @dir='out']" />
222 <programlisting>
223 <!--emit return type-->
224 <xsl:call-template name="emitType">
225 <xsl:with-param name="type" select="$returnidltype" />
226 </xsl:call-template>
227 <xsl:if test="(param[@dir='return']/@array='yes') or (param[@dir='return']/@safearray='yes')">
228 <xsl:text>[]</xsl:text>
229 </xsl:if>
230 <xsl:value-of select="concat(' ', $ifname, '::', @name, '(')" />
231 <xsl:if test="$paramsinout">
232 <xsl:for-each select="$paramsinout">
233 <xsl:text>&#10;</xsl:text>
234 <xsl:value-of select="concat(' [', @dir, '] ')" />
235 <xsl:if test="@mod = 'ptr'">
236 <xsl:text>[ptr] </xsl:text>
237 </xsl:if>
238 <xsl:call-template name="emitType">
239 <xsl:with-param name="type" select="@type" />
240 </xsl:call-template>
241 <emphasis role="bold">
242 <xsl:value-of select="concat(' ', @name)" />
243 </emphasis>
244 <xsl:if test="(@array='yes') or (@safearray='yes')">
245 <xsl:text>[]</xsl:text>
246 </xsl:if>
247 <xsl:if test="not(position()=last())">
248 <xsl:text>, </xsl:text>
249 </xsl:if>
250 </xsl:for-each>
251 </xsl:if>
252 <xsl:text>)</xsl:text>
253 </programlisting>
254
255 <xsl:if test="$paramsinout">
256 <glosslist>
257 <xsl:for-each select="$paramsinout">
258 <glossentry>
259 <glossterm>
260 <xsl:value-of select="@name" />
261 </glossterm>
262 <glossdef>
263 <xsl:if test="not(desc)">
264 <para/>
265 </xsl:if>
266 <xsl:apply-templates select="desc" />
267 </glossdef>
268 </glossentry>
269 </xsl:for-each>
270 </glosslist>
271 </xsl:if>
272
273 <!-- dump the description here -->
274 <xsl:apply-templates select="desc" />
275
276 <xsl:if test="desc/result">
277 <para>If this method fails, the following error codes may be reported:</para>
278 <itemizedlist>
279 <xsl:for-each select="desc/result">
280 <listitem>
281 <para><code><xsl:value-of select="@name" />: </code>
282 <xsl:apply-templates />
283 </para>
284 </listitem>
285 </xsl:for-each>
286 </itemizedlist>
287 </xsl:if>
288 </sect2>
289 </xsl:for-each>
290<!-- </sect2> -->
291 </xsl:if>
292
293 </sect1>
294 </xsl:if>
295 </xsl:for-each>
296 </chapter>
297
298 <chapter id="sdkref_enums">
299 <title>Enumerations (enums)</title>
300 <xsl:for-each select="//enum">
301 <xsl:sort select="@name"/>
302
303 <xsl:variable name="ifname" select="@name" />
304 <xsl:variable name="wsmap" select="@wsmap" />
305 <xsl:variable name="wscpp" select="@wscpp" />
306
307 <sect1>
308 <xsl:attribute name="id">
309 <xsl:value-of select="$ifname" />
310 </xsl:attribute>
311 <title><xsl:value-of select="$ifname" /></title>
312
313 <xsl:apply-templates select="desc" />
314
315 <glosslist>
316 <xsl:for-each select="const">
317 <glossentry>
318 <glossterm>
319 <xsl:attribute name="id">
320 <xsl:call-template name="makeLinkId">
321 <xsl:with-param name="ifname" select="$ifname" />
322 <xsl:with-param name="member" select="@name" />
323 </xsl:call-template>
324 </xsl:attribute>
325 <xsl:value-of select="@name" />
326 </glossterm>
327 <glossdef>
328 <xsl:if test="not(desc)">
329 <para/>
330 </xsl:if>
331 <xsl:apply-templates select="desc" />
332 </glossdef>
333 </glossentry>
334 </xsl:for-each>
335 </glosslist>
336 </sect1>
337 </xsl:for-each>
338 </chapter>
339
340</xsl:template>
341
342<!-- - - - - - - - - - - - - - - - - - - - - - -
343 if
344 - - - - - - - - - - - - - - - - - - - - - - -->
345
346<!--
347 * ignore all |if|s except those for WSDL target
348-->
349<xsl:template match="if">
350 <xsl:if test="@target='wsdl'">
351 <xsl:apply-templates/>
352 </xsl:if>
353</xsl:template>
354
355<!-- - - - - - - - - - - - - - - - - - - - - - -
356 cpp
357 - - - - - - - - - - - - - - - - - - - - - - -->
358
359<xsl:template match="cpp">
360<!-- ignore this -->
361</xsl:template>
362
363<!-- - - - - - - - - - - - - - - - - - - - - - -
364 result
365 - - - - - - - - - - - - - - - - - - - - - - -->
366
367<xsl:template match="result">
368 <!-- ignore this, we handle them explicitly in method loops -->
369</xsl:template>
370
371<!-- - - - - - - - - - - - - - - - - - - - - - -
372 library
373 - - - - - - - - - - - - - - - - - - - - - - -->
374
375<xsl:template match="library">
376 <xsl:apply-templates />
377</xsl:template>
378
379<!-- - - - - - - - - - - - - - - - - - - - - - -
380 class
381 - - - - - - - - - - - - - - - - - - - - - - -->
382
383<xsl:template match="module/class">
384<!-- TODO swallow for now -->
385</xsl:template>
386
387<!-- - - - - - - - - - - - - - - - - - - - - - -
388 enum
389 - - - - - - - - - - - - - - - - - - - - - - -->
390
391<xsl:template match="enum">
392</xsl:template>
393
394<!-- - - - - - - - - - - - - - - - - - - - - - -
395 const
396 - - - - - - - - - - - - - - - - - - - - - - -->
397
398<!--
399<xsl:template match="const">
400 <xsl:apply-templates />
401</xsl:template>
402-->
403
404<!-- - - - - - - - - - - - - - - - - - - - - - -
405 desc
406 - - - - - - - - - - - - - - - - - - - - - - -->
407
408<xsl:template match="desc">
409 <!-- todo: wrapping the entire content in a single para is actually not
410 entirely correct, as it contains empty lines denoting new paragraphs -->
411 <para>
412 <xsl:apply-templates />
413 </para>
414</xsl:template>
415
416<xsl:template name="getCurrentInterface">
417 <xsl:for-each select="ancestor-or-self::*">
418 <xsl:if test="name()='interface'">
419 <xsl:value-of select="@name"/>
420 </xsl:if>
421 </xsl:for-each>
422</xsl:template>
423
424<!-- <link to="DeviceType::HardDisk"/> -->
425<xsl:template match="link">
426 <link>
427 <xsl:variable name="tmp" select="@to" />
428 <xsl:variable name="enumNameFromCombinedName">
429 <xsl:value-of select="substring-before($tmp, '_')" />
430 </xsl:variable>
431 <xsl:variable name="enumValueFromCombinedName">
432 <xsl:value-of select="substring-after($tmp, '_')" />
433 </xsl:variable>
434 <xsl:choose>
435 <xsl:when test="count(key('G_keyInterfacesByName',$tmp)) > 0 or count(key('G_keyEnumsByName',$tmp)) > 0"><!-- link to interface only -->
436 <xsl:attribute name="linkend"><xsl:value-of select="@to" /></xsl:attribute>
437 <xsl:value-of select="$tmp" />
438 </xsl:when>
439 <xsl:when test="count(key('G_keyEnumsByName',$enumNameFromCombinedName)) > 0">
440 <xsl:attribute name="linkend">
441 <xsl:value-of select="concat($enumNameFromCombinedName, '__', $enumValueFromCombinedName)" />
442 </xsl:attribute>
443 <xsl:value-of select="$enumValueFromCombinedName" />
444 </xsl:when>
445 <xsl:otherwise>
446 <xsl:variable name="currentif">
447 <xsl:call-template name="getCurrentInterface" />
448 </xsl:variable>
449 <xsl:variable name="if"><!-- interface -->
450 <xsl:choose>
451 <xsl:when test="contains(@to, '#')">
452 <xsl:value-of select="$currentif" />
453 </xsl:when>
454 <xsl:otherwise>
455 <xsl:value-of select="substring-before(@to, '::')" />
456 </xsl:otherwise>
457 </xsl:choose>
458 </xsl:variable>
459 <xsl:variable name="member"><!-- member in that interface -->
460 <xsl:choose>
461 <xsl:when test="contains(@to, '#')">
462 <xsl:value-of select="substring-after(@to, '#')" />
463 </xsl:when>
464 <xsl:otherwise>
465 <xsl:value-of select="substring-after(@to, '::')" />
466 </xsl:otherwise>
467 </xsl:choose>
468 </xsl:variable>
469
470 <xsl:attribute name="linkend"><xsl:value-of select="concat($if, '__', $member)" /></xsl:attribute>
471 <xsl:variable name="autotextsuffix">
472 <xsl:choose>
473 <!-- if link points to a method, append "()" -->
474 <xsl:when test="key('G_keyInterfacesByName',$if)/method[@name=$member]">
475 <xsl:value-of select="'()'" />
476 </xsl:when>
477 <!-- if link points to a safearray attribute, append "[]" -->
478 <xsl:when test="key('G_keyInterfacesByName',$if)/attribute[@name=$member]/@safearray = 'yes'">
479 <xsl:value-of select="'[]'" />
480 </xsl:when>
481 <xsl:when test="key('G_keyInterfacesByName',$if)/attribute[@name=$member]"/>
482 <xsl:when test="key('G_keyEnumsByName',$if)/const[@name=$member]"/>
483 <xsl:when test="count(key('G_keyResultsByName',$tmp)) > 0"/>
484 <xsl:otherwise>
485 <xsl:message terminate="yes">
486 <xsl:value-of select="concat('Invalid link pointing to &quot;', $tmp, '&quot;')" />
487 </xsl:message>
488 </xsl:otherwise>
489 </xsl:choose>
490 </xsl:variable>
491 <xsl:choose>
492 <xsl:when test="./text()"><!-- link text given in source -->
493 <xsl:apply-templates />
494 </xsl:when>
495 <xsl:when test="$if=$currentif"><!-- "near" link to method or attribute in current interface -->
496 <xsl:value-of select="concat($member, $autotextsuffix)" />
497 </xsl:when>
498 <xsl:otherwise><!-- "far" link to other method or attribute -->
499 <xsl:value-of select="concat($if, '::', $member, $autotextsuffix)" />
500 </xsl:otherwise>
501 </xsl:choose>
502 </xsl:otherwise>
503 </xsl:choose>
504 </link>
505</xsl:template>
506
507<!-- - - - - - - - - - - - - - - - - - - - - - -
508 note
509 - - - - - - - - - - - - - - - - - - - - - - -->
510
511<xsl:template match="note">
512 <xsl:if test="not(@internal='yes')">
513 <note><para>
514 <xsl:apply-templates />
515 </para></note>
516 </xsl:if>
517</xsl:template>
518
519<xsl:template match="tt">
520 <computeroutput>
521 <xsl:apply-templates />
522 </computeroutput>
523</xsl:template>
524
525<xsl:template match="b">
526 <emphasis role="bold">
527 <xsl:apply-templates />
528 </emphasis>
529</xsl:template>
530
531<xsl:template match="i">
532 <emphasis>
533 <xsl:apply-templates />
534 </emphasis>
535</xsl:template>
536
537<xsl:template match="see">
538 <xsl:text>See also: </xsl:text>
539 <xsl:apply-templates />
540</xsl:template>
541
542<xsl:template match="ul">
543 <itemizedlist>
544 <xsl:apply-templates />
545 </itemizedlist>
546</xsl:template>
547
548<xsl:template match="ol">
549 <orderedlist>
550 <xsl:apply-templates />
551 </orderedlist>
552</xsl:template>
553
554<xsl:template match="li">
555 <listitem>
556 <para>
557 <xsl:apply-templates />
558 </para>
559 </listitem>
560</xsl:template>
561
562<xsl:template match="h3">
563 <emphasis role="bold">
564 <xsl:apply-templates />
565 </emphasis>
566</xsl:template>
567
568<xsl:template match="pre">
569 <screen><xsl:apply-templates /></screen>
570</xsl:template>
571
572<xsl:template match="table">
573 <xsl:apply-templates /> <!-- todo -->
574</xsl:template>
575
576</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette