br
[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 Wolne Lektury. 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                 <style>
28                   .ilustr.prawo img {
29                   float: right;
30                   }
31                   .ilustr.lewo img {
32                   float: left;
33                   }
34                   .ilustr.srodek {
35                   text-align: center;
36                   }
37                   .ilustr .stop {
38                   clear: both;
39                   }
40                   .ilustr.oblew .stop {
41                   clear: none;
42                   }
43
44                   .ilustr.oblew img {
45                     margin-bottom: 1em;
46                   }
47                   .ilustr.oblew.lewo img {
48                     margin-right: 2em;
49                     }
50                     .ilustr.oblew.prawo img {
51                     margin-left: 2em;
52                     }
53
54
55                     .ilustr img {
56                     min-width: 200px !important;
57                     }
58                     @media screen and (max-width: 320px) {
59                     .ilustr img {
60                     width: 100% !important;
61                     min-width: auto !important;
62                     }
63                     .ilustr.lewo img {
64                     float: none;
65                     }
66                     .ilustr.prawo img {
67                     float:none;
68                     }
69                     .ilustr.oblew.prawo img {
70                     margin-left: 0;
71                     }
72                     .ilustr.oblew.lewo img{
73                     margin-right: 0;
74                     }
75                     .ilustr .stop {
76                     clear: none;
77                     }
78
79                     }
80                 </style>
81             </head>
82             <body>
83               <xsl:call-template name="book-text" />
84
85               <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
86               <script src="http://malsup.github.io/min/jquery.cycle2.min.js"></script>
87             </body>
88             </html>
89         </xsl:when>
90         <xsl:otherwise>
91             <xsl:call-template name="book-text" />
92         </xsl:otherwise>
93     </xsl:choose>
94 </xsl:template>
95
96 <xsl:template name="book-text">
97     <div id="book-text">
98       <xsl:attribute name="lang">
99         <xsl:value-of select="@lang" />
100       </xsl:attribute>
101         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
102         <xsl:if test="not(@nonotes) and count(descendant::*[self::pe or self::pa or self::pr or self::pt or self::ptrad][not(parent::extra)])">
103             <div id="footnotes">
104                 <h3>Przypisy</h3>
105                 <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt or self::ptrad][not(parent::extra)]">
106                     <div>
107                         <xsl:attribute name="class">fn-<xsl:value-of select="name()" /></xsl:attribute>
108                         <a name="{concat('footnote-', generate-id(.))}" />
109                         <a href="{concat('#anchor-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt or self::ptrad]) + 1" />]</a>
110                         <xsl:choose>
111                             <xsl:when test="count(akap|akap_cd|strofa) = 0">
112                                 <p><xsl:apply-templates select="text()|*" mode="inline" />
113                                 <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
114                                 <xsl:if test="name()='pt'"> [przypis tłumacza]</xsl:if>
115                                 <xsl:if test="name()='pr'"> [przypis redakcyjny]</xsl:if>
116                                 <xsl:if test="name()='pe'"> [przypis edytorski]</xsl:if>
117                                 <xsl:if test="name()='ptrad'"> [przypis tradycyjny]</xsl:if>
118                                 </p>
119                             </xsl:when>
120                             <xsl:otherwise>
121                               <xsl:apply-templates />
122                               <p>
123                                 <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
124                                 <xsl:if test="name()='pt'"> [przypis tłumacza]</xsl:if>
125                                 <xsl:if test="name()='pr'"> [przypis redakcyjny]</xsl:if>
126                                 <xsl:if test="name()='pe'"> [przypis edytorski]</xsl:if>
127                                 <xsl:if test="name()='ptrad'"> [przypis tradycyjny]</xsl:if>
128                               </p>
129                             </xsl:otherwise>
130                         </xsl:choose>
131                     </div>
132                 </xsl:for-each>
133             </div>
134         </xsl:if>
135     </div>
136 </xsl:template>
137
138
139 <!-- ============================================================================== -->
140 <!-- = MASTER TAG                                                                 = -->
141 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
142 <!-- ============================================================================== -->
143 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
144     <xsl:apply-templates select="nota_red" mode="special" />
145     <xsl:if test="nazwa_utworu">
146         <h1>
147             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
148             <xsl:call-template name="translators" />
149         </h1>
150     </xsl:if>
151     <xsl:apply-templates />
152 </xsl:template>
153
154
155 <!-- ==================================================================================== -->
156 <!-- = BLOCK TAGS                                                                       = -->
157 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
158 <!-- ==================================================================================== -->
159 <xsl:template match="nota">
160     <div class="note"><xsl:apply-templates /></div>
161 </xsl:template>
162
163 <xsl:template match="lista_osob">
164     <xsl:call-template name="section-anchor"/>
165     <div class="person-list">
166         <h3><xsl:value-of select="naglowek_listy" /></h3>
167         <ol>
168             <xsl:apply-templates select="lista_osoba" />
169         </ol>
170     </div>
171 </xsl:template>
172
173 <xsl:template match="dedykacja">
174     <div class="dedication"><xsl:apply-templates /></div>
175 </xsl:template>
176
177 <xsl:template match="ramka">
178     <div class="frame"><xsl:apply-templates /></div>
179 </xsl:template>
180
181 <xsl:template match="kwestia">
182     <div class="kwestia">
183         <xsl:apply-templates select="strofa|akap|didaskalia" />
184     </div>
185 </xsl:template>
186
187 <xsl:template match="dlugi_cytat|poezja_cyt">
188     <blockquote><xsl:apply-templates /></blockquote>
189 </xsl:template>
190
191 <xsl:template match="motto">
192     <xsl:call-template name="section-anchor"/>
193     <div class="motto">
194       <xsl:call-template name="block-args" />
195       <xsl:apply-templates />
196     </div>
197 </xsl:template>
198
199 <xsl:template match="ilustr" mode="inline">
200     <xsl:apply-templates select="."/>
201 </xsl:template>
202
203 <xsl:template match="ilustr">
204   <div>
205     <xsl:call-template name="block-args" />
206
207     <xsl:attribute name="class">
208       <xsl:text>ilustr </xsl:text>
209       <xsl:value-of select="@wyrownanie"/>
210       <xsl:if test="@oblew">
211         <xsl:text> oblew</xsl:text>
212       </xsl:if>
213     </xsl:attribute>
214     
215     <img>
216       <xsl:attribute name="src">
217         <xsl:value-of select="@src" />
218       </xsl:attribute>
219       <xsl:attribute name="srcset">
220         <xsl:value-of select="@srcset" />
221       </xsl:attribute>
222       <xsl:attribute name="sizes">
223         (min-width: 718px) 600px,
224         (min-width: 600px) calc(100vw - 118px),
225         (min-width: 320px) calc(100vw - 75px),
226         (min-width: 15em) calc(100wv - 60px),
227         calc(100wv - 40px)
228       </xsl:attribute>
229       <xsl:attribute name="alt">
230         <xsl:value-of select="@alt" />
231       </xsl:attribute>
232       <xsl:attribute name="title">
233         <xsl:value-of select="@alt" />
234       </xsl:attribute>
235
236       <xsl:if test="@szer">
237         <xsl:attribute name="style">
238           <xsl:text>width: </xsl:text>
239           <xsl:value-of select="@szer"/>
240         </xsl:attribute>
241       </xsl:if>
242     </img>
243
244     <div class="stop"></div>
245   </div>
246 </xsl:template>
247
248 <xsl:template match="animacja">
249   <div class="animacja cycle-slideshow" data-cycle-pause-on-hover="true" data-cycle-next="> img" data-cycle-fx="fadeout" data-cycle-paused="true">
250     <xsl:call-template name="block-args" />
251     <xsl:apply-templates/>
252   </div>
253 </xsl:template>
254
255
256 <!-- ========================================== -->
257 <!-- = PARAGRAPH TAGS                         = -->
258 <!-- = (can contain inline and special tags)  = -->
259 <!-- ========================================== -->
260 <!-- Title page -->
261 <xsl:template match="autor_utworu" mode="header">
262   <span class="author">
263     <xsl:call-template name="block-args" />
264     <xsl:apply-templates mode="inline" />
265   </span>
266 </xsl:template>
267
268 <xsl:template match="nazwa_utworu" mode="header">
269   <span class="title">
270     <xsl:call-template name="block-args" />
271     <xsl:apply-templates mode="inline" />
272   </span>
273 </xsl:template>
274
275 <xsl:template match="dzielo_nadrzedne" mode="header">
276   <span class="collection">
277     <xsl:call-template name="block-args" />
278     <xsl:apply-templates mode="inline" />
279   </span>
280 </xsl:template>
281
282 <xsl:template match="podtytul" mode="header">
283   <span class="subtitle">
284     <xsl:call-template name="block-args" />
285     <xsl:apply-templates mode="inline" />
286   </span>
287 </xsl:template>
288
289 <!-- Section headers (included in index)-->
290 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
291   <xsl:call-template name="section-anchor"/>
292   <h2>
293     <xsl:call-template name="block-args" />
294     <xsl:apply-templates mode="inline" />
295   </h2>
296 </xsl:template>
297
298 <xsl:template match="podtytul_akt|podtytul_czesc">
299   <div class="subtitle2">
300     <xsl:call-template name="block-args" />
301     <xsl:apply-templates mode="inline" />
302   </div>
303 </xsl:template>
304
305 <xsl:template match="naglowek_scena|naglowek_rozdzial">
306     <xsl:call-template name="section-anchor"/>
307     <h3>
308       <xsl:call-template name="block-args" />
309       <xsl:apply-templates mode="inline" />
310     </h3>
311 </xsl:template>
312
313 <xsl:template match="podtytul_scena|podtytul_rozdzial">
314   <div class="subtitle3">
315     <xsl:call-template name="block-args" />
316     <xsl:apply-templates mode="inline" />
317   </div>
318 </xsl:template>
319
320 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
321   <xsl:call-template name="section-anchor"/>
322   <h4>
323     <xsl:call-template name="block-args" />
324     <xsl:apply-templates mode="inline" />
325   </h4>
326 </xsl:template>
327
328 <xsl:template match="podtytul_podrozdzial">
329   <div class="subtitle4">
330     <xsl:call-template name="block-args" />
331     <xsl:apply-templates mode="inline" />
332   </div>
333 </xsl:template>
334
335 <!-- Other paragraph tags -->
336 <xsl:template match="miejsce_czas">
337   <xsl:call-template name="section-anchor"/>
338   <p class="place-and-time">
339     <xsl:call-template name="block-args" />
340     <xsl:apply-templates mode="inline" />
341   </p>
342 </xsl:template>
343
344 <xsl:template match="didaskalia">
345   <xsl:call-template name="section-anchor"/>
346   <div class="didaskalia">
347     <xsl:call-template name="block-args" />
348     <xsl:apply-templates mode="inline" />
349   </div>
350 </xsl:template>
351
352 <xsl:template match="lista_osoba">
353     <li><xsl:apply-templates mode="inline" /></li>
354 </xsl:template>
355
356 <xsl:template match="akap|akap_dialog|akap_cd">
357     <p class="paragraph">
358       <xsl:call-template name="block-args" />
359       <xsl:call-template name="section-anchor"/>
360         <xsl:apply-templates mode="inline" />
361     </p>
362 </xsl:template>
363
364 <xsl:template match="list">
365     <blockquote class="letter"><xsl:apply-templates /></blockquote>
366 </xsl:template>
367 <xsl:template match="adresat">
368   <p class="paragraph adresat">
369     <xsl:call-template name="block-args" />
370     <xsl:call-template name="section-anchor"/>
371     <xsl:apply-templates mode="inline" />
372   </p>
373 </xsl:template>
374 <xsl:template match="miejsce_data">
375   <p class="paragraph miejsce_data">
376     <xsl:call-template name="block-args" />
377     <xsl:call-template name="section-anchor"/>
378     <xsl:apply-templates mode="inline" />
379   </p>
380 </xsl:template>
381 <xsl:template match="naglowek_listu">
382   <p class="paragraph naglowek_listu">
383     <xsl:call-template name="block-args" />
384     <xsl:call-template name="section-anchor"/>
385     <xsl:apply-templates mode="inline" />
386   </p>
387 </xsl:template>
388 <xsl:template match="pozdrowienie">
389   <p class="paragraph pozdrowienie">
390     <xsl:call-template name="block-args" />
391     <xsl:call-template name="section-anchor"/>
392     <xsl:apply-templates mode="inline" />
393   </p>
394 </xsl:template>
395 <xsl:template match="podpis">
396   <p class="paragraph podpis">
397     <xsl:call-template name="block-args" />
398     <xsl:call-template name="section-anchor"/>
399     <xsl:apply-templates mode="inline" />
400   </p>
401 </xsl:template>
402
403 <xsl:template match="strofa" mode="inline">
404     <xsl:apply-templates select="." />
405 </xsl:template>
406
407 <xsl:template match="strofa">
408   <div class="stanza">
409     <xsl:call-template name="block-args" />
410       <xsl:call-template name="section-anchor"/>
411         <xsl:choose>
412             <xsl:when test="count(br) > 0">
413                 <xsl:call-template name="verse">
414                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
415                     <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' or name() = 'wers_srodek'][1]" />
416                 </xsl:call-template>
417                 <xsl:for-each select="br">              
418                                 <!-- Each BR tag "consumes" text after it -->
419                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
420                     <xsl:call-template name="verse">
421                         <xsl:with-param name="verse-content"
422                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
423                         <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' or name() = 'wers_srodek')][1]" />
424                     </xsl:call-template>
425                 </xsl:for-each>
426             </xsl:when>
427             <xsl:otherwise>
428                 <xsl:call-template name="verse">
429                     <xsl:with-param name="verse-content" select="text() | node()" />
430                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej|wers_srodek[1]" />
431                  </xsl:call-template>
432             </xsl:otherwise>
433         </xsl:choose>
434     </div>
435 </xsl:template>
436
437 <xsl:template name="verse">
438     <xsl:param name="verse-content" />
439     <xsl:param name="verse-type" />
440     <div class="verse">
441       <xsl:attribute name="class">
442         <xsl:text>verse</xsl:text>
443         <xsl:choose>
444             <xsl:when test="name($verse-type) = 'wers_akap'">
445               <xsl:text> verse-p</xsl:text>
446             </xsl:when>
447             <xsl:when test="name($verse-type) = 'wers_wciety'">
448               <xsl:text> verse-indent</xsl:text>
449               <xsl:if test="$verse-content/@typ">
450                 <xsl:text> verse-indent-</xsl:text>
451                 <xsl:value-of select="$verse-content/@typ" />
452               </xsl:if>
453             </xsl:when>
454             <xsl:when test="name($verse-type) = 'wers_cd'">
455               <xsl:text> verse-cont</xsl:text>
456             </xsl:when>
457             <xsl:when test="name($verse-type) = 'wers_do_prawej'">
458               <xsl:text> verse-right</xsl:text>
459             </xsl:when>
460             <xsl:when test="name($verse-type) = 'wers_srodek'">
461               <xsl:text> verse-center</xsl:text>
462             </xsl:when>
463         </xsl:choose>
464       </xsl:attribute>
465       <xsl:apply-templates select="$verse-content" mode="inline" />
466     </div>
467 </xsl:template>
468
469 <xsl:template match="motto_podpis">
470     <xsl:call-template name="section-anchor"/>
471     <p class="motto_podpis">
472       <xsl:call-template name="block-args" />
473       <xsl:apply-templates mode="inline" />
474     </p>
475 </xsl:template>
476
477 <xsl:template match="tabela|tabelka">
478     <xsl:call-template name="section-anchor"/>
479     <xsl:choose>
480         <xsl:when test="@ramka = '1'">
481           <table class="border">
482             <xsl:call-template name="block-args" />
483             <xsl:apply-templates />
484           </table>
485         </xsl:when>
486         <xsl:otherwise>
487           <table>
488             <xsl:call-template name="block-args" />
489             <xsl:apply-templates />
490           </table>
491         </xsl:otherwise>
492     </xsl:choose>
493 </xsl:template>
494 <xsl:template match="wiersz">
495     <tr><xsl:apply-templates /></tr>
496 </xsl:template>
497 <xsl:template match="kol">
498     <td><xsl:apply-templates mode="inline" /></td>
499 </xsl:template>
500
501 <xsl:template match="mat">
502     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
503 </xsl:template>
504
505
506 <!-- ================================================ -->
507 <!-- = INLINE TAGS                                  = -->
508 <!-- = (contain other inline tags and special tags) = -->
509 <!-- ================================================ -->
510 <!-- Annotations -->
511 <xsl:template match="pa|pe|pr|pt|ptrad" mode="inline">
512   <xsl:if test="not(//@nonotes)">
513     <a name="{concat('anchor-', generate-id(.))}" />
514     <a href="{concat('#footnote-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt or self::ptrad]) + 1" />]</a>
515   </xsl:if>
516 </xsl:template>
517
518 <xsl:template match="ref" mode="inline">
519   <a class="reference" data-uri="">
520     <xsl:attribute name="data-uri">
521       <xsl:value-of select="@href"/>
522     </xsl:attribute>
523   </a>
524 </xsl:template>
525
526 <!-- Other inline tags -->
527 <xsl:template match="mat" mode="inline">
528     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*|text()" /></math>
529 </xsl:template>
530
531 <xsl:template match="didask_tekst" mode="inline">
532     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
533 </xsl:template>
534
535 <xsl:template match="slowo_obce" mode="inline">
536   <em>
537     <xsl:attribute name="class">
538       <xsl:text>foreign-word</xsl:text>
539       <xsl:if test="@protect">
540         <xsl:text> foreign-word-protected</xsl:text>
541       </xsl:if>
542     </xsl:attribute>
543     <xsl:apply-templates mode="inline" />
544   </em>
545 </xsl:template>
546
547 <xsl:template match="tytul_dziela" mode="inline">
548     <em class="book-title">
549         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
550     </em>
551 </xsl:template>
552
553 <xsl:template match="wyroznienie" mode="inline">
554     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
555 </xsl:template>
556
557 <xsl:template match="wieksze_odstepy" mode="inline">
558     <em class="wieksze-odstepy"><xsl:apply-templates mode="inline" /></em>
559 </xsl:template>
560
561 <xsl:template match="indeks_dolny" mode="inline">
562     <sub><xsl:apply-templates mode="inline" /></sub>
563 </xsl:template>
564
565 <xsl:template match="osoba" mode="inline">
566     <em class="person"><xsl:apply-templates mode="inline" /></em>
567 </xsl:template>
568
569 <xsl:template match="br" mode="inline">
570     <br/>
571 </xsl:template>
572
573 <xsl:template match="www" mode="inline">
574     <a target="_blank">
575         <xsl:attribute name="href">
576             <xsl:value-of select="text()"/>
577         </xsl:attribute>
578         <xsl:apply-templates mode="inline" />
579     </a>
580 </xsl:template>
581
582 <!-- ============================================== -->
583 <!-- = STANDALONE TAGS                            = -->
584 <!-- = (cannot contain any other tags)            = -->
585 <!-- ============================================== -->
586 <xsl:template match="sekcja_swiatlo">
587     <hr class="spacer" />
588 </xsl:template>
589
590 <xsl:template match="sekcja_asterysk">
591     <p class="spacer-asterisk">*</p>
592 </xsl:template>
593
594 <xsl:template match="separator_linia">
595     <hr class="spacer-line" />
596 </xsl:template>
597
598
599 <!-- ================ -->
600 <!-- = SPECIAL TAGS = -->
601 <!-- ================ -->
602 <!-- Themes -->
603 <xsl:template match="begin" mode="inline">
604     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
605     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
606         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
607     </a>
608 </xsl:template>
609
610 <xsl:template match="end" mode="inline">
611     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
612 </xsl:template>
613
614 <xsl:template match="begin|end">
615     <xsl:apply-templates select='.' mode="inline" />
616 </xsl:template>
617
618 <xsl:template match="motyw" mode="inline" />
619
620
621 <xsl:template match="nota_red" mode="special">
622     <div id="nota_red">
623         <xsl:apply-templates />
624     </div>
625 </xsl:template>
626
627
628 <xsl:template name="translators">
629     <xsl:if test="//dc:contributor.translator">
630         <span class="translator">
631             <xsl:text>tłum. </xsl:text>
632             <xsl:for-each select="//dc:contributor.translator">
633                 <xsl:if test="position() != 1">, </xsl:if>
634                 <xsl:apply-templates mode="person" />
635             </xsl:for-each>
636         </span>
637     </xsl:if>
638 </xsl:template>
639
640 <xsl:template match="text()" mode="person">
641     <xsl:value-of select="wl:person_name(.)" />
642 </xsl:template>
643
644 <xsl:template match="rownolegle">
645     <xsl:apply-templates mode="rownolegle" />
646 </xsl:template>
647 <xsl:template match="*" mode="rownolegle">
648   <!-- is it last? -->
649   <div>
650     <xsl:attribute name="class">
651       <xsl:text>rownolegly-blok</xsl:text>
652       <xsl:if test="not(following-sibling::*)">
653         <xsl:text> last</xsl:text>
654       </xsl:if>
655       <xsl:if test="not(preceding-sibling::*)">
656         <xsl:text> first</xsl:text>
657       </xsl:if>
658     </xsl:attribute>
659     <xsl:attribute name="style">
660       <xsl:text>border-left: 2px solid red; padding-left: .5em;</xsl:text>
661       <xsl:if test="not(following-sibling::*)">
662         <xsl:text> border-radius: 0 0 0 .75em;</xsl:text>
663       </xsl:if>
664       <xsl:if test="not(preceding-sibling::*)">
665         <xsl:text> border-radius: .75em 0 0 0;</xsl:text>
666       </xsl:if>
667     </xsl:attribute>
668     <xsl:apply-templates match="." />
669   </div>
670 </xsl:template>
671
672 <xsl:template match="tab" mode="inline">
673   <span>
674     <xsl:choose>
675       <xsl:when test="@szer">
676         <xsl:attribute name="style">display: inline-block; width: <xsl:value-of select="@szer" />em</xsl:attribute>
677       </xsl:when>
678       <xsl:otherwise>
679         <xsl:attribute name="style">display: inline-block; width: 1em</xsl:attribute>
680       </xsl:otherwise>
681     </xsl:choose>
682   </span>
683 </xsl:template>
684
685
686 <xsl:template match="werset">
687     <p class="werset paragraph">
688       <xsl:call-template name="block-args" />
689       <xsl:call-template name="section-anchor"/>
690         <xsl:apply-templates mode="inline" />
691     </p>
692 </xsl:template>
693
694
695 <!-- ================ -->
696 <!-- = IGNORED TAGS = -->
697 <!-- ================ -->
698 <xsl:template match="extra|uwaga" />
699 <xsl:template match="extra|uwaga" mode="inline" />
700
701 <xsl:template match="nota_red" />
702 <xsl:template match="abstrakt" />
703
704 <!-- ======== -->
705 <!-- = TEXT = -->
706 <!-- ======== -->
707 <xsl:template match="text()" />
708 <xsl:template match="text()" mode="inline">
709     <xsl:value-of select="wl:substitute_entities(.)" />
710 </xsl:template>
711
712 <!-- ========= -->
713 <!-- = utils = -->
714 <!-- ========= -->
715 <xsl:template name="section-anchor">
716   <!-- 
717        this formula works as follows:
718        - get all ancestors including self
719        - choose the header (third one from root): utwor/book-type/header
720        - get all preceding siblings
721        - count them
722        - create an <a name="sec123"/> tag.
723   -->
724         <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
725 </xsl:template>
726
727 <xsl:template name="block-args">
728   <xsl:if test="@id">
729     <xsl:attribute name="id">
730       <xsl:text>wl-</xsl:text>
731       <xsl:value-of select="@id"/>
732     </xsl:attribute>
733   </xsl:if>
734 </xsl:template>
735
736 <xsl:template match="numeracja">
737         <span class="numeracja">
738                 <xsl:attribute name="data-start">
739                         <xsl:value-of select="@start" />
740                 </xsl:attribute>
741                 <xsl:attribute name="data-link">
742                         <xsl:value-of select="@link" />
743                 </xsl:attribute>
744         </span>
745 </xsl:template>
746
747 </xsl:stylesheet>