03b7901b616b8ee6912dec6cf3b97d761ada3da5
[pub/USBasp.git] / LUFA / StudioIntegration / HV1 / transform_base.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:exsl="http://exslt.org/common"
5 extension-element-prefixes="exsl"
6 exclude-result-prefixes="exsl"
7 version="1.0">
8
9 <xsl:output
10 method="xml" indent="yes"
11 doctype-public="-//OASIS//DTD DocBook XML V4.5//EN"
12 doctype-system="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"/>
13
14 <xsl:template name="write.api.overview.contents">
15
16 <xsl:if test="count(ancestor::*/sectiondef[memberdef/@kind = 'variable' or memberdef/@kind = 'typedef']) > 0">
17 <section>
18 <title>Variable and Type Definitions</title>
19
20 <xsl:for-each select="ancestor::*/sectiondef[memberdef/@kind = 'variable' or memberdef/@kind = 'typedef']">
21 <section>
22 <title>
23 <xsl:value-of select="header"/>
24 </title>
25
26 <xsl:apply-templates select="description"/>
27 <xsl:apply-templates select="memberdef[@kind = 'variable' or @kind = 'typedef']"/>
28 </section>
29 </xsl:for-each>
30 </section>
31 </xsl:if>
32
33 <xsl:if test="count(ancestor::*/innerclass) > 0">
34 <section>
35 <title>Structure Definitions</title>
36
37 <xsl:for-each select="ancestor::*/innerclass">
38 <xsl:apply-templates select="ancestor::*/compounddef[@id = current()/@refid]"/>
39 </xsl:for-each>
40 </section>
41 </xsl:if>
42
43 <xsl:if test="count(ancestor::*/sectiondef[memberdef/@kind = 'define' or @kind = 'define']) > 0">
44 <section>
45 <title>Macro Definitions</title>
46
47 <xsl:for-each select="ancestor::*/sectiondef[memberdef/@kind = 'define' or @kind = 'define']">
48 <section>
49 <title>
50 <xsl:value-of select="header"/>
51 </title>
52
53 <xsl:apply-templates select="description"/>
54 <xsl:apply-templates select="memberdef[@kind = 'define']"/>
55 </section>
56 </xsl:for-each>
57 </section>
58 </xsl:if>
59
60 <xsl:if test="count(ancestor::*/sectiondef[memberdef/@kind = 'function']) > 0">
61 <section>
62 <title>Function Definitions</title>
63
64 <xsl:for-each select="ancestor::*/sectiondef[memberdef/@kind = 'function']">
65 <section>
66 <title>
67 <xsl:value-of select="header"/>
68 </title>
69
70 <xsl:apply-templates select="description"/>
71 <xsl:apply-templates select="memberdef[@kind = 'function']"/>
72 </section>
73 </xsl:for-each>
74 </section>
75 </xsl:if>
76
77 <xsl:if test="count(ancestor::*/sectiondef[@kind = 'enum']) > 0">
78 <section>
79 <title>Enumeration Definitions</title>
80
81 <xsl:apply-templates select="ancestor::*/sectiondef[@kind = 'enum']"/>
82 </section>
83 </xsl:if>
84
85 </xsl:template>
86
87 <xsl:template match="compounddef">
88 <!-- Discard compounddef elements unless a later template matches -->
89 </xsl:template>
90
91 <xsl:template match="compounddef[@kind = 'struct' or @kind = 'union']">
92 <section id="{@id}" xreflabel="{compoundname}">
93 <title>
94 <xsl:choose>
95 <xsl:when test="@kind = 'struct'">
96 <xsl:text>Struct </xsl:text>
97 </xsl:when>
98 <xsl:when test="@kind = 'union'">
99 <xsl:text>Union </xsl:text>
100 </xsl:when>
101 </xsl:choose>
102
103 <xsl:value-of select="compoundname"/>
104 </title>
105
106 <xsl:apply-templates select="detaileddescription"/>
107
108 <xsl:for-each select="sectiondef[@kind = 'public-attrib']">
109 <informaltable tabstyle="striped">
110 <tgroup cols="3">
111 <thead>
112 <row>
113 <entry>Type</entry>
114 <entry>Name</entry>
115 <entry>Description</entry>
116 </row>
117 </thead>
118 <tbody>
119 <xsl:for-each select="memberdef">
120 <row id="{@id}" xreflabel="{name}">
121 <entry>
122 <xsl:apply-templates select="type"/>
123 </entry>
124 <entry>
125 <xsl:value-of select="name"/>
126 <xsl:if test="starts-with(argsstring, '[')">
127 <xsl:text>[]</xsl:text>
128 </xsl:if>
129 </entry>
130 <entry>
131 <xsl:apply-templates select="detaileddescription" mode="struct"/>
132 </entry>
133 </row>
134 </xsl:for-each>
135 </tbody>
136 </tgroup>
137 </informaltable>
138 <para>&#xa0;</para>
139 </xsl:for-each>
140 </section>
141 </xsl:template>
142
143 <xsl:template match="memberdef[@kind = 'function']">
144 <section id="{@id}" xreflabel="{name}">
145 <title> Function <xsl:value-of select="name"/>() </title>
146
147 <para>
148 <emphasis role="italic">
149 <xsl:value-of select="briefdescription"/>
150 </emphasis>
151 </para>
152
153 <programlisting language="c">
154 <xsl:value-of select="definition"/>
155 <xsl:text>&#10;&#9;&#9;</xsl:text>
156 <xsl:apply-templates select="argsstring"/>
157 </programlisting>
158
159 <xsl:apply-templates select="detaileddescription"/>
160
161 <para>&#xa0;</para>
162 </section>
163 </xsl:template>
164
165 <xsl:template match="memberdef[@kind = 'enum']">
166 <section id="{@id}" xreflabel="{name}">
167 <title> Enum <xsl:value-of select="name"/> </title>
168
169 <xsl:apply-templates select="detaileddescription"/>
170
171 <informaltable tabstyle="striped">
172 <tgroup cols="2">
173 <thead>
174 <row>
175 <entry>Enum Value</entry>
176 <entry>Description</entry>
177 </row>
178 </thead>
179 <tbody>
180 <xsl:for-each select="enumvalue">
181 <row>
182 <entry>
183 <para id="{@id}" xreflabel="{name}">
184 <xsl:value-of select="name"/>
185 </para>
186 </entry>
187 <entry>
188 <xsl:apply-templates select="detaileddescription"/>
189 </entry>
190 </row>
191 </xsl:for-each>
192 </tbody>
193 </tgroup>
194 </informaltable>
195
196 <para>&#xa0;</para>
197 </section>
198 </xsl:template>
199
200 <xsl:template match="memberdef[@kind = 'define']">
201 <section id="{@id}" xreflabel="{name}">
202 <title> Macro <xsl:value-of select="name"/> </title>
203
204 <programlisting language="c">
205 <xsl:text>#define </xsl:text>
206 <xsl:value-of select="name"/>
207 <xsl:if test="count(param) > 0">
208 <xsl:text>(</xsl:text>
209 <xsl:for-each select="param/defname">
210 <xsl:if test="position() > 1">
211 <xsl:text>, </xsl:text>
212 </xsl:if>
213 <xsl:value-of select="."/>
214 </xsl:for-each>
215 <xsl:text>)</xsl:text>
216 </xsl:if>
217 <xsl:text> </xsl:text>
218
219 <!-- Split long macro definitions across multiple lines -->
220 <xsl:if test="(string-length(initializer) > 50) or (count(param) > 0)">
221 <xsl:text>\&#10;&#09;&#9;</xsl:text>
222 </xsl:if>
223
224 <xsl:value-of select="initializer"/>
225 </programlisting>
226
227 <xsl:apply-templates select="detaileddescription"/>
228
229 <para>&#xa0;</para>
230 </section>
231 </xsl:template>
232
233 <xsl:template match="memberdef[@kind = 'variable' or @kind = 'typedef']">
234 <section id="{@id}" xreflabel="{name}">
235 <title>
236 <!-- Doxygen gets confused and thinks function pointer type definitions
237 are variables, so we need to map them to this common section and
238 check the definition to see which of the two it is. -->
239 <xsl:choose>
240 <xsl:when test="contains(definition,'typedef')">
241 <xsl:text>Type </xsl:text>
242 </xsl:when>
243
244 <xsl:otherwise>
245 <xsl:text>Variable </xsl:text>
246 </xsl:otherwise>
247 </xsl:choose>
248
249 <xsl:value-of select="name"/>
250 </title>
251
252 <programlisting language="c">
253 <xsl:value-of select="definition"/>
254 </programlisting>
255
256 <xsl:apply-templates select="detaileddescription"/>
257
258 <para>&#xa0;</para>
259 </section>
260 </xsl:template>
261
262 <xsl:template match="sectiondef">
263 <para>
264 <xsl:value-of select="description"/>
265 </para>
266
267 <xsl:apply-templates select="memberdef"/>
268 </xsl:template>
269
270 <xsl:template match="simplesect" mode="struct">
271 <footnote>
272 <xsl:apply-templates select="para"/>
273 </footnote>
274 </xsl:template>
275
276 <xsl:template match="simplesect">
277 <xsl:choose>
278 <xsl:when test="@kind = 'warning'">
279 <warning>
280 <title>Warning</title>
281 <xsl:apply-templates select="para"/>
282 </warning>
283 </xsl:when>
284
285 <xsl:when test="@kind = 'return'">
286 <note>
287 <title>Returns</title>
288 <xsl:apply-templates select="para"/>
289 </note>
290 </xsl:when>
291
292 <xsl:when test="@kind = 'pre'">
293 <note>
294 <title>Precondition</title>
295 <xsl:apply-templates select="para"/>
296 </note>
297 </xsl:when>
298
299 <xsl:when test="@kind = 'par'">
300 <note>
301 <title>
302 <xsl:value-of select="title"/>
303 </title>
304 <xsl:apply-templates select="para"/>
305 </note>
306 </xsl:when>
307
308 <xsl:when test="@kind = 'see'">
309 <note>
310 <title>See also</title>
311 <xsl:apply-templates select="para"/>
312 </note>
313 </xsl:when>
314
315 <xsl:when test="@kind = 'note'">
316 <!-- Notes can have special prefix keywords to transform them into
317 special styles for training documents ("AlfonsoNotes(TM)") -->
318 <xsl:variable name="note.prefix" select="substring-before(para[1]/text(), ' ')"/>
319
320 <note>
321 <xsl:choose>
322 <xsl:when test="$note.prefix = 'TODO:'">
323 <xsl:attribute name="role">todo</xsl:attribute>
324 <title>To Do</title>
325 </xsl:when>
326
327 <xsl:when test="$note.prefix = 'TIP:'">
328 <xsl:attribute name="role">tip</xsl:attribute>
329 <title>Tip</title>
330 </xsl:when>
331
332 <xsl:when test="$note.prefix = 'INFO:'">
333 <xsl:attribute name="role">info</xsl:attribute>
334 <title>Info</title>
335 </xsl:when>
336
337 <xsl:when test="$note.prefix = 'RESULT:'">
338 <xsl:attribute name="role">result</xsl:attribute>
339 <title>Result</title>
340 </xsl:when>
341
342 <xsl:when test="$note.prefix = 'EXECUTE:'">
343 <xsl:attribute name="role">execute</xsl:attribute>
344 <title>Execute</title>
345 </xsl:when>
346
347 <xsl:when test="$note.prefix = 'WARNING:'">
348 <xsl:attribute name="role">warning</xsl:attribute>
349 <title>Warning</title>
350 </xsl:when>
351
352 <xsl:otherwise/>
353 </xsl:choose>
354
355 <xsl:apply-templates select="para"/>
356 </note>
357 </xsl:when>
358
359 </xsl:choose>
360 </xsl:template>
361
362 <!-- Strip off the special note type prefix from the special training document
363 style notes ("AlfonsoNotes(TM)") if one is present. -->
364 <xsl:template match="para[parent::simplesect/@kind='note']/text()">
365 <xsl:variable name="note.prefix" select="substring-before(., ' ')"/>
366 <xsl:variable name="note.content" select="substring-after(., ' ')"/>
367
368 <xsl:choose>
369 <xsl:when test="$note.prefix = 'TODO:'">
370 <xsl:value-of select="$note.content"/>
371 </xsl:when>
372
373 <xsl:when test="$note.prefix = 'TIP:'">
374 <xsl:value-of select="$note.content"/>
375 </xsl:when>
376
377 <xsl:when test="$note.prefix = 'INFO:'">
378 <xsl:value-of select="$note.content"/>
379 </xsl:when>
380
381 <xsl:when test="$note.prefix = 'RESULT:'">
382 <xsl:value-of select="$note.content"/>
383 </xsl:when>
384
385 <xsl:when test="$note.prefix = 'EXECUTE:'">
386 <xsl:value-of select="$note.content"/>
387 </xsl:when>
388
389 <xsl:when test="$note.prefix = 'WARNING:'">
390 <xsl:value-of select="$note.content"/>
391 </xsl:when>
392
393 <xsl:otherwise>
394 <xsl:value-of select="."/>
395 </xsl:otherwise>
396 </xsl:choose>
397 </xsl:template>
398
399 <xsl:template match="parameterlist[@kind = 'param']">
400 <table tabstyle="striped">
401 <title>Parameters</title>
402 <tgroup cols="3">
403 <thead>
404 <row>
405 <entry>Data Direction</entry>
406 <entry>Parameter Name</entry>
407 <entry>Description</entry>
408 </row>
409 </thead>
410 <tbody>
411 <xsl:for-each select="parameteritem">
412 <row>
413 <xsl:apply-templates select="."/>
414 </row>
415 </xsl:for-each>
416 </tbody>
417 </tgroup>
418 </table>
419 </xsl:template>
420
421 <xsl:template match="parameterlist[@kind = 'retval']">
422 <table tabstyle="striped">
423 <title>Return Values</title>
424 <tgroup cols="2">
425 <thead>
426 <row>
427 <entry>Return Value</entry>
428 <entry>Description</entry>
429 </row>
430 </thead>
431 <tbody>
432 <xsl:for-each select="parameteritem">
433 <row>
434 <xsl:apply-templates select="."/>
435 </row>
436 </xsl:for-each>
437 </tbody>
438 </tgroup>
439 </table>
440 </xsl:template>
441
442 <xsl:template match="parameteritem">
443 <xsl:if test="parent::parameterlist/@kind = 'param'">
444 <entry>
445 <para>
446 <xsl:choose>
447 <xsl:when test="not(descendant::parametername/@direction)">
448 <emphasis role="italic">?</emphasis>
449 </xsl:when>
450 <xsl:otherwise>
451 <emphasis role="bold">[<xsl:value-of select="descendant::parametername/@direction"/>]</emphasis>
452 </xsl:otherwise>
453 </xsl:choose>
454 </para>
455 </entry>
456 </xsl:if>
457
458 <entry>
459 <para>
460 <xsl:value-of select="parameternamelist/parametername"/>
461 </para>
462 </entry>
463
464 <entry>
465 <xsl:apply-templates select="parameterdescription"/>
466 </entry>
467 </xsl:template>
468
469 <xsl:template match="type">
470 <xsl:apply-templates/>
471 </xsl:template>
472
473 <xsl:template match="sect1">
474 <section id="{@id}" xreflabel="{title}">
475 <title>
476 <xsl:value-of select="title"/>
477 </title>
478
479 <xsl:apply-templates select="para"/>
480 <xsl:apply-templates select="sect2"/>
481 </section>
482 </xsl:template>
483
484 <xsl:template match="sect2">
485 <section id="{@id}" xreflabel="{title}">
486 <title>
487 <xsl:value-of select="title"/>
488 </title>
489
490 <xsl:apply-templates select="para"/>
491 <xsl:apply-templates select="sect3"/>
492 </section>
493 </xsl:template>
494
495 <xsl:template match="sect3">
496 <section id="{@id}" xreflabel="{title}">
497 <title>
498 <xsl:value-of select="title"/>
499 </title>
500
501 <xsl:apply-templates select="para"/>
502 </section>
503 </xsl:template>
504
505 <xsl:template match="detaileddescription">
506 <xsl:apply-templates select="para"/>
507 <xsl:apply-templates select="sect1"/>
508 </xsl:template>
509
510 <xsl:template match="para">
511 <para>
512 <xsl:apply-templates/>
513 </para>
514 </xsl:template>
515
516 <xsl:template match="bold">
517 <emphasis role="bold">
518 <xsl:value-of select="."/>
519 </emphasis>
520 </xsl:template>
521
522 <xsl:template match="emphasis">
523 <emphasis role="italic">
524 <xsl:value-of select="."/>
525 </emphasis>
526 </xsl:template>
527
528 <xsl:template match="computeroutput">
529 <computeroutput>
530 <xsl:value-of select="."/>
531 </computeroutput>
532 </xsl:template>
533
534 <xsl:template match="ulink">
535 <ulink url="{@url}">
536 <xsl:value-of select="."/>
537 </ulink>
538 </xsl:template>
539
540 <xsl:template match="registered">
541 <xsl:text>&#174;</xsl:text>
542 </xsl:template>
543
544 <xsl:template match="copy">
545 <xsl:text>&#169;</xsl:text>
546 </xsl:template>
547
548 <xsl:template match="trademark">
549 <xsl:text>&#8482;</xsl:text>
550 </xsl:template>
551
552 <xsl:template match="ref">
553 <xsl:choose>
554 <!-- Don't show links inside program listings -->
555 <xsl:when test="ancestor::programlisting">
556 <xsl:value-of select="."/>
557 </xsl:when>
558
559 <!-- Show links outside program listings -->
560 <xsl:otherwise>
561 <link linkend="{@refid}" xrefstyle="nopage">
562 <xsl:value-of select="text()"/>
563 </link>
564 </xsl:otherwise>
565 </xsl:choose>
566 </xsl:template>
567
568 <xsl:template match="formula">
569 <equation>
570 <!-- LaTeX equation generation requires JLatexMath and its associated
571 FOP plugin, or you will get missing equations in the output -->
572 <latex align="center" xmlns="http://forge.scilab.org/p/jlatexmath">
573 <xsl:value-of select="."/>
574 </latex>
575 </equation>
576 </xsl:template>
577
578 <xsl:template match="table">
579 <xsl:choose>
580 <xsl:when test="caption">
581 <table tabstyle="striped">
582 <title>
583 <xsl:value-of select="caption"/>
584 </title>
585 <xsl:call-template name="write.table.content"/>
586 </table>
587 </xsl:when>
588 <xsl:otherwise>
589 <informaltable tabstyle="striped">
590 <xsl:call-template name="write.table.content"/>
591 </informaltable>
592 </xsl:otherwise>
593 </xsl:choose>
594 </xsl:template>
595
596 <xsl:template name="write.table.content">
597 <tgroup cols="{@cols}">
598 <thead>
599 <xsl:for-each select="row[1]">
600 <row>
601 <xsl:for-each select="entry">
602 <entry>
603 <xsl:apply-templates select="."/>
604 </entry>
605 </xsl:for-each>
606 </row>
607 </xsl:for-each>
608 </thead>
609 <tbody>
610 <xsl:for-each select="row[position() != 1]">
611 <row>
612 <xsl:for-each select="entry">
613 <entry>
614 <xsl:apply-templates select="."/>
615 </entry>
616 </xsl:for-each>
617 </row>
618 </xsl:for-each>
619 </tbody>
620 </tgroup>
621 </xsl:template>
622
623 <xsl:template match="itemizedlist">
624 <itemizedlist>
625 <xsl:apply-templates select="listitem"/>
626 </itemizedlist>
627 </xsl:template>
628
629 <xsl:template match="orderedlist">
630 <orderedlist>
631 <xsl:apply-templates select="listitem"/>
632 </orderedlist>
633 </xsl:template>
634
635 <xsl:template match="listitem">
636 <listitem>
637 <xsl:apply-templates/>
638 </listitem>
639 </xsl:template>
640
641 <xsl:template match="programlisting">
642 <programlisting language="c">
643 <xsl:for-each select="codeline[position() > 1 or highlight]">
644 <xsl:apply-templates select="."/>
645 <xsl:text>&#10;</xsl:text>
646 </xsl:for-each>
647 </programlisting>
648 </xsl:template>
649
650 <xsl:template match="highlight">
651 <emphasis>
652 <xsl:attribute name="role">
653 <xsl:value-of select="@class"/>
654 </xsl:attribute>
655 <xsl:apply-templates/>
656 </emphasis>
657 </xsl:template>
658
659 <xsl:template match="sp[ancestor::codeline]">
660 <xsl:choose>
661 <!-- Need to check if this is the first part of the line - if so we may
662 need to strip off any leading <sp/> element indentation -->
663 <xsl:when test="ancestor::highlight = ancestor::codeline/highlight[1]">
664 <!-- Doxygen retains a level of indentation in some code fragments - obtain
665 the base indentation level by counting the leading <sp/> elements of the
666 first code line, and use that to remove the indentation on the rest -->
667 <xsl:variable name="leading.spaces" select="count(ancestor::programlisting/codeline[highlight][1]/highlight[1]/sp[not(preceding-sibling::text())])"/>
668
669 <xsl:if test="position() > $leading.spaces">
670 <xsl:text> </xsl:text>
671 </xsl:if>
672 </xsl:when>
673
674 <xsl:otherwise>
675 <xsl:text> </xsl:text>
676 </xsl:otherwise>
677 </xsl:choose>
678 </xsl:template>
679
680 <xsl:template match="image">
681 <figure>
682 <title>
683 <xsl:value-of select="."/>
684 </title>
685
686 <mediaobject>
687 <imageobject>
688 <imagedata scalefit="1" width="{@width}">
689 <xsl:attribute name="fileref">html/<xsl:value-of select="@name"/></xsl:attribute>
690 </imagedata>
691 </imageobject>
692 </mediaobject>
693 </figure>
694 </xsl:template>
695
696 <xsl:template match="anchor">
697 <anchor id="{@id}"/>
698 </xsl:template>
699
700 <xsl:template match="dot">
701 <!-- We get raw DOT syntax rather than a rendered image: write the DOT code
702 to a new unique file, and make a image reference to a SVG version of
703 that file. The build system should then call dot to render all generated
704 DOT files into their SVG equivalents before rendering the PDF. -->
705 <xsl:variable name="filename" select="generate-id(.)" />
706 <exsl:document href="{$filename}.dot" method="text">
707 <xsl:value-of select="." />
708 </exsl:document>
709
710 <figure>
711 <title>
712 <xsl:value-of select="ancestor::*/title"/>
713 </title>
714 <mediaobject>
715 <imageobject>
716 <imagedata format="SVG">
717 <xsl:attribute name="fileref">
718 <xsl:value-of select="$filename" />
719 <xsl:text>.svg</xsl:text>
720 </xsl:attribute>
721 </imagedata>
722 </imageobject>
723 </mediaobject>
724 </figure>
725 </xsl:template>
726
727 <xsl:template match="argsstring" name="split.functions.args">
728 <xsl:param name="text" select="."/>
729 <xsl:value-of select="substring-before(concat($text,','),',')"/>
730 <xsl:if test="contains($text,',')">
731 <xsl:text>,&#10;&#09;&#9;</xsl:text>
732 <xsl:call-template name="split.functions.args">
733 <xsl:with-param name="text" select="substring-after($text,',')"/>
734 </xsl:call-template>
735 </xsl:if>
736 </xsl:template>
737 </xsl:stylesheet>