1<?xml version="1.0"?>
2<!--
3  This stylesheet is imported by the other stylesheets (e.g. newapi.xsl
4  and api.xsl).  For flexibility, it depends upon a global param
5  which is normally defined in the importing stylesheet.  This is:
6   href_base	The most superior documentation directory (e.g. XML/)
7-->
8<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
9  <xsl:output method="xml" encoding="ISO-8859-1"
10      doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
11      doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
12
13  <!-- dirname is used to 'choose' between libxslt and libexslt -->
14  <xsl:param name="dirname" select="''"/>
15  <!-- libname is the name of the library being documented -->
16  <xsl:param name="libname" select="'libxslt'"/>
17  <!-- logo_base points to the *.png logos used in headers -->
18  <xsl:param name="logo_base" select="''"/>
19
20  <!-- href_base gives the location of 'base documentation' files 
21       and can be changed by importing stylesheets -->
22  <xsl:variable name="href_base" select="''"/>
23
24  <xsl:variable name="home_base">
25    <xsl:choose>
26      <xsl:when test="$dirname != ''">
27        <xsl:value-of select = "'../'"/>
28      </xsl:when>
29      <xsl:otherwise>
30        <xsl:value-of select = "''"/>
31      </xsl:otherwise>
32    </xsl:choose>
33  </xsl:variable>
34
35  <xsl:variable name="menu_name" select="'Main Menu'"/>
36
37<!--
38 - returns the filename associated to an ID in the original file
39 -->
40  <xsl:template name="filename">
41    <xsl:param name="name" select="string(@href)"/>
42    <xsl:choose>
43      <xsl:when test="$name = '#Introducti'">
44        <xsl:text>intro.html</xsl:text>
45      </xsl:when>
46      <xsl:when test="$name = '#Documentat'">
47        <xsl:text>docs.html</xsl:text>
48      </xsl:when>
49      <xsl:when test="$name = '#Reporting'">
50        <xsl:text>bugs.html</xsl:text>
51      </xsl:when>
52      <xsl:when test="$name = '#help'">
53        <xsl:text>help.html</xsl:text>
54      </xsl:when>
55      <xsl:when test="$name = '#Help'">
56        <xsl:text>help.html</xsl:text>
57      </xsl:when>
58      <xsl:when test="$name = '#Downloads'">
59        <xsl:text>downloads.html</xsl:text>
60      </xsl:when>
61      <xsl:when test="$name = '#News'">
62        <xsl:text>news.html</xsl:text>
63      </xsl:when>
64      <xsl:when test="$name = '#Contributi'">
65        <xsl:text>contribs.html</xsl:text>
66      </xsl:when>
67      <xsl:when test="$name = '#xsltproc'">
68        <xsl:text>xsltproc2.html</xsl:text>
69      </xsl:when>
70      <xsl:when test="$name = '#API'">
71        <xsl:text>API.html</xsl:text>
72      </xsl:when>
73      <xsl:when test="$name = '#Extensions'">
74        <xsl:text>extensions.html</xsl:text>
75      </xsl:when>
76      <xsl:when test="$name = '#Internals'">
77        <xsl:text>internals.html</xsl:text>
78      </xsl:when>
79      <xsl:when test="$name = '#DocBook'">
80        <xsl:text>docbook.html</xsl:text>
81      </xsl:when>
82      <xsl:when test="$name = '#FAQ'">
83        <xsl:text>FAQ.html</xsl:text>
84      </xsl:when>
85      <xsl:when test="$name = '#Python'">
86        <xsl:text>python.html</xsl:text>
87      </xsl:when>
88      <xsl:when test="$name = ''">
89        <xsl:text>unknown.html</xsl:text>
90      </xsl:when>
91      <xsl:otherwise>
92        <xsl:value-of select="$name"/>
93      </xsl:otherwise>
94    </xsl:choose>
95  </xsl:template>
96
97<!--
98 - The table of content
99 -->
100  <xsl:variable name="toc">
101    <form action="{$home_base}search.php"
102          enctype="application/x-www-form-urlencoded" method="get">
103      <input name="query" type="text" size="20" value=""/>
104      <input name="submit" type="submit" value="Search ..."/>
105    </form>
106    <ul>
107      <li><a href="index.html">Home</a></li>
108      <xsl:for-each select="/html/body/h2">
109        <xsl:variable name="filename">
110          <xsl:call-template name="filename">
111            <xsl:with-param name="name" select="concat('#', string(a[1]/@name))"/>
112          </xsl:call-template>
113        </xsl:variable>
114        <li>
115          <xsl:element name="a">
116            <xsl:attribute name="href">
117              <xsl:value-of select="$filename"/>
118            </xsl:attribute>
119            <xsl:value-of select="."/>
120          </xsl:element>
121        </li>
122      </xsl:for-each>
123
124      <xsl:choose>
125        <xsl:when test="$dirname != ''">
126	  <li><a href="/index.html" style="font-weight:bold">libxslt</a></li>
127	</xsl:when>
128	<xsl:otherwise>
129	  <li><a href="EXSLT/index.html" style="font-weight:bold">libexslt</a></li>
130          <li><a href="xslt.html">flat page</a>, <a href="site.xsl">stylesheet</a></li>
131	</xsl:otherwise>
132      </xsl:choose>
133
134      <li><a href="html/index.html" style="font-weight:bold">API Menu</a></li>
135      <li><a href="ChangeLog.html">ChangeLog</a></li>
136    </ul>
137  </xsl:variable>
138
139  <xsl:variable name="api">
140    <ul>
141      <li><a href="{$href_base}APIchunk0.html">Alphabetic</a></li>
142      <li><a href="{$href_base}APIconstructors.html">Constructors</a></li>
143      <li><a href="{$href_base}APIfunctions.html">Functions/Types</a></li>
144      <li><a href="{$href_base}APIfiles.html">Modules</a></li>
145      <li><a href="{$href_base}APIsymbols.html">Symbols</a></li>
146    </ul>
147  </xsl:variable>
148
149  <xsl:variable name="related">
150    <ul>
151      <xsl:choose>
152        <xsl:when test="$dirname = ''">
153      <li><a href="{$href_base}tutorial/libxslttutorial.html">Tutorial</a>,
154          <a href="{$href_base}tutorial2/libxslt_pipes.html">Tutorial2</a></li>
155      <li><a href="{$href_base}xsltproc.html">Man page for xsltproc</a></li>
156        </xsl:when>
157      </xsl:choose>
158      <li><a href="http://mail.gnome.org/archives/xslt/">Mail archive</a></li>
159      <li><a href="http://xmlsoft.org/">XML libxml2</a></li>
160      <li><a href="ftp://xmlsoft.org/">FTP</a></li>
161      <li><a href="http://www.zlatkovic.com/projects/libxml/">Windows binaries</a></li>
162      <li><a href="http://garypennington.net/libxml2/">Solaris binaries</a></li>
163      <li><a href="http://www.explain.com.au/oss/libxml2xslt.html">MacOsX binaries</a></li>
164      <li><a href="http://bugzilla.gnome.org/buglist.cgi?product=libxslt">Bug Tracker</a></li>
165      <li><a href="http://codespeak.net/lxml/">lxml Python bindings</a></li>
166      <li><a href="http://cpan.uwinnipeg.ca/dist/XML-LibXSLT">Perl XSLT bindings</a></li>
167      <li><a href="http://www.zend.com/php5/articles/php5-xmlphp.php#Heading17">XSLT with PHP</a></li>
168      <li><a href="http://www.mod-xslt2.com/">Apache module</a></li>
169      <li><a href="http://sourceforge.net/projects/libxml2-pas/">Pascal bindings</a></li>
170      <li><a href="http://xsldbg.sourceforge.net/">Xsldbg Debugger</a></li>
171    </ul>
172  </xsl:variable>
173
174  <xsl:template name="develtoc">
175    <table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000">
176      <tr>
177        <td>
178          <table width="100%" border="0" cellspacing="1" cellpadding="3">
179            <tr>
180              <td colspan="1" bgcolor="#eecfa1" align="center">
181                <center>
182                  <b><xsl:value-of select="$menu_name"/></b>
183                </center>
184              </td>
185            </tr>
186            <tr>
187              <td bgcolor="#fffacd">
188                <xsl:copy-of select="$toc"/>
189              </td>
190            </tr>
191          </table>
192          <table width="100%" border="0" cellspacing="1" cellpadding="3">
193            <tr>
194              <td colspan="1" bgcolor="#eecfa1" align="center">
195                <center>
196                  <b>Related links</b>
197                </center>
198              </td>
199            </tr>
200            <tr>
201              <td bgcolor="#fffacd">
202                <xsl:copy-of select="$related"/>
203              </td>
204            </tr>
205          </table>
206          <table width="100%" border="0" cellspacing="1" cellpadding="3">
207            <tr>
208              <td colspan="1" bgcolor="#eecfa1" align="center">
209                <center>
210                  <b>API Indexes</b>
211                </center>
212              </td>
213            </tr>
214            <tr>
215              <td bgcolor="#fffacd">
216                <xsl:copy-of select="$api"/>
217              </td>
218            </tr>
219          </table>
220        </td>
221      </tr>
222    </table>
223  </xsl:template>
224
225  <xsl:template mode="head" match="title">
226    <title>
227      <xsl:apply-templates/>
228    </title>
229  </xsl:template>
230  <xsl:template mode="head" match="meta">
231</xsl:template>
232
233<!--
234 - The global title
235 -->
236  <xsl:variable name="globaltitle" select="string(/html/body/h1[1])"/>
237<!--
238 - Write the styles in the head
239 -->
240  <xsl:template name="style">
241    <style type="text/css">
242TD {font-family: Verdana,Arial,Helvetica}
243BODY {font-family: Verdana,Arial,Helvetica; margin-top: 2em; margin-left: 0em; margin-right: 0em}
244H1 {font-family: Verdana,Arial,Helvetica}
245H2 {font-family: Verdana,Arial,Helvetica}
246H3 {font-family: Verdana,Arial,Helvetica}
247A:link, A:visited, A:active { text-decoration: underline }
248    </style>
249  </xsl:template>
250
251<!--
252 - Write the title box on top
253 -->
254  <xsl:template name="titlebox">
255    <xsl:param name="title" select="'Main Page'"/>
256    <table border="0" width="100%" cellpadding="5" cellspacing="0" align="center">
257      <tr>
258        <td width="120">
259          <a href="http://swpat.ffii.org/"><img src="{$logo_base}epatents.png" alt="Action against software patents"/></a>
260        </td>
261        <td width="180">
262          <a href="http://www.gnome.org/"><img src="{$logo_base}gnome2.png" alt="GNOME2 Logo"/></a>
263          <a href="http://www.w3.org/Status"><img src="{$logo_base}w3c.png" alt="W3C logo"/></a>
264          <a href="http://www.redhat.com"><img src="{$logo_base}redhat.gif" alt="Red Hat Logo"/></a>
265          <div align="left">
266            <a href="http://xmlsoft.org/XSLT/"><img src="{$logo_base}Libxslt-Logo-180x168.gif" alt="Made with Libxslt Logo"/></a>
267          </div>
268        </td>
269        <td>
270          <table border="0" width="90%" cellpadding="2" cellspacing="0" align="center" bgcolor="#000000">
271            <tr>
272              <td>
273                <table width="100%" border="0" cellspacing="1" cellpadding="3" bgcolor="#fffacd">
274                  <tr>
275                    <td align="center">
276                      <xsl:element name="h1">
277                        <xsl:value-of select="$globaltitle"/>
278                      </xsl:element>
279                      <xsl:element name="h2">
280                        <xsl:value-of select="$title"/>
281                      </xsl:element>
282                    </td>
283                  </tr>
284                </table>
285              </td>
286            </tr>
287          </table>
288        </td>
289      </tr>
290    </table>
291  </xsl:template>
292
293<!--
294 - Handling of nodes in the body before the first H2, table of content
295 - Everything is just copied over, except href which may get rewritten
296 - and h1/h2/a at the top level
297 -->
298  <xsl:template priority="2" mode="subcontent" match="a">
299    <xsl:variable name="filename">
300      <xsl:call-template name="filename">
301        <xsl:with-param name="name" select="string(@href)"/>
302      </xsl:call-template>
303    </xsl:variable>
304    <xsl:copy>
305      <xsl:attribute name="href">
306        <xsl:value-of select="$filename"/>
307      </xsl:attribute>
308      <xsl:apply-templates mode="subcontent" select="node()"/>
309    </xsl:copy>
310  </xsl:template>
311
312  <xsl:template mode="subcontent" match="@*|node()">
313    <xsl:copy>
314      <xsl:apply-templates mode="subcontent" select="@*|node()"/>
315    </xsl:copy>
316  </xsl:template>
317  <xsl:template mode="content" match="@*|node()">
318    <xsl:if test="name() != 'h1' and name() != 'h2'">
319      <xsl:copy>
320        <xsl:apply-templates mode="subcontent" select="@*|node()"/>
321      </xsl:copy>
322    </xsl:if>
323  </xsl:template>
324
325<!--
326 - Handling of nodes in the body after an H2
327 - Open a new file and dump all the siblings up to the next H2
328 -->
329  <xsl:template name="subfile">
330    <xsl:param name="header" select="following-sibling::h2[1]"/>
331    <xsl:variable name="filename">
332      <xsl:call-template name="filename">
333        <xsl:with-param name="name" select="concat('#', string($header/a[1]/@name))"/>
334      </xsl:call-template>
335    </xsl:variable>
336    <xsl:variable name="title">
337      <xsl:value-of select="$header"/>
338    </xsl:variable>
339    <xsl:variable name="content">
340      <xsl:apply-templates mode="subfile" select=
341         "$header/following-sibling::*[preceding-sibling::h2[1] = $header and name() != 'h2' and position() != last()]"/>
342    </xsl:variable>
343    <xsl:call-template name="new_page">
344      <xsl:with-param name="filename" select="concat($dirname, $filename)"/>
345      <xsl:with-param name="title" select="$title"/>
346      <xsl:with-param name="target" select="$content"/>
347    </xsl:call-template>
348  </xsl:template>
349
350  <xsl:template mode="subfile" match="@*|node()">
351    <xsl:copy>
352      <xsl:apply-templates mode="content" select="@*|node()"/>
353    </xsl:copy>
354  </xsl:template>
355
356<!--
357 - Handling of the initial body and head HTML document
358 -->
359  <xsl:template match="body">
360    <xsl:variable name="firsth2" select="/h2[1]"/>
361    <xsl:variable name="rest2" select="/h2[position()&gt;1]"/>
362    <xsl:variable name="content">
363      <xsl:apply-templates mode="content" select="($firsth2/preceding-sibling::*)"/>
364      <xsl:for-each select="/h2">
365        <xsl:call-template name="subfile">
366          <xsl:with-param name="header" select="."/>
367        </xsl:call-template>
368      </xsl:for-each>
369    </xsl:variable>
370    <xsl:call-template name="generic_page">
371      <xsl:with-param name="title" select="$libname"/>
372      <xsl:with-param name="target" select="$content"/>
373    </xsl:call-template>
374
375  </xsl:template>
376
377  <xsl:template match="head">
378  <!--
379    The output <head> node is created during initial processing
380  -->
381  </xsl:template>
382
383  <xsl:template match="html">
384  <!--
385    The output <html> node is created during initial processing
386  -->
387    <xsl:apply-templates/>
388  </xsl:template>
389
390<!--
391  new_page creates a new output document using the parameter "filename", then calls upon
392  the template generic_page to do the actual page generation.
393-->
394  <xsl:template name="new_page">
395    <xsl:param name="filename"/>  <!-- Output filename -->
396    <xsl:param name="title"/>     <!-- Page title -->
397    <xsl:param name="target"/>    <!-- The nodes (RTF) to be copied into document -->
398    <xsl:document href="{$filename}" method="xml" encoding="ISO-8859-1"
399          doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
400          doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
401      <xsl:call-template name="generic_page">
402        <xsl:with-param name="title" select="$title"/>
403        <xsl:with-param name="target" select="$target"/>
404	  <xsl:with-param name="toc" select="$toc"/>
405      </xsl:call-template>
406    </xsl:document>
407  </xsl:template>
408
409<!--
410  generic_page produces the "standard" page used by all the different doc files.
411-->
412  <xsl:template name="generic_page">
413    <xsl:param name="title"/>
414    <xsl:param name="target"/>    <!-- The nodes (RTF) that make up the main page content -->
415      <html>
416        <head>
417        <xsl:call-template name="style"/>
418	<xsl:element name="title">
419	  <xsl:value-of select="$title"/>
420	</xsl:element>
421        </head>
422        <body bgcolor="#8b7765" text="#000000" link="#a06060" vlink="#000000">
423          <xsl:call-template name="titlebox">
424	    <xsl:with-param name="title" select="$title"/>
425	  </xsl:call-template>
426          <table border="0" cellpadding="4" cellspacing="0" width="100%" align="center">
427            <tr>
428              <td bgcolor="#8b7765">
429                <table border="0" cellspacing="0" cellpadding="2" width="100%">
430                  <tr>
431                    <td valign="top" width="200" bgcolor="#8b7765">
432                      <xsl:call-template name="develtoc"/>
433                    </td>
434                    <td valign="top" bgcolor="#8b7765">
435                      <table border="0" cellspacing="0" cellpadding="1" width="100%">
436                        <tr>
437                          <td>
438                            <table border="0" cellspacing="0" cellpadding="1" width="100%" bgcolor="#000000">
439                              <tr>
440                                <td>
441                                  <table border="0" cellpadding="3" cellspacing="1" width="100%">
442                                    <tr>
443                                      <td bgcolor="#fffacd">
444                                        <xsl:copy-of select="$target"/>
445                                        <p><a href="{$href_base}bugs.html">Daniel Veillard</a></p>
446                                      </td>
447                                    </tr>
448                                  </table>
449                                </td>
450                              </tr>
451                            </table>
452                          </td>
453                        </tr>
454                      </table>
455                    </td>
456                  </tr>
457                </table>
458              </td>
459            </tr>
460          </table>
461        </body>
462      </html>
463  </xsl:template>
464</xsl:stylesheet>
465