Mercurial > hg > lib > markup
comparison xml/doc.xsl @ 2:2b399c612a3e
from elsewhere, pbly out of date
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 25 May 2021 13:59:08 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:f005daf4488a | 2:2b399c612a3e |
---|---|
1 <?xml version='1.0'?> | |
2 <!DOCTYPE xsl:stylesheet SYSTEM "xsl.dtd" [ | |
3 <!ENTITY nbsp " "> | |
4 ]> | |
5 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns="http://www.w3.org/1999/xhtml"> | |
6 | |
7 <xsl:param name="font">DejaVu Sans, Arial</xsl:param> | |
8 <xsl:param name="font-size">12pt</xsl:param> | |
9 <xsl:param name="topChrome" select="xyzzy"/> | |
10 <xsl:param name="botChrome" select="xyzzy"/> | |
11 | |
12 <xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/> | |
13 | |
14 <xsl:variable name="toc" select="count(//div/@id)>1"/> | |
15 | |
16 <!-- The real stylesheet starts here --> | |
17 <xsl:template match="/"> | |
18 <html xmlns="http://www.w3.org/1999/xhtml"> | |
19 <head> | |
20 <meta name="copyright" content="Copyright (C) 2007 Henry S. Thompson"/> | |
21 <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> | |
22 <style type="text/css"> | |
23 @page { size: A4 portrait; margin: 2cm} | |
24 @media screen { | |
25 body {width: 20cm; margin-left: auto; margin-right: auto} | |
26 } | |
27 body {font-size: <xsl:value-of select="$font-size"/>} | |
28 pre.code {font-family: monospace} | |
29 pre {margin-left: 0em} | |
30 ul.nolabel { margin: 0; margin-left: -2.5em} | |
31 ul.naked li { list-style-type: none } | |
32 ol ol {list-style-type: lower-alpha} | |
33 div.ndli { margin-bottom: 1ex } | |
34 .math {font-family: 'Arial Unicode MS', 'Lucida Sans Unicode', serif} | |
35 .sub {font-size: 80%; vertical-align: sub} | |
36 .termref {text-decoration: none; color: #606000} | |
37 div.toc h2 {font-size: 120%; margin-top: 0em; margin-bottom: 0em} | |
38 div.toc h4 {font-size: 100%; margin-top: 0em; margin-bottom: 0em; | |
39 margin-left: 1em} | |
40 div.toc h1 {font-size: 140%; margin-bottom: 0em} | |
41 div.toc ul {margin-top: 1ex} | |
42 .byline {font-size: 120%} | |
43 div.figure {margin-left: 2em} | |
44 div.caption {font-style: italic; font-weight: bold; margin-top: 1em} | |
45 i i {font-style: normal} | |
46 <xsl:value-of select="doc/head/style"/> | |
47 <xsl:if test="$topChrome"> | |
48 <xsl:text>.skiplink {display: none} | |
49 div#banner img {border: none} | |
50 A.headertext:link, A.headertext:visited { | |
51 color:#ffffff; | |
52 text-decoration:none; | |
53 font-weight:bold; | |
54 font-size: small; | |
55 /* font-size:89%;*/ | |
56 } | |
57 | |
58 A.headertext:hover, A.headertext:active { | |
59 color:#ffffff; | |
60 text-decoration:underline; | |
61 font-weight:bold; | |
62 font-size: small; | |
63 /* font-size:89%;*/ | |
64 }</xsl:text> | |
65 </xsl:if> | |
66 </style> | |
67 <title> | |
68 <xsl:for-each select="doc/head/title"> | |
69 <xsl:value-of select="."/> | |
70 </xsl:for-each> | |
71 </title> | |
72 <xsl:if test="doc/@style"> | |
73 <link href="http://www.w3.org/StyleSheets/{doc/@style}.css" rel="stylesheet" type="text/css"/> | |
74 </xsl:if> | |
75 </head> | |
76 <body style="font-family: {$font}; background: rgb(254,250,246)"> | |
77 <xsl:if test="$topChrome"> | |
78 <xsl:copy-of select="$topChrome"/></xsl:if> | |
79 <xsl:apply-templates/> | |
80 <xsl:if test="$botChrome"> | |
81 <xsl:copy-of select="$botChrome"/></xsl:if> | |
82 </body> | |
83 </html> | |
84 </xsl:template> | |
85 | |
86 <xsl:template match="doc"> | |
87 <xsl:apply-templates/> | |
88 </xsl:template> | |
89 | |
90 <xsl:template match="head/style"/> | |
91 | |
92 <xsl:template match="body"> | |
93 <xsl:choose> | |
94 <xsl:when test="$toc"> | |
95 <!-- Provide a TOC --> | |
96 <xsl:apply-templates select="div[not(@id)]"/> | |
97 <div class="toc"> | |
98 <h1>Table of Contents</h1> | |
99 <ul class="naked"> | |
100 <xsl:for-each select=".//div[@id]"> | |
101 <li> | |
102 <xsl:apply-templates select="title" mode="toc"/> | |
103 </li> | |
104 </xsl:for-each> | |
105 </ul> | |
106 </div> | |
107 <xsl:apply-templates select="div[@id]"/> | |
108 </xsl:when> | |
109 <xsl:otherwise> | |
110 <xsl:apply-templates/> | |
111 </xsl:otherwise> | |
112 </xsl:choose> | |
113 </xsl:template> | |
114 | |
115 <xsl:template match="head"> | |
116 <div style="text-align: center"> | |
117 <xsl:if test="$topChrome//x:a[@href='#main']" xmlns:x="http://www.w3.org/1999/xhtml"> | |
118 <xsl:attribute name="id">main</xsl:attribute> | |
119 </xsl:if> | |
120 <xsl:apply-templates/> | |
121 </div> | |
122 </xsl:template> | |
123 | |
124 <xsl:template match="author|date"> | |
125 <div class="byline"> | |
126 <xsl:apply-templates/> | |
127 </div> | |
128 </xsl:template> | |
129 | |
130 <xsl:template match="head/title"> | |
131 <h1> | |
132 <xsl:apply-templates/> | |
133 </h1> | |
134 </xsl:template> | |
135 | |
136 <xsl:template match="div/title"> | |
137 <h2> | |
138 <xsl:call-template name="title"> | |
139 <xsl:with-param name="name" select="../@id"/> | |
140 </xsl:call-template> | |
141 </h2> | |
142 </xsl:template> | |
143 | |
144 <xsl:template name="title"> | |
145 <xsl:param name="name" select="xyzzy"/> | |
146 <xsl:param name="href" select="xyzzy"/> | |
147 <xsl:choose> | |
148 <xsl:when test="$toc and ($name or $href)"> | |
149 <xsl:number format="1.1. " level="multiple" count="div[@id]"/> | |
150 <xsl:text> </xsl:text> | |
151 </xsl:when> | |
152 <xsl:when test="not($toc)"> | |
153 <xsl:number format="1.1. " level="multiple" count="div"/> | |
154 <xsl:text> </xsl:text> | |
155 </xsl:when> | |
156 </xsl:choose> | |
157 <xsl:choose> | |
158 <xsl:when test="$name"> | |
159 <a name="{$name}"> | |
160 <xsl:apply-templates/> | |
161 </a> | |
162 </xsl:when> | |
163 <xsl:when test="$href"> | |
164 <a href="#{$href}"> | |
165 <xsl:apply-templates/> | |
166 </a> | |
167 </xsl:when> | |
168 <xsl:otherwise> | |
169 <xsl:apply-templates/> | |
170 </xsl:otherwise> | |
171 </xsl:choose> | |
172 </xsl:template> | |
173 | |
174 <xsl:template match="div//div/title" priority="2"> | |
175 <h4> | |
176 <xsl:call-template name="title"> | |
177 <xsl:with-param name="name" select="../@id"/> | |
178 </xsl:call-template> | |
179 </h4> | |
180 </xsl:template> | |
181 | |
182 <xsl:template match="title" mode="toc"> | |
183 <h2> | |
184 <xsl:call-template name="title"> | |
185 <xsl:with-param name="href" select="../@id"/> | |
186 </xsl:call-template> | |
187 </h2> | |
188 </xsl:template> | |
189 | |
190 <xsl:template match="div//div/title" priority="2" mode="toc"> | |
191 <h4> | |
192 <xsl:call-template name="title"> | |
193 <xsl:with-param name="href" select="../@id"/> | |
194 </xsl:call-template> | |
195 </h4> | |
196 </xsl:template> | |
197 | |
198 <xsl:template match="image[contains(@source,'.svg')]"> | |
199 <xsl:if test="not(substring-after(@source,'.svg')='')"><xsl:message terminate="yes">Confused by internal '.svg' in <xsl:value-of select="@source"/></xsl:message></xsl:if> | |
200 <iframe src="{@source}" frameborder="no" width="100%"> | |
201 <xsl:for-each select="@*"> | |
202 <xsl:if test="not(local-name()='source' or local-name()='textGloss' or local-name()='float')"> | |
203 <xsl:copy> | |
204 <xsl:value-of select="."/> | |
205 </xsl:copy> | |
206 </xsl:if> | |
207 </xsl:for-each> | |
208 </iframe> | |
209 </xsl:template> | |
210 | |
211 <xsl:template match="image"> | |
212 <img src="{@source}" style="border: 0"> | |
213 <xsl:attribute name="alt"> | |
214 <xsl:choose> | |
215 <xsl:when test="@textGloss"> | |
216 <xsl:value-of select="@textGloss"/> | |
217 </xsl:when> | |
218 <xsl:otherwise> | |
219 <xsl:value-of select="."/> | |
220 </xsl:otherwise> | |
221 </xsl:choose> | |
222 </xsl:attribute> | |
223 <xsl:for-each select="@*"> | |
224 <xsl:if test="not(local-name()='source' or local-name()='textGloss')"> | |
225 <xsl:copy> | |
226 <xsl:value-of select="."/> | |
227 </xsl:copy> | |
228 </xsl:if> | |
229 </xsl:for-each> | |
230 </img> | |
231 </xsl:template> | |
232 | |
233 <xsl:template match="figure"> | |
234 <div class="figure"> | |
235 <xsl:apply-templates/> | |
236 </div> | |
237 </xsl:template> | |
238 | |
239 <xsl:template match="figure/caption"> | |
240 <div class="caption"><xsl:text>Figure </xsl:text> | |
241 <xsl:number count="figure" level="any"/> | |
242 <xsl:text>. </xsl:text> | |
243 <xsl:apply-templates/> | |
244 </div> | |
245 </xsl:template> | |
246 | |
247 <xsl:template match="note"> | |
248 <div style="width: 20%; float: right; clear: right; margin-left: .5em"> | |
249 <small><i><xsl:apply-templates/></i></small> | |
250 </div> | |
251 </xsl:template> | |
252 | |
253 <xsl:template match="item/note"> | |
254 <div style="margin-left: 2em"> | |
255 <small><i><xsl:apply-templates/></i></small> | |
256 </div> | |
257 </xsl:template> | |
258 | |
259 <xsl:template match="emph"> | |
260 <i> | |
261 <xsl:apply-templates/> | |
262 </i> | |
263 </xsl:template> | |
264 | |
265 <xsl:template match="emph[@color]"> | |
266 <span style="color: {@color}"> | |
267 <xsl:apply-templates/> | |
268 </span> | |
269 </xsl:template> | |
270 | |
271 <xsl:template match="name"> | |
272 <b> | |
273 <xsl:apply-templates/> | |
274 </b> | |
275 </xsl:template> | |
276 | |
277 <xsl:template match="link[@href]"> | |
278 <a href="{@href}"> | |
279 <xsl:if test="@target and not(number(@target))"> | |
280 <xsl:attribute name="target"> | |
281 <xsl:value-of select="@target"/> | |
282 </xsl:attribute> | |
283 </xsl:if> | |
284 <xsl:apply-templates/> | |
285 </a> | |
286 </xsl:template> | |
287 | |
288 <xsl:template match="link[@name]"> | |
289 <a> | |
290 <xsl:attribute name="name"> | |
291 <xsl:value-of select="@name"/> | |
292 </xsl:attribute> | |
293 <xsl:apply-templates/> | |
294 </a> | |
295 </xsl:template> | |
296 | |
297 <xsl:template match="display/node()[self::code and position()=1 and position()=last()]" priority="2"> | |
298 <pre class="code"> | |
299 <xsl:apply-templates/> | |
300 </pre> | |
301 </xsl:template> | |
302 | |
303 <xsl:template match="display"> | |
304 <blockquote> | |
305 <div> | |
306 <xsl:apply-templates/> | |
307 </div> | |
308 </blockquote> | |
309 </xsl:template> | |
310 | |
311 | |
312 <xsl:template match="list[@type="defn"]"> | |
313 <dl> | |
314 <xsl:apply-templates/> | |
315 </dl> | |
316 </xsl:template> | |
317 | |
318 <xsl:template match="list[@type="1defn"]"> | |
319 <ul class="naked"> | |
320 <xsl:apply-templates/> | |
321 </ul> | |
322 </xsl:template> | |
323 | |
324 <xsl:template match="list[@type="defn"]/item"> | |
325 <xsl:variable name="n" select="translate(@term,' /','_.')"/> | |
326 <dt><b> | |
327 <a name="{$n}"><xsl:value-of select="@term"/></a> | |
328 </b></dt> | |
329 <dd><xsl:apply-templates/></dd> | |
330 </xsl:template> | |
331 | |
332 <xsl:template match="list[@type="1defn"]/item"> | |
333 <xsl:variable name="n" select="translate(@term,' /','_.')"/> | |
334 <li> | |
335 <a name="{$n}"><b><xsl:value-of select="@term"/></b></a> | |
336 <xsl:apply-templates/></li> | |
337 </xsl:template> | |
338 | |
339 <xsl:template match="term"> | |
340 <a href="#{translate(@def,' ','_')}" class="termref"> | |
341 <xsl:text>·</xsl:text> | |
342 <xsl:value-of select="@def"/> | |
343 <xsl:text>·</xsl:text> | |
344 </a> | |
345 </xsl:template> | |
346 | |
347 <xsl:template match="list[@type='normal' or not(@type)]"> | |
348 <!-- Firefox doesn't do local DTD attr defaults :-) --> | |
349 <ul> | |
350 <xsl:apply-templates/> | |
351 </ul> | |
352 </xsl:template> | |
353 | |
354 <xsl:template match="list[@type="enum"]"> | |
355 <ol> | |
356 <xsl:apply-templates/> | |
357 </ol> | |
358 </xsl:template> | |
359 | |
360 <xsl:template match="list/item" priority="0"> | |
361 <li><xsl:apply-templates/></li> | |
362 </xsl:template> | |
363 | |
364 <xsl:template match="list[@type='naked']"> | |
365 <ul class="naked nolabel"> | |
366 <xsl:apply-templates/> | |
367 </ul> | |
368 </xsl:template> | |
369 | |
370 <xsl:template match="list[@type='ndivs']"> | |
371 <div class="ndl"> | |
372 <xsl:apply-templates/> | |
373 </div> | |
374 </xsl:template> | |
375 | |
376 <xsl:template match="list[@type='ndivs']/item"> | |
377 <div class="ndli"> | |
378 <xsl:apply-templates/> | |
379 </div> | |
380 </xsl:template> | |
381 | |
382 <xsl:template match="list[@type='2col']"> | |
383 <xsl:variable name="n" select="count(item)"/> | |
384 <div style="float: left;width: 50%"><xsl:apply-templates select="item[position()<=($n div 2)]"/></div> | |
385 <div style="margin-left: 50%"><xsl:apply-templates select="item[position()>($n div 2)]"/></div> | |
386 </xsl:template> | |
387 | |
388 <xsl:template match="list[@type='2col']/item"> | |
389 <div> | |
390 <xsl:if test="../@indent"> | |
391 <xsl:attribute name="style"> | |
392 <xsl:text>margin-left: </xsl:text> | |
393 <xsl:value-of select="../@indent"/> | |
394 </xsl:attribute> | |
395 </xsl:if> | |
396 <xsl:apply-templates/> | |
397 </div> | |
398 </xsl:template> | |
399 | |
400 <xsl:template match="list[@type="tdefn"]"> | |
401 <table> | |
402 <tbody> | |
403 <xsl:apply-templates/> | |
404 </tbody> | |
405 </table> | |
406 </xsl:template> | |
407 | |
408 <xsl:template match="list[@type='tdefn']/item"> | |
409 <tr> | |
410 <td><xsl:value-of select="@term"/></td> | |
411 <td><xsl:apply-templates/></td> | |
412 </tr> | |
413 </xsl:template> | |
414 | |
415 <xsl:template match="div|p|table|code|caption|col|colgroup|thead|tfoot|tbody|td|th|span|sup|sub|tr"> | |
416 <xsl:element name="{local-name()}" namespace="http://www.w3.org/1999/xhtml"> | |
417 <xsl:apply-templates select="@*|node()"/> | |
418 </xsl:element> | |
419 </xsl:template> | |
420 | |
421 <!-- | |
422 XHTML | |
423 | |
424 We just copy any unrecognised stuff, as is. | |
425 This means you can mix XHTML with no-namespace elts and | |
426 get the 'right' effect. | |
427 --> | |
428 | |
429 <xsl:template match="*|@*"> | |
430 <xsl:copy> | |
431 <xsl:apply-templates select="* | @* | text()"/> | |
432 </xsl:copy> | |
433 </xsl:template> | |
434 | |
435 </xsl:stylesheet> |