Handling od wers_cd tags (currently we just indent it by 12ems).
[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" version="2.0" />
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="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
319                     <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][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="verse-content" 
326                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
327                         <xsl:with-param name="verse-type" select="following-sibling::*[count(preceding-sibling::br) = $lnum+1 and (name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd')][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="verse-content" select="text() | node()" />
334                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[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="verse-content" />
343     <xsl:param name="verse-type" />
344     <p class="verse">
345         <xsl:choose>
346             <xsl:when test="name($verse-type) = 'wers_akap'">
347                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
348             </xsl:when>
349             <xsl:when test="name($verse-type) = 'wers_wciety'">
350                 <xsl:choose>
351                     <xsl:when test="$verse-content/@typ">
352                         <xsl:attribute name="style">padding-left: <xsl:value-of select="$verse-content/@typ" />em</xsl:attribute>
353                     </xsl:when>
354                     <xsl:otherwise>
355                         <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
356                     </xsl:otherwise>
357                 </xsl:choose>
358             </xsl:when>
359             <xsl:when test="name($verse-type) = 'wers_cd'">
360                 <xsl:attribute name="style">padding-left: 12em</xsl:attribute>
361             </xsl:when>
362         </xsl:choose>
363         <xsl:apply-templates select="$verse-content" mode="inline" />
364     </p>
365 </xsl:template>
366
367 <xsl:template match="motto_podpis">
368     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
369 </xsl:template>
370
371
372 <!-- ================================================ -->
373 <!-- = INLINE TAGS                                  = -->
374 <!-- = (contain other inline tags and special tags) = -->
375 <!-- ================================================ -->
376 <!-- Annotations -->
377 <xsl:template match="pa|pe|pr|pt" mode="inline">
378     <a name="{concat('anchor-', generate-id(.))}" />
379     <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>
380 </xsl:template>
381
382 <!-- Other inline tags -->
383 <xsl:template match="mat" mode="inline">
384     <em class="math"><xsl:apply-templates mode="inline" /></em>
385 </xsl:template>
386
387 <xsl:template match="didask_tekst" mode="inline">
388     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
389 </xsl:template>
390
391 <xsl:template match="slowo_obce" mode="inline">
392     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
393 </xsl:template>
394
395 <xsl:template match="tytul_dziela" mode="inline">
396     <em class="book-title">
397         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
398     </em>
399 </xsl:template>
400
401 <xsl:template match="wyroznienie" mode="inline">
402     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
403 </xsl:template>
404
405 <xsl:template match="osoba" mode="inline">
406     <em class="person"><xsl:apply-templates mode="inline" /></em>
407 </xsl:template>
408
409
410 <!-- ============================================== -->
411 <!-- = STANDALONE TAGS                            = -->
412 <!-- = (cannot contain any other tags)            = -->
413 <!-- ============================================== -->
414 <xsl:template match="sekcja_swiatlo">
415     <hr class="spacer" />
416 </xsl:template>
417
418 <xsl:template match="sekcja_asterysk">
419     <p class="spacer-asterisk">*</p>
420 </xsl:template>
421
422 <xsl:template match="separator_linia">
423     <hr class="spacer-line" />
424 </xsl:template>
425
426
427 <!-- ================ -->
428 <!-- = SPECIAL TAGS = -->
429 <!-- ================ -->
430 <!-- Themes -->
431 <xsl:template match="begin" mode="inline">
432     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
433     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
434         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
435     </a>
436 </xsl:template>
437
438 <xsl:template match="end" mode="inline">
439     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
440 </xsl:template>
441
442 <xsl:template match="begin|end">
443     <xsl:apply-templates select='.' mode="inline" />
444 </xsl:template>
445
446 <xsl:template match="motyw" mode="inline" />
447
448
449 <!-- ================ -->
450 <!-- = IGNORED TAGS = -->
451 <!-- ================ -->
452 <xsl:template match="extra|uwaga" />
453 <xsl:template match="extra|uwaga" mode="inline" />
454
455
456 <!-- ======== -->
457 <!-- = TEXT = -->
458 <!-- ======== -->
459 <xsl:template match="text()" />
460 <xsl:template match="text()" mode="inline">
461     <xsl:value-of select="wl:substitute_entities(.)" />
462 </xsl:template>
463
464
465 </xsl:stylesheet>
466