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