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