4579003dd004758debf40bbfae7a17b98e4089e2
[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   <!-- Remove the automatically inserted search form (we build our own) -->\r
152   <xsl:template match="li[form]"> \r
153   </xsl:template>\r
154   \r
155   <xsl:template match="dl[dt/b/a/text()='Bug:']">\r
156     <xsl:call-template name="add-class">\r
157       <xsl:with-param name="class">xref-bug</xsl:with-param>\r
158     </xsl:call-template>\r
159   </xsl:template>\r
160 \r
161   <xsl:template match="dl[dt/b/a/text()='Fix:']">\r
162     <xsl:call-template name="add-class">\r
163       <xsl:with-param name="class">xref-fix</xsl:with-param>\r
164     </xsl:call-template>\r
165   </xsl:template>\r
166 \r
167   <xsl:template match="dl[dt/b/a/text()='Todo:']">\r
168     <xsl:call-template name="add-class">\r
169       <xsl:with-param name="class">xref-todo</xsl:with-param>\r
170     </xsl:call-template>\r
171   </xsl:template>\r
172 \r
173   <xsl:template match="dl[dt/b/a/text()='Idea:']">\r
174     <xsl:call-template name="add-class">\r
175       <xsl:with-param name="class">xref-idea</xsl:with-param>\r
176     </xsl:call-template>\r
177   </xsl:template>\r
178 \r
179   <xsl:template match="dl[dt/b/text()='Parameters:']">\r
180     <xsl:call-template name="add-class">\r
181       <xsl:with-param name="class">parameters</xsl:with-param>\r
182     </xsl:call-template>\r
183   </xsl:template>\r
184 \r
185   <xsl:template match="dl[dt/b/text()='Implementation note:']">\r
186     <xsl:call-template name="add-class">\r
187       <xsl:with-param name="class">implementation</xsl:with-param>\r
188     </xsl:call-template>\r
189   </xsl:template>\r
190 \r
191   <xsl:template match="table[descendant::td[@class='memItemLeft']]">\r
192     <xsl:call-template name="add-class">\r
193       <xsl:with-param name="class">members</xsl:with-param>\r
194     </xsl:call-template>\r
195   </xsl:template>\r
196 \r
197   <xsl:template match="a[@href=string(current())]" priority="1">\r
198     <xsl:call-template name="add-class">\r
199       <xsl:with-param name="class">literal</xsl:with-param>\r
200     </xsl:call-template>\r
201   </xsl:template>\r
202 \r
203   <xsl:template match="a[contains(@href,'http://')]">\r
204     <xsl:call-template name="add-class">\r
205       <xsl:with-param name="class">ext</xsl:with-param>\r
206     </xsl:call-template>\r
207   </xsl:template>\r
208 \r
209   <xsl:template match="a[not(@href)]">\r
210     <xsl:call-template name="add-class">\r
211       <xsl:with-param name="class">anchor</xsl:with-param>\r
212     </xsl:call-template>\r
213   </xsl:template>\r
214 \r
215   <xsl:template match="div[@class='memdoc']/p[1]">\r
216     <xsl:call-template name="add-class">\r
217       <xsl:with-param name="class">memtitle</xsl:with-param>\r
218     </xsl:call-template>\r
219   </xsl:template>\r
220 \r
221   <xsl:template match="p[starts-with(text(),'Definition at line ')]">\r
222     <xsl:call-template name="add-class">\r
223       <xsl:with-param name="class">sourceline</xsl:with-param>\r
224     </xsl:call-template>\r
225   </xsl:template>\r
226 \r
227   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'References ')]">\r
228     <xsl:call-template name="add-class">\r
229       <xsl:with-param name="class">references</xsl:with-param>\r
230     </xsl:call-template>\r
231   </xsl:template>\r
232 \r
233   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Referenced by ')]">\r
234     <xsl:call-template name="add-class">\r
235       <xsl:with-param name="class">referencedby</xsl:with-param>\r
236     </xsl:call-template>\r
237   </xsl:template>\r
238 \r
239   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented from ')]">\r
240     <xsl:call-template name="add-class">\r
241       <xsl:with-param name="class">reimplementedfrom</xsl:with-param>\r
242     </xsl:call-template>\r
243   </xsl:template>\r
244 \r
245   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented in ')]">\r
246     <xsl:call-template name="add-class">\r
247       <xsl:with-param name="class">reimplementedin</xsl:with-param>\r
248     </xsl:call-template>\r
249   </xsl:template>\r
250 \r
251   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Implemented in ')]">\r
252     <xsl:call-template name="add-class">\r
253       <xsl:with-param name="class">implementedin</xsl:with-param>\r
254     </xsl:call-template>\r
255   </xsl:template>\r
256 \r
257   <xsl:template match="p[starts-with(text(),'Inherited by ')]">\r
258     <xsl:call-template name="break-comma"/>\r
259   </xsl:template>\r
260 \r
261   <xsl:template match="p[starts-with(text(),'Inherits ')]">\r
262     <xsl:call-template name="break-comma"/>\r
263   </xsl:template>\r
264 \r
265   <!-- Remove external items from the namespace index -->\r
266   <xsl:template match="div[@id='content2']/table[contains(preceding-sibling::h1/text(),'Namespace Reference')]/tr[td[@class='memItemRight']/a[1][@class='elRef'][@doxygen]]">\r
267   </xsl:template>\r
268   \r
269   <!-- Remove [external] references from the modules page -->\r
270   <xsl:template match="div[@id='content2']/ul/li[a/@class='elRef'][a/@doxygen][code/text()='[external]'][not(ul)]">\r
271   </xsl:template>\r
272 \r
273   <!-- Insert 'senf/'  into include paths -->\r
274   <xsl:template match="code[starts-with(text(),'#include &lt;')]/a">\r
275     <xsl:copy>\r
276       <xsl:call-template name="copy-attributes"/>\r
277       <xsl:text>senf/</xsl:text>\r
278       <xsl:apply-templates/>\r
279     </xsl:copy>\r
280   </xsl:template>\r
281 \r
282 </xsl:stylesheet>\r