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