The conversion to HTML creates proper XHTML.
[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="xml" indent="yes" encoding="iso-8859-1"
6             doctype-system="http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd"
7             doctype-public="-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"/>
8
9 <xsl:template match="doc">
10 <html>
11   <xsl:attribute name='xmlns'>http://www.w3.org/1999/xhtml</xsl:attribute>
12 <head>
13    <link>
14    <xsl:attribute name="rel">stylesheet</xsl:attribute>
15    <xsl:attribute name="type">text/css</xsl:attribute>
16    <xsl:attribute name="href"><xsl:value-of select="@style"/></xsl:attribute>
17    </link>
18    <title>
19       <xsl:value-of select="*/titlepage/title"/>
20    </title>
21    <style type="text/css">
22       .center
23       {
24          text-align : center ;
25       }
26       table.docinfo
27       {
28          margin-left  : 10% ;
29          margin-right : 10% ;
30          border-style : solid ;
31       }
32       th
33       {
34          border-style : solid ;
35          border-width : thin ;
36       }
37       h3.toc
38       {
39          margin-left : 2em ;
40       }
41       pre.example
42       {
43          border : solid ;
44          padding-bottom : 1em ;
45       }
46       span.red
47       {
48          color : red ;
49       }
50       span.green
51       {
52          color : green ;
53       }
54       span.blue
55       {
56          color : blue ;
57       }
58       span.cyan
59       {
60          color : cyan ;
61       }
62       span.magenta
63       {
64          color : magenta ;
65       }
66       span.yellow
67       {
68          color : yellow ;
69       }
70       span.orange
71       {
72          color : orange ;
73       }
74       span.violet
75       {
76          color : violet ;
77       }
78       span.purple
79       {
80          color : purple ;
81       }
82       span.brown
83       {
84          color : brown ;
85       }
86       span.pink
87       {
88          color : pink ;
89       }
90       span.olive
91       {
92          color : olive ;
93       }
94       span.black
95       {
96          color : black ;
97       }
98       span.darkgray
99       {
100          color : darkgray ;
101       }
102       span.gray
103       {
104          color : gray ;
105       }
106       span.lightgray
107       {
108          color : lightgray ;
109       }
110       span.white
111       {
112          color : white ;
113       }
114    </style>
115 </head>
116 <body>
117    <xsl:apply-templates/>
118    <hr/>
119    <xsl:apply-templates select="//footnote" mode="footnotes"/>
120 </body>
121 </html>
122 </xsl:template>
123
124 <xsl:template match="titlepage">
125    <div>
126    <xsl:attribute name="class">titlepage</xsl:attribute>
127    <xsl:apply-templates/>
128    </div>
129 </xsl:template>
130
131 <xsl:template match="title">
132    <h1>
133    <xsl:attribute name="class">titlepage</xsl:attribute>
134    <xsl:apply-templates/>
135    </h1>
136 </xsl:template>
137
138 <xsl:template match="subtitle">
139    <h2>
140    <xsl:attribute name="class">titlepage</xsl:attribute>
141    <xsl:apply-templates/>
142    </h2>
143 </xsl:template>
144
145 <xsl:template match="author">
146    <xsl:apply-templates/><br/>
147 </xsl:template>
148
149 <xsl:template match="date">
150    <p><xsl:apply-templates/></p>
151 </xsl:template>
152
153 <xsl:template match="docinfo">
154    <table class="docinfo">
155    <tr><th colspan="2">Document Information</th></tr>
156    <xsl:apply-templates/>
157    </table>
158 </xsl:template>
159
160 <xsl:template match="infoitem">
161    <tr>
162      <td><xsl:value-of select="@label"/></td>
163      <td><xsl:apply-templates/></td>
164    </tr>
165 </xsl:template>
166
167 <xsl:template match="abstract">
168    <blockquote>
169    <p><b>Abstract:</b></p>
170    <p>
171    <xsl:apply-templates/>
172    </p>
173    </blockquote>
174 </xsl:template>
175
176 <!--  A template to create the section number for a node -->
177
178 <xsl:template name="section-number" mode="section-number" match="node()">
179    <xsl:number count="chapter|section" level="multiple" format="1.1 "/>
180 </xsl:template>
181
182 <!--  Create a table of contents -->
183
184 <xsl:template match="toc">
185 <h1>Table Of Contents</h1>
186 <xsl:for-each select="../chapter">
187    <h2>
188    <xsl:number count="chapter"/>
189    <xsl:text>  </xsl:text>
190    <a>
191    <xsl:attribute name="href">#CH<xsl:number count="chapter"/></xsl:attribute>
192    <xsl:value-of select="heading"/>
193    </a>
194    </h2>
195    <xsl:for-each select="section">
196       <h3 class="toc">
197       <xsl:number count="chapter|section" level="multiple" format="1.1 "/>
198       <a>
199       <xsl:attribute name="href">#SEC<xsl:number count="chapter|section" level="multiple" format="1.1"/></xsl:attribute>
200       <xsl:value-of select="heading"/>
201       </a>
202       </h3>
203    </xsl:for-each>
204 </xsl:for-each>
205 <hr></hr>
206 </xsl:template>
207
208 <!--  Chapter and section headings are all automatically numbered -->
209
210 <xsl:template match="chapter/heading">
211    <h1>
212      <xsl:number count="chapter"/>
213      <xsl:text>  </xsl:text>
214       <a>
215       <xsl:attribute name="id">CH<xsl:number count="chapter"/></xsl:attribute>
216       </a>
217      <xsl:apply-templates/>
218    </h1>
219 </xsl:template>
220
221 <xsl:template match="section/heading">
222    <h2>
223      <xsl:number count="chapter|section" level="multiple" format="1.1 "/>
224      <a>
225      <xsl:attribute name="id">SEC<xsl:number count="chapter|section" level="multiple" format="1.1"/></xsl:attribute>
226      </a>
227      <xsl:apply-templates/>
228    </h2>
229 </xsl:template>
230
231 <xsl:template match="subsection/heading">
232    <h3>
233      <xsl:number count="chapter|section|subsection" level="multiple" format="1.1.1 "/>
234      <xsl:apply-templates/>
235    </h3>
236 </xsl:template>
237
238 <xsl:template match="subsubsection/heading">
239    <h4>
240      <xsl:number count="chapter|section|subsection|subsubsection" level="multiple"
241                  format="1.1.1.1 "/>
242      <xsl:apply-templates/>
243    </h4>
244 </xsl:template>
245
246 <xsl:template match="paragraph/heading">
247    <h4>
248      <xsl:number count="chapter|section|subsection|subsubsection|paragraph"
249                  level="multiple"
250                  format="1.1.1.1.1 "/>
251      <xsl:apply-templates/>
252    </h4>
253 </xsl:template>
254
255 <xsl:template match="subparagraph/heading">
256    <h4>
257      <xsl:number count="chapter|section|subsection|subsubsection|paragraph|subparagraph"
258                  level="multiple"
259                  format="1.1.1.1.1.1 "/>
260      <xsl:apply-templates/>
261    </h4>
262 </xsl:template>
263
264 <!--  Trivial elements are convreted directly -->
265
266 <xsl:template match="para">
267    <p>
268      <xsl:apply-templates/>
269    </p>
270 </xsl:template>
271
272 <xsl:template match="quote">
273    <blockquote><p>
274      <xsl:apply-templates/>
275    </p></blockquote>
276 </xsl:template>
277
278 <xsl:template match="verbatim">
279 <pre>
280  <xsl:apply-templates/>
281 </pre>
282 </xsl:template>
283
284 <xsl:template match="example">
285 <pre class='example'>
286  <xsl:apply-templates/>
287 </pre>
288 </xsl:template>
289
290 <xsl:template match="itemize">
291 <ul>
292    <xsl:apply-templates/>
293 </ul>
294 </xsl:template>
295
296 <xsl:template match="enumerate">
297 <ol>
298    <xsl:apply-templates/>
299 </ol>
300 </xsl:template>
301
302 <xsl:template match="description">
303 <dl>
304    <xsl:apply-templates/>
305 </dl>
306 </xsl:template>
307
308 <xsl:template match="itemize/item">
309 <li>
310    <xsl:apply-templates/>
311 </li>
312 </xsl:template>
313
314 <xsl:template match="enumerate/item">
315 <li>
316    <xsl:apply-templates/>
317 </li>
318 </xsl:template>
319
320 <xsl:template match="description/item">
321 <dt><xsl:value-of select='@tag'/></dt>
322 <dd>
323    <xsl:apply-templates/>
324 </dd>
325 </xsl:template>
326
327 <xsl:template match="footnote">
328 <sup><a>
329   <xsl:attribute name='href'>#footnote<xsl:number level='any'/></xsl:attribute>
330   <xsl:number level='any'/>
331 </a></sup>
332 </xsl:template>
333
334 <xsl:template match="footnote" mode="footnotes">
335 <p>
336 <sup><a><xsl:attribute name='id'>footnote<xsl:number level='any'/></xsl:attribute>
337         <xsl:number level='any'/></a></sup> <xsl:apply-templates/>
338 </p>
339 </xsl:template>
340
341 <xsl:template match="emph">
342 <em><xsl:apply-templates/></em>
343 </xsl:template>
344
345 <xsl:template match="strong">
346 <strong><xsl:apply-templates/></strong>
347 </xsl:template>
348
349 <xsl:template match="code">
350 <code><xsl:apply-templates/></code>
351 </xsl:template>
352
353 <xsl:template match="remark">
354 <span><xsl:attribute name="class">remark</xsl:attribute><xsl:apply-templates/></span>
355 </xsl:template>
356
357 <xsl:template match="sub">
358 <sub><xsl:apply-templates/></sub>
359 </xsl:template>
360
361 <xsl:template match="sup">
362 <sup><xsl:apply-templates/></sup>
363 </xsl:template>
364
365 <xsl:template match="color">
366 <span><xsl:attribute name="class"><xsl:value-of select="@colorname"/></xsl:attribute><xsl:apply-templates/></span>
367 </xsl:template>
368
369 <xsl:template match="big">
370 <big><xsl:apply-templates/></big>
371 </xsl:template>
372
373 <xsl:template match="small">
374 <small><xsl:apply-templates/></small>
375 </xsl:template>
376
377 <xsl:template match="table">
378 <table>
379 <xsl:apply-templates/>
380 </table>
381 </xsl:template>
382
383 <xsl:template match="newline"><br/></xsl:template>
384
385 <xsl:template match="row">
386 <tr><xsl:apply-templates/></tr>
387 </xsl:template>
388
389 <xsl:template match="thead">
390 <tr><xsl:apply-templates/></tr>
391 </xsl:template>
392
393 <xsl:template match="thead/col">
394 <th><xsl:apply-templates/></th>
395 </xsl:template>
396
397 <xsl:template match="row/col">
398 <td><xsl:apply-templates/></td>
399 </xsl:template>
400
401 <xsl:template match="picture">
402    <img><xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
403    </img>
404 </xsl:template>
405
406 <xsl:template match="label">
407    <a><xsl:attribute name='id'>
408       <xsl:value-of select="@name"/>
409    </xsl:attribute></a>
410 </xsl:template>
411
412 <xsl:template match="index"></xsl:template>
413
414 <xsl:template match="ref">
415    <a><xsl:attribute name='href'>#<xsl:value-of select="@to"/></xsl:attribute>
416      <xsl:apply-templates/>
417      <!--<xsl:apply-templates select="id(@to)" mode="section-number"/>-->
418    </a>
419 </xsl:template>
420
421 <xsl:template match="page"></xsl:template>
422
423 <xsl:template match="reference">
424 <a>
425 <xsl:attribute name="href">
426 <xsl:value-of select="@href"/>
427 </xsl:attribute>
428 <xsl:apply-templates/>
429 </a>
430 </xsl:template>
431
432 <xsl:template match="math">
433 <math>
434 <xsl:attribute name="xmlns">http://www.w3.org/1998/Math/MathML</xsl:attribute>
435 <xsl:copy-of select='./*'/>
436 </math>
437 </xsl:template>
438
439 <xsl:template match="svg">
440 <svg>
441 <xsl:attribute name="xmlns">http://www.w3.org/2000/svg</xsl:attribute>
442 <xsl:copy-of select='./*'/>
443 </svg>
444 </xsl:template>
445
446 </xsl:stylesheet>
447