Response images.
[librarian.git] / src / 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:strip-space  elements="opowiadanie powiesc dramat_wierszowany_l dramat_wierszowany_lp dramat_wspolczesny liryka_l liryka_lp wywiad"/>
14 <xsl:template match="utwor">
15     <xsl:choose>
16         <xsl:when test="@full-page">
17             <html>
18             <head>
19                 <title>Książka z serwisu WolneLektury.pl</title>
20                 <meta charset="utf-8" />
21                 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
22                 <link rel="stylesheet" type="text/css">
23                         <xsl:attribute name="href">
24                                 <xsl:value-of select="$css" />
25                         </xsl:attribute>
26                 </link>
27             </head>
28             <body>
29               <xsl:call-template name="book-text" />
30
31               <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
32               <script src="http://malsup.github.io/min/jquery.cycle2.min.js"></script>
33             </body>
34             </html>
35         </xsl:when>
36         <xsl:otherwise>
37             <xsl:call-template name="book-text" />
38         </xsl:otherwise>
39     </xsl:choose>
40 </xsl:template>
41
42 <xsl:template name="book-text">
43     <div id="book-text">
44         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
45         <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)])">
46             <div id="footnotes">
47                 <h3>Przypisy</h3>
48                 <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)]">
49                     <div>
50                         <xsl:attribute name="class">fn-<xsl:value-of select="name()" /></xsl:attribute>
51                         <a name="{concat('footnote-', generate-id(.))}" />
52                         <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>
53                         <xsl:choose>
54                             <xsl:when test="count(akap|akap_cd|strofa) = 0">
55                                 <p><xsl:apply-templates select="text()|*" mode="inline" />
56                                 <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
57                                 <xsl:if test="name()='pt'"> [przypis tłumacza]</xsl:if>
58                                 <xsl:if test="name()='pr'"> [przypis redakcyjny]</xsl:if>
59                                 <xsl:if test="name()='pe'"> [przypis edytorski]</xsl:if>
60                                 </p>
61                             </xsl:when>
62                             <xsl:otherwise>
63                                 <xsl:apply-templates select="text()|*" mode="inline" />
64                             </xsl:otherwise>
65                         </xsl:choose>
66                     </div>
67                 </xsl:for-each>
68             </div>
69         </xsl:if>
70     </div>
71 </xsl:template>
72
73
74 <!-- ============================================================================== -->
75 <!-- = MASTER TAG                                                                 = -->
76 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
77 <!-- ============================================================================== -->
78 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
79     <xsl:apply-templates select="nota_red" mode="special" />
80     <xsl:if test="nazwa_utworu">
81         <h1>
82             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
83             <xsl:call-template name="translators" />
84         </h1>
85     </xsl:if>
86     <xsl:apply-templates />
87 </xsl:template>
88
89
90 <!-- ==================================================================================== -->
91 <!-- = BLOCK TAGS                                                                       = -->
92 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
93 <!-- ==================================================================================== -->
94 <xsl:template match="nota">
95     <div class="note"><xsl:apply-templates /></div>
96 </xsl:template>
97
98 <xsl:template match="lista_osob">
99     <xsl:call-template name="section-anchor"/>
100     <div class="person-list">
101         <h3><xsl:value-of select="naglowek_listy" /></h3>
102         <ol>
103             <xsl:apply-templates select="lista_osoba" />
104         </ol>
105     </div>
106 </xsl:template>
107
108 <xsl:template match="dedykacja">
109     <div class="dedication"><xsl:apply-templates /></div>
110 </xsl:template>
111
112 <xsl:template match="ramka">
113     <div class="frame"><xsl:apply-templates /></div>
114 </xsl:template>
115
116 <xsl:template match="kwestia">
117     <div class="kwestia">
118         <xsl:apply-templates select="strofa|akap|didaskalia" />
119     </div>
120 </xsl:template>
121
122 <xsl:template match="dlugi_cytat|poezja_cyt">
123     <blockquote><xsl:apply-templates /></blockquote>
124 </xsl:template>
125
126 <xsl:template match="motto">
127     <xsl:call-template name="section-anchor"/>
128     <div class="motto"><xsl:apply-templates /></div>
129 </xsl:template>
130
131 <xsl:template match="ilustr" mode="inline">
132     <xsl:apply-templates select="."/>
133 </xsl:template>
134
135 <xsl:template match="ilustr">
136     <img>
137         <xsl:attribute name="src">
138             <xsl:value-of select="@src" />
139         </xsl:attribute>
140         <xsl:attribute name="srcset">
141           <xsl:value-of select="@srcset" />
142         </xsl:attribute>
143         <xsl:attribute name="sizes">
144           (min-width: 718px) 600px,
145           (min-width: 600px) calc(100vw - 118px),
146           (min-width: 320px) calc(100vw - 75px),
147           (min-width: 15em) calc(100wv - 60px),
148           calc(100wv - 40px)
149         </xsl:attribute>
150         <xsl:attribute name="alt">
151             <xsl:value-of select="@alt" />
152         </xsl:attribute>
153         <xsl:attribute name="title">
154             <xsl:value-of select="@alt" />
155         </xsl:attribute>
156     </img>
157 </xsl:template>
158
159 <xsl:template match="animacja">
160   <div class="animacja cycle-slideshow" data-cycle-pause-on-hover="true" data-cycle-next="> img" data-cycle-fx="fadeout" data-cycle-paused="true">
161     <xsl:apply-templates/>
162   </div>
163 </xsl:template>
164
165
166 <!-- ========================================== -->
167 <!-- = PARAGRAPH TAGS                         = -->
168 <!-- = (can contain inline and special tags)  = -->
169 <!-- ========================================== -->
170 <!-- Title page -->
171 <xsl:template match="autor_utworu" mode="header">
172     <span class="author"><xsl:apply-templates mode="inline" /></span>
173 </xsl:template>
174
175 <xsl:template match="nazwa_utworu" mode="header">
176     <span class="title"><xsl:apply-templates mode="inline" /></span>
177 </xsl:template>
178
179 <xsl:template match="dzielo_nadrzedne" mode="header">
180     <span class="collection"><xsl:apply-templates mode="inline" /></span>
181 </xsl:template>
182
183 <xsl:template match="podtytul" mode="header">
184     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
185 </xsl:template>
186
187 <!-- Section headers (included in index)-->
188 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
189   <xsl:call-template name="section-anchor"/>
190     <h2><xsl:apply-templates mode="inline" /></h2>
191 </xsl:template>
192
193 <xsl:template match="podtytul_akt|podtytul_czesc">
194   <div class="subtitle2">
195     <xsl:apply-templates mode="inline" />
196   </div>
197 </xsl:template>
198
199 <xsl:template match="naglowek_scena|naglowek_rozdzial">
200     <xsl:call-template name="section-anchor"/>
201     <h3><xsl:apply-templates mode="inline" /></h3>
202 </xsl:template>
203
204 <xsl:template match="podtytul_scena|podtytul_rozdzial">
205   <div class="subtitle3">
206     <xsl:apply-templates mode="inline" />
207   </div>
208 </xsl:template>
209
210 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
211       <xsl:call-template name="section-anchor"/>
212     <h4><xsl:apply-templates mode="inline" /></h4>
213 </xsl:template>
214
215 <xsl:template match="podtytul_podrozdzial">
216   <div class="subtitle4">
217     <xsl:apply-templates mode="inline" />
218   </div>
219 </xsl:template>
220
221 <!-- Other paragraph tags -->
222 <xsl:template match="miejsce_czas">
223       <xsl:call-template name="section-anchor"/>
224     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
225 </xsl:template>
226
227 <xsl:template match="didaskalia">
228       <xsl:call-template name="section-anchor"/>
229     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
230 </xsl:template>
231
232 <xsl:template match="lista_osoba">
233     <li><xsl:apply-templates mode="inline" /></li>
234 </xsl:template>
235
236 <xsl:template match="akap|akap_dialog|akap_cd">
237     <p class="paragraph">
238       <xsl:call-template name="section-anchor"/>
239         <xsl:apply-templates mode="inline" />
240     </p>
241 </xsl:template>
242
243 <xsl:template match="strofa" mode="inline">
244     <xsl:apply-templates select="." />
245 </xsl:template>
246
247 <xsl:template match="strofa">
248     <div class="stanza">
249       <xsl:call-template name="section-anchor"/>
250         <xsl:choose>
251             <xsl:when test="count(br) > 0">
252                 <xsl:call-template name="verse">
253                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
254                     <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd' or name() = 'wers_do_prawej'][1]" />
255                 </xsl:call-template>
256                 <xsl:for-each select="br">              
257                                 <!-- Each BR tag "consumes" text after it -->
258                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
259                     <xsl:call-template name="verse">
260                         <xsl:with-param name="verse-content"
261                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
262                         <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' or name() = 'wers_do_prawej')][1]" />
263                     </xsl:call-template>
264                 </xsl:for-each>
265             </xsl:when>
266             <xsl:otherwise>
267                 <xsl:call-template name="verse">
268                     <xsl:with-param name="verse-content" select="text() | node()" />
269                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej[1]" />
270                  </xsl:call-template>
271             </xsl:otherwise>
272         </xsl:choose>
273     </div>
274 </xsl:template>
275
276 <xsl:template name="verse">
277     <xsl:param name="verse-content" />
278     <xsl:param name="verse-type" />
279     <div class="verse">
280         <xsl:choose>
281             <xsl:when test="name($verse-type) = 'wers_akap'">
282                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
283             </xsl:when>
284             <xsl:when test="name($verse-type) = 'wers_wciety'">
285                 <xsl:choose>
286                     <xsl:when test="$verse-content/@typ">
287                         <xsl:attribute name="style">padding-left: <xsl:value-of select="$verse-content/@typ" />em</xsl:attribute>
288                     </xsl:when>
289                     <xsl:otherwise>
290                         <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
291                     </xsl:otherwise>
292                 </xsl:choose>
293             </xsl:when>
294             <xsl:when test="name($verse-type) = 'wers_cd'">
295                 <xsl:attribute name="style">padding-left: 12em</xsl:attribute>
296             </xsl:when>
297             <xsl:when test="name($verse-type) = 'wers_do_prawej'">
298                 <xsl:attribute name="style">text-align: right</xsl:attribute>
299             </xsl:when>
300         </xsl:choose>
301         <xsl:apply-templates select="$verse-content" mode="inline" />
302     </div>
303 </xsl:template>
304
305 <xsl:template match="motto_podpis">
306     <xsl:call-template name="section-anchor"/>
307     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
308 </xsl:template>
309
310 <xsl:template match="tabela|tabelka">
311     <xsl:call-template name="section-anchor"/>
312     <xsl:choose>
313         <xsl:when test="@ramka = '1'">
314             <table class="border"><xsl:apply-templates /></table>
315         </xsl:when>
316         <xsl:otherwise>
317             <table><xsl:apply-templates /></table>
318         </xsl:otherwise>
319     </xsl:choose>
320 </xsl:template>
321 <xsl:template match="wiersz">
322     <tr><xsl:apply-templates /></tr>
323 </xsl:template>
324 <xsl:template match="kol">
325     <td><xsl:apply-templates mode="inline" /></td>
326 </xsl:template>
327
328 <xsl:template match="mat">
329     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
330 </xsl:template>
331
332
333 <!-- ================================================ -->
334 <!-- = INLINE TAGS                                  = -->
335 <!-- = (contain other inline tags and special tags) = -->
336 <!-- ================================================ -->
337 <!-- Annotations -->
338 <xsl:template match="pa|pe|pr|pt" mode="inline">
339     <a name="{concat('anchor-', generate-id(.))}" />
340     <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>
341 </xsl:template>
342
343 <xsl:template match="ref" mode="inline">
344   <a class="reference" data-uri="">
345     <xsl:attribute name="data-uri">
346       <xsl:value-of select="@href"/>
347     </xsl:attribute>
348   </a>
349 </xsl:template>
350
351 <!-- Other inline tags -->
352 <xsl:template match="mat" mode="inline">
353     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
354 </xsl:template>
355
356 <xsl:template match="didask_tekst" mode="inline">
357     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
358 </xsl:template>
359
360 <xsl:template match="slowo_obce" mode="inline">
361     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
362 </xsl:template>
363
364 <xsl:template match="tytul_dziela" mode="inline">
365     <em class="book-title">
366         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
367     </em>
368 </xsl:template>
369
370 <xsl:template match="wyroznienie" mode="inline">
371     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
372 </xsl:template>
373
374 <xsl:template match="wieksze_odstepy" mode="inline">
375     <em class="wieksze-odstepy"><xsl:apply-templates mode="inline" /></em>
376 </xsl:template>
377
378 <xsl:template match="indeks_dolny" mode="inline">
379     <sub><xsl:apply-templates mode="inline" /></sub>
380 </xsl:template>
381
382 <xsl:template match="osoba" mode="inline">
383     <em class="person"><xsl:apply-templates mode="inline" /></em>
384 </xsl:template>
385
386
387 <!-- ============================================== -->
388 <!-- = STANDALONE TAGS                            = -->
389 <!-- = (cannot contain any other tags)            = -->
390 <!-- ============================================== -->
391 <xsl:template match="sekcja_swiatlo">
392     <hr class="spacer" />
393 </xsl:template>
394
395 <xsl:template match="sekcja_asterysk">
396     <p class="spacer-asterisk">*</p>
397 </xsl:template>
398
399 <xsl:template match="separator_linia">
400     <hr class="spacer-line" />
401 </xsl:template>
402
403
404 <!-- ================ -->
405 <!-- = SPECIAL TAGS = -->
406 <!-- ================ -->
407 <!-- Themes -->
408 <xsl:template match="begin" mode="inline">
409     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
410     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
411         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
412     </a>
413 </xsl:template>
414
415 <xsl:template match="end" mode="inline">
416     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
417 </xsl:template>
418
419 <xsl:template match="begin|end">
420     <xsl:apply-templates select='.' mode="inline" />
421 </xsl:template>
422
423 <xsl:template match="motyw" mode="inline" />
424
425
426 <xsl:template match="nota_red" mode="special">
427     <div id="nota_red">
428         <xsl:apply-templates />
429     </div>
430 </xsl:template>
431
432
433 <xsl:template name="translators">
434     <xsl:if test="//dc:contributor.translator">
435         <span class="translator">
436             <xsl:text>tłum. </xsl:text>
437             <xsl:for-each select="//dc:contributor.translator">
438                 <xsl:if test="position() != 1">, </xsl:if>
439                 <xsl:apply-templates mode="person" />
440             </xsl:for-each>
441         </span>
442     </xsl:if>
443 </xsl:template>
444
445 <xsl:template match="text()" mode="person">
446     <xsl:value-of select="wl:person_name(.)" />
447 </xsl:template>
448
449
450 <!-- ================ -->
451 <!-- = IGNORED TAGS = -->
452 <!-- ================ -->
453 <xsl:template match="extra|uwaga" />
454 <xsl:template match="extra|uwaga" mode="inline" />
455
456 <xsl:template match="nota_red" />
457 <xsl:template match="abstrakt" />
458
459 <!-- ======== -->
460 <!-- = TEXT = -->
461 <!-- ======== -->
462 <xsl:template match="text()" />
463 <xsl:template match="text()" mode="inline">
464     <xsl:value-of select="wl:substitute_entities(.)" />
465 </xsl:template>
466
467 <!-- ========= -->
468 <!-- = utils = -->
469 <!-- ========= -->
470 <xsl:template name="section-anchor">
471   <!-- 
472        this formula works as follows:
473        - get all ancestors including self
474        - choose the header (third one from root): utwor/book-type/header
475        - get all preceding siblings
476        - count them
477        - create an <a name="sec123"/> tag.
478   -->
479         <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
480 </xsl:template>
481
482 </xsl:stylesheet>