3 Stylesheet to generate the HTML documentation from an XML API descriptions:
4 xsltproc newapi.xsl libxslt-api.xml
8 Note: This stylesheet was adapted from the original (written for libxml2)
9 by William Brack, who is fully responsible for any mistakes or
10 problems. The major enhancement is changing all references to the
11 library and to the output directory into references to global
12 parameters ('libdir' and 'html_dir' respectively).
14 <xsl:stylesheet version="1.0"
15 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
16 xmlns:exsl="http://exslt.org/common"
17 xmlns:str="http://exslt.org/strings"
18 extension-element-prefixes="exsl str"
19 exclude-result-prefixes="exsl str">
21 <!-- Import the main part of the site stylesheets -->
22 <xsl:import href="site.xsl"/>
24 <!-- Generate XHTML-1.0 transitional -->
25 <xsl:output method="xml" encoding="ISO-8859-1" indent="yes"
26 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
27 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
29 <!-- Build keys for all symbols -->
30 <xsl:key name="symbols" match="/api/symbols/*" use="@name"/>
33 Note that variables declared as "param" may be changed at runtime
35 <!-- the name of the library being documented -->
36 <xsl:param name="libname">libxslt</xsl:param>
38 <!-- the directory for the 'home' files-->
39 <xsl:param name="dirname" select="'../'"/>
41 <!-- the location of logos for the pages -->
42 <xsl:param name="logo_base" select="'../'"/>
44 <!-- these override the definition in site.xsl -->
45 <xsl:variable name="href_base" select="'../'"/>
46 <xsl:variable name="html_dir" select="'html/'"/>
47 <xsl:variable name="api_base" select="''"/>
48 <xsl:variable name="globaltitle">
50 <xsl:when test="$libname='libxslt'">
51 <xsl:value-of select="'The XSLT C library for GNOME'"/>
53 <xsl:when test="$libname='libxml'">
54 <xsl:value-of select="'The XML C library for GNOME'"/>
56 <xsl:when test="$libname='libexslt'">
57 <xsl:value-of select="'The EXSLT C library for GNOME'"/>
60 <xsl:value-of select="'Unknown Library'"/>
65 <!-- The table of content for the HTML API pages -->
66 <xsl:variable name="menu_name">API Menu</xsl:variable>
67 <xsl:variable name="toc">
68 <form action="../search.php"
69 enctype="application/x-www-form-urlencoded" method="get">
70 <input name="query" type="text" size="20" value=""/>
71 <input name="submit" type="submit" value="Search ..."/>
73 <ul><!-- style="margin-left: -1em" -->
74 <li><a style="font-weight:bold"
75 href="{$href_base}index.html">Main Menu</a></li>
76 <li><a style="font-weight:bold"
77 href="{$href_base}docs.html">Developer Menu</a></li>
78 <!-- Coming soon .....
79 <li><a style="font-weight:bold"
80 href="{$href_base}examples/index.html">Code Examples</a></li>
82 <li><a style="font-weight:bold"
83 href="index.html">API Menu</a></li>
84 <!-- Coming soon .....
85 <li><a href="{$href_base}guidelines.html">XSLT Guidelines</a></li>
87 <li><a href="{$href_base}ChangeLog.html">ChangeLog</a></li>
90 <xsl:template name="toc">
91 <table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000">
94 <table width="100%" border="0" cellspacing="1" cellpadding="3">
96 <td colspan="1" bgcolor="#eecfa1" align="center">
98 <b><xsl:value-of select="$menu_name"/></b>
103 <td bgcolor="#fffacd">
104 <xsl:copy-of select="$toc"/>
108 <table width="100%" border="0" cellspacing="1" cellpadding="3">
110 <td colspan="1" bgcolor="#eecfa1" align="center">
117 <td bgcolor="#fffacd">
118 <xsl:copy-of select="$api"/>
122 <table width="100%" border="0" cellspacing="1" cellpadding="3">
124 <td colspan="1" bgcolor="#eecfa1" align="center">
131 <td bgcolor="#fffacd">
132 <xsl:copy-of select="$related"/>
141 <xsl:template name="docstyle">
142 <style type="text/css">
143 div.deprecated pre.programlisting {border-style: double;border-color:red}
144 pre.programlisting {border-style: double;background: #EECFA1}
147 <xsl:template name="navbar">
148 <xsl:variable name="previous" select="preceding-sibling::file[1]"/>
149 <xsl:variable name="next" select="following-sibling::file[1]"/>
150 <table class="navigation" width="100%" summary="Navigation header"
151 cellpadding="2" cellspacing="2">
153 <xsl:if test="$previous">
154 <td><a accesskey="p" href="{$libname}-{$previous/@name}.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></img></a></td>
155 <th align="left"><a href="{$libname}-{$previous/@name}.html"><xsl:value-of select="$previous/@name"/></a></th>
157 <td><a accesskey="u" href="index.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></img></a></td>
158 <th align="left"><a href="index.html">API documentation</a></th>
159 <td><a accesskey="h" href="../index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></img></a></td>
160 <th align="center"><a href="../index.html">Home</a></th>
161 <xsl:if test="$next">
162 <th align="right"><a href="{$libname}-{$next/@name}.html"><xsl:value-of select="$next/@name"/></a></th>
163 <td><a accesskey="n" href="{$libname}-{$next/@name}.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></img></a></td>
169 <!-- This is convoluted but needed to force the current document to
170 be the API one and not the result tree from the tokenize() result,
171 because the keys are only defined on the main document -->
172 <xsl:template mode="dumptoken" match='*'>
173 <xsl:param name="token"/>
174 <xsl:variable name="ref" select="key('symbols', $token)"/>
176 <xsl:when test="$ref">
177 <a href="{$libname}-{$ref/@file}.html#{$ref/@name}"><xsl:value-of select="$token"/></a>
180 <xsl:value-of select="$token"/>
185 <!-- dumps a string, making cross-reference links -->
186 <xsl:template name="dumptext">
187 <xsl:param name="text"/>
188 <xsl:variable name="ctxt" select='.'/>
189 <!-- <xsl:value-of select="$text"/> -->
190 <xsl:for-each select="str:tokenize($text, ' 	')">
191 <xsl:apply-templates select="$ctxt" mode='dumptoken'>
192 <xsl:with-param name="token" select="string(.)"/>
193 </xsl:apply-templates>
194 <xsl:if test="position() != last()">
195 <xsl:text> </xsl:text>
200 <xsl:template match="macro" mode="toc">
201 <pre class="programlisting">
202 <xsl:text>#define </xsl:text><a href="#{@name}"><xsl:value-of select="@name"/></a>
206 <xsl:template match="variable" mode="toc">
207 <pre class="programlisting">
208 <xsl:text>Variable </xsl:text>
209 <xsl:call-template name="dumptext">
210 <xsl:with-param name="text" select="string(@type)"/>
212 <xsl:text> </xsl:text>
213 <a name="{@name}"></a>
214 <xsl:value-of select="@name"/>
221 <xsl:template match="typedef" mode="toc">
222 <xsl:variable name="name" select="string(@name)"/>
223 <pre class="programlisting">
225 <xsl:when test="@type = 'enum'">
226 <xsl:text>Enum </xsl:text>
227 <a href="#{$name}"><xsl:value-of select="$name"/></a>
232 <xsl:text>Typedef </xsl:text>
233 <xsl:call-template name="dumptext">
234 <xsl:with-param name="text" select="@type"/>
236 <xsl:text> </xsl:text>
237 <a name="{$name}"><xsl:value-of select="$name"/></a>
245 <xsl:template match="typedef[@type = 'enum']">
246 <xsl:variable name="name" select="string(@name)"/>
247 <h3>Enum <a name="{$name}"><xsl:value-of select="$name"/></a></h3>
248 <pre class="programlisting">
249 <xsl:text>Enum </xsl:text>
250 <xsl:value-of select="$name"/>
253 <xsl:for-each select="/api/symbols/enum[@type = $name]">
254 <xsl:sort select="@value" data-type="number" order="ascending"/>
255 <xsl:text> </xsl:text>
256 <a name="{@name}"><xsl:value-of select="@name"/></a>
257 <xsl:text> = </xsl:text>
258 <xsl:value-of select="@value"/>
259 <xsl:if test="@info != ''">
260 <xsl:text> : </xsl:text>
261 <xsl:call-template name="dumptext">
262 <xsl:with-param name="text" select="@info"/>
273 <xsl:template match="struct" mode="toc">
274 <pre class="programlisting">
275 <xsl:text>Structure </xsl:text><a href="#{@name}"><xsl:value-of select="@name"/></a><br/>
276 <xsl:value-of select="@type"/><xsl:text>
278 <xsl:if test="not(field)">
279 <xsl:text>The content of this structure is not made public by the API.
285 <xsl:template match="struct">
286 <h3><a name="{@name}">Structure <xsl:value-of select="@name"/></a></h3>
287 <pre class="programlisting">
288 <xsl:text>Structure </xsl:text><xsl:value-of select="@name"/><br/>
289 <xsl:value-of select="@type"/><xsl:text> {
291 <xsl:if test="not(field)">
292 <xsl:text>The content of this structure is not made public by the API.
295 <xsl:for-each select="field">
296 <xsl:text> </xsl:text>
297 <xsl:call-template name="dumptext">
298 <xsl:with-param name="text" select="@type"/>
300 <xsl:text>	</xsl:text>
301 <xsl:value-of select="@name"/>
302 <xsl:if test="@info != ''">
303 <xsl:text>	: </xsl:text>
304 <xsl:call-template name="dumptext">
305 <xsl:with-param name="text" select="substring(@info, 1, 40)"/>
311 <xsl:text>}</xsl:text>
315 <xsl:template match="macro">
316 <xsl:variable name="name" select="string(@name)"/>
317 <h3><a name="{$name}"></a>Macro: <xsl:value-of select="$name"/></h3>
318 <pre><xsl:text>#define </xsl:text><xsl:value-of select="$name"/></pre>
320 <xsl:call-template name="dumptext">
321 <xsl:with-param name="text" select="info"/>
327 <xsl:template match="function" mode="toc">
328 <xsl:variable name="name" select="string(@name)"/>
329 <xsl:variable name="nlen" select="string-length($name)"/>
330 <xsl:variable name="tlen" select="string-length(return/@type)"/>
331 <xsl:variable name="blen" select="(($nlen + 8) - (($nlen + 8) mod 8)) + (($tlen + 8) - (($tlen + 8) mod 8))"/>
332 <pre class="programlisting">
333 <xsl:call-template name="dumptext">
334 <xsl:with-param name="text" select="return/@type"/>
336 <xsl:text>	</xsl:text>
337 <a href="#{@name}"><xsl:value-of select="@name"/></a>
338 <xsl:if test="$blen - 40 < -8">
339 <xsl:text>	</xsl:text>
341 <xsl:if test="$blen - 40 < 0">
342 <xsl:text>	</xsl:text>
344 <xsl:text>	(</xsl:text>
345 <xsl:if test="not(arg)">
346 <xsl:text>void</xsl:text>
348 <xsl:for-each select="arg">
349 <xsl:call-template name="dumptext">
350 <xsl:with-param name="text" select="@type"/>
352 <xsl:text> </xsl:text>
353 <xsl:value-of select="@name"/>
354 <xsl:if test="position() != last()">
355 <xsl:text>, </xsl:text><br/>
356 <xsl:if test="$blen - 40 > 8">
357 <xsl:text>	</xsl:text>
359 <xsl:if test="$blen - 40 > 0">
360 <xsl:text>	</xsl:text>
362 <xsl:text>					 </xsl:text>
365 <xsl:text>)</xsl:text>
370 <xsl:template match="functype" mode="toc">
371 <xsl:variable name="name" select="string(@name)"/>
372 <xsl:variable name="nlen" select="string-length($name)"/>
373 <xsl:variable name="tlen" select="string-length(return/@type)"/>
374 <xsl:variable name="blen" select="(($nlen + 8) - (($nlen + 8) mod 8)) + (($tlen + 8) - (($tlen + 8) mod 8))"/>
375 <pre class="programlisting">
376 <xsl:text>Function type: </xsl:text>
377 <a href="#{$name}"><xsl:value-of select="$name"/></a>
380 <xsl:call-template name="dumptext">
381 <xsl:with-param name="text" select="return/@type"/>
383 <xsl:text>	</xsl:text>
384 <a href="#{$name}"><xsl:value-of select="$name"/></a>
385 <xsl:if test="$blen - 40 < -8">
386 <xsl:text>	</xsl:text>
388 <xsl:if test="$blen - 40 < 0">
389 <xsl:text>	</xsl:text>
391 <xsl:text>	(</xsl:text>
392 <xsl:if test="not(arg)">
393 <xsl:text>void</xsl:text>
395 <xsl:for-each select="arg">
396 <xsl:call-template name="dumptext">
397 <xsl:with-param name="text" select="@type"/>
399 <xsl:text> </xsl:text>
400 <xsl:value-of select="@name"/>
401 <xsl:if test="position() != last()">
402 <xsl:text>, </xsl:text><br/>
403 <xsl:if test="$blen - 40 > 8">
404 <xsl:text>	</xsl:text>
406 <xsl:if test="$blen - 40 > 0">
407 <xsl:text>	</xsl:text>
409 <xsl:text>					 </xsl:text>
419 <xsl:template match="functype">
420 <xsl:variable name="name" select="string(@name)"/>
421 <xsl:variable name="nlen" select="string-length($name)"/>
422 <xsl:variable name="tlen" select="string-length(return/@type)"/>
423 <xsl:variable name="blen" select="(($nlen + 8) - (($nlen + 8) mod 8)) + (($tlen + 8) - (($tlen + 8) mod 8))"/>
425 <a name="{$name}"></a>
426 <xsl:text>Function type: </xsl:text>
427 <xsl:value-of select="$name"/>
429 <pre class="programlisting">
430 <xsl:text>Function type: </xsl:text>
431 <xsl:value-of select="$name"/>
434 <xsl:call-template name="dumptext">
435 <xsl:with-param name="text" select="return/@type"/>
437 <xsl:text>	</xsl:text>
438 <xsl:value-of select="@name"/>
439 <xsl:if test="$blen - 40 < -8">
440 <xsl:text>	</xsl:text>
442 <xsl:if test="$blen - 40 < 0">
443 <xsl:text>	</xsl:text>
445 <xsl:text>	(</xsl:text>
446 <xsl:if test="not(arg)">
447 <xsl:text>void</xsl:text>
449 <xsl:for-each select="arg">
450 <xsl:call-template name="dumptext">
451 <xsl:with-param name="text" select="@type"/>
453 <xsl:text> </xsl:text>
454 <xsl:value-of select="@name"/>
455 <xsl:if test="position() != last()">
456 <xsl:text>, </xsl:text><br/>
457 <xsl:if test="$blen - 40 > 8">
458 <xsl:text>	</xsl:text>
460 <xsl:if test="$blen - 40 > 0">
461 <xsl:text>	</xsl:text>
463 <xsl:text>					 </xsl:text>
470 <xsl:call-template name="dumptext">
471 <xsl:with-param name="text" select="info"/>
474 <xsl:if test="arg | return">
475 <div class="variablelist"><table border="0"><col align="left"/><tbody>
476 <xsl:for-each select="arg">
478 <td><span class="term"><i><tt><xsl:value-of select="@name"/></tt></i>:</span></td>
480 <xsl:call-template name="dumptext">
481 <xsl:with-param name="text" select="@info"/>
486 <xsl:if test="return/@info">
488 <td><span class="term"><i><tt>Returns</tt></i>:</span></td>
490 <xsl:call-template name="dumptext">
491 <xsl:with-param name="text" select="return/@info"/>
496 </tbody></table></div>
503 <xsl:template match="function">
504 <xsl:variable name="name" select="string(@name)"/>
505 <xsl:variable name="nlen" select="string-length($name)"/>
506 <xsl:variable name="tlen" select="string-length(return/@type)"/>
507 <xsl:variable name="blen" select="(($nlen + 8) - (($nlen + 8) mod 8)) + (($tlen + 8) - (($tlen + 8) mod 8))"/>
508 <h3><a name="{$name}"></a>Function: <xsl:value-of select="$name"/></h3>
509 <pre class="programlisting">
510 <xsl:call-template name="dumptext">
511 <xsl:with-param name="text" select="return/@type"/>
513 <xsl:text>	</xsl:text>
514 <xsl:value-of select="@name"/>
515 <xsl:if test="$blen - 40 < -8">
516 <xsl:text>	</xsl:text>
518 <xsl:if test="$blen - 40 < 0">
519 <xsl:text>	</xsl:text>
521 <xsl:text>	(</xsl:text>
522 <xsl:if test="not(arg)">
523 <xsl:text>void</xsl:text>
525 <xsl:for-each select="arg">
526 <xsl:call-template name="dumptext">
527 <xsl:with-param name="text" select="@type"/>
529 <xsl:text> </xsl:text>
530 <xsl:value-of select="@name"/>
531 <xsl:if test="position() != last()">
532 <xsl:text>, </xsl:text><br/>
533 <xsl:if test="$blen - 40 > 8">
534 <xsl:text>	</xsl:text>
536 <xsl:if test="$blen - 40 > 0">
537 <xsl:text>	</xsl:text>
539 <xsl:text>					 </xsl:text>
542 <xsl:text>)</xsl:text><br/>
547 <xsl:call-template name="dumptext">
548 <xsl:with-param name="text" select="info"/>
552 <xsl:if test="arg | return/@info">
553 <div class="variablelist"><table border="0"><col align="left"/><tbody>
554 <xsl:for-each select="arg">
556 <td><span class="term"><i><tt><xsl:value-of select="@name"/></tt></i>:</span></td>
558 <xsl:call-template name="dumptext">
559 <xsl:with-param name="text" select="@info"/>
564 <xsl:if test="return/@info">
566 <td><span class="term"><i><tt>Returns</tt></i>:</span></td>
568 <xsl:call-template name="dumptext">
569 <xsl:with-param name="text" select="return/@info"/>
574 </tbody></table></div>
578 <xsl:template match="exports" mode="toc">
579 <xsl:apply-templates select="key('symbols', string(@symbol))[1]" mode="toc"/>
582 <xsl:template match="exports">
583 <xsl:apply-templates select="key('symbols', string(@symbol))[1]"/>
586 <xsl:template name="description">
587 <xsl:if test="deprecated">
588 <h2 style="font-weight:bold;color:red;text-align:center">This module is deprecated</h2>
590 <xsl:if test="description">
591 <p><xsl:value-of select="description"/></p>
595 <xsl:template match="file">
596 <xsl:variable name="name" select="@name"/>
597 <xsl:variable name="title">Module <xsl:value-of select="$name"/> from <xsl:value-of select="/api/@name"/></xsl:variable>
598 <xsl:variable name="content">
599 <xsl:call-template name="navbar"/>
600 <xsl:call-template name="description"/>
602 <xsl:when test="deprecated">
603 <div class="deprecated">
604 <h2>Table of Contents</h2>
605 <xsl:apply-templates select="exports" mode="toc"/>
609 <xsl:apply-templates select="exports"/>
613 <h2>Table of Contents</h2>
614 <xsl:apply-templates select="exports[@type='macro']" mode="toc">
615 <xsl:sort select='@symbol'/>
616 </xsl:apply-templates>
617 <xsl:apply-templates select="exports[@type='enum']" mode="toc">
618 <xsl:sort select='@symbol'/>
619 </xsl:apply-templates>
620 <xsl:apply-templates select="exports[@type='typedef']" mode="toc">
621 <xsl:sort select='@symbol'/>
622 </xsl:apply-templates>
623 <xsl:apply-templates select="exports[@type='struct']" mode="toc">
624 <xsl:sort select='@symbol'/>
625 </xsl:apply-templates>
626 <xsl:apply-templates select="exports[@type='function']" mode="toc">
627 <xsl:sort select='@symbol'/>
628 </xsl:apply-templates>
632 <xsl:apply-templates select="exports[@type='macro']">
633 <xsl:sort select='@symbol'/>
634 </xsl:apply-templates>
635 <xsl:apply-templates select="exports[@type='enum']">
636 <xsl:sort select='@symbol'/>
637 </xsl:apply-templates>
638 <xsl:apply-templates select="exports[@type='typedef']">
639 <xsl:sort select='@symbol'/>
640 </xsl:apply-templates>
641 <xsl:apply-templates select="exports[@type='struct']">
642 <xsl:sort select='@symbol'/>
643 </xsl:apply-templates>
644 <xsl:apply-templates select="exports[@type='function']">
645 <xsl:sort select='@symbol'/>
646 </xsl:apply-templates>
650 <xsl:call-template name="new_page">
651 <xsl:with-param name="filename"
652 select="concat($html_dir, $libname, '-', $name, '.html')"/>
653 <xsl:with-param name="title" select="$title"/>
654 <xsl:with-param name="target" select="$content"/>
658 <xsl:template match="file" mode="toc">
659 <xsl:variable name="name" select="@name"/>
661 <a href="{$libname}-{$name}.html"><xsl:value-of select="$name"/></a>
662 <xsl:text>: </xsl:text>
663 <xsl:value-of select="summary"/>
667 <xsl:template name="mainpage">
668 <xsl:param name="file" select="concat($html_dir, 'index.html')"/>
669 <xsl:variable name="title">Reference Manual for <xsl:value-of select="/api/@name"/></xsl:variable>
670 <xsl:variable name="content">
671 <h2>Table of Contents</h2>
673 <xsl:apply-templates select="/api/files/file" mode="toc"/>
676 <xsl:call-template name="new_page">
677 <xsl:with-param name="filename" select="$file"/>
678 <xsl:with-param name="title" select="$title"/>
679 <xsl:with-param name="target" select="$content"/>
683 <xsl:template match="/">
684 <xsl:message>Processing library <xsl:value-of select="$libname"
685 />, output directory is <xsl:value-of select="$html_dir"
687 <!-- Save the main index.html as well as a couple of copies -->
688 <xsl:call-template name="mainpage"/>
689 <xsl:call-template name="mainpage">
690 <xsl:with-param name="file" select="concat($html_dir, '/book1.html')"/>
692 <xsl:call-template name="mainpage">
693 <xsl:with-param name="file" select="concat($html_dir, '/',
694 $libname, '-lib.html')"/>
696 <!-- now build the file for each of the modules -->
697 <xsl:apply-templates select="/api/files/file"/>