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