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