doclib: Add 'Download' link to FTP space on berlios
[senf.git] / doclib / html-munge.xsl
1 <?xml version="1.0" encoding="utf-8"?>\r
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  version="1.0">\r
3 \r
4   <xsl:output \r
5     method="html" \r
6     encoding="html" \r
7     doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"\r
8     doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>\r
9 \r
10   <xsl:param name="topdir" select="''"/>\r
11   \r
12   <xsl:template match="*" name="copy">\r
13     <xsl:copy>\r
14       <xsl:call-template name="copy-attributes"/>\r
15       <xsl:apply-templates/>\r
16     </xsl:copy>\r
17   </xsl:template>\r
18 \r
19   <xsl:template name="copy-attributes">\r
20     <xsl:for-each select="@*">\r
21       <xsl:attribute name="{name(current())}">\r
22         <xsl:choose>\r
23           <xsl:when test="contains(current(),'@TOPDIR@')">\r
24             <xsl:value-of select="substring-before(current(),'@TOPDIR@')"/>\r
25             <xsl:value-of select="$topdir"/>\r
26             <xsl:value-of select="substring-after(current(),'@TOPDIR@')"/>\r
27           </xsl:when>\r
28           <xsl:otherwise>\r
29             <xsl:value-of select="current()"/>\r
30           </xsl:otherwise>\r
31         </xsl:choose>\r
32       </xsl:attribute>\r
33     </xsl:for-each>\r
34   </xsl:template>\r
35 \r
36   <!-- Replace @TOPDIR@ with relative top directory path -->\r
37 \r
38   <xsl:template match="@*[contains(current(),'@TOPDIR@')]">\r
39     <xsl:value-of select="substring-before(current(),'@TOPDIR@')"/>\r
40     <xsl:value-of select="$topdir"/>\r
41     <xsl:value-of select="substring-after(current(),'@TOPDIR@')"/>\r
42   </xsl:template>\r
43   \r
44   <!-- Add 'class' attribute to some special paragraphs/lists -->\r
45   \r
46   <xsl:template name="add-class">\r
47     <xsl:param name="class"/>\r
48     <xsl:copy>\r
49       <xsl:call-template name="copy-attributes"/>\r
50       <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>\r
51       <xsl:apply-templates/>\r
52     </xsl:copy>\r
53   </xsl:template>\r
54 \r
55   <!-- Add '<br/>' tag after every ', ' -->\r
56   <!-- This code is not very robust, it works with the doxygen output though -->\r
57 \r
58   <xsl:template name="break-comma">\r
59     <xsl:copy>\r
60       <xsl:call-template name="copy-attributes"/>\r
61       <xsl:attribute name="class">commalist</xsl:attribute>\r
62       <xsl:apply-templates mode="break-comma"/>\r
63     </xsl:copy>\r
64   </xsl:template>\r
65  \r
66   <xsl:template match="text()[1]" mode="break-comma">\r
67     <xsl:value-of select="current()"/><br/>\r
68   </xsl:template>\r
69 \r
70   <xsl:template match="*" mode="break-comma">\r
71     <xsl:call-template name="copy"/>\r
72   </xsl:template>\r
73 \r
74   <xsl:template match="text()[contains(current(),' and') or contains(current(),'and ')]" mode="break-comma" priority="1">\r
75     <xsl:value-of select="substring-before(current(),'and')"/>\r
76     <br/>\r
77     <xsl:value-of select="substring-after(current(),'and')"/>\r
78   </xsl:template>\r
79 \r
80   <xsl:template match="text()[contains(current(),',')]" mode="break-comma">\r
81     <xsl:value-of select="substring-before(current(),',')"/>\r
82     <xsl:text>,</xsl:text><br/>\r
83     <xsl:value-of select="substring-after(current(),',')"/>\r
84   </xsl:template>\r
85 \r
86   <!-- ====================================================================== -->\r
87 \r
88   <!-- Hack Glossary menu highlight -->\r
89 \r
90   <xsl:template match="div[@class='tabs menu']/ul[1]">\r
91     <xsl:choose>\r
92       <xsl:when test="//h1[.//text()='Glossary']">\r
93         <xsl:call-template name="add-class">\r
94           <xsl:with-param name="class">glossary</xsl:with-param>\r
95         </xsl:call-template>\r
96       </xsl:when>\r
97       <xsl:otherwise>\r
98         <xsl:copy>\r
99           <xsl:call-template name="copy-attributes"/>\r
100           <xsl:apply-templates/>\r
101         </xsl:copy>\r
102       </xsl:otherwise>\r
103     </xsl:choose>\r
104   </xsl:template>\r
105 \r
106   <!-- Autogenerate table-of-contents for a page -->\r
107 \r
108   <xsl:template match="div[@id='autotoc']">\r
109     <xsl:copy>\r
110       <xsl:call-template name="copy-attributes"/>\r
111       <h1>Contents</h1>\r
112       <ul>\r
113         <xsl:for-each select="following::h2|following::h3|following::h4">\r
114           <xsl:element name="li">\r
115             <xsl:attribute name="class"><xsl:value-of select="concat('level_',local-name())"/></xsl:attribute>\r
116             <b><xsl:call-template name="section-number"/></b>\r
117             <xsl:element name="a">\r
118               <xsl:attribute name="href"><xsl:value-of select="concat('#',a/@name)"/></xsl:attribute>\r
119               <xsl:value-of select="string(current())"/>\r
120             </xsl:element>\r
121           </xsl:element>\r
122         </xsl:for-each>\r
123       </ul>\r
124     </xsl:copy>\r
125   </xsl:template>\r
126 \r
127   <xsl:template name="section-number">\r
128     <xsl:number level="any" from="h1" count="h2"/>\r
129     <xsl:text>.</xsl:text>\r
130     <xsl:if test="self::h3|self::h4">\r
131       <xsl:number level="any" from="h2" count="h3"/>\r
132       <xsl:text>.</xsl:text>\r
133     </xsl:if>\r
134     <xsl:if test="self::h4">\r
135       <xsl:number level="any" from="h3" count="h4"/>\r
136       <xsl:text>.</xsl:text>\r
137     </xsl:if>\r
138     <xsl:text> </xsl:text>\r
139   </xsl:template>\r
140   \r
141   <xsl:template match="h2|h3|h4">\r
142     <xsl:copy>\r
143       <xsl:call-template name="copy-attributes"/>\r
144       <xsl:if test="preceding::div[@id='autotoc']">\r
145         <xsl:call-template name="section-number"/>\r
146       </xsl:if>\r
147       <xsl:apply-templates/>\r
148     </xsl:copy>\r
149   </xsl:template>\r
150   \r
151   <!-- Build dia image-map from special div/span elements -->\r
152   <xsl:template match="div[@class='diamap']">\r
153     <xsl:element name="map">\r
154       <xsl:attribute name="name"><xsl:value-of select="@name"/></xsl:attribute>\r
155       <xsl:for-each select="span">\r
156         <xsl:if test="a">\r
157           <xsl:variable name="name" select="string(a[1])"/>\r
158           <xsl:element name="area">\r
159             <xsl:attribute name="shape">rect</xsl:attribute>\r
160             <xsl:attribute name="alt"><xsl:value-of select="$name"/></xsl:attribute>\r
161             <xsl:attribute name="title"><xsl:value-of select="$name"/></xsl:attribute>\r
162             <xsl:attribute name="href"><xsl:value-of select="a[1]/@href"/></xsl:attribute>\r
163             <xsl:attribute name="coords"><xsl:value-of select="@coords"/></xsl:attribute>\r
164           </xsl:element>\r
165         </xsl:if>\r
166       </xsl:for-each>\r
167     </xsl:element>\r
168   </xsl:template>\r
169 \r
170   <!-- Remove the automatically inserted search form (we build our own) -->\r
171   <xsl:template match="li[form]"> \r
172   </xsl:template>\r
173 \r
174   <xsl:template match="table[preceding-sibling::*[1][self::div][@class='qindex']]">\r
175     <xsl:call-template name="add-class">\r
176       <xsl:with-param name="class">qindextable</xsl:with-param>\r
177     </xsl:call-template>\r
178   </xsl:template>\r
179   \r
180   <xsl:template match="dl[dt/b/a/text()='Bug:']">\r
181     <xsl:call-template name="add-class">\r
182       <xsl:with-param name="class">xref-bug</xsl:with-param>\r
183     </xsl:call-template>\r
184   </xsl:template>\r
185 \r
186   <xsl:template match="dl[dt/b/a/text()='Fix:']">\r
187     <xsl:call-template name="add-class">\r
188       <xsl:with-param name="class">xref-fix</xsl:with-param>\r
189     </xsl:call-template>\r
190   </xsl:template>\r
191 \r
192   <xsl:template match="dl[dt/b/a/text()='Todo:']">\r
193     <xsl:call-template name="add-class">\r
194       <xsl:with-param name="class">xref-todo</xsl:with-param>\r
195     </xsl:call-template>\r
196   </xsl:template>\r
197 \r
198   <xsl:template match="dl[dt/b/a/text()='Idea:']">\r
199     <xsl:call-template name="add-class">\r
200       <xsl:with-param name="class">xref-idea</xsl:with-param>\r
201     </xsl:call-template>\r
202   </xsl:template>\r
203 \r
204   <xsl:template match="dl[dt/b/text()='Parameters:']|dl[dt/b/text()='Template Parameters:']">\r
205     <xsl:call-template name="add-class">\r
206       <xsl:with-param name="class">parameters</xsl:with-param>\r
207     </xsl:call-template>\r
208   </xsl:template>\r
209 \r
210   <xsl:template match="dl[dt/b/text()='Implementation note:']">\r
211     <xsl:call-template name="add-class">\r
212       <xsl:with-param name="class">implementation</xsl:with-param>\r
213     </xsl:call-template>\r
214   </xsl:template>\r
215 \r
216   <xsl:template match="table[descendant::td[@class='memItemLeft']]">\r
217     <xsl:call-template name="add-class">\r
218       <xsl:with-param name="class">members</xsl:with-param>\r
219     </xsl:call-template>\r
220   </xsl:template>\r
221 \r
222   <xsl:template match="a[@href=string(current())]" priority="1">\r
223     <xsl:call-template name="add-class">\r
224       <xsl:with-param name="class">literal</xsl:with-param>\r
225     </xsl:call-template>\r
226   </xsl:template>\r
227 \r
228   <xsl:template match="a[contains(@href,'http://')]">\r
229     <xsl:call-template name="add-class">\r
230       <xsl:with-param name="class">ext</xsl:with-param>\r
231     </xsl:call-template>\r
232   </xsl:template>\r
233 \r
234   <xsl:template match="a[not(@href)]">\r
235     <xsl:call-template name="add-class">\r
236       <xsl:with-param name="class">anchor</xsl:with-param>\r
237     </xsl:call-template>\r
238   </xsl:template>\r
239 \r
240   <xsl:template match="div[@class='memdoc']/p[1]">\r
241     <xsl:call-template name="add-class">\r
242       <xsl:with-param name="class">memtitle</xsl:with-param>\r
243     </xsl:call-template>\r
244   </xsl:template>\r
245 \r
246   <xsl:template match="p[starts-with(text(),'Definition at line ')]">\r
247     <xsl:call-template name="add-class">\r
248       <xsl:with-param name="class">sourceline</xsl:with-param>\r
249     </xsl:call-template>\r
250   </xsl:template>\r
251 \r
252   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'References ')]">\r
253     <xsl:call-template name="add-class">\r
254       <xsl:with-param name="class">references</xsl:with-param>\r
255     </xsl:call-template>\r
256   </xsl:template>\r
257 \r
258   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Referenced by ')]">\r
259     <xsl:call-template name="add-class">\r
260       <xsl:with-param name="class">referencedby</xsl:with-param>\r
261     </xsl:call-template>\r
262   </xsl:template>\r
263 \r
264   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented from ')]">\r
265     <xsl:call-template name="add-class">\r
266       <xsl:with-param name="class">reimplementedfrom</xsl:with-param>\r
267     </xsl:call-template>\r
268   </xsl:template>\r
269 \r
270   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented in ')]">\r
271     <xsl:call-template name="add-class">\r
272       <xsl:with-param name="class">reimplementedin</xsl:with-param>\r
273     </xsl:call-template>\r
274   </xsl:template>\r
275 \r
276   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Implemented in ')]">\r
277     <xsl:call-template name="add-class">\r
278       <xsl:with-param name="class">implementedin</xsl:with-param>\r
279     </xsl:call-template>\r
280   </xsl:template>\r
281 \r
282   <xsl:template match="p[starts-with(text(),'Inherited by ')]">\r
283     <xsl:call-template name="break-comma"/>\r
284   </xsl:template>\r
285 \r
286   <xsl:template match="p[starts-with(text(),'Inherits ')]">\r
287     <xsl:call-template name="break-comma"/>\r
288   </xsl:template>\r
289 \r
290   <!-- Remove external items from the namespace index -->\r
291   <xsl:template match="div[@id='content2']/table[contains(preceding-sibling::h1/text(),'Namespace Reference')]/tr[td[@class='memItemRight']/a[1][@class='elRef'][@doxygen]]">\r
292   </xsl:template>\r
293   \r
294   <!-- Remove [external] references from the modules page -->\r
295   <xsl:template match="div[@id='content2']/ul/li[a/@class='elRef'][a/@doxygen][code/text()='[external]'][not(ul)]">\r
296   </xsl:template>\r
297 \r
298   <!-- Insert 'senf/'  into include paths -->\r
299   <xsl:template match="code[starts-with(text(),'#include &lt;')]/a">\r
300     <xsl:copy>\r
301       <xsl:call-template name="copy-attributes"/>\r
302       <xsl:text>senf/</xsl:text>\r
303       <xsl:apply-templates/>\r
304     </xsl:copy>\r
305   </xsl:template>\r
306 \r
307 </xsl:stylesheet>\r