Added new version of Moralność pani Dulskiej to books.
[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: 14px;
16                 font: Georgia, "Times New Roman", serif;
17                 line-height: 1.5em;
18                 margin: 3em;
19                 max-width: 36em;
20             }
21
22             a {
23                 color: blue;
24                 text-decoration: none;
25             }
26
27             /* =================================================== */
28             /* = Common elements: headings, paragraphs and lines = */
29             /* =================================================== */
30             h1 {
31                 font-size: 3em;
32                 margin: 1.5em 0;
33                 text-align: center;
34                 line-height: 1.5em;
35                 font-weight: bold;
36             }
37
38             h2 {
39                 font-size: 2em;
40                 margin: 1.5em 0 0;
41                 font-weight: bold;
42                 line-height: 1.5em;
43             }
44
45             h3 {
46                 font-size: 1.5em;
47                 margin: 1.5em 0 0;
48                 font-weight: normal;
49                 line-height: 1.5em;
50             }
51
52             h4 {
53                 font-size: 1em;
54                 margin: 1.5em 0 0;
55                 line-height: 1.5em;
56             }
57
58             p {
59                 margin: 0;
60             }
61
62             /* ======================== */
63             /* = Footnotes and themes = */
64             /* ======================== */
65             .theme-begin {
66                 border-left: 0.1em solid #DDDDDD;
67                 color: #777;
68                 padding: 0 0.5em;
69                 width: 7.5em;
70                 font-style: normal;
71                 font-weight: normal;
72                 font-size: 16px;
73                 float: right;
74                 margin-right: -9.5em;
75                 clear: both;
76                 left: 40em;
77                 line-height: 1.5em;
78                 text-align: left;
79             }
80
81             .annotation {
82                 font-style: normal;
83                 font-weight: normal;
84                 font-size: 12px;
85             }
86
87             #footnotes .annotation {
88                 display: block;
89                 float: left;
90                 width: 2.5em;
91                 clear: both;
92             }
93
94             #footnotes div {
95                 margin: 1.5em 0 0 0;
96             }
97
98             #footnotes p {
99                 margin-left: 2.5em;
100                 font-size: 0.875em;
101             }
102
103             blockquote {
104                 font-size: 0.875em;
105             }
106
107             /* =================== */
108             /* = Custom elements = */
109             /* =================== */
110             span.author {
111                 font-size: 0.5em;
112                 display: block;
113                 line-height: 1.5em;
114                 margin-bottom: 0.25em;
115             }
116
117             span.collection {
118                 font-size: 0.375em;
119                 display: block;
120                 line-height: 1.5em;
121                 margin-bottom: -0.25em;
122             }
123
124             span.subtitle {
125                 font-size: 0.5em;
126                 display: block;
127                 line-height: 1.5em;
128                 margin-top: -0.25em;
129             }
130
131             div.didaskalia {
132                 font-style: italic;
133                 margin: 0.5em 0 0;
134             }
135
136             div.kwestia {
137                 margin: 0.5em 0 0;
138             }
139
140             div.stanza {
141                 margin: 1.5em 0 0;
142             }
143
144             div.kwestia div.stanza {
145                 margin: 0;
146             }
147
148             p.paragraph {
149                 text-align: justify;
150                 margin: 1.5em 0 0;
151             }
152
153             p.motto {
154                 text-align: justify;
155                 font-style: italic;
156                 margin: 1.5em 0 0;
157             }
158
159             p.motto_podpis {
160                 font-size: 0.875em;
161             }
162
163             div.fragment {
164                 border-bottom: 0.1em solid #999;
165                 padding-bottom: 1.5em;
166             }
167
168             div.note p, div.note p.paragraph {
169                 text-align: right;
170                 font-style: italic;
171             }
172
173             hr.spacer {
174                 height: 3em;
175                 visibility: hidden;
176             }
177
178             .anchor {
179                 position: absolute;
180                 margin: -0.25em -0.5em;
181                 left: 1em;
182                 color: #777;
183                 font-size: 12px;
184                 width: 2em;
185                 text-align: center;
186                 padding: 0.25em 0.5em;
187                 line-height: 1.5em;
188             }
189
190             .anchor:hover, #book-text .anchor:active {
191                 color: #FFF;
192                 background-color: #CCC;
193             }
194             
195             #toc {
196                 display: none;
197             }
198         </style>
199         <body>
200         <div id="book-text">
201             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
202             <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)])">
203                 <div id="footnotes">
204                     <h3>Przypisy</h3>
205                     <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)]">
206                         <div>
207                             <a name="{concat('footnote-', generate-id(.))}" />
208                             <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>
209                             <xsl:choose>
210                                 <xsl:when test="count(akap|akap_cd|strofa) = 0">
211                                     <p><xsl:apply-templates select="text()|*" mode="inline" /></p>
212                                 </xsl:when>
213                                 <xsl:otherwise>
214                                     <xsl:apply-templates select="text()|*" mode="inline" />
215                                 </xsl:otherwise>
216                             </xsl:choose>
217                         </div>
218                     </xsl:for-each>
219                 </div>
220             </xsl:if>
221         </div>
222         </body>
223     </html>
224 </xsl:template>
225
226
227 <!-- ============================================================================== -->
228 <!-- = MASTER TAG                                                                 = -->
229 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
230 <!-- ============================================================================== -->
231 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
232     <xsl:if test="nazwa_utworu">
233         <h1>
234             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
235         </h1>
236     </xsl:if>
237     <xsl:apply-templates />
238 </xsl:template>
239
240
241 <!-- ==================================================================================== -->
242 <!-- = BLOCK TAGS                                                                       = -->
243 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
244 <!-- ==================================================================================== -->
245 <xsl:template match="nota">
246     <div class="note"><xsl:apply-templates /></div>
247 </xsl:template>
248
249 <xsl:template match="lista_osob">
250     <div class="person-list">
251         <h3><xsl:value-of select="naglowek_listy" /></h3>
252         <ol>
253             <xsl:apply-templates select="lista_osoba" />
254         </ol>
255     </div>
256 </xsl:template>
257
258 <xsl:template match="dedykacja">
259     <div class="dedication"><xsl:apply-templates /></div>
260 </xsl:template>
261
262 <xsl:template match="kwestia">
263     <div class="kwestia">
264         <xsl:apply-templates select="strofa|akap|didaskalia" />
265     </div>
266 </xsl:template>
267
268 <xsl:template match="dlugi_cytat|poezja_cyt">
269     <blockquote><xsl:apply-templates /></blockquote>
270 </xsl:template>
271
272 <xsl:template match="motto">
273     <div class="motto"><xsl:apply-templates mode="inline" /></div>
274 </xsl:template>
275
276
277 <!-- ========================================== -->
278 <!-- = PARAGRAPH TAGS                         = -->
279 <!-- = (can contain inline and special tags)  = -->
280 <!-- ========================================== -->
281 <!-- Title page -->
282 <xsl:template match="autor_utworu" mode="header">
283     <span class="author"><xsl:apply-templates mode="inline" /></span>
284 </xsl:template>
285
286 <xsl:template match="nazwa_utworu" mode="header">
287     <span class="title"><xsl:apply-templates mode="inline" /></span>
288 </xsl:template>
289
290 <xsl:template match="dzielo_nadrzedne" mode="header">
291     <span class="collection"><xsl:apply-templates mode="inline" /></span>
292 </xsl:template>
293
294 <xsl:template match="podtytul" mode="header">
295     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
296 </xsl:template>
297
298 <!-- Section headers (included in index)-->
299 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
300     <h2><xsl:apply-templates mode="inline" /></h2>
301 </xsl:template>
302
303 <xsl:template match="naglowek_scena|naglowek_rozdzial">
304     <h3><xsl:apply-templates mode="inline" /></h3>
305 </xsl:template>
306
307 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
308     <h4><xsl:apply-templates mode="inline" /></h4>
309 </xsl:template>
310
311 <!-- Other paragraph tags -->
312 <xsl:template match="miejsce_czas">
313     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
314 </xsl:template>
315
316 <xsl:template match="didaskalia">
317     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
318 </xsl:template>
319
320 <xsl:template match="lista_osoba">
321     <li><xsl:apply-templates mode="inline" /></li>
322 </xsl:template>
323
324 <xsl:template match="akap|akap_dialog|akap_cd">
325     <p class="paragraph"><xsl:apply-templates mode="inline" /></p>
326 </xsl:template>
327
328 <xsl:template match="strofa">
329     <div class="stanza">
330         <xsl:choose>
331             <xsl:when test="count(br) > 0">     
332                 <xsl:call-template name="verse">
333                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
334                     <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
335                 </xsl:call-template>    
336                 <xsl:for-each select="br">              
337                                 <!-- Each BR tag "consumes" text after it -->
338                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
339                     <xsl:call-template name="verse">
340                         <xsl:with-param name="verse-content" 
341                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
342                         <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]" />
343                     </xsl:call-template>
344                 </xsl:for-each>
345             </xsl:when>
346             <xsl:otherwise>
347                 <xsl:call-template name="verse">
348                     <xsl:with-param name="verse-content" select="text() | node()" />
349                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
350                  </xsl:call-template>           
351             </xsl:otherwise>
352         </xsl:choose>
353     </div>
354 </xsl:template>
355
356 <xsl:template name="verse">
357     <xsl:param name="verse-content" />
358     <xsl:param name="verse-type" />
359     <p class="verse">
360         <xsl:choose>
361             <xsl:when test="name($verse-type) = 'wers_akap'">
362                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
363             </xsl:when>
364             <xsl:when test="name($verse-type) = 'wers_wciety'">
365                 <xsl:choose>
366                     <xsl:when test="$verse-content/@typ">
367                         <xsl:attribute name="style">padding-left: <xsl:value-of select="$verse-content/@typ" />em</xsl:attribute>
368                     </xsl:when>
369                     <xsl:otherwise>
370                         <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
371                     </xsl:otherwise>
372                 </xsl:choose>
373             </xsl:when>
374             <xsl:when test="name($verse-type) = 'wers_cd'">
375                 <xsl:attribute name="style">padding-left: 12em</xsl:attribute>
376             </xsl:when>
377         </xsl:choose>
378         <xsl:apply-templates select="$verse-content" mode="inline" />
379     </p>
380 </xsl:template>
381
382 <xsl:template match="motto_podpis">
383     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
384 </xsl:template>
385
386
387 <!-- ================================================ -->
388 <!-- = INLINE TAGS                                  = -->
389 <!-- = (contain other inline tags and special tags) = -->
390 <!-- ================================================ -->
391 <!-- Annotations -->
392 <xsl:template match="pa|pe|pr|pt" mode="inline">
393     <a name="{concat('anchor-', generate-id(.))}" />
394     <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>
395 </xsl:template>
396
397 <!-- Other inline tags -->
398 <xsl:template match="mat" mode="inline">
399     <em class="math"><xsl:apply-templates mode="inline" /></em>
400 </xsl:template>
401
402 <xsl:template match="didask_tekst" mode="inline">
403     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
404 </xsl:template>
405
406 <xsl:template match="slowo_obce" mode="inline">
407     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
408 </xsl:template>
409
410 <xsl:template match="tytul_dziela" mode="inline">
411     <em class="book-title">
412         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
413     </em>
414 </xsl:template>
415
416 <xsl:template match="wyroznienie" mode="inline">
417     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
418 </xsl:template>
419
420 <xsl:template match="osoba" mode="inline">
421     <em class="person"><xsl:apply-templates mode="inline" /></em>
422 </xsl:template>
423
424
425 <!-- ============================================== -->
426 <!-- = STANDALONE TAGS                            = -->
427 <!-- = (cannot contain any other tags)            = -->
428 <!-- ============================================== -->
429 <xsl:template match="sekcja_swiatlo">
430     <hr class="spacer" />
431 </xsl:template>
432
433 <xsl:template match="sekcja_asterysk">
434     <p class="spacer-asterisk">*</p>
435 </xsl:template>
436
437 <xsl:template match="separator_linia">
438     <hr class="spacer-line" />
439 </xsl:template>
440
441
442 <!-- ================ -->
443 <!-- = SPECIAL TAGS = -->
444 <!-- ================ -->
445 <!-- Themes -->
446 <xsl:template match="begin" mode="inline">
447     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
448     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
449         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
450     </a>
451 </xsl:template>
452
453 <xsl:template match="end" mode="inline">
454     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
455 </xsl:template>
456
457 <xsl:template match="begin|end">
458     <xsl:apply-templates select='.' mode="inline" />
459 </xsl:template>
460
461 <xsl:template match="motyw" mode="inline" />
462
463
464 <!-- ================ -->
465 <!-- = IGNORED TAGS = -->
466 <!-- ================ -->
467 <xsl:template match="extra|uwaga" />
468 <xsl:template match="extra|uwaga" mode="inline" />
469
470
471 <!-- ======== -->
472 <!-- = TEXT = -->
473 <!-- ======== -->
474 <xsl:template match="text()" />
475 <xsl:template match="text()" mode="inline">
476     <xsl:value-of select="wl:substitute_entities(.)" />
477 </xsl:template>
478
479
480 </xsl:stylesheet>
481