minor fix
[librarian.git] / librarian / xslt / book2html.xslt
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3  
4    This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
5    Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6   
7 -->
8 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9     xmlns:wl="http://wolnelektury.pl/functions" >
10
11 <xsl:output encoding="utf-8" indent="yes" omit-xml-declaration = "yes" version="2.0" />
12 <xsl:template match="utwor">
13     <!-- <html>
14         <head>
15             <title>Książka z serwisu WolneLektury.pl</title>
16             <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
17         </head>
18         <style>
19             body {
20                 font-size: 16px;
21                 font: Georgia, "Times New Roman", serif;
22                 line-height: 1.5em;
23                 margin: 0;
24             }
25
26             a {
27                 color: blue;
28                 text-decoration: none;
29             }
30
31             #book-text {
32                 margin: 3em;
33                 max-width: 36em;
34             }
35
36             /* ================================== */
37             /* = Header with logo and menu      = */
38             /* ================================== */
39             #header {
40                 margin: 3.4em 0 0 1.4em;
41             }
42
43             img {
44                 border: none;
45             }
46
47
48             #menu {
49                 position: fixed;
50                 left: 0em;
51                 top: 0em;
52                 width: 100%;
53                 height: 1.5em;
54                 background: #333;
55                 color: #FFF;
56                 opacity: 0.9;
57             }
58
59             #menu ul {
60                 list-style: none;
61                 padding: 0;
62                 margin: 0;
63             }
64
65             #menu li a {
66                 display: block;
67                 float: left;
68                 width: 7.5em;
69                 height: 1.5em;
70                 margin-left: 0.5em;
71                 text-align: center;
72                 color: #FFF;
73             }
74
75             #menu li a:hover, #menu li a:active {
76                 color: #000;
77                 background: #FFF url(/media/img/arrow-down.png) no-repeat center right;
78             }
79
80             #menu li a.selected {
81                 color: #000;
82                 background: #FFF url(/media/img/arrow-up.png) no-repeat center right;
83             }
84
85             #toc, #themes {
86                 position: fixed;
87                 left: 0em;
88                 top: 1.5em;
89                 width: 37em;
90                 padding: 1.5em;
91                 background: #FFF;
92                 border-bottom: 0.25em solid #DDD;
93                 border-right: 0.25em solid #DDD;
94                 display: none;
95                 height: 16em;
96                 overflow-x: hidden;
97                 overflow-y: auto;
98                 opacity: 0.9;
99             }
100
101             #toc ol, #themes ol {
102                 list-style: none;
103                 padding: 0;
104                 margin: 0;
105             }
106
107             #toc ol li {
108                 font-weight: bold;
109             }
110
111             #toc ol ol {
112                 padding: 0 0 1.5em 1.5em;
113                 margin: 0;
114             }
115
116             #toc ol ol li {
117                 font-weight: normal;
118             }
119
120             #toc h2 {
121                 display: none;
122             }
123
124             #toc .anchor {
125                 float: none;
126                 margin: 0;
127                 color: blue;
128                 font-size: 16px;
129                 position: inherit;
130             }
131
132             /* =================================================== */
133             /* = Common elements: headings, paragraphs and lines = */
134             /* =================================================== */
135             h1 {
136                 font-size: 3em;
137                 margin: 1.5em 0;
138                 text-align: center;
139                 line-height: 1.5em;
140                 font-weight: bold;
141             }
142
143             h2 {
144                 font-size: 2em;
145                 margin: 1.5em 0 0;
146                 font-weight: bold;
147                 line-height: 1.5em;
148             }
149
150             h3 {
151                 font-size: 1.5em;
152                 margin: 1.5em 0 0;
153                 font-weight: normal;
154                 line-height: 1.5em;
155             }
156
157             h4 {
158                 font-size: 1em;
159                 margin: 1.5em 0 0;
160                 line-height: 1.5em;
161             }
162
163             p {
164                 margin: 0;
165             }
166
167             /* ======================== */
168             /* = Footnotes and themes = */
169             /* ======================== */
170             .theme-begin {
171                 border-left: 0.1em solid #DDDDDD;
172                 color: #777;
173                 padding: 0 0.5em;
174                 width: 7.5em;
175                 font-style: normal;
176                 font-weight: normal;
177                 font-size: 16px;
178                 float: right;
179                 margin-right: -9.5em;
180                 clear: both;
181                 left: 40em;
182                 line-height: 1.5em;
183                 text-align: left;
184             }
185
186             .annotation {
187                 font-style: normal;
188                 font-weight: normal;
189                 font-size: 12px;
190             }
191
192             #footnotes .annotation {
193                 display: block;
194                 float: left;
195                 width: 2.5em;
196                 clear: both;
197             }
198
199             #footnotes div {
200                 margin: 1.5em 0 0 0;
201             }
202
203             #footnotes p {
204                 margin-left: 2.5em;
205                 font-size: 0.875em;
206             }
207
208             blockquote {
209                 font-size: 0.875em;
210             }
211
212             /* ============= */
213             /* = Numbering = */
214             /* ============= */
215             .anchor {
216                 position: absolute;
217                 margin: -0.25em -0.5em;
218                 left: 1em;
219                 color: #777;
220                 font-size: 12px;
221                 width: 2em;
222                 text-align: center;
223                 padding: 0.25em 0.5em;
224                 line-height: 1.5em;
225             }
226
227             .anchor:hover, #book-text .anchor:active {
228                 color: #FFF;
229                 background-color: #CCC;
230             }
231
232             /* =================== */
233             /* = Custom elements = */
234             /* =================== */
235             span.author {
236                 font-size: 0.5em;
237                 display: block;
238                 line-height: 1.5em;
239                 margin-bottom: 0.25em;
240             }
241
242             span.collection {
243                 font-size: 0.375em;
244                 display: block;
245                 line-height: 1.5em;
246                 margin-bottom: -0.25em;
247             }
248
249             span.subtitle {
250                 font-size: 0.5em;
251                 display: block;
252                 line-height: 1.5em;
253                 margin-top: -0.25em;
254             }
255
256             div.didaskalia {
257                 font-style: italic;
258                 margin: 0.5em 0 0 1.5em;
259             }
260
261             div.kwestia {
262                 margin: 0.5em 0 0;
263             }
264
265             div.stanza {
266                 margin: 1.5em 0 0;
267             }
268
269             div.kwestia div.stanza {
270                 margin: 0;
271             }
272
273             p.paragraph {
274                 text-align: justify;
275                 margin: 1.5em 0 0;
276             }
277
278             p.motto {
279                 text-align: justify;
280                 font-style: italic;
281                 margin: 1.5em 0 0;
282             }
283
284             p.motto_podpis {
285                 font-size: 0.875em;
286                 text-align: right;
287             }
288
289             div.fragment {
290                 border-bottom: 0.1em solid #999;
291                 padding-bottom: 1.5em;
292             }
293
294             div.note p, div.dedication p, div.note p.paragraph, div.dedication p.paragraph {
295                 text-align: right;
296                 font-style: italic;
297             }
298
299             hr.spacer {
300                 height: 3em;
301                 visibility: hidden;
302             }
303
304             hr.spacer-line {
305                 margin: 1.5em 0;
306                 border: none;
307                 border-bottom: 0.1em solid #000;
308             }
309
310             p.spacer-asterisk {
311                 padding: 0;
312                 margin: 1.5em 0;
313                 text-align: center;
314             }
315
316             div.person-list ol {
317                 list-style: none;
318                 padding: 0 0 0 1.5em;
319             }
320
321             p.place-and-time {
322                 font-style: italic;
323             }
324
325             em.math, em.foreign-word, em.book-title, em.didaskalia {
326                 font-style: italic;
327             }
328
329             em.author-emphasis {
330                 letter-spacing: 0.1em;
331             }
332
333             em.person {
334                 font-style: normal;
335                 font-variant: small-caps;
336             }
337         </style>
338         <body> -->
339         <div id="book-text">
340             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
341             <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)])">
342                 <div id="footnotes">
343                     <h3>Przypisy</h3>
344                     <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)]">
345                         <div>
346                             <a name="{concat('footnote-', generate-id(.))}" />
347                             <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>
348                             <xsl:choose>
349                                 <xsl:when test="count(akap|akap_cd|strofa) = 0">
350                                     <p><xsl:apply-templates select="text()|*" mode="inline" /></p>
351                                 </xsl:when>
352                                 <xsl:otherwise>
353                                     <xsl:apply-templates select="text()|*" mode="inline" />
354                                 </xsl:otherwise>
355                             </xsl:choose>
356                         </div>
357                     </xsl:for-each>
358                 </div>
359             </xsl:if>
360         </div>
361         <!-- </body>
362     </html> -->
363 </xsl:template>
364
365
366 <!-- ============================================================================== -->
367 <!-- = MASTER TAG                                                                 = -->
368 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
369 <!-- ============================================================================== -->
370 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
371     <xsl:apply-templates select="nota_red" mode="special" />
372     <xsl:if test="nazwa_utworu">
373         <h1>
374             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
375         </h1>
376     </xsl:if>
377     <xsl:apply-templates />
378 </xsl:template>
379
380
381 <!-- ==================================================================================== -->
382 <!-- = BLOCK TAGS                                                                       = -->
383 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
384 <!-- ==================================================================================== -->
385 <xsl:template match="nota">
386     <div class="note"><xsl:apply-templates /></div>
387 </xsl:template>
388
389 <xsl:template match="lista_osob">
390     <div class="person-list">
391         <h3><xsl:value-of select="naglowek_listy" /></h3>
392         <ol>
393             <xsl:apply-templates select="lista_osoba" />
394         </ol>
395     </div>
396 </xsl:template>
397
398 <xsl:template match="dedykacja">
399     <div class="dedication"><xsl:apply-templates /></div>
400 </xsl:template>
401
402 <xsl:template match="kwestia">
403     <div class="kwestia">
404         <xsl:apply-templates select="strofa|akap|didaskalia" />
405     </div>
406 </xsl:template>
407
408 <xsl:template match="dlugi_cytat|poezja_cyt">
409     <blockquote><xsl:apply-templates /></blockquote>
410 </xsl:template>
411
412 <xsl:template match="motto">
413     <div class="motto"><xsl:apply-templates mode="inline" /></div>
414 </xsl:template>
415
416
417 <!-- ========================================== -->
418 <!-- = PARAGRAPH TAGS                         = -->
419 <!-- = (can contain inline and special tags)  = -->
420 <!-- ========================================== -->
421 <!-- Title page -->
422 <xsl:template match="autor_utworu" mode="header">
423     <span class="author"><xsl:apply-templates mode="inline" /></span>
424 </xsl:template>
425
426 <xsl:template match="nazwa_utworu" mode="header">
427     <span class="title"><xsl:apply-templates mode="inline" /></span>
428 </xsl:template>
429
430 <xsl:template match="dzielo_nadrzedne" mode="header">
431     <span class="collection"><xsl:apply-templates mode="inline" /></span>
432 </xsl:template>
433
434 <xsl:template match="podtytul" mode="header">
435     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
436 </xsl:template>
437
438 <!-- Section headers (included in index)-->
439 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
440     <h2><xsl:apply-templates mode="inline" /></h2>
441 </xsl:template>
442
443 <xsl:template match="naglowek_scena|naglowek_rozdzial">
444     <h3><xsl:apply-templates mode="inline" /></h3>
445 </xsl:template>
446
447 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
448     <h4><xsl:apply-templates mode="inline" /></h4>
449 </xsl:template>
450
451 <!-- Other paragraph tags -->
452 <xsl:template match="miejsce_czas">
453     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
454 </xsl:template>
455
456 <xsl:template match="didaskalia">
457     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
458 </xsl:template>
459
460 <xsl:template match="lista_osoba">
461     <li><xsl:apply-templates mode="inline" /></li>
462 </xsl:template>
463
464 <xsl:template match="akap|akap_dialog|akap_cd">
465     <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
466 </xsl:template>
467
468 <xsl:template match="strofa">
469     <div class="stanza">
470         <xsl:choose>
471             <xsl:when test="count(br) > 0">     
472                 <xsl:call-template name="verse">
473                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
474                     <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
475                 </xsl:call-template>    
476                 <xsl:for-each select="br">              
477                                 <!-- Each BR tag "consumes" text after it -->
478                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
479                     <xsl:call-template name="verse">
480                         <xsl:with-param name="verse-content" 
481                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
482                         <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]" />
483                     </xsl:call-template>
484                 </xsl:for-each>
485             </xsl:when>
486             <xsl:otherwise>
487                 <xsl:call-template name="verse">
488                     <xsl:with-param name="verse-content" select="text() | node()" />
489                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
490                  </xsl:call-template>           
491             </xsl:otherwise>
492         </xsl:choose>
493     </div>
494 </xsl:template>
495
496 <xsl:template name="verse">
497     <xsl:param name="verse-content" />
498     <xsl:param name="verse-type" />
499     <p class="verse">
500         <xsl:choose>
501             <xsl:when test="name($verse-type) = 'wers_akap'">
502                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
503             </xsl:when>
504             <xsl:when test="name($verse-type) = 'wers_wciety'">
505                 <xsl:choose>
506                     <xsl:when test="$verse-content/@typ">
507                         <xsl:attribute name="style">padding-left: <xsl:value-of select="$verse-content/@typ" />em</xsl:attribute>
508                     </xsl:when>
509                     <xsl:otherwise>
510                         <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
511                     </xsl:otherwise>
512                 </xsl:choose>
513             </xsl:when>
514             <xsl:when test="name($verse-type) = 'wers_cd'">
515                 <xsl:attribute name="style">padding-left: 12em</xsl:attribute>
516             </xsl:when>
517         </xsl:choose>
518         <xsl:apply-templates select="$verse-content" mode="inline" />
519     </p>
520 </xsl:template>
521
522 <xsl:template match="motto_podpis">
523     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
524 </xsl:template>
525
526
527 <!-- ================================================ -->
528 <!-- = INLINE TAGS                                  = -->
529 <!-- = (contain other inline tags and special tags) = -->
530 <!-- ================================================ -->
531 <!-- Annotations -->
532 <xsl:template match="pa|pe|pr|pt" mode="inline">
533     <a name="{concat('anchor-', generate-id(.))}" />
534     <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>
535 </xsl:template>
536
537 <!-- Other inline tags -->
538 <xsl:template match="mat" mode="inline">
539     <em class="math"><xsl:apply-templates mode="inline" /></em>
540 </xsl:template>
541
542 <xsl:template match="didask_tekst" mode="inline">
543     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
544 </xsl:template>
545
546 <xsl:template match="slowo_obce" mode="inline">
547     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
548 </xsl:template>
549
550 <xsl:template match="tytul_dziela" mode="inline">
551     <em class="book-title">
552         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
553     </em>
554 </xsl:template>
555
556 <xsl:template match="wyroznienie" mode="inline">
557     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
558 </xsl:template>
559
560 <xsl:template match="osoba" mode="inline">
561     <em class="person"><xsl:apply-templates mode="inline" /></em>
562 </xsl:template>
563
564
565 <!-- ============================================== -->
566 <!-- = STANDALONE TAGS                            = -->
567 <!-- = (cannot contain any other tags)            = -->
568 <!-- ============================================== -->
569 <xsl:template match="sekcja_swiatlo">
570     <hr class="spacer" />
571 </xsl:template>
572
573 <xsl:template match="sekcja_asterysk">
574     <p class="spacer-asterisk">*</p>
575 </xsl:template>
576
577 <xsl:template match="separator_linia">
578     <hr class="spacer-line" />
579 </xsl:template>
580
581
582 <!-- ================ -->
583 <!-- = SPECIAL TAGS = -->
584 <!-- ================ -->
585 <!-- Themes -->
586 <xsl:template match="begin" mode="inline">
587     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
588     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
589         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
590     </a>
591 </xsl:template>
592
593 <xsl:template match="end" mode="inline">
594     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
595 </xsl:template>
596
597 <xsl:template match="begin|end">
598     <xsl:apply-templates select='.' mode="inline" />
599 </xsl:template>
600
601 <xsl:template match="motyw" mode="inline" />
602
603
604 <xsl:template match="nota_red" mode="special">
605     <div id="nota_red">
606         <xsl:apply-templates />
607     </div>
608 </xsl:template>
609
610
611 <!-- ================ -->
612 <!-- = IGNORED TAGS = -->
613 <!-- ================ -->
614 <xsl:template match="extra|uwaga" />
615 <xsl:template match="extra|uwaga" mode="inline" />
616
617 <xsl:template match="nota_red" />
618
619 <!-- ======== -->
620 <!-- = TEXT = -->
621 <!-- ======== -->
622 <xsl:template match="text()" />
623 <xsl:template match="text()" mode="inline">
624     <xsl:value-of select="wl:substitute_entities(.)" />
625 </xsl:template>
626
627
628 </xsl:stylesheet>