change passing customizations to TeX source
[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" />
420                                 <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
421                                 </p>
422                             </xsl:when>
423                             <xsl:otherwise>
424                                 <xsl:apply-templates select="text()|*" mode="inline" />
425                             </xsl:otherwise>
426                         </xsl:choose>
427                     </div>
428                 </xsl:for-each>
429             </div>
430         </xsl:if>
431     </div>
432 </xsl:template>
433
434
435 <!-- ============================================================================== -->
436 <!-- = MASTER TAG                                                                 = -->
437 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
438 <!-- ============================================================================== -->
439 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
440     <xsl:apply-templates select="nota_red" mode="special" />
441     <xsl:if test="nazwa_utworu">
442         <h1>
443             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
444             <xsl:call-template name="translators" />
445         </h1>
446     </xsl:if>
447     <xsl:apply-templates />
448 </xsl:template>
449
450
451 <!-- ==================================================================================== -->
452 <!-- = BLOCK TAGS                                                                       = -->
453 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
454 <!-- ==================================================================================== -->
455 <xsl:template match="nota">
456     <div class="note"><xsl:apply-templates /></div>
457 </xsl:template>
458
459 <xsl:template match="lista_osob">
460     <div class="person-list">
461         <h3><xsl:value-of select="naglowek_listy" /></h3>
462         <ol>
463             <xsl:apply-templates select="lista_osoba" />
464         </ol>
465     </div>
466 </xsl:template>
467
468 <xsl:template match="dedykacja">
469     <div class="dedication"><xsl:apply-templates /></div>
470 </xsl:template>
471
472 <xsl:template match="kwestia">
473     <div class="kwestia">
474         <xsl:apply-templates select="strofa|akap|didaskalia" />
475     </div>
476 </xsl:template>
477
478 <xsl:template match="dlugi_cytat|poezja_cyt">
479     <blockquote><xsl:apply-templates /></blockquote>
480 </xsl:template>
481
482 <xsl:template match="motto">
483     <div class="motto"><xsl:apply-templates mode="inline" /></div>
484 </xsl:template>
485
486
487 <!-- ========================================== -->
488 <!-- = PARAGRAPH TAGS                         = -->
489 <!-- = (can contain inline and special tags)  = -->
490 <!-- ========================================== -->
491 <!-- Title page -->
492 <xsl:template match="autor_utworu" mode="header">
493     <span class="author"><xsl:apply-templates mode="inline" /></span>
494 </xsl:template>
495
496 <xsl:template match="nazwa_utworu" mode="header">
497     <span class="title"><xsl:apply-templates mode="inline" /></span>
498 </xsl:template>
499
500 <xsl:template match="dzielo_nadrzedne" mode="header">
501     <span class="collection"><xsl:apply-templates mode="inline" /></span>
502 </xsl:template>
503
504 <xsl:template match="podtytul" mode="header">
505     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
506 </xsl:template>
507
508 <!-- Section headers (included in index)-->
509 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
510     <h2><xsl:apply-templates mode="inline" /></h2>
511 </xsl:template>
512
513 <xsl:template match="naglowek_scena|naglowek_rozdzial">
514     <h3><xsl:apply-templates mode="inline" /></h3>
515 </xsl:template>
516
517 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
518     <h4><xsl:apply-templates mode="inline" /></h4>
519 </xsl:template>
520
521 <!-- Other paragraph tags -->
522 <xsl:template match="miejsce_czas">
523     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
524 </xsl:template>
525
526 <xsl:template match="didaskalia">
527     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
528 </xsl:template>
529
530 <xsl:template match="lista_osoba">
531     <li><xsl:apply-templates mode="inline" /></li>
532 </xsl:template>
533
534 <xsl:template match="akap|akap_dialog|akap_cd">
535     <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
536 </xsl:template>
537
538 <xsl:template match="strofa">
539     <div class="stanza">
540         <xsl:choose>
541             <xsl:when test="count(br) > 0">
542                 <xsl:call-template name="verse">
543                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
544                     <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
545                 </xsl:call-template>
546                 <xsl:for-each select="br">              
547                                 <!-- Each BR tag "consumes" text after it -->
548                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
549                     <xsl:call-template name="verse">
550                         <xsl:with-param name="verse-content"
551                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
552                         <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]" />
553                     </xsl:call-template>
554                 </xsl:for-each>
555             </xsl:when>
556             <xsl:otherwise>
557                 <xsl:call-template name="verse">
558                     <xsl:with-param name="verse-content" select="text() | node()" />
559                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
560                  </xsl:call-template>
561             </xsl:otherwise>
562         </xsl:choose>
563     </div>
564 </xsl:template>
565
566 <xsl:template name="verse">
567     <xsl:param name="verse-content" />
568     <xsl:param name="verse-type" />
569     <p class="verse">
570         <xsl:choose>
571             <xsl:when test="name($verse-type) = 'wers_akap'">
572                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
573             </xsl:when>
574             <xsl:when test="name($verse-type) = 'wers_wciety'">
575                 <xsl:choose>
576                     <xsl:when test="$verse-content/@typ">
577                         <xsl:attribute name="style">padding-left: <xsl:value-of select="$verse-content/@typ" />em</xsl:attribute>
578                     </xsl:when>
579                     <xsl:otherwise>
580                         <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
581                     </xsl:otherwise>
582                 </xsl:choose>
583             </xsl:when>
584             <xsl:when test="name($verse-type) = 'wers_cd'">
585                 <xsl:attribute name="style">padding-left: 12em</xsl:attribute>
586             </xsl:when>
587         </xsl:choose>
588         <xsl:apply-templates select="$verse-content" mode="inline" />
589     </p>
590 </xsl:template>
591
592 <xsl:template match="motto_podpis">
593     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
594 </xsl:template>
595
596
597 <!-- ================================================ -->
598 <!-- = INLINE TAGS                                  = -->
599 <!-- = (contain other inline tags and special tags) = -->
600 <!-- ================================================ -->
601 <!-- Annotations -->
602 <xsl:template match="pa|pe|pr|pt" mode="inline">
603     <a name="{concat('anchor-', generate-id(.))}" />
604     <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>
605 </xsl:template>
606
607 <!-- Other inline tags -->
608 <xsl:template match="mat" mode="inline">
609     <em class="math"><xsl:apply-templates mode="inline" /></em>
610 </xsl:template>
611
612 <xsl:template match="didask_tekst" mode="inline">
613     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
614 </xsl:template>
615
616 <xsl:template match="slowo_obce" mode="inline">
617     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
618 </xsl:template>
619
620 <xsl:template match="tytul_dziela" mode="inline">
621     <em class="book-title">
622         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
623     </em>
624 </xsl:template>
625
626 <xsl:template match="wyroznienie" mode="inline">
627     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
628 </xsl:template>
629
630 <xsl:template match="osoba" mode="inline">
631     <em class="person"><xsl:apply-templates mode="inline" /></em>
632 </xsl:template>
633
634
635 <!-- ============================================== -->
636 <!-- = STANDALONE TAGS                            = -->
637 <!-- = (cannot contain any other tags)            = -->
638 <!-- ============================================== -->
639 <xsl:template match="sekcja_swiatlo">
640     <hr class="spacer" />
641 </xsl:template>
642
643 <xsl:template match="sekcja_asterysk">
644     <p class="spacer-asterisk">*</p>
645 </xsl:template>
646
647 <xsl:template match="separator_linia">
648     <hr class="spacer-line" />
649 </xsl:template>
650
651
652 <!-- ================ -->
653 <!-- = SPECIAL TAGS = -->
654 <!-- ================ -->
655 <!-- Themes -->
656 <xsl:template match="begin" mode="inline">
657     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
658     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
659         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
660     </a>
661 </xsl:template>
662
663 <xsl:template match="end" mode="inline">
664     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
665 </xsl:template>
666
667 <xsl:template match="begin|end">
668     <xsl:apply-templates select='.' mode="inline" />
669 </xsl:template>
670
671 <xsl:template match="motyw" mode="inline" />
672
673
674 <xsl:template match="nota_red" mode="special">
675     <div id="nota_red">
676         <xsl:apply-templates />
677     </div>
678 </xsl:template>
679
680
681 <xsl:template name="translators">
682     <xsl:if test="//dc:contributor.translator">
683         <span class="translator">
684             <xsl:text>tłum. </xsl:text>
685             <xsl:for-each select="//dc:contributor.translator">
686                 <xsl:if test="position() != 1">, </xsl:if>
687                 <xsl:apply-templates mode="person" />
688             </xsl:for-each>
689         </span>
690     </xsl:if>
691 </xsl:template>
692
693 <xsl:template match="text()" mode="person">
694     <xsl:value-of select="wl:person_name(.)" />
695 </xsl:template>
696
697
698 <!-- ================ -->
699 <!-- = IGNORED TAGS = -->
700 <!-- ================ -->
701 <xsl:template match="extra|uwaga" />
702 <xsl:template match="extra|uwaga" mode="inline" />
703
704 <xsl:template match="nota_red" />
705
706 <!-- ======== -->
707 <!-- = TEXT = -->
708 <!-- ======== -->
709 <xsl:template match="text()" />
710 <xsl:template match="text()" mode="inline">
711     <xsl:value-of select="wl:substitute_entities(.)" />
712 </xsl:template>
713
714
715 </xsl:stylesheet>