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