Simplify LUFA Doxygen to Docbook transform, use parameterized page compounddef template.
[pub/USBasp.git] / LUFA / StudioIntegration / HV1 / lufa_docbook_transform.xslt
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
5 <xsl:output method="xml" indent="no"/>
6
7 <xsl:param name="keyword.namespace" select="'Atmel.Language.C'"/>
8
9 <xsl:template name="generate.book.title">
10 <xsl:text>LUFA Library</xsl:text>
11 </xsl:template>
12
13 <xsl:template name="generate.book.id">
14 <xsl:param name="book.title"/>
15 <xsl:choose>
16 <xsl:when test="@id">
17 <xsl:value-of select="@id"/>
18 </xsl:when>
19 <xsl:otherwise>
20 <xsl:value-of select="translate($book.title, ' ','')"/>
21 </xsl:otherwise>
22 </xsl:choose>
23 </xsl:template>
24
25 <xsl:template name="generate.index.id">
26 <xsl:param name="name"/>
27 <xsl:variable name="book.title">
28 <xsl:call-template name="generate.book.title"/>
29 </xsl:variable>
30 <xsl:variable name="book.id">
31 <xsl:call-template name="generate.book.id">
32 <xsl:with-param name="book.title" select="$book.title"/>
33 </xsl:call-template>
34 </xsl:variable>
35
36 <indexterm id="{$keyword.namespace}.{$name}">
37 <primary>
38 <xsl:value-of select="$book.title"/>
39 </primary>
40 <secondary>
41 <xsl:value-of select="$name"/>
42 </secondary>
43 </indexterm>
44 </xsl:template>
45
46 <xsl:template match="doxygen">
47 <xsl:variable name="book.title">
48 <xsl:call-template name="generate.book.title"/>
49 </xsl:variable>
50
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 id="{$book.id}">
58 <title>
59 <xsl:value-of select="$book.title"/>
60 </title>
61
62 <!-- Add index chapter -->
63 <xsl:apply-templates select="compounddef[@kind = 'page' and @id = 'indexpage']">
64 <xsl:with-param name="element.type" select="'chapter'"/>
65 <xsl:with-param name="page.title" select="'Library Information'"/>
66 </xsl:apply-templates>
67
68 <!-- Add free-floating chapters -->
69 <xsl:apply-templates select="compounddef[@kind = 'page' and not(@id = 'indexpage') and not(//innerpage/@refid = @id)]">
70 <xsl:with-param name="element.type" select="'chapter'"/>
71 </xsl:apply-templates>
72
73 <!-- Add Modules chapter -->
74 <chapter>
75 <title>Modules</title>
76 <xsl:apply-templates select="compounddef[@kind = 'group' and not(//innergroup/@refid = @id)]"/>
77 </chapter>
78 </book>
79 </xsl:template>
80
81 <xsl:template match="compounddef[@kind = 'page']">
82 <xsl:param name="element.type" select="'section'"/>
83 <xsl:param name="page.title" select="title"/>
84
85 <xsl:element name="{$element.type}">
86 <xsl:attribute name="id">
87 <xsl:value-of select="@id"/>
88 </xsl:attribute>
89
90 <title>
91 <xsl:value-of select="$page.title"/>
92 </title>
93
94 <xsl:apply-templates select="detaileddescription"/>
95
96 <xsl:for-each select="innerpage">
97 <xsl:apply-templates select="ancestor::*/compounddef[@kind = 'page' and @id = current()/@refid]"/>
98 </xsl:for-each>
99 </xsl:element>
100 </xsl:template>
101
102 <xsl:template match="compounddef[@kind = 'group']">
103 <section id="{@id}">
104 <title>
105 <xsl:value-of select="title"/>
106 </title>
107
108 <xsl:variable name="name">
109 <xsl:value-of select="translate(compoundname, '_', '/')"/>
110 <xsl:text>.h</xsl:text>
111 </xsl:variable>
112
113 <xsl:variable name="name.escaped">
114 <xsl:value-of select="translate(compoundname, '_', '.')"/>
115 <xsl:text>.h</xsl:text>
116 </xsl:variable>
117
118 <indexterm id="{$keyword.namespace}.{$name.escaped}">
119 <primary>Header</primary>
120 <secondary>
121 <xsl:value-of select="$name"/>
122 </secondary>
123 </indexterm>
124
125 <xsl:call-template name="generate.index.id">
126 <xsl:with-param name="name" select="$name"/>
127 </xsl:call-template>
128
129 <indexterm>
130 <primary>
131 <xsl:value-of select="$name"/>
132 </primary>
133 </indexterm>
134
135 <xsl:apply-templates select="detaileddescription"/>
136
137 <xsl:apply-templates select="sectiondef"/>
138
139 <xsl:for-each select="innerclass">
140 <xsl:apply-templates select="ancestor::*/compounddef[@id = current()/@refid]"/>
141 </xsl:for-each>
142
143 <xsl:for-each select="innergroup">
144 <xsl:apply-templates select="ancestor::*/compounddef[@kind = 'group' and @id = current()/@refid]"/>
145 </xsl:for-each>
146 </section>
147 </xsl:template>
148
149 <xsl:template match="compounddef[@kind = 'struct' or @kind = 'union']">
150 <xsl:variable name="name" select="compoundname"/>
151
152 <section id="{@id}" xreflabel="{$name}">
153 <title>
154 <xsl:choose>
155 <xsl:when test="@kind = 'struct'">
156 <xsl:text>Struct </xsl:text>
157 </xsl:when>
158
159 <xsl:when test="@kind = 'union'">
160 <xsl:text>Union </xsl:text>
161 </xsl:when>
162 </xsl:choose>
163
164 <xsl:value-of select="$name"/>
165 </title>
166
167 <xsl:call-template name="generate.index.id">
168 <xsl:with-param name="name" select="$name"/>
169 </xsl:call-template>
170
171 <xsl:apply-templates select="detaileddescription"/>
172
173 <xsl:for-each select="sectiondef[@kind = 'public-attrib']">
174 <table tabstyle="striped">
175 <title>
176 <xsl:value-of select="$name"/>
177 </title>
178 <tgroup cols="3">
179 <colspec colnum="1" colname="start.col"/>
180 <colspec colnum="3" colname="stop.col"/>
181 <spanspec spanname="full" namest="start.col" nameend="stop.col"/>
182 <thead>
183 <row>
184 <entry>Type</entry>
185 <entry>Name</entry>
186 <entry>Description</entry>
187 </row>
188 </thead>
189 <tbody>
190 <xsl:for-each select="memberdef">
191 <row id="{@id}" xreflabel="{name}">
192 <entry>
193 <xsl:value-of select="type"/>
194 </entry>
195 <entry>
196 <xsl:value-of select="name"/>
197 <xsl:if test="starts-with(argsstring, '[')">
198 <xsl:text>[]</xsl:text>
199 </xsl:if>
200 <indexterm id="{$keyword.namespace}.{$name}.{name}"/>
201 </entry>
202 <entry>
203 <xsl:apply-templates select="detaileddescription"/>
204 </entry>
205 </row>
206 </xsl:for-each>
207 </tbody>
208 </tgroup>
209 </table>
210 </xsl:for-each>
211 </section>
212 </xsl:template>
213
214 <xsl:template match="memberdef[@kind = 'function']">
215 <section id="{@id}" xreflabel="{name}">
216 <title>
217 <xsl:text>Function </xsl:text>
218 <xsl:value-of select="name"/>
219 <xsl:text>()</xsl:text>
220 </title>
221
222 <xsl:call-template name="generate.index.id">
223 <xsl:with-param name="name" select="name"/>
224 </xsl:call-template>
225
226 <para>
227 <emphasis role="italic">
228 <xsl:value-of select="briefdescription"/>
229 </emphasis>
230 </para>
231
232 <programlisting language="c">
233 <emphasis role="keyword">
234 <xsl:value-of select="type"/>
235 </emphasis>
236 <xsl:text> </xsl:text>
237 <xsl:value-of select="name"/>
238 <xsl:text>(</xsl:text>
239
240 <xsl:choose>
241 <xsl:when test="not(param[1]/declname)">
242 <emphasis role="keyword">void</emphasis>
243 </xsl:when>
244
245 <xsl:otherwise>
246 <xsl:for-each select="param">
247 <xsl:if test="position() > 1">
248 <xsl:text>,</xsl:text>
249 </xsl:if>
250 <xsl:text>&#10;&#9;</xsl:text>
251 <emphasis role="keyword">
252 <xsl:value-of select="type"/>
253 </emphasis>
254 <xsl:text> </xsl:text>
255 <xsl:value-of select="declname"/>
256 </xsl:for-each>
257 </xsl:otherwise>
258 </xsl:choose>
259
260 <xsl:text>)</xsl:text>
261 </programlisting>
262
263 <xsl:apply-templates select="detaileddescription"/>
264 </section>
265 </xsl:template>
266
267 <xsl:template match="memberdef[@kind = 'enum']">
268 <section id="{@id}" xreflabel="{name}">
269 <title>
270 <xsl:text>Enum </xsl:text>
271 <xsl:value-of select="name"/>
272 </title>
273
274 <xsl:call-template name="generate.index.id">
275 <xsl:with-param name="name" select="name"/>
276 </xsl:call-template>
277
278 <xsl:apply-templates select="detaileddescription"/>
279
280 <table tabstyle="striped">
281 <title>Members</title>
282 <tgroup cols="2">
283 <thead>
284 <row>
285 <entry>Enum Value</entry>
286 <entry>Description</entry>
287 </row>
288 </thead>
289 <tbody>
290 <xsl:for-each select="enumvalue">
291 <row>
292 <entry>
293 <para id="{@id}" xreflabel="{name}">
294 <xsl:value-of select="name"/>
295 <indexterm id="{$keyword.namespace}.{name}"/>
296 </para>
297 </entry>
298 <entry>
299 <xsl:apply-templates select="detaileddescription"/>
300 </entry>
301 </row>
302 </xsl:for-each>
303 </tbody>
304 </tgroup>
305 </table>
306 </section>
307 </xsl:template>
308
309 <xsl:template match="memberdef[@kind = 'define']">
310 <section id="{@id}" xreflabel="{name}">
311 <title>
312 <xsl:text>Macro </xsl:text>
313 <xsl:value-of select="name"/>
314 </title>
315
316 <xsl:call-template name="generate.index.id">
317 <xsl:with-param name="name" select="name"/>
318 </xsl:call-template>
319
320 <programlisting language="c">
321 <emphasis role="preprocessor">
322 <xsl:text>#define </xsl:text>
323 <xsl:value-of select="name"/>
324 <xsl:if test="count(param) > 0">
325 <xsl:text>(</xsl:text>
326 <xsl:for-each select="param/defname">
327 <xsl:if test="position() > 1">
328 <xsl:text>,</xsl:text>
329 </xsl:if>
330 <xsl:value-of select="."/>
331 </xsl:for-each>
332 <xsl:text>)</xsl:text>
333 </xsl:if>
334 <xsl:text> </xsl:text>
335
336 <!-- Split long macro definitions across multiple lines -->
337 <xsl:if test="(string-length(initializer) > 50) or (count(param) > 0)">
338 <xsl:text>\&#10;&#9;</xsl:text>
339 </xsl:if>
340
341 <xsl:value-of select="initializer"/>
342 </emphasis>
343 <xsl:text> </xsl:text>
344 </programlisting>
345
346 <xsl:apply-templates select="detaileddescription"/>
347 </section>
348 </xsl:template>
349
350 <xsl:template match="memberdef[@kind = 'variable' or @kind = 'typedef']">
351 <section id="{@id}" xreflabel="{name}">
352 <!-- Doxygen gets confused and thinks function pointer type definitions
353 are variables, so we need to map them to this common section and
354 check the definition to see which of the two it is. -->
355 <xsl:choose>
356 <xsl:when test="contains(definition, 'typedef')">
357 <title>
358 <xsl:text>Type </xsl:text>
359 <xsl:value-of select="name"/>
360 </title>
361
362 <xsl:call-template name="generate.index.id">
363 <xsl:with-param name="name" select="name"/>
364 </xsl:call-template>
365
366 <programlisting language="c">
367 <emphasis role="keyword">
368 <xsl:text>typedef </xsl:text>
369 <xsl:value-of select="type"/>
370 </emphasis>
371 <xsl:text> </xsl:text>
372 <xsl:value-of select="name"/>
373 <xsl:text> </xsl:text>
374 <xsl:value-of select="argsstring"/>
375 </programlisting>
376 </xsl:when>
377
378 <xsl:otherwise>
379 <title>
380 <xsl:text>Variable </xsl:text>
381 <xsl:value-of select="name"/>
382 </title>
383
384 <xsl:call-template name="generate.index.id">
385 <xsl:with-param name="name" select="name"/>
386 </xsl:call-template>
387
388 <programlisting language="c">
389 <emphasis role="keyword">
390 <xsl:value-of select="type"/>
391 </emphasis>
392 <xsl:text> </xsl:text>
393 <xsl:value-of select="name"/>
394 </programlisting>
395 </xsl:otherwise>
396 </xsl:choose>
397
398 <xsl:apply-templates select="detaileddescription"/>
399 </section>
400 </xsl:template>
401
402 <xsl:template match="linebreak | simplesectsep">
403 <literallayout>
404 </literallayout>
405 </xsl:template>
406
407 <xsl:template match="verbatim">
408 <programlisting>
409 <xsl:apply-templates/>
410 </programlisting>
411 </xsl:template>
412
413 <xsl:template match="sectiondef">
414 <para>
415 <xsl:value-of select="description"/>
416 </para>
417
418 <xsl:apply-templates select="memberdef"/>
419 </xsl:template>
420
421 <xsl:template match="simplesect" mode="struct">
422 <footnote>
423 <xsl:apply-templates/>
424 </footnote>
425 </xsl:template>
426
427 <xsl:template match="simplesect">
428 <xsl:choose>
429 <xsl:when test="@kind = 'par'">
430 <note>
431 <title>
432 <xsl:value-of select="title"/>
433 </title>
434 <xsl:apply-templates/>
435 </note>
436 </xsl:when>
437
438 <xsl:when test="@kind = 'return'">
439 <note>
440 <title>Returns</title>
441 <xsl:apply-templates/>
442 </note>
443 </xsl:when>
444
445 <xsl:when test="@kind = 'warning'">
446 <warning>
447 <title>Warning</title>
448 <xsl:apply-templates/>
449 </warning>
450 </xsl:when>
451
452 <xsl:when test="@kind = 'pre'">
453 <note>
454 <title>Precondition</title>
455 <xsl:apply-templates/>
456 </note>
457 </xsl:when>
458
459 <xsl:when test="@kind = 'see'">
460 <note>
461 <title>See also</title>
462 <xsl:apply-templates/>
463 </note>
464 </xsl:when>
465
466 <xsl:when test="@kind = 'note'">
467 <note>
468 <title>Note</title>
469 <xsl:apply-templates/>
470 </note>
471 </xsl:when>
472
473 </xsl:choose>
474 </xsl:template>
475
476 <xsl:template match="parameterlist[@kind = 'param']">
477 <table tabstyle="striped">
478 <title>Parameters</title>
479 <tgroup cols="3">
480 <thead>
481 <row>
482 <entry>Data Direction</entry>
483 <entry>Parameter Name</entry>
484 <entry>Description</entry>
485 </row>
486 </thead>
487 <tbody>
488 <xsl:for-each select="parameteritem">
489 <row>
490 <xsl:apply-templates select="."/>
491 </row>
492 </xsl:for-each>
493 </tbody>
494 </tgroup>
495 </table>
496 </xsl:template>
497
498 <xsl:template match="parameterlist[@kind = 'retval']">
499 <table tabstyle="striped">
500 <title>Return Values</title>
501 <tgroup cols="2">
502 <thead>
503 <row>
504 <entry>Return Value</entry>
505 <entry>Description</entry>
506 </row>
507 </thead>
508 <tbody>
509 <xsl:for-each select="parameteritem">
510 <row>
511 <xsl:apply-templates select="."/>
512 </row>
513 </xsl:for-each>
514 </tbody>
515 </tgroup>
516 </table>
517 </xsl:template>
518
519 <xsl:template match="parameteritem">
520 <xsl:if test="parent::parameterlist/@kind = 'param'">
521 <entry>
522 <para>
523 <xsl:choose>
524 <xsl:when test="not(descendant::parametername/@direction)">
525 <emphasis role="italic">?</emphasis>
526 </xsl:when>
527
528 <xsl:otherwise>
529 <emphasis role="bold">
530 [<xsl:value-of select="descendant::parametername/@direction"/>]
531 </emphasis>
532 </xsl:otherwise>
533 </xsl:choose>
534 </para>
535 </entry>
536 </xsl:if>
537
538 <entry>
539 <para>
540 <xsl:value-of select="parameternamelist/parametername"/>
541 </para>
542 </entry>
543
544 <entry>
545 <xsl:apply-templates select="parameterdescription"/>
546 </entry>
547 </xsl:template>
548
549 <xsl:template match="parameterdescription">
550 <para>
551 <xsl:apply-templates/>
552 </para>
553 </xsl:template>
554
555 <xsl:template match="type">
556 <xsl:apply-templates/>
557 </xsl:template>
558
559 <xsl:template match="bold">
560 <emphasis role="bold">
561 <xsl:apply-templates/>
562 </emphasis>
563 </xsl:template>
564
565 <xsl:template match="emphasis">
566 <emphasis role="italic">
567 <xsl:apply-templates/>
568 </emphasis>
569 </xsl:template>
570
571 <xsl:template match="small">
572 <xsl:apply-templates/>
573 </xsl:template>
574
575 <xsl:template match="mdash | ndash">
576 <xsl:text>--</xsl:text>
577 </xsl:template>
578
579 <xsl:template match="computeroutput | preformatted">
580 <computeroutput>
581 <xsl:apply-templates/>
582 </computeroutput>
583 </xsl:template>
584
585 <xsl:template match="codeline">
586 <xsl:apply-templates/>
587 </xsl:template>
588
589 <xsl:template match="ulink">
590 <ulink url="{@url}">
591 <xsl:value-of select="."/>
592 </ulink>
593 </xsl:template>
594
595 <xsl:template match="superscript">
596 <superscript>
597 <xsl:apply-templates/>
598 </superscript>
599 </xsl:template>
600
601 <xsl:template match="subscript">
602 <subscript>
603 <xsl:apply-templates/>
604 </subscript>
605 </xsl:template>
606
607 <xsl:template match="para">
608 <para>
609 <xsl:apply-templates/>
610 </para>
611 </xsl:template>
612
613 <xsl:template match="ref">
614 <xsl:choose>
615 <!-- Don't show links inside program listings -->
616 <xsl:when test="ancestor::programlisting">
617 <xsl:value-of select="."/>
618 </xsl:when>
619
620 <!-- Don't show links to file compound definitions, as they are discarded -->
621 <xsl:when test="ancestor::*/compounddef[@kind = 'file' and @id = current()/@refid]">
622 <xsl:value-of select="."/>
623 </xsl:when>
624
625 <!-- Show links outside program listings -->
626 <xsl:otherwise>
627 <link linkend="{@refid}">
628 <xsl:value-of select="text()"/>
629 </link>
630 </xsl:otherwise>
631 </xsl:choose>
632 </xsl:template>
633
634 <xsl:template match="entry">
635 <entry>
636 <xsl:apply-templates/>
637 </entry>
638 </xsl:template>
639
640 <xsl:template match="table">
641 <xsl:choose>
642 <xsl:when test="caption">
643 <table tabstyle="striped">
644 <title>
645 <xsl:value-of select="caption"/>
646 </title>
647
648 <xsl:call-template name="write.table.content"/>
649 </table>
650 </xsl:when>
651
652 <xsl:otherwise>
653 <informaltable tabstyle="striped">
654 <xsl:call-template name="write.table.content"/>
655 </informaltable>
656 </xsl:otherwise>
657 </xsl:choose>
658 </xsl:template>
659
660 <xsl:template name="write.table.content">
661 <tgroup cols="{@cols}">
662 <thead>
663 <xsl:for-each select="row[1]">
664 <row>
665 <xsl:apply-templates select="entry"/>
666 </row>
667 </xsl:for-each>
668 </thead>
669 <tbody>
670 <xsl:for-each select="row[position() != 1]">
671 <row>
672 <xsl:apply-templates select="entry"/>
673 </row>
674 </xsl:for-each>
675 </tbody>
676 </tgroup>
677 </xsl:template>
678
679 <xsl:template match="itemizedlist">
680 <itemizedlist>
681 <xsl:apply-templates/>
682 </itemizedlist>
683 </xsl:template>
684
685 <xsl:template match="orderedlist">
686 <orderedlist>
687 <xsl:apply-templates/>
688 </orderedlist>
689 </xsl:template>
690
691 <xsl:template match="listitem">
692 <listitem>
693 <xsl:apply-templates/>
694 </listitem>
695 </xsl:template>
696
697 <xsl:template match="programlisting">
698 <programlisting language="c">
699 <xsl:for-each select="codeline[position() > 1 or highlight]">
700 <xsl:apply-templates select="."/>
701 <xsl:text>&#10;</xsl:text>
702 </xsl:for-each>
703 </programlisting>
704 </xsl:template>
705
706 <xsl:template match="highlight">
707 <emphasis role="{@class}">
708 <xsl:apply-templates/>
709 </emphasis>
710 </xsl:template>
711
712 <xsl:template match="sp[ancestor::codeline]">
713 <xsl:text> </xsl:text>
714 </xsl:template>
715
716 <xsl:template match="image">
717 <mediaobject>
718 <imageobject>
719 <imagedata align="center">
720 <xsl:attribute name="fileref">
721 <xsl:text>images/</xsl:text>
722 <xsl:value-of select="@name"/>
723 </xsl:attribute>
724 </imagedata>
725 </imageobject>
726 </mediaobject>
727 </xsl:template>
728
729 <xsl:template match="detaileddescription">
730 <xsl:apply-templates/>
731 </xsl:template>
732
733 <xsl:template match="sect1 | sect2 | sect3 | sect4 | sect5 | sect6 | sect7 | sect8 | sect9">
734 <section>
735 <xsl:if test="@id">
736 <xsl:attribute name="id">
737 <xsl:value-of select="@id"/>
738 </xsl:attribute>
739 </xsl:if>
740
741 <title>
742 <xsl:value-of select="title"/>
743 </title>
744
745 <xsl:apply-templates/>
746 </section>
747 </xsl:template>
748
749 <xsl:template match="anchor">
750 <xsl:if test="@id">
751 <indexterm id="{@id}"/>
752 </xsl:if>
753 </xsl:template>
754
755 <xsl:template match="title"/>
756
757 <xsl:template match="htmlonly"/>
758
759 <xsl:template match="*">
760 <xsl:message>NO XSL TEMPLATE MATCH: <xsl:value-of select="name()"/></xsl:message>
761 </xsl:template>
762
763 </xsl:stylesheet>