1 <?xml version="1.0" encoding="utf-8"?>
 
   4    This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 
   5    Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 
   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/" >
 
  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">
 
  16         <xsl:when test="@full-page">
 
  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" />
 
  47                   .ilustr.oblew.lewo img {
 
  50                     .ilustr.oblew.prawo img {
 
  56                     min-width: 200px !important;
 
  58                     @media screen and (max-width: 320px) {
 
  60                     width: 100% !important;
 
  61                     min-width: auto !important;
 
  69                     .ilustr.oblew.prawo img {
 
  72                     .ilustr.oblew.lewo img{
 
  83               <xsl:call-template name="book-text" />
 
  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>
 
  91             <xsl:call-template name="book-text" />
 
  96 <xsl:template name="book-text">
 
  98       <xsl:attribute name="lang">
 
  99         <xsl:value-of select="@lang" />
 
 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)])">
 
 105                 <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt or self::ptrad][not(parent::extra)]">
 
 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>
 
 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>
 
 121                               <xsl:apply-templates />
 
 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>
 
 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">
 
 147             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
 
 148             <xsl:call-template name="translators" />
 
 151     <xsl:apply-templates />
 
 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>
 
 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>
 
 168             <xsl:apply-templates select="lista_osoba" />
 
 173 <xsl:template match="dedykacja">
 
 174     <div class="dedication"><xsl:apply-templates /></div>
 
 177 <xsl:template match="ramka">
 
 178     <div class="frame"><xsl:apply-templates /></div>
 
 181 <xsl:template match="kwestia">
 
 182     <div class="kwestia">
 
 183         <xsl:apply-templates select="strofa|akap|didaskalia" />
 
 187 <xsl:template match="dlugi_cytat|poezja_cyt">
 
 188     <blockquote><xsl:apply-templates /></blockquote>
 
 191 <xsl:template match="motto">
 
 192     <xsl:call-template name="section-anchor"/>
 
 194       <xsl:call-template name="block-args" />
 
 195       <xsl:apply-templates />
 
 199 <xsl:template match="ilustr" mode="inline">
 
 200     <xsl:apply-templates select="."/>
 
 203 <xsl:template match="ilustr">
 
 205     <xsl:call-template name="block-args" />
 
 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>
 
 216       <xsl:attribute name="src">
 
 217         <xsl:value-of select="@src" />
 
 219       <xsl:attribute name="srcset">
 
 220         <xsl:value-of select="@srcset" />
 
 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),
 
 229       <xsl:attribute name="alt">
 
 230         <xsl:value-of select="@alt" />
 
 232       <xsl:attribute name="title">
 
 233         <xsl:value-of select="@alt" />
 
 236       <xsl:if test="@szer">
 
 237         <xsl:attribute name="style">
 
 238           <xsl:text>width: </xsl:text>
 
 239           <xsl:value-of select="@szer"/>
 
 244     <div class="stop"></div>
 
 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/>
 
 256 <!-- ========================================== -->
 
 257 <!-- = PARAGRAPH TAGS                         = -->
 
 258 <!-- = (can contain inline and special tags)  = -->
 
 259 <!-- ========================================== -->
 
 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" />
 
 268 <xsl:template match="nazwa_utworu" mode="header">
 
 270     <xsl:call-template name="block-args" />
 
 271     <xsl:apply-templates mode="inline" />
 
 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" />
 
 282 <xsl:template match="podtytul" mode="header">
 
 283   <span class="subtitle">
 
 284     <xsl:call-template name="block-args" />
 
 285     <xsl:apply-templates mode="inline" />
 
 289 <!-- Section headers (included in index)-->
 
 290 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
 
 291   <xsl:call-template name="section-anchor"/>
 
 293     <xsl:call-template name="block-args" />
 
 294     <xsl:apply-templates mode="inline" />
 
 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" />
 
 305 <xsl:template match="naglowek_scena|naglowek_rozdzial">
 
 306     <xsl:call-template name="section-anchor"/>
 
 308       <xsl:call-template name="block-args" />
 
 309       <xsl:apply-templates mode="inline" />
 
 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" />
 
 320 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
 
 321   <xsl:call-template name="section-anchor"/>
 
 323     <xsl:call-template name="block-args" />
 
 324     <xsl:apply-templates mode="inline" />
 
 328 <xsl:template match="podtytul_podrozdzial">
 
 329   <div class="subtitle4">
 
 330     <xsl:call-template name="block-args" />
 
 331     <xsl:apply-templates mode="inline" />
 
 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" />
 
 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" />
 
 352 <xsl:template match="lista_osoba">
 
 353     <li><xsl:apply-templates mode="inline" /></li>
 
 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" />
 
 364 <xsl:template match="list">
 
 365     <blockquote class="letter"><xsl:apply-templates /></blockquote>
 
 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" />
 
 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" />
 
 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" />
 
 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" />
 
 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" />
 
 403 <xsl:template match="strofa" mode="inline">
 
 404     <xsl:apply-templates select="." />
 
 407 <xsl:template match="strofa">
 
 409     <xsl:call-template name="block-args" />
 
 410       <xsl:call-template name="section-anchor"/>
 
 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]" />
 
 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]" />
 
 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]" />
 
 437 <xsl:template name="verse">
 
 438     <xsl:param name="verse-content" />
 
 439     <xsl:param name="verse-type" />
 
 441       <xsl:attribute name="class">
 
 442         <xsl:text>verse</xsl:text>
 
 444             <xsl:when test="name($verse-type) = 'wers_akap'">
 
 445               <xsl:text> verse-p</xsl:text>
 
 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" />
 
 454             <xsl:when test="name($verse-type) = 'wers_cd'">
 
 455               <xsl:text> verse-cont</xsl:text>
 
 457             <xsl:when test="name($verse-type) = 'wers_do_prawej'">
 
 458               <xsl:text> verse-right</xsl:text>
 
 460             <xsl:when test="name($verse-type) = 'wers_srodek'">
 
 461               <xsl:text> verse-center</xsl:text>
 
 465       <xsl:apply-templates select="$verse-content" mode="inline" />
 
 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" />
 
 477 <xsl:template match="tabela|tabelka">
 
 478     <xsl:call-template name="section-anchor"/>
 
 480         <xsl:when test="@ramka = '1'">
 
 481           <table class="border">
 
 482             <xsl:call-template name="block-args" />
 
 483             <xsl:apply-templates />
 
 488             <xsl:call-template name="block-args" />
 
 489             <xsl:apply-templates />
 
 494 <xsl:template match="wiersz">
 
 495     <tr><xsl:apply-templates /></tr>
 
 497 <xsl:template match="kol">
 
 498     <td><xsl:apply-templates mode="inline" /></td>
 
 501 <xsl:template match="mat">
 
 502     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
 
 506 <!-- ================================================ -->
 
 507 <!-- = INLINE TAGS                                  = -->
 
 508 <!-- = (contain other inline tags and special tags) = -->
 
 509 <!-- ================================================ -->
 
 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>
 
 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"/>
 
 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>
 
 531 <xsl:template match="didask_tekst" mode="inline">
 
 532     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
 
 535 <xsl:template match="slowo_obce" mode="inline">
 
 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>
 
 543     <xsl:apply-templates mode="inline" />
 
 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>
 
 553 <xsl:template match="wyroznienie" mode="inline">
 
 554     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
 
 557 <xsl:template match="wieksze_odstepy" mode="inline">
 
 558     <em class="wieksze-odstepy"><xsl:apply-templates mode="inline" /></em>
 
 561 <xsl:template match="indeks_dolny" mode="inline">
 
 562     <sub><xsl:apply-templates mode="inline" /></sub>
 
 565 <xsl:template match="osoba" mode="inline">
 
 566     <em class="person"><xsl:apply-templates mode="inline" /></em>
 
 569 <xsl:template match="www" mode="inline">
 
 571         <xsl:attribute name="href">
 
 572             <xsl:value-of select="text()"/>
 
 574         <xsl:apply-templates mode="inline" />
 
 578 <!-- ============================================== -->
 
 579 <!-- = STANDALONE TAGS                            = -->
 
 580 <!-- = (cannot contain any other tags)            = -->
 
 581 <!-- ============================================== -->
 
 582 <xsl:template match="sekcja_swiatlo">
 
 583     <hr class="spacer" />
 
 586 <xsl:template match="sekcja_asterysk">
 
 587     <p class="spacer-asterisk">*</p>
 
 590 <xsl:template match="separator_linia">
 
 591     <hr class="spacer-line" />
 
 595 <!-- ================ -->
 
 596 <!-- = SPECIAL TAGS = -->
 
 597 <!-- ================ -->
 
 599 <xsl:template match="begin" mode="inline">
 
 600     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
 
 601     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
 
 602         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
 
 606 <xsl:template match="end" mode="inline">
 
 607     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
 
 610 <xsl:template match="begin|end">
 
 611     <xsl:apply-templates select='.' mode="inline" />
 
 614 <xsl:template match="motyw" mode="inline" />
 
 617 <xsl:template match="nota_red" mode="special">
 
 619         <xsl:apply-templates />
 
 624 <xsl:template name="translators">
 
 625     <xsl:if test="//dc:contributor.translator">
 
 626         <span class="translator">
 
 627             <xsl:text>tłum. </xsl:text>
 
 628             <xsl:for-each select="//dc:contributor.translator">
 
 629                 <xsl:if test="position() != 1">, </xsl:if>
 
 630                 <xsl:apply-templates mode="person" />
 
 636 <xsl:template match="text()" mode="person">
 
 637     <xsl:value-of select="wl:person_name(.)" />
 
 640 <xsl:template match="rownolegle">
 
 641     <xsl:apply-templates mode="rownolegle" />
 
 643 <xsl:template match="*" mode="rownolegle">
 
 646     <xsl:attribute name="class">
 
 647       <xsl:text>rownolegly-blok</xsl:text>
 
 648       <xsl:if test="not(following-sibling::*)">
 
 649         <xsl:text> last</xsl:text>
 
 651       <xsl:if test="not(preceding-sibling::*)">
 
 652         <xsl:text> first</xsl:text>
 
 655     <xsl:attribute name="style">
 
 656       <xsl:text>border-left: 2px solid red; padding-left: .5em;</xsl:text>
 
 657       <xsl:if test="not(following-sibling::*)">
 
 658         <xsl:text> border-radius: 0 0 0 .75em;</xsl:text>
 
 660       <xsl:if test="not(preceding-sibling::*)">
 
 661         <xsl:text> border-radius: .75em 0 0 0;</xsl:text>
 
 664     <xsl:apply-templates match="." />
 
 668 <xsl:template match="tab" mode="inline">
 
 671       <xsl:when test="@szer">
 
 672         <xsl:attribute name="style">display: inline-block; width: <xsl:value-of select="@szer" />em</xsl:attribute>
 
 675         <xsl:attribute name="style">display: inline-block; width: 1em</xsl:attribute>
 
 682 <xsl:template match="werset">
 
 683     <p class="werset paragraph">
 
 684       <xsl:call-template name="block-args" />
 
 685       <xsl:call-template name="section-anchor"/>
 
 686         <xsl:apply-templates mode="inline" />
 
 691 <!-- ================ -->
 
 692 <!-- = IGNORED TAGS = -->
 
 693 <!-- ================ -->
 
 694 <xsl:template match="extra|uwaga" />
 
 695 <xsl:template match="extra|uwaga" mode="inline" />
 
 697 <xsl:template match="nota_red" />
 
 698 <xsl:template match="abstrakt" />
 
 703 <xsl:template match="text()" />
 
 704 <xsl:template match="text()" mode="inline">
 
 705     <xsl:value-of select="wl:substitute_entities(.)" />
 
 711 <xsl:template name="section-anchor">
 
 713        this formula works as follows:
 
 714        - get all ancestors including self
 
 715        - choose the header (third one from root): utwor/book-type/header
 
 716        - get all preceding siblings
 
 718        - create an <a name="sec123"/> tag.
 
 720         <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
 
 723 <xsl:template name="block-args">
 
 725     <xsl:attribute name="id">
 
 726       <xsl:text>wl-</xsl:text>
 
 727       <xsl:value-of select="@id"/>
 
 732 <xsl:template match="numeracja">
 
 733         <span class="numeracja">
 
 734                 <xsl:attribute name="data-start">
 
 735                         <xsl:value-of select="@start" />
 
 737                 <xsl:attribute name="data-link">
 
 738                         <xsl:value-of select="@link" />