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