Update Doxygen-to-Docbook transform with the latest transform rules for functions...
[pub/USBasp.git] / LUFA / StudioIntegration / HV1 / lufa_docbook_transform.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
4 <xsl:import href="transform_base.xsl"/>
5
6 <xsl:output method="xml" indent="no"/>
7
8 <xsl:param name="keyword.namespace" select="'Atmel.Language.C'"/>
9
10 <xsl:template name="generate.book.title">
11 <xsl:text>LUFA Library</xsl:text>
12 </xsl:template>
13
14 <xsl:template name="generate.book.id">
15 <xsl:param name="book.title"/>
16 <xsl:choose>
17 <xsl:when test="@id">
18 <xsl:value-of select="@id"/>
19 </xsl:when>
20 <xsl:otherwise>
21 <xsl:value-of select="translate($book.title, ' ','')"/>
22 </xsl:otherwise>
23 </xsl:choose>
24 </xsl:template>
25
26 <xsl:template name="generate.index.id">
27 <xsl:param name="name"/>
28 <xsl:variable name="book.title">
29 <xsl:call-template name="generate.book.title"/>
30 </xsl:variable>
31 <xsl:variable name="book.id">
32 <xsl:call-template name="generate.book.id">
33 <xsl:with-param name="book.title" select="$book.title"/>
34 </xsl:call-template>
35 </xsl:variable>
36
37 <indexterm id="{$keyword.namespace}.{$name}">
38 <primary>
39 <xsl:value-of select="$book.title"/>
40 </primary>
41 <secondary>
42 <xsl:value-of select="$name"/>
43 </secondary>
44 </indexterm>
45 </xsl:template>
46
47 <xsl:template match="doxygen">
48 <xsl:variable name="book.title">
49 <xsl:call-template name="generate.book.title"/>
50 </xsl:variable>
51 <xsl:variable name="book.id">
52 <xsl:call-template name="generate.book.id">
53 <xsl:with-param name="book.title" select="$book.title"/>
54 </xsl:call-template>
55 </xsl:variable>
56
57 <book name="{$book.id}">
58 <title>
59 <xsl:value-of select="$book.title"/>
60 </title>
61
62 <!-- Add index chapter -->
63 <xsl:call-template name="generate.top.level.page">
64 <xsl:with-param name="top.level.page" select="compounddef[@kind = 'page' and contains(@id, 'index')]"/>
65 </xsl:call-template>
66
67 <!-- Add free-floating chapters -->
68 <xsl:for-each select="compounddef[@kind = 'page' and not(contains(@id, 'index'))]">
69 <xsl:if test="not(//innerpage[@refid = current()/@id])">
70 <xsl:call-template name="generate.top.level.page">
71 <xsl:with-param name="top.level.page" select="current()"/>
72 </xsl:call-template>
73 </xsl:if>
74 </xsl:for-each>
75
76 <!-- Add Module chapter -->
77 <chapter>
78 <title>Modules</title>
79 <xsl:for-each select="compounddef[@kind = 'group']">
80 <xsl:if test="not(//innergroup[@refid = current()/@id])">
81 <xsl:apply-templates select="current()"/>
82 </xsl:if>
83 </xsl:for-each>
84 </chapter>
85 </book>
86 </xsl:template>
87
88 <xsl:template name="generate.top.level.page">
89 <xsl:param name="top.level.page"/>
90 <chapter id="{$top.level.page/@id}">
91 <title>
92 <xsl:value-of select="$top.level.page/title"/>
93 </title>
94 <xsl:apply-templates select="$top.level.page/detaileddescription"/>
95 <xsl:for-each select="$top.level.page/innerpage">
96 <xsl:apply-templates select="ancestor::*/compounddef[@kind = 'page' and @id = current()/@refid]"/>
97 </xsl:for-each>
98 </chapter>
99 </xsl:template>
100
101 <xsl:template match="compounddef[@kind = 'page']">
102 <section id="{@id}">
103 <title>
104 <xsl:value-of select="title"/>
105 </title>
106 <xsl:apply-templates select="detaileddescription"/>
107 <xsl:for-each select="innerpage">
108 <xsl:apply-templates select="ancestor::*/compounddef[@kind = 'page' and @id = current()/@refid]"/>
109 </xsl:for-each>
110 </section>
111 </xsl:template>
112
113 <xsl:template match="compounddef[@kind = 'group']">
114 <section id="{@id}">
115 <title>
116 <xsl:value-of select="title"/>
117 </title>
118
119 <xsl:variable name="book.title">
120 <xsl:call-template name="generate.book.title"/>
121 </xsl:variable>
122
123 <xsl:variable name="name">
124 <xsl:choose>
125 <xsl:when test="contains(compoundname, '_')">
126 <xsl:value-of select="translate(compoundname, '_', '/')"/>
127 <xsl:text>.h</xsl:text>
128 </xsl:when>
129 <xsl:otherwise>
130 <xsl:value-of select="compoundname"/>
131 <xsl:text>.h</xsl:text>
132 </xsl:otherwise>
133 </xsl:choose>
134 </xsl:variable>
135
136 <xsl:variable name="name.escaped">
137 <xsl:choose>
138 <xsl:when test="contains(compoundname, '_')">
139 <xsl:value-of select="translate(compoundname, '_', '.')"/>
140 <xsl:text>.h</xsl:text>
141 </xsl:when>
142 <xsl:otherwise>
143 <xsl:value-of select="compoundname"/>
144 <xsl:text>.h</xsl:text>
145 </xsl:otherwise>
146 </xsl:choose>
147 </xsl:variable>
148
149 <indexterm id="{$keyword.namespace}.{$name.escaped}">
150 <primary>Header</primary>
151 <secondary>
152 <xsl:value-of select="$name"/>
153 </secondary>
154 </indexterm>
155
156 <xsl:call-template name="generate.index.id">
157 <xsl:with-param name="name" select="$name"/>
158 </xsl:call-template>
159
160 <indexterm>
161 <primary>
162 <xsl:value-of select="$name"/>
163 </primary>
164 </indexterm>
165
166 <xsl:apply-templates select="detaileddescription" />
167
168 <xsl:apply-templates select="sectiondef" />
169
170 <xsl:for-each select="innerclass">
171 <xsl:apply-templates select="ancestor::*/compounddef[@id = current()/@refid]"/>
172 </xsl:for-each>
173
174 <xsl:for-each select="innergroup">
175 <xsl:apply-templates select="ancestor::*/compounddef[@kind = 'group' and @id = current()/@refid]"/>
176 </xsl:for-each>
177 </section>
178 </xsl:template>
179
180 <xsl:template match="compounddef[@kind = 'struct' or @kind = 'union']">
181 <xsl:variable name="name" select="compoundname"/>
182
183 <section id="{@id}" xreflabel="{$name}">
184 <title>
185 <xsl:choose>
186 <xsl:when test="@kind = 'struct'">
187 <xsl:text>Struct </xsl:text>
188 </xsl:when>
189 <xsl:when test="@kind = 'union'">
190 <xsl:text>Union </xsl:text>
191 </xsl:when>
192 </xsl:choose>
193 <xsl:value-of select="$name"/>
194 </title>
195
196 <xsl:call-template name="generate.index.id">
197 <xsl:with-param name="name" select="$name"/>
198 </xsl:call-template>
199
200 <xsl:apply-templates select="detaileddescription"/>
201
202 <xsl:for-each select="sectiondef[@kind='public-attrib']">
203 <table tabstyle="striped">
204 <title>
205 <xsl:value-of select="$name"/>
206 </title>
207 <tgroup cols="3">
208 <colspec colnum="1" colname="start.col"/>
209 <colspec colnum="3" colname="stop.col"/>
210 <spanspec spanname="full" namest="start.col" nameend="stop.col"/>
211 <thead>
212 <row>
213 <entry>Type</entry>
214 <entry>Name</entry>
215 <entry>Description</entry>
216 </row>
217 </thead>
218 <tbody>
219 <xsl:for-each select="memberdef">
220 <row id="{@id}" xreflabel="{name}">
221 <entry>
222 <xsl:apply-templates select="type"/>
223 </entry>
224 <entry>
225 <xsl:value-of select="name"/>
226 <xsl:if test="starts-with(argsstring, '[')">
227 <xsl:text>[]</xsl:text>
228 </xsl:if>
229 <indexterm id="{$keyword.namespace}.{$name}.{name}"/>
230 </entry>
231 <entry>
232 <xsl:apply-templates select="detaileddescription"/>
233 </entry>
234 </row>
235 </xsl:for-each>
236 </tbody>
237 </tgroup>
238 </table>
239 </xsl:for-each>
240 </section>
241 </xsl:template>
242
243 <xsl:template match="memberdef[@kind = 'function']">
244 <xsl:variable name="name" select="name"/>
245
246 <section id="{@id}" xreflabel="{name}">
247 <title>
248 <xsl:text>Function </xsl:text>
249 <xsl:value-of select="name"/>
250 <xsl:text>()</xsl:text>
251 </title>
252
253 <xsl:call-template name="generate.index.id">
254 <xsl:with-param name="name" select="$name"/>
255 </xsl:call-template>
256
257 <para>
258 <emphasis role="italic">
259 <xsl:value-of select="briefdescription"/>
260 </emphasis>
261 </para>
262
263 <programlisting language="c">
264 <emphasis role="keyword">
265 <xsl:value-of select="type"/>
266 </emphasis>
267 <xsl:text> </xsl:text>
268 <xsl:value-of select="name"/>
269 <xsl:text>(</xsl:text>
270
271 <xsl:choose>
272 <xsl:when test="argsstring = '(void)'">
273 <emphasis role="keyword">void</emphasis>
274 </xsl:when>
275
276 <xsl:otherwise>
277 <xsl:for-each select="param">
278 <xsl:if test="position() > 1">
279 <xsl:text>,</xsl:text>
280 </xsl:if>
281 <xsl:text>&#10;&#9;&#9;</xsl:text>
282 <emphasis role="keyword">
283 <xsl:value-of select="type"/>
284 </emphasis>
285 <xsl:text> </xsl:text>
286 <xsl:value-of select="declname"/>
287 </xsl:for-each>
288 </xsl:otherwise>
289 </xsl:choose>
290
291 <xsl:text>)</xsl:text>
292 </programlisting>
293
294 <xsl:apply-templates select="detaileddescription"/>
295 </section>
296 </xsl:template>
297
298 <xsl:template match="memberdef[@kind = 'enum']">
299 <xsl:variable name="name" select="name"/>
300
301 <section id="{@id}" xreflabel="{name}">
302 <title>
303 <xsl:text>Enum </xsl:text>
304 <xsl:value-of select="name"/>
305 </title>
306
307 <xsl:call-template name="generate.index.id">
308 <xsl:with-param name="name" select="$name"/>
309 </xsl:call-template>
310
311 <xsl:apply-templates select="detaileddescription"/>
312
313 <table tabstyle="striped">
314 <title>Members</title>
315 <tgroup cols="2">
316 <thead>
317 <row>
318 <entry>Enum Value</entry>
319 <entry>Description</entry>
320 </row>
321 </thead>
322 <tbody>
323 <xsl:for-each select="enumvalue">
324 <row>
325 <entry>
326 <para id="{@id}" xreflabel="{name}">
327 <xsl:value-of select="name"/>
328 </para>
329 </entry>
330 <entry>
331 <xsl:apply-templates select="detaileddescription"/>
332 </entry>
333 </row>
334 </xsl:for-each>
335 </tbody>
336 </tgroup>
337 </table>
338 </section>
339 </xsl:template>
340
341 <xsl:template match="memberdef[@kind = 'define']">
342 <xsl:variable name="name" select="name"/>
343
344 <section id="{@id}" xreflabel="{name}">
345 <title>
346 <xsl:text>Macro </xsl:text>
347 <xsl:value-of select="name"/>
348 </title>
349
350 <xsl:call-template name="generate.index.id">
351 <xsl:with-param name="name" select="$name"/>
352 </xsl:call-template>
353
354 <programlisting language="c">
355 <emphasis role="preprocessor">
356 <xsl:text>#define </xsl:text>
357 <xsl:value-of select="name"/>
358 <xsl:if test="count(param) > 0">
359 <xsl:text>(</xsl:text>
360 <xsl:for-each select="param/defname">
361 <xsl:if test="position() > 1">
362 <xsl:text>,</xsl:text>
363 </xsl:if>
364 <xsl:value-of select="."/>
365 </xsl:for-each>
366 <xsl:text>)</xsl:text>
367 </xsl:if>
368 <xsl:text> </xsl:text>
369
370 <!-- Split long macro definitions across multiple lines -->
371 <xsl:if test="(string-length(initializer) > 50) or (count(param) > 0)">
372 <xsl:text>\&#10;&#09;&#9;</xsl:text>
373 </xsl:if>
374
375 <xsl:value-of select="initializer"/>
376 </emphasis>
377 <xsl:text> </xsl:text>
378 </programlisting>
379
380 <xsl:apply-templates select="detaileddescription"/>
381 </section>
382 </xsl:template>
383
384 <xsl:template match="memberdef[@kind = 'variable' or @kind = 'typedef']">
385 <xsl:variable name="name" select="name"/>
386
387 <section id="{@id}" xreflabel="{name}">
388 <!-- Doxygen gets confused and thinks function pointer type definitions
389 are variables, so we need to map them to this common section and
390 check the definition to see which of the two it is. -->
391 <xsl:choose>
392 <xsl:when test="contains(definition,'typedef')">
393 <title>
394 <xsl:text>Type </xsl:text>
395 <xsl:value-of select="name"/>
396 </title>
397
398 <xsl:call-template name="generate.index.id">
399 <xsl:with-param name="name" select="$name"/>
400 </xsl:call-template>
401
402 <programlisting language="c">
403 <emphasis role="keyword">
404 <xsl:text>typedef </xsl:text>
405 <xsl:value-of select="type"/>
406 </emphasis>
407 <xsl:text> </xsl:text>
408 <xsl:value-of select="name"/>
409 <xsl:text> </xsl:text>
410 <xsl:value-of select="argsstring"/>
411 </programlisting>
412 </xsl:when>
413
414 <xsl:otherwise>
415 <title>
416 <xsl:text>Variable </xsl:text>
417 <xsl:value-of select="name"/>
418 </title>
419
420 <xsl:call-template name="generate.index.id">
421 <xsl:with-param name="name" select="$name"/>
422 </xsl:call-template>
423
424 <programlisting language="c">
425 <emphasis role="keyword">
426 <xsl:value-of select="type"/>
427 </emphasis>
428 <xsl:text> </xsl:text>
429 <xsl:value-of select="name"/>
430 </programlisting>
431 </xsl:otherwise>
432 </xsl:choose>
433
434 <xsl:apply-templates select="detaileddescription"/>
435 </section>
436 </xsl:template>
437
438 <xsl:template match="linebreak">
439 <xsl:text>&#10;</xsl:text>
440 </xsl:template>
441
442 <xsl:template match="image">
443 <figure>
444 <title>
445 <xsl:value-of select="."/>
446 </title>
447
448 <mediaobject>
449 <imageobject>
450 <imagedata>
451 <xsl:attribute name="fileref">images/<xsl:value-of select="@name"/></xsl:attribute>
452 </imagedata>
453 </imageobject>
454 </mediaobject>
455 </figure>
456 </xsl:template>
457
458 <xsl:template match="detaileddescription">
459 <xsl:apply-templates/>
460 </xsl:template>
461
462 <xsl:template match="sect1 | sect2 | sect3 | sect4 | sect5 | sect6 | sect7 | sect8 | sect9">
463 <section>
464 <xsl:if test="@id">
465 <xsl:attribute name="id">
466 <xsl:value-of select="@id"/>
467 </xsl:attribute>
468 </xsl:if>
469
470 <title>
471 <xsl:value-of select="title"/>
472 </title>
473
474 <xsl:apply-templates/>
475 </section>
476 </xsl:template>
477
478 <xsl:template match="anchor">
479 <xsl:if test="@id">
480 <indexterm id="{@id}"/>
481 </xsl:if>
482 </xsl:template>
483
484 <xsl:template match="title"/>
485
486 <xsl:template match="indexentry">
487 <xsl:variable name="prim">
488 <xsl:choose>
489 <xsl:when test="contains(primaryie, ',')">
490 <xsl:value-of select="normalize-space(substring-before(primaryie, ','))"/>
491 </xsl:when>
492 <xsl:otherwise>
493 <xsl:value-of select="primaryie"/>
494 </xsl:otherwise>
495 </xsl:choose>
496 </xsl:variable>
497
498 <xsl:variable name="sec">
499 <xsl:choose>
500 <xsl:when test="contains(primaryie, ',')">
501 <xsl:value-of select="normalize-space(substring-after(primaryie, ','))"/>
502 </xsl:when>
503 <xsl:when test="seondariye">
504 <xsl:value-of select="secondaryie"/>
505 </xsl:when>
506 <xsl:otherwise/>
507 </xsl:choose>
508 </xsl:variable>
509
510 <xsl:variable name="tert">
511 <xsl:choose>
512 <xsl:when test="contains(primaryie, ',')">
513 <xsl:choose>
514 <xsl:when test="secondaryie">
515 <xsl:value-of select="secondaryie"/>
516 </xsl:when>
517 </xsl:choose>
518 </xsl:when>
519 <xsl:when test="tertiaryie">
520 <xsl:value-of select="tertiaryie"/>
521 </xsl:when>
522 <xsl:otherwise/>
523 </xsl:choose>
524 </xsl:variable>
525
526 <indexterm>
527 <xsl:if test="@id">
528 <xsl:attribute name="id">
529 <xsl:value-of select="@id"/>
530 </xsl:attribute>
531 </xsl:if>
532 <xsl:if test="$prim">
533 <primary>
534 <xsl:value-of select="$prim"/>
535 </primary>
536 </xsl:if>
537 <xsl:if test="$sec">
538 <secondary>
539 <xsl:value-of select="$sec"/>
540 </secondary>
541 </xsl:if>
542 <xsl:if test="$tert">
543 <tertiary>
544 <xsl:value-of select="$tert"/>
545 </tertiary>
546 </xsl:if>
547 </indexterm>
548 </xsl:template>
549 </xsl:stylesheet>