HowTos/NewPacket: Some updates
[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   <!-- Remove the automatically inserted search form (we build our own) -->\r
89   <xsl:template match="li[form]"> \r
90   </xsl:template>\r
91   \r
92   <xsl:template match="dl[dt/b/a/text()='Bug:']">\r
93     <xsl:call-template name="add-class">\r
94       <xsl:with-param name="class">xref-bug</xsl:with-param>\r
95     </xsl:call-template>\r
96   </xsl:template>\r
97 \r
98   <xsl:template match="dl[dt/b/a/text()='Fix:']">\r
99     <xsl:call-template name="add-class">\r
100       <xsl:with-param name="class">xref-fix</xsl:with-param>\r
101     </xsl:call-template>\r
102   </xsl:template>\r
103 \r
104   <xsl:template match="dl[dt/b/a/text()='Todo:']">\r
105     <xsl:call-template name="add-class">\r
106       <xsl:with-param name="class">xref-todo</xsl:with-param>\r
107     </xsl:call-template>\r
108   </xsl:template>\r
109 \r
110   <xsl:template match="dl[dt/b/a/text()='Idea:']">\r
111     <xsl:call-template name="add-class">\r
112       <xsl:with-param name="class">xref-idea</xsl:with-param>\r
113     </xsl:call-template>\r
114   </xsl:template>\r
115 \r
116   <xsl:template match="dl[dt/b/text()='Parameters:']">\r
117     <xsl:call-template name="add-class">\r
118       <xsl:with-param name="class">parameters</xsl:with-param>\r
119     </xsl:call-template>\r
120   </xsl:template>\r
121 \r
122   <xsl:template match="dl[dt/b/text()='Implementation note:']">\r
123     <xsl:call-template name="add-class">\r
124       <xsl:with-param name="class">implementation</xsl:with-param>\r
125     </xsl:call-template>\r
126   </xsl:template>\r
127 \r
128   <xsl:template match="table[descendant::td[@class='memItemLeft']]">\r
129     <xsl:call-template name="add-class">\r
130       <xsl:with-param name="class">members</xsl:with-param>\r
131     </xsl:call-template>\r
132   </xsl:template>\r
133 \r
134   <xsl:template match="a[@href=string(current())]" priority="1">\r
135     <xsl:call-template name="add-class">\r
136       <xsl:with-param name="class">literal</xsl:with-param>\r
137     </xsl:call-template>\r
138   </xsl:template>\r
139 \r
140   <xsl:template match="a[contains(@href,'http://')]">\r
141     <xsl:call-template name="add-class">\r
142       <xsl:with-param name="class">ext</xsl:with-param>\r
143     </xsl:call-template>\r
144   </xsl:template>\r
145 \r
146   <xsl:template match="a[not(@href)]">\r
147     <xsl:call-template name="add-class">\r
148       <xsl:with-param name="class">anchor</xsl:with-param>\r
149     </xsl:call-template>\r
150   </xsl:template>\r
151 \r
152   <xsl:template match="div[@class='memdoc']/p[1]">\r
153     <xsl:call-template name="add-class">\r
154       <xsl:with-param name="class">memtitle</xsl:with-param>\r
155     </xsl:call-template>\r
156   </xsl:template>\r
157 \r
158   <xsl:template match="p[starts-with(text(),'Definition at line ')]">\r
159     <xsl:call-template name="add-class">\r
160       <xsl:with-param name="class">sourceline</xsl:with-param>\r
161     </xsl:call-template>\r
162   </xsl:template>\r
163 \r
164   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'References ')]">\r
165     <xsl:call-template name="add-class">\r
166       <xsl:with-param name="class">references</xsl:with-param>\r
167     </xsl:call-template>\r
168   </xsl:template>\r
169 \r
170   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Referenced by ')]">\r
171     <xsl:call-template name="add-class">\r
172       <xsl:with-param name="class">referencedby</xsl:with-param>\r
173     </xsl:call-template>\r
174   </xsl:template>\r
175 \r
176   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented from ')]">\r
177     <xsl:call-template name="add-class">\r
178       <xsl:with-param name="class">reimplementedfrom</xsl:with-param>\r
179     </xsl:call-template>\r
180   </xsl:template>\r
181 \r
182   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Reimplemented in ')]">\r
183     <xsl:call-template name="add-class">\r
184       <xsl:with-param name="class">reimplementedin</xsl:with-param>\r
185     </xsl:call-template>\r
186   </xsl:template>\r
187 \r
188   <xsl:template match="div[@class='memdoc']/p[starts-with(text(),'Implemented in ')]">\r
189     <xsl:call-template name="add-class">\r
190       <xsl:with-param name="class">implementedin</xsl:with-param>\r
191     </xsl:call-template>\r
192   </xsl:template>\r
193 \r
194   <xsl:template match="p[starts-with(text(),'Inherited by ')]">\r
195     <xsl:call-template name="break-comma"/>\r
196   </xsl:template>\r
197 \r
198   <xsl:template match="p[starts-with(text(),'Inherits ')]">\r
199     <xsl:call-template name="break-comma"/>\r
200   </xsl:template>\r
201 \r
202   <!-- Remove external items from the namespace index -->\r
203   <xsl:template match="div[@id='content2']/table[contains(preceding-sibling::h1/text(),'Namespace Reference')]/tr[td[@class='memItemRight']/a[1][@class='elRef'][@doxygen]]">\r
204   </xsl:template>\r
205   \r
206   <!-- Remove [external] references from the modules page -->\r
207   <xsl:template match="div[@id='content2']/ul/li[a/@class='elRef'][a/@doxygen][code/text()='[external]'][not(ul)]">\r
208   </xsl:template>\r
209   \r
210 </xsl:stylesheet>\r