New elements: newline, newpage
[xmldoc.git] / html.xsl
1 <?xml version="1.0"?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3
4 <xsl:strip-space elements="doc chapter section"/>
5 <xsl:output method="html" indent="yes" encoding="iso-8859-1"/>
6
7 <xsl:template match="doc">
8 <html>
9 <head>
10    <link>
11    <xsl:attribute name="rel">stylesheet</xsl:attribute>
12    <xsl:attribute name="type">text/css</xsl:attribute>
13    <xsl:attribute name="href"><xsl:value-of select="@style"/></xsl:attribute>
14    </link>
15    <title>
16       <xsl:value-of select="*/titlepage/title"/>
17    </title>
18 </head>
19 <body>
20    <xsl:apply-templates/>
21    <hr/>
22    <xsl:apply-templates select="//footnote" mode="footnotes"/>
23 </body>
24 </html>
25 </xsl:template>
26
27 <xsl:template match="titlepage">
28    <div>
29    <xsl:attribute name="class">titlepage</xsl:attribute>
30    <xsl:apply-templates/>
31    </div>
32 </xsl:template>
33
34 <xsl:template match="title">
35    <h1>
36    <xsl:attribute name="class">titlepage</xsl:attribute>
37    <xsl:apply-templates/>
38    </h1>
39 </xsl:template>
40
41 <xsl:template match="subtitle">
42    <h2>
43    <xsl:attribute name="class">titlepage</xsl:attribute>
44    <xsl:apply-templates/>
45    </h2>
46 </xsl:template>
47
48 <xsl:template match="author">
49    <xsl:apply-templates/><br/>
50 </xsl:template>
51
52 <xsl:template match="date">
53    <p><xsl:apply-templates/></p>
54 </xsl:template>
55
56 <xsl:template match="docinfo">
57    <center><table border="2" width="90%">
58    <tr><th colspan="2">Document Information</th></tr>
59    <xsl:apply-templates/>
60    </table></center>
61 </xsl:template>
62
63 <xsl:template match="infoitem">
64    <tr>
65      <td><xsl:value-of select="@label"/></td>
66      <td><xsl:apply-templates/></td>
67    </tr>
68 </xsl:template>
69
70 <xsl:template match="abstract">
71    <blockquote>
72    <b>Abstract:</b><br/>
73    <xsl:apply-templates/>
74    </blockquote>
75 </xsl:template>
76
77 <!--  A template to create the section number for a node -->
78
79 <xsl:template name="section-number" mode="section-number" match="node()">
80    <xsl:number count="chapter|section" level="multiple" format="1.1 "/>
81 </xsl:template>
82
83 <!--  Create a table of contents -->
84
85 <xsl:template match="toc">
86 <h1>Table Of Contents</h1>
87 <xsl:for-each select="../chapter">
88    <h2>
89    <xsl:number count="chapter"/>
90    <xsl:text>  </xsl:text>
91    <a>
92    <xsl:attribute name="href">#CH<xsl:number count="chapter"/></xsl:attribute>
93    <xsl:value-of select="heading"/>
94    </a>
95    </h2>
96    <ul>
97    <xsl:for-each select="section">
98       <h3>
99       <xsl:number count="chapter|section" level="multiple" format="1.1 "/>
100       <a>
101       <xsl:attribute name="href">#SEC<xsl:number count="chapter|section" level="multiple" format="1.1"/></xsl:attribute>
102       <xsl:value-of select="heading"/>
103       </a>
104       </h3>
105    </xsl:for-each>
106    </ul>
107 </xsl:for-each>
108 <hr></hr>
109 </xsl:template>
110
111 <!--  Chapter and section headings are all automatically numbered -->
112
113 <xsl:template match="chapter/heading">
114    <h1>
115      <xsl:number count="chapter"/>
116      <xsl:text>  </xsl:text>
117       <a>
118       <xsl:attribute name="name">CH<xsl:number count="chapter"/></xsl:attribute>
119       </a>
120      <xsl:apply-templates/>
121    </h1>
122 </xsl:template>
123
124 <xsl:template match="section/heading">
125    <h2>
126      <xsl:number count="chapter|section" level="multiple" format="1.1 "/>
127      <a>
128      <xsl:attribute name="name">SEC<xsl:number count="chapter|section" level="multiple" format="1.1"/></xsl:attribute>
129      </a>
130      <xsl:apply-templates/>
131    </h2>
132 </xsl:template>
133
134 <xsl:template match="subsection/heading">
135    <h3>
136      <xsl:number count="chapter|section|subsection" level="multiple" format="1.1.1 "/>
137      <xsl:apply-templates/>
138    </h3>
139 </xsl:template>
140
141 <xsl:template match="subsubsection/heading">
142    <h4>
143      <xsl:number count="chapter|section|subsection|subsubsection" level="multiple"
144                  format="1.1.1.1 "/>
145      <xsl:apply-templates/>
146    </h4>
147 </xsl:template>
148
149 <xsl:template match="paragraph/heading">
150    <h4>
151      <xsl:number count="chapter|section|subsection|subsubsection|paragraph"
152                  level="multiple"
153                  format="1.1.1.1.1 "/>
154      <xsl:apply-templates/>
155    </h4>
156 </xsl:template>
157
158 <xsl:template match="subparagraph/heading">
159    <h4>
160      <xsl:number count="chapter|section|subsection|subsubsection|paragraph|subparagraph"
161                  level="multiple"
162                  format="1.1.1.1.1.1 "/>
163      <xsl:apply-templates/>
164    </h4>
165 </xsl:template>
166
167 <!--  Trivial elements are convreted directly -->
168
169 <xsl:template match="para">
170    <p>
171      <xsl:apply-templates/>
172    </p>
173 </xsl:template>
174
175 <xsl:template match="quote">
176    <blockquote>
177      <xsl:apply-templates/>
178    </blockquote>
179 </xsl:template>
180
181 <xsl:template match="verbatim">
182 <pre>
183  <xsl:apply-templates/>
184 </pre>
185 </xsl:template>
186
187 <xsl:template match="itemize">
188 <ul>
189    <xsl:apply-templates/>
190 </ul>
191 </xsl:template>
192
193 <xsl:template match="enumerate">
194 <ol>
195    <xsl:apply-templates/>
196 </ol>
197 </xsl:template>
198
199 <xsl:template match="item">
200 <li>
201    <xsl:apply-templates/>
202 </li>
203 </xsl:template>
204
205 <xsl:template match="footnote">
206 <sup><a>
207   <xsl:attribute name='href'>#footnote<xsl:number level='any'/></xsl:attribute>
208   <xsl:number level='any'/>
209 </a></sup>
210 </xsl:template>
211
212 <xsl:template match="footnote" mode="footnotes">
213 <sup><a><xsl:attribute name='name'>footnote<xsl:number level='any'/></xsl:attribute>
214         <xsl:number level='any'/></a></sup> <xsl:apply-templates/><br/>
215
216 </xsl:template>
217
218 <xsl:template match="emph">
219 <em><xsl:apply-templates/></em>
220 </xsl:template>
221
222 <xsl:template match="strong">
223 <strong><xsl:apply-templates/></strong>
224 </xsl:template>
225
226 <xsl:template match="code">
227 <code><xsl:apply-templates/></code>
228 </xsl:template>
229
230 <xsl:template match="remark">
231 <span><xsl:attribute name="class">remark</xsl:attribute><xsl:apply-templates/></span>
232 </xsl:template>
233
234 <xsl:template match="sub">
235 <sub><xsl:apply-templates/></sub>
236 </xsl:template>
237
238 <xsl:template match="sup">
239 <sup><xsl:apply-templates/></sup>
240 </xsl:template>
241
242 <xsl:template match="table">
243 <table>
244 <xsl:apply-templates/>
245 </table>
246 </xsl:template>
247
248 <xsl:template match="newline"><br/></xsl:template>
249
250 <xsl:template match="row">
251 <tr><xsl:apply-templates/></tr>
252 </xsl:template>
253
254 <xsl:template match="thead">
255 <tr><xsl:apply-templates/></tr>
256 </xsl:template>
257
258 <xsl:template match="thead/col">
259 <th><xsl:apply-templates/></th>
260 </xsl:template>
261
262 <xsl:template match="row/col">
263 <td><xsl:apply-templates/></td>
264 </xsl:template>
265
266 <xsl:template match="picture">
267    <img><xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
268    </img>
269 </xsl:template>
270
271 <xsl:template match="label">
272    <a><xsl:attribute name='name'>
273       <xsl:value-of select="@name"/>
274    </xsl:attribute></a>
275 </xsl:template>
276
277 <xsl:template match="ref">
278    <a><xsl:attribute name='href'>#<xsl:value-of select="@to"/></xsl:attribute>
279      <xsl:apply-templates/>
280      <xsl:apply-templates select="id(@to)" mode="section-number"/>
281    </a>
282 </xsl:template>
283
284 <xsl:template match="page"></xsl:template>
285
286 <xsl:template match="reference">
287 <a>
288 <xsl:attribute name="href">
289 <xsl:value-of select="@href"/>
290 </xsl:attribute>
291 <xsl:apply-templates/>
292 </a>
293 </xsl:template>
294
295 </xsl:stylesheet>
296