Added commented out markup to make full HTML files in book2html.
[wolnelektury.git] / lib / librarian / book2html.xslt
1 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2     xmlns:wl="http://wolnelektury.pl/functions" >
3
4 <xsl:output encoding="utf-8" indent="yes" omit-xml-declaration = "yes" />
5
6
7 <xsl:template match="utwor">
8     <!-- <html>
9         <head>
10             <title>Książka z serwisu WolneLektury.pl</title>
11             <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
12             <link rel="stylesheet" href="master.css" type="text/css" media="all" charset="utf-8" />
13         </head>
14         <style>
15             body {
16                 font-size: 14px;
17                 font: Georgia, "Times New Roman", serif;
18                 line-height: 1.5em;
19                 margin: 3em;
20                 max-width: 36em;
21             }
22
23             a {
24                 color: blue;
25                 text-decoration: none;
26             }
27
28             /* =================================================== */
29             /* = Common elements: headings, paragraphs and lines = */
30             /* =================================================== */
31             h1 {
32                 font-size: 3em;
33                 margin: 1.5em 0;
34                 text-align: center;
35                 line-height: 1.5em;
36                 font-weight: bold;
37             }
38
39             h2 {
40                 font-size: 2em;
41                 margin: 1.5em 0 0;
42                 font-weight: bold;
43                 line-height: 1.5em;
44             }
45
46             h3 {
47                 font-size: 1.5em;
48                 margin: 1.5em 0 0;
49                 font-weight: normal;
50                 line-height: 1.5em;
51             }
52
53             h4 {
54                 font-size: 1em;
55                 margin: 1.5em 0 0;
56                 line-height: 1.5em;
57             }
58
59             p {
60                 margin: 0;
61             }
62
63             /* ======================== */
64             /* = Footnotes and themes = */
65             /* ======================== */
66             .theme-begin {
67                 border-left: 0.1em solid #DDDDDD;
68                 color: #666;
69                 float: right;
70                 margin: 0 -9.5em 0 0;
71                 padding: 0 0.5em;
72                 width: 7.5em;
73                 font-style: normal;
74                 font-weight: normal;
75                 font-size: 16px;
76                 display: none;
77             }
78
79             .annotation {
80                 font-style: normal;
81                 font-weight: normal;
82                 font-size: 16px;
83                 display: none;
84             }
85
86             #footnotes {
87                 display: none;
88             }
89
90             #footnotes .annotation {
91                 display: block;
92                 float: left;
93                 width: 2.5em;
94                 clear: both;
95             }
96
97             #footnotes div {
98                 margin: 1.5em 0 0 0;
99             }
100
101             #footnotes p {
102                 margin-left: 2.5em;
103             }
104
105             /* =================== */
106             /* = Custom elements = */
107             /* =================== */
108             span.author {
109                 font-size: 0.5em;
110                 display: block;
111                 line-height: 1.5em;
112                 margin-bottom: 0.25em;
113             }
114
115             span.collection {
116                 font-size: 0.375em;
117                 display: block;
118                 line-height: 1.5em;
119                 margin-bottom: -0.25em;
120             }
121
122             span.subtitle {
123                 font-size: 0.5em;
124                 display: block;
125                 line-height: 1.5em;
126                 margin-top: -0.25em;
127             }
128
129             div.didaskalia {
130                 font-style: italic;
131                 margin: 0.5em 0 0;
132             }
133
134             div.kwestia {
135                 margin: 0.5em 0 0;
136             }
137
138             div.stanza {
139                 margin: 1.5em 0 0;
140             }
141
142             div.kwestia div.stanza {
143                 margin: 0;
144             }
145
146             p.paragraph {
147                 text-align: justify;
148                 margin: 1.5em 0 0;
149             }
150
151             p.motto {
152                 text-align: justify;
153                 font-style: italic;
154                 margin: 1.5em 0 0;
155             }
156
157             p.motto_podpis {
158                 font-size: 0.875em;
159             }
160
161             div.fragment {
162                 border-bottom: 0.1em solid #999;
163                 padding-bottom: 1.5em;
164             }
165
166             div.note p, div.note p.paragraph {
167                 text-align: right;
168                 font-style: italic;
169             }
170
171             hr.spacer {
172                 height: 3em;
173                 visibility: hidden;
174             }
175
176             .anchor {
177                 display: none;
178             }
179
180             #toc {
181                 display: none;
182             }
183         </style>
184         <body> -->
185         <div id="book-text">
186             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
187             <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)])">
188                 <div id="footnotes">
189                     <h3>Przypisy</h3>
190                     <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)]">
191                         <div>
192                             <a name="{concat('footnote-', generate-id(.))}" />
193                             <a href="{concat('#anchor-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt]) + 1" />]</a>
194                             <xsl:choose>
195                                 <xsl:when test="count(akap|akap_cd|strofa) = 0">
196                                     <p><xsl:apply-templates select="text()|*" mode="inline" /></p>
197                                 </xsl:when>
198                                 <xsl:otherwise>
199                                     <xsl:apply-templates select="text()|*" mode="inline" />
200                                 </xsl:otherwise>
201                             </xsl:choose>
202                         </div>
203                     </xsl:for-each>
204                 </div>
205             </xsl:if>
206         </div>
207         <!-- </body>
208     </html> -->
209 </xsl:template>
210
211
212 <!-- ============================================================================== -->
213 <!-- = MASTER TAG                                                                 = -->
214 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
215 <!-- ============================================================================== -->
216 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
217     <xsl:if test="nazwa_utworu">
218         <h1>
219             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
220         </h1>
221     </xsl:if>
222     <xsl:apply-templates />
223 </xsl:template>
224
225
226 <!-- ==================================================================================== -->
227 <!-- = BLOCK TAGS                                                                       = -->
228 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
229 <!-- ==================================================================================== -->
230 <xsl:template match="nota">
231     <div class="note"><xsl:apply-templates /></div>
232 </xsl:template>
233
234 <xsl:template match="lista_osob">
235     <div class="person-list">
236         <h3><xsl:value-of select="naglowek_listy" /></h3>
237         <ol>
238             <xsl:apply-templates select="lista_osoba" />
239         </ol>
240     </div>
241 </xsl:template>
242
243 <xsl:template match="dedykacja">
244     <div class="dedication"><xsl:apply-templates /></div>
245 </xsl:template>
246
247 <xsl:template match="kwestia">
248     <div class="kwestia">
249         <xsl:apply-templates select="strofa|akap" />
250     </div>
251 </xsl:template>
252
253 <xsl:template match="dlugi_cytat|poezja_cyt">
254     <blockquote><xsl:apply-templates /></blockquote>
255 </xsl:template>
256
257 <xsl:template match="motto">
258     <div class="motto"><xsl:apply-templates mode="inline" /></div>
259 </xsl:template>
260
261
262 <!-- ========================================== -->
263 <!-- = PARAGRAPH TAGS                         = -->
264 <!-- = (can contain inline and special tags)  = -->
265 <!-- ========================================== -->
266 <!-- Title page -->
267 <xsl:template match="autor_utworu" mode="header">
268     <span class="author"><xsl:apply-templates mode="inline" /></span>
269 </xsl:template>
270
271 <xsl:template match="nazwa_utworu" mode="header">
272     <span class="title"><xsl:apply-templates mode="inline" /></span>
273 </xsl:template>
274
275 <xsl:template match="dzielo_nadrzedne" mode="header">
276     <span class="collection"><xsl:apply-templates mode="inline" /></span>
277 </xsl:template>
278
279 <xsl:template match="podtytul" mode="header">
280     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
281 </xsl:template>
282
283 <!-- Section headers (included in index)-->
284 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
285     <h2><xsl:apply-templates mode="inline" /></h2>
286 </xsl:template>
287
288 <xsl:template match="naglowek_scena|naglowek_rozdzial">
289     <h3><xsl:apply-templates mode="inline" /></h3>
290 </xsl:template>
291
292 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
293     <h4><xsl:apply-templates mode="inline" /></h4>
294 </xsl:template>
295
296 <!-- Other paragraph tags -->
297 <xsl:template match="miejsce_czas">
298     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
299 </xsl:template>
300
301 <xsl:template match="didaskalia">
302     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
303 </xsl:template>
304
305 <xsl:template match="lista_osoba">
306     <li><xsl:apply-templates mode="inline" /></li>
307 </xsl:template>
308
309 <xsl:template match="akap|akap_dialog|akap_cd">
310     <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
311 </xsl:template>
312
313 <xsl:template match="strofa">
314     <div class="stanza">
315         <xsl:choose>
316             <xsl:when test="count(br) > 0">     
317                 <xsl:call-template name="verse">
318                     <xsl:with-param name="line-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
319                     <xsl:with-param name="line-number" select="1" />
320                 </xsl:call-template>    
321                 <xsl:for-each select="br">              
322                                 <!-- Each BR tag "consumes" text after it -->
323                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
324                     <xsl:call-template name="verse">
325                         <xsl:with-param name="line-number" select="$lnum+2" />
326                         <xsl:with-param name="line-content" 
327                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
328                     </xsl:call-template>
329                 </xsl:for-each>
330             </xsl:when>
331             <xsl:otherwise>
332                 <xsl:call-template name="verse">
333                     <xsl:with-param name="line-content" select="text() | node()" />
334                     <xsl:with-param name="line-number" select="1" />
335                  </xsl:call-template>           
336             </xsl:otherwise>
337         </xsl:choose>
338     </div>
339 </xsl:template>
340
341 <xsl:template name="verse">
342     <xsl:param name="line-content" />
343     <xsl:param name="line-number" />
344     <p class="verse">
345         <xsl:choose>
346             <xsl:when test="name($line-content) = 'wers_akap'">
347                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
348             </xsl:when>
349             <xsl:when test="name($line-content) = 'wers_wciety'">
350                 <xsl:attribute name="style">padding-left: <xsl:value-of select="$line-content/@typ" />em</xsl:attribute>
351             </xsl:when>
352         </xsl:choose>
353         <xsl:apply-templates select="$line-content" mode="inline" />
354     </p>
355 </xsl:template>
356
357 <xsl:template match="motto_podpis">
358     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
359 </xsl:template>
360
361
362 <!-- ================================================ -->
363 <!-- = INLINE TAGS                                  = -->
364 <!-- = (contain other inline tags and special tags) = -->
365 <!-- ================================================ -->
366 <!-- Annotations -->
367 <xsl:template match="pa|pe|pr|pt" mode="inline">
368     <a name="{concat('anchor-', generate-id(.))}" />
369     <a href="{concat('#footnote-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt]) + 1" />]</a>
370 </xsl:template>
371
372 <!-- Other inline tags -->
373 <xsl:template match="mat" mode="inline">
374     <em class="math"><xsl:apply-templates mode="inline" /></em>
375 </xsl:template>
376
377 <xsl:template match="didask_tekst" mode="inline">
378     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
379 </xsl:template>
380
381 <xsl:template match="slowo_obce" mode="inline">
382     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
383 </xsl:template>
384
385 <xsl:template match="tytul_dziela" mode="inline">
386     <em class="book-title">
387         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
388     </em>
389 </xsl:template>
390
391 <xsl:template match="wyroznienie" mode="inline">
392     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
393 </xsl:template>
394
395 <xsl:template match="osoba" mode="inline">
396     <em class="person"><xsl:apply-templates mode="inline" /></em>
397 </xsl:template>
398
399
400 <!-- ============================================== -->
401 <!-- = STANDALONE TAGS                            = -->
402 <!-- = (cannot contain any other tags)            = -->
403 <!-- ============================================== -->
404 <xsl:template match="sekcja_swiatlo">
405     <hr class="spacer" />
406 </xsl:template>
407
408 <xsl:template match="sekcja_asterysk">
409     <p class="spacer-asterisk">*</p>
410 </xsl:template>
411
412 <xsl:template match="separator_linia">
413     <hr class="spacer-line" />
414 </xsl:template>
415
416
417 <!-- ================ -->
418 <!-- = SPECIAL TAGS = -->
419 <!-- ================ -->
420 <!-- Themes -->
421 <xsl:template match="begin" mode="inline">
422     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
423     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
424         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
425     </a>
426 </xsl:template>
427
428 <xsl:template match="end" mode="inline">
429     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
430 </xsl:template>
431
432 <xsl:template match="begin|end">
433     <xsl:apply-templates select='.' mode="inline" />
434 </xsl:template>
435
436 <xsl:template match="motyw" mode="inline" />
437
438
439 <!-- ================ -->
440 <!-- = IGNORED TAGS = -->
441 <!-- ================ -->
442 <xsl:template match="extra|uwaga" />
443 <xsl:template match="extra|uwaga" mode="inline" />
444
445
446 <!-- ======== -->
447 <!-- = TEXT = -->
448 <!-- ======== -->
449 <xsl:template match="text()" />
450 <xsl:template match="text()" mode="inline">
451     <xsl:value-of select="wl:substitute_entities(.)" />
452 </xsl:template>
453
454
455 </xsl:stylesheet>
456