Fix up Atmel Studio F1 lookup index terms for Pages and Groups.
[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.Page.</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.Group.</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 <indexterm id="{$keyword.namespace}.{$name}.{name}"/>
192 </entry>
193 <entry>
194 <xsl:apply-templates select="detaileddescription"/>
195 </entry>
196 </row>
197 </xsl:for-each>
198 </tbody>
199 </tgroup>
200 </table>
201 </xsl:for-each>
202 </section>
203 </xsl:template>
204
205 <xsl:template match="memberdef[@kind = 'function']">
206 <section id="{@id}" xreflabel="{name}">
207 <title>
208 <xsl:text>Function </xsl:text>
209 <xsl:value-of select="name"/>
210 <xsl:text>()</xsl:text>
211 </title>
212
213 <xsl:call-template name="generate.index.id">
214 <xsl:with-param name="name" select="name"/>
215 </xsl:call-template>
216
217 <para>
218 <emphasis role="italic">
219 <xsl:value-of select="briefdescription"/>
220 </emphasis>
221 </para>
222
223 <programlisting language="c">
224 <emphasis role="keyword">
225 <xsl:value-of select="type"/>
226 </emphasis>
227 <xsl:text> </xsl:text>
228 <xsl:value-of select="name"/>
229 <xsl:text>(</xsl:text>
230
231 <xsl:choose>
232 <xsl:when test="not(param[1]/declname)">
233 <emphasis role="keyword">void</emphasis>
234 </xsl:when>
235
236 <xsl:otherwise>
237 <xsl:for-each select="param">
238 <xsl:if test="position() > 1">
239 <xsl:text>,</xsl:text>
240 </xsl:if>
241 <xsl:text>&#10;&#9;</xsl:text>
242 <emphasis role="keyword">
243 <xsl:value-of select="type"/>
244 </emphasis>
245 <xsl:text> </xsl:text>
246 <xsl:value-of select="declname"/>
247 </xsl:for-each>
248 </xsl:otherwise>
249 </xsl:choose>
250
251 <xsl:text>)</xsl:text>
252 </programlisting>
253
254 <xsl:apply-templates select="detaileddescription"/>
255 </section>
256 </xsl:template>
257
258 <xsl:template match="memberdef[@kind = 'enum']">
259 <section id="{@id}" xreflabel="{name}">
260 <title>
261 <xsl:text>Enum </xsl:text>
262 <xsl:value-of select="name"/>
263 </title>
264
265 <xsl:call-template name="generate.index.id">
266 <xsl:with-param name="name" select="name"/>
267 </xsl:call-template>
268
269 <xsl:apply-templates select="detaileddescription"/>
270
271 <table tabstyle="striped">
272 <title>Members</title>
273 <tgroup cols="2">
274 <thead>
275 <row>
276 <entry>Enum Value</entry>
277 <entry>Description</entry>
278 </row>
279 </thead>
280 <tbody>
281 <xsl:for-each select="enumvalue">
282 <row>
283 <entry>
284 <para id="{@id}" xreflabel="{name}">
285 <xsl:value-of select="name"/>
286 <indexterm id="{$keyword.namespace}.{name}"/>
287 </para>
288 </entry>
289 <entry>
290 <xsl:apply-templates select="detaileddescription"/>
291 </entry>
292 </row>
293 </xsl:for-each>
294 </tbody>
295 </tgroup>
296 </table>
297 </section>
298 </xsl:template>
299
300 <xsl:template match="memberdef[@kind = 'define']">
301 <section id="{@id}" xreflabel="{name}">
302 <title>
303 <xsl:text>Macro </xsl:text>
304 <xsl:value-of select="name"/>
305 </title>
306
307 <xsl:call-template name="generate.index.id">
308 <xsl:with-param name="name" select="name"/>
309 </xsl:call-template>
310
311 <programlisting language="c">
312 <emphasis role="preprocessor">
313 <xsl:text>#define </xsl:text>
314 <xsl:value-of select="name"/>
315 <xsl:if test="count(param) > 0">
316 <xsl:text>(</xsl:text>
317 <xsl:for-each select="param/defname">
318 <xsl:if test="position() > 1">
319 <xsl:text>,</xsl:text>
320 </xsl:if>
321 <xsl:value-of select="."/>
322 </xsl:for-each>
323 <xsl:text>)</xsl:text>
324 </xsl:if>
325 <xsl:text> </xsl:text>
326
327 <!-- Split long macro definitions across multiple lines -->
328 <xsl:if test="(string-length(initializer) > 50) or (count(param) > 0)">
329 <xsl:text>\&#10;&#9;</xsl:text>
330 </xsl:if>
331
332 <xsl:value-of select="initializer"/>
333 </emphasis>
334 <xsl:text> </xsl:text>
335 </programlisting>
336
337 <xsl:apply-templates select="detaileddescription"/>
338 </section>
339 </xsl:template>
340
341 <xsl:template match="memberdef[@kind = 'variable' or @kind = 'typedef']">
342 <section id="{@id}" xreflabel="{name}">
343 <!-- Doxygen gets confused and thinks function pointer type definitions
344 are variables, so we need to map them to this common section and
345 check the definition to see which of the two it is. -->
346 <xsl:choose>
347 <xsl:when test="contains(definition, 'typedef')">
348 <title>
349 <xsl:text>Type </xsl:text>
350 <xsl:value-of select="name"/>
351 </title>
352
353 <xsl:call-template name="generate.index.id">
354 <xsl:with-param name="name" select="name"/>
355 </xsl:call-template>
356
357 <programlisting language="c">
358 <emphasis role="keyword">
359 <xsl:text>typedef </xsl:text>
360 <xsl:value-of select="type"/>
361 </emphasis>
362 <xsl:text> </xsl:text>
363 <xsl:value-of select="name"/>
364 <xsl:text> </xsl:text>
365 <xsl:value-of select="argsstring"/>
366 </programlisting>
367 </xsl:when>
368
369 <xsl:otherwise>
370 <title>
371 <xsl:text>Variable </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:value-of select="type"/>
382 </emphasis>
383 <xsl:text> </xsl:text>
384 <xsl:value-of select="name"/>
385 </programlisting>
386 </xsl:otherwise>
387 </xsl:choose>
388
389 <xsl:apply-templates select="detaileddescription"/>
390 </section>
391 </xsl:template>
392
393 <xsl:template match="linebreak | simplesectsep">
394 <literallayout>
395 </literallayout>
396 </xsl:template>
397
398 <xsl:template match="verbatim">
399 <programlisting>
400 <xsl:apply-templates/>
401 </programlisting>
402 </xsl:template>
403
404 <xsl:template match="sectiondef">
405 <para>
406 <xsl:value-of select="description"/>
407 </para>
408
409 <xsl:apply-templates select="memberdef"/>
410 </xsl:template>
411
412 <xsl:template match="simplesect" mode="struct">
413 <footnote>
414 <xsl:apply-templates/>
415 </footnote>
416 </xsl:template>
417
418 <xsl:template match="simplesect">
419 <xsl:choose>
420 <xsl:when test="@kind = 'par'">
421 <note>
422 <title>
423 <xsl:value-of select="title"/>
424 </title>
425 <xsl:apply-templates/>
426 </note>
427 </xsl:when>
428
429 <xsl:when test="@kind = 'return'">
430 <note>
431 <title>Returns</title>
432 <xsl:apply-templates/>
433 </note>
434 </xsl:when>
435
436 <xsl:when test="@kind = 'warning'">
437 <warning>
438 <title>Warning</title>
439 <xsl:apply-templates/>
440 </warning>
441 </xsl:when>
442
443 <xsl:when test="@kind = 'pre'">
444 <note>
445 <title>Precondition</title>
446 <xsl:apply-templates/>
447 </note>
448 </xsl:when>
449
450 <xsl:when test="@kind = 'see'">
451 <note>
452 <title>See also</title>
453 <xsl:apply-templates/>
454 </note>
455 </xsl:when>
456
457 <xsl:when test="@kind = 'note'">
458 <note>
459 <title>Note</title>
460 <xsl:apply-templates/>
461 </note>
462 </xsl:when>
463
464 </xsl:choose>
465 </xsl:template>
466
467 <xsl:template match="parameterlist[@kind = 'param']">
468 <table tabstyle="striped">
469 <title>Parameters</title>
470 <tgroup cols="3">
471 <thead>
472 <row>
473 <entry>Data Direction</entry>
474 <entry>Parameter Name</entry>
475 <entry>Description</entry>
476 </row>
477 </thead>
478 <tbody>
479 <xsl:for-each select="parameteritem">
480 <row>
481 <xsl:apply-templates select="."/>
482 </row>
483 </xsl:for-each>
484 </tbody>
485 </tgroup>
486 </table>
487 </xsl:template>
488
489 <xsl:template match="parameterlist[@kind = 'retval']">
490 <table tabstyle="striped">
491 <title>Return Values</title>
492 <tgroup cols="2">
493 <thead>
494 <row>
495 <entry>Return Value</entry>
496 <entry>Description</entry>
497 </row>
498 </thead>
499 <tbody>
500 <xsl:for-each select="parameteritem">
501 <row>
502 <xsl:apply-templates select="."/>
503 </row>
504 </xsl:for-each>
505 </tbody>
506 </tgroup>
507 </table>
508 </xsl:template>
509
510 <xsl:template match="parameteritem">
511 <xsl:if test="parent::parameterlist/@kind = 'param'">
512 <entry>
513 <para>
514 <xsl:choose>
515 <xsl:when test="not(descendant::parametername/@direction)">
516 <emphasis role="italic">?</emphasis>
517 </xsl:when>
518
519 <xsl:otherwise>
520 <emphasis role="bold">
521 [<xsl:value-of select="descendant::parametername/@direction"/>]
522 </emphasis>
523 </xsl:otherwise>
524 </xsl:choose>
525 </para>
526 </entry>
527 </xsl:if>
528
529 <entry>
530 <para>
531 <xsl:value-of select="parameternamelist/parametername"/>
532 </para>
533 </entry>
534
535 <entry>
536 <xsl:apply-templates select="parameterdescription"/>
537 </entry>
538 </xsl:template>
539
540 <xsl:template match="parameterdescription">
541 <para>
542 <xsl:apply-templates/>
543 </para>
544 </xsl:template>
545
546 <xsl:template match="type">
547 <xsl:apply-templates/>
548 </xsl:template>
549
550 <xsl:template match="bold">
551 <emphasis role="bold">
552 <xsl:apply-templates/>
553 </emphasis>
554 </xsl:template>
555
556 <xsl:template match="emphasis">
557 <emphasis role="italic">
558 <xsl:apply-templates/>
559 </emphasis>
560 </xsl:template>
561
562 <xsl:template match="small">
563 <xsl:apply-templates/>
564 </xsl:template>
565
566 <xsl:template match="mdash | ndash">
567 <xsl:text>--</xsl:text>
568 </xsl:template>
569
570 <xsl:template match="computeroutput | preformatted">
571 <computeroutput>
572 <xsl:apply-templates/>
573 </computeroutput>
574 </xsl:template>
575
576 <xsl:template match="codeline">
577 <xsl:apply-templates/>
578 </xsl:template>
579
580 <xsl:template match="ulink">
581 <ulink url="{@url}">
582 <xsl:value-of select="."/>
583 </ulink>
584 </xsl:template>
585
586 <xsl:template match="superscript">
587 <superscript>
588 <xsl:apply-templates/>
589 </superscript>
590 </xsl:template>
591
592 <xsl:template match="subscript">
593 <subscript>
594 <xsl:apply-templates/>
595 </subscript>
596 </xsl:template>
597
598 <xsl:template match="para">
599 <para>
600 <xsl:apply-templates/>
601 </para>
602 </xsl:template>
603
604 <xsl:template match="ref">
605 <xsl:choose>
606 <!-- Don't show links inside program listings -->
607 <xsl:when test="ancestor::programlisting">
608 <xsl:value-of select="."/>
609 </xsl:when>
610
611 <!-- Don't show links to file compound definitions, as they are discarded -->
612 <xsl:when test="ancestor::*/compounddef[@kind = 'file' and @id = current()/@refid]">
613 <xsl:value-of select="."/>
614 </xsl:when>
615
616 <!-- Show links outside program listings -->
617 <xsl:otherwise>
618 <link linkend="{@refid}">
619 <xsl:value-of select="text()"/>
620 </link>
621 </xsl:otherwise>
622 </xsl:choose>
623 </xsl:template>
624
625 <xsl:template match="entry">
626 <entry>
627 <xsl:apply-templates/>
628 </entry>
629 </xsl:template>
630
631 <xsl:template match="table">
632 <xsl:choose>
633 <xsl:when test="caption">
634 <table tabstyle="striped">
635 <title>
636 <xsl:value-of select="caption"/>
637 </title>
638
639 <xsl:call-template name="write.table.content"/>
640 </table>
641 </xsl:when>
642
643 <xsl:otherwise>
644 <informaltable tabstyle="striped">
645 <xsl:call-template name="write.table.content"/>
646 </informaltable>
647 </xsl:otherwise>
648 </xsl:choose>
649 </xsl:template>
650
651 <xsl:template name="write.table.content">
652 <tgroup cols="{@cols}">
653 <thead>
654 <xsl:for-each select="row[1]">
655 <row>
656 <xsl:apply-templates select="entry"/>
657 </row>
658 </xsl:for-each>
659 </thead>
660 <tbody>
661 <xsl:for-each select="row[position() != 1]">
662 <row>
663 <xsl:apply-templates select="entry"/>
664 </row>
665 </xsl:for-each>
666 </tbody>
667 </tgroup>
668 </xsl:template>
669
670 <xsl:template match="itemizedlist">
671 <itemizedlist>
672 <xsl:apply-templates/>
673 </itemizedlist>
674 </xsl:template>
675
676 <xsl:template match="orderedlist">
677 <orderedlist>
678 <xsl:apply-templates/>
679 </orderedlist>
680 </xsl:template>
681
682 <xsl:template match="listitem">
683 <listitem>
684 <xsl:apply-templates/>
685 </listitem>
686 </xsl:template>
687
688 <xsl:template match="programlisting">
689 <programlisting language="c">
690 <xsl:for-each select="codeline[position() > 1 or highlight]">
691 <xsl:apply-templates select="."/>
692 <xsl:text>&#10;</xsl:text>
693 </xsl:for-each>
694 </programlisting>
695 </xsl:template>
696
697 <xsl:template match="highlight">
698 <emphasis role="{@class}">
699 <xsl:apply-templates/>
700 </emphasis>
701 </xsl:template>
702
703 <xsl:template match="sp[ancestor::codeline]">
704 <xsl:text> </xsl:text>
705 </xsl:template>
706
707 <xsl:template match="image">
708 <mediaobject>
709 <imageobject>
710 <imagedata align="center">
711 <xsl:attribute name="fileref">
712 <xsl:text>images/</xsl:text>
713 <xsl:value-of select="@name"/>
714 </xsl:attribute>
715 </imagedata>
716 </imageobject>
717 </mediaobject>
718 </xsl:template>
719
720 <xsl:template match="detaileddescription">
721 <xsl:apply-templates/>
722 </xsl:template>
723
724 <xsl:template match="sect1 | sect2 | sect3 | sect4 | sect5 | sect6 | sect7 | sect8 | sect9">
725 <section>
726 <xsl:if test="@id">
727 <xsl:attribute name="id">
728 <xsl:value-of select="@id"/>
729 </xsl:attribute>
730 </xsl:if>
731
732 <title>
733 <xsl:value-of select="title"/>
734 </title>
735
736 <xsl:apply-templates/>
737 </section>
738 </xsl:template>
739
740 <xsl:template match="anchor">
741 <xsl:if test="@id">
742 <indexterm id="{@id}"/>
743 </xsl:if>
744 </xsl:template>
745
746 <xsl:template match="title"/>
747
748 <xsl:template match="htmlonly"/>
749
750 <xsl:template match="*">
751 <xsl:message>NO XSL TEMPLATE MATCH: <xsl:value-of select="name()"/></xsl:message>
752 </xsl:template>
753
754 </xsl:stylesheet>