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