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:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
  99         <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt or self::ptrad][not(parent::extra)])">
 
 102                 <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt or self::ptrad][not(parent::extra)]">
 
 104                         <xsl:attribute name="class">fn-<xsl:value-of select="name()" /></xsl:attribute>
 
 105                         <a name="{concat('footnote-', generate-id(.))}" />
 
 106                         <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>
 
 108                             <xsl:when test="count(akap|akap_cd|strofa) = 0">
 
 109                                 <p><xsl:apply-templates select="text()|*" mode="inline" />
 
 110                                 <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
 
 111                                 <xsl:if test="name()='pt'"> [przypis tłumacza]</xsl:if>
 
 112                                 <xsl:if test="name()='pr'"> [przypis redakcyjny]</xsl:if>
 
 113                                 <xsl:if test="name()='pe'"> [przypis edytorski]</xsl:if>
 
 114                                 <xsl:if test="name()='ptrad'"> [przypis tradycyjny]</xsl:if>
 
 118                               <xsl:apply-templates />
 
 120                                 <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
 
 121                                 <xsl:if test="name()='pt'"> [przypis tłumacza]</xsl:if>
 
 122                                 <xsl:if test="name()='pr'"> [przypis redakcyjny]</xsl:if>
 
 123                                 <xsl:if test="name()='pe'"> [przypis edytorski]</xsl:if>
 
 124                                 <xsl:if test="name()='ptrad'"> [przypis tradycyjny]</xsl:if>
 
 136 <!-- ============================================================================== -->
 
 137 <!-- = MASTER TAG                                                                 = -->
 
 138 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
 
 139 <!-- ============================================================================== -->
 
 140 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
 
 141     <xsl:apply-templates select="nota_red" mode="special" />
 
 142     <xsl:if test="nazwa_utworu">
 
 144             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
 
 145             <xsl:call-template name="translators" />
 
 148     <xsl:apply-templates />
 
 152 <!-- ==================================================================================== -->
 
 153 <!-- = BLOCK TAGS                                                                       = -->
 
 154 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
 
 155 <!-- ==================================================================================== -->
 
 156 <xsl:template match="nota">
 
 157     <div class="note"><xsl:apply-templates /></div>
 
 160 <xsl:template match="lista_osob">
 
 161     <xsl:call-template name="section-anchor"/>
 
 162     <div class="person-list">
 
 163         <h3><xsl:value-of select="naglowek_listy" /></h3>
 
 165             <xsl:apply-templates select="lista_osoba" />
 
 170 <xsl:template match="dedykacja">
 
 171     <div class="dedication"><xsl:apply-templates /></div>
 
 174 <xsl:template match="ramka">
 
 175     <div class="frame"><xsl:apply-templates /></div>
 
 178 <xsl:template match="kwestia">
 
 179     <div class="kwestia">
 
 180         <xsl:apply-templates select="strofa|akap|didaskalia" />
 
 184 <xsl:template match="dlugi_cytat|poezja_cyt">
 
 185     <blockquote><xsl:apply-templates /></blockquote>
 
 188 <xsl:template match="motto">
 
 189     <xsl:call-template name="section-anchor"/>
 
 191       <xsl:call-template name="block-args" />
 
 192       <xsl:apply-templates />
 
 196 <xsl:template match="ilustr" mode="inline">
 
 197     <xsl:apply-templates select="."/>
 
 200 <xsl:template match="ilustr">
 
 202     <xsl:call-template name="block-args" />
 
 204     <xsl:attribute name="class">
 
 205       <xsl:text>ilustr </xsl:text>
 
 206       <xsl:value-of select="@wyrownanie"/>
 
 207       <xsl:if test="@oblew">
 
 208         <xsl:text> oblew</xsl:text>
 
 213       <xsl:attribute name="src">
 
 214         <xsl:value-of select="@src" />
 
 216       <xsl:attribute name="srcset">
 
 217         <xsl:value-of select="@srcset" />
 
 219       <xsl:attribute name="sizes">
 
 220         (min-width: 718px) 600px,
 
 221         (min-width: 600px) calc(100vw - 118px),
 
 222         (min-width: 320px) calc(100vw - 75px),
 
 223         (min-width: 15em) calc(100wv - 60px),
 
 226       <xsl:attribute name="alt">
 
 227         <xsl:value-of select="@alt" />
 
 229       <xsl:attribute name="title">
 
 230         <xsl:value-of select="@alt" />
 
 233       <xsl:if test="@szer">
 
 234         <xsl:attribute name="style">
 
 235           <xsl:text>width: </xsl:text>
 
 236           <xsl:value-of select="@szer"/>
 
 241     <div class="stop"></div>
 
 245 <xsl:template match="animacja">
 
 246   <div class="animacja cycle-slideshow" data-cycle-pause-on-hover="true" data-cycle-next="> img" data-cycle-fx="fadeout" data-cycle-paused="true">
 
 247     <xsl:call-template name="block-args" />
 
 248     <xsl:apply-templates/>
 
 253 <!-- ========================================== -->
 
 254 <!-- = PARAGRAPH TAGS                         = -->
 
 255 <!-- = (can contain inline and special tags)  = -->
 
 256 <!-- ========================================== -->
 
 258 <xsl:template match="autor_utworu" mode="header">
 
 259   <span class="author">
 
 260     <xsl:call-template name="block-args" />
 
 261     <xsl:apply-templates mode="inline" />
 
 265 <xsl:template match="nazwa_utworu" mode="header">
 
 267     <xsl:call-template name="block-args" />
 
 268     <xsl:apply-templates mode="inline" />
 
 272 <xsl:template match="dzielo_nadrzedne" mode="header">
 
 273   <span class="collection">
 
 274     <xsl:call-template name="block-args" />
 
 275     <xsl:apply-templates mode="inline" />
 
 279 <xsl:template match="podtytul" mode="header">
 
 280   <span class="subtitle">
 
 281     <xsl:call-template name="block-args" />
 
 282     <xsl:apply-templates mode="inline" />
 
 286 <!-- Section headers (included in index)-->
 
 287 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
 
 288   <xsl:call-template name="section-anchor"/>
 
 290     <xsl:call-template name="block-args" />
 
 291     <xsl:apply-templates mode="inline" />
 
 295 <xsl:template match="podtytul_akt|podtytul_czesc">
 
 296   <div class="subtitle2">
 
 297     <xsl:call-template name="block-args" />
 
 298     <xsl:apply-templates mode="inline" />
 
 302 <xsl:template match="naglowek_scena|naglowek_rozdzial">
 
 303     <xsl:call-template name="section-anchor"/>
 
 305       <xsl:call-template name="block-args" />
 
 306       <xsl:apply-templates mode="inline" />
 
 310 <xsl:template match="podtytul_scena|podtytul_rozdzial">
 
 311   <div class="subtitle3">
 
 312     <xsl:call-template name="block-args" />
 
 313     <xsl:apply-templates mode="inline" />
 
 317 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
 
 318   <xsl:call-template name="section-anchor"/>
 
 320     <xsl:call-template name="block-args" />
 
 321     <xsl:apply-templates mode="inline" />
 
 325 <xsl:template match="podtytul_podrozdzial">
 
 326   <div class="subtitle4">
 
 327     <xsl:call-template name="block-args" />
 
 328     <xsl:apply-templates mode="inline" />
 
 332 <!-- Other paragraph tags -->
 
 333 <xsl:template match="miejsce_czas">
 
 334   <xsl:call-template name="section-anchor"/>
 
 335   <p class="place-and-time">
 
 336     <xsl:call-template name="block-args" />
 
 337     <xsl:apply-templates mode="inline" />
 
 341 <xsl:template match="didaskalia">
 
 342   <xsl:call-template name="section-anchor"/>
 
 343   <div class="didaskalia">
 
 344     <xsl:call-template name="block-args" />
 
 345     <xsl:apply-templates mode="inline" />
 
 349 <xsl:template match="lista_osoba">
 
 350     <li><xsl:apply-templates mode="inline" /></li>
 
 353 <xsl:template match="akap|akap_dialog|akap_cd">
 
 354     <p class="paragraph">
 
 355       <xsl:call-template name="block-args" />
 
 356       <xsl:call-template name="section-anchor"/>
 
 357         <xsl:apply-templates mode="inline" />
 
 361 <xsl:template match="list">
 
 362     <blockquote class="letter"><xsl:apply-templates /></blockquote>
 
 364 <xsl:template match="adresat">
 
 365   <p class="paragraph adresat">
 
 366     <xsl:call-template name="block-args" />
 
 367     <xsl:call-template name="section-anchor"/>
 
 368     <xsl:apply-templates mode="inline" />
 
 371 <xsl:template match="miejsce_data">
 
 372   <p class="paragraph miejsce_data">
 
 373     <xsl:call-template name="block-args" />
 
 374     <xsl:call-template name="section-anchor"/>
 
 375     <xsl:apply-templates mode="inline" />
 
 378 <xsl:template match="naglowek_listu">
 
 379   <p class="paragraph naglowek_listu">
 
 380     <xsl:call-template name="block-args" />
 
 381     <xsl:call-template name="section-anchor"/>
 
 382     <xsl:apply-templates mode="inline" />
 
 385 <xsl:template match="pozdrowienie">
 
 386   <p class="paragraph pozdrowienie">
 
 387     <xsl:call-template name="block-args" />
 
 388     <xsl:call-template name="section-anchor"/>
 
 389     <xsl:apply-templates mode="inline" />
 
 392 <xsl:template match="podpis">
 
 393   <p class="paragraph podpis">
 
 394     <xsl:call-template name="block-args" />
 
 395     <xsl:call-template name="section-anchor"/>
 
 396     <xsl:apply-templates mode="inline" />
 
 400 <xsl:template match="strofa" mode="inline">
 
 401     <xsl:apply-templates select="." />
 
 404 <xsl:template match="strofa">
 
 406     <xsl:call-template name="block-args" />
 
 407       <xsl:call-template name="section-anchor"/>
 
 409             <xsl:when test="count(br) > 0">
 
 410                 <xsl:call-template name="verse">
 
 411                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
 
 412                     <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]" />
 
 414                 <xsl:for-each select="br">              
 
 415                                 <!-- Each BR tag "consumes" text after it -->
 
 416                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
 
 417                     <xsl:call-template name="verse">
 
 418                         <xsl:with-param name="verse-content"
 
 419                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
 
 420                         <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]" />
 
 425                 <xsl:call-template name="verse">
 
 426                     <xsl:with-param name="verse-content" select="text() | node()" />
 
 427                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej|wers_srodek[1]" />
 
 434 <xsl:template name="verse">
 
 435     <xsl:param name="verse-content" />
 
 436     <xsl:param name="verse-type" />
 
 438       <xsl:attribute name="class">
 
 439         <xsl:text>verse</xsl:text>
 
 441             <xsl:when test="name($verse-type) = 'wers_akap'">
 
 442               <xsl:text> verse-p</xsl:text>
 
 444             <xsl:when test="name($verse-type) = 'wers_wciety'">
 
 445               <xsl:text> verse-indent</xsl:text>
 
 446               <xsl:if test="$verse-content/@typ">
 
 447                 <xsl:text> verse-indent-</xsl:text>
 
 448                 <xsl:value-of select="$verse-content/@typ" />
 
 451             <xsl:when test="name($verse-type) = 'wers_cd'">
 
 452               <xsl:text> verse-cont</xsl:text>
 
 454             <xsl:when test="name($verse-type) = 'wers_do_prawej'">
 
 455               <xsl:text> verse-right</xsl:text>
 
 457             <xsl:when test="name($verse-type) = 'wers_srodek'">
 
 458               <xsl:text> verse-center</xsl:text>
 
 462       <xsl:apply-templates select="$verse-content" mode="inline" />
 
 466 <xsl:template match="motto_podpis">
 
 467     <xsl:call-template name="section-anchor"/>
 
 468     <p class="motto_podpis">
 
 469       <xsl:call-template name="block-args" />
 
 470       <xsl:apply-templates mode="inline" />
 
 474 <xsl:template match="tabela|tabelka">
 
 475     <xsl:call-template name="section-anchor"/>
 
 477         <xsl:when test="@ramka = '1'">
 
 478           <table class="border">
 
 479             <xsl:call-template name="block-args" />
 
 480             <xsl:apply-templates />
 
 485             <xsl:call-template name="block-args" />
 
 486             <xsl:apply-templates />
 
 491 <xsl:template match="wiersz">
 
 492     <tr><xsl:apply-templates /></tr>
 
 494 <xsl:template match="kol">
 
 495     <td><xsl:apply-templates mode="inline" /></td>
 
 498 <xsl:template match="mat">
 
 499     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
 
 503 <!-- ================================================ -->
 
 504 <!-- = INLINE TAGS                                  = -->
 
 505 <!-- = (contain other inline tags and special tags) = -->
 
 506 <!-- ================================================ -->
 
 508 <xsl:template match="pa|pe|pr|pt|ptrad" mode="inline">
 
 509     <a name="{concat('anchor-', generate-id(.))}" />
 
 510     <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>
 
 513 <xsl:template match="ref" mode="inline">
 
 514   <a class="reference" data-uri="">
 
 515     <xsl:attribute name="data-uri">
 
 516       <xsl:value-of select="@href"/>
 
 521 <!-- Other inline tags -->
 
 522 <xsl:template match="mat" mode="inline">
 
 523     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*|text()" /></math>
 
 526 <xsl:template match="didask_tekst" mode="inline">
 
 527     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
 
 530 <xsl:template match="slowo_obce" mode="inline">
 
 532     <xsl:attribute name="class">
 
 533       <xsl:text>foreign-word</xsl:text>
 
 534       <xsl:if test="@protect">
 
 535         <xsl:text> foreign-word-protected</xsl:text>
 
 538     <xsl:apply-templates mode="inline" />
 
 542 <xsl:template match="tytul_dziela" mode="inline">
 
 543     <em class="book-title">
 
 544         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
 
 548 <xsl:template match="wyroznienie" mode="inline">
 
 549     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
 
 552 <xsl:template match="wieksze_odstepy" mode="inline">
 
 553     <em class="wieksze-odstepy"><xsl:apply-templates mode="inline" /></em>
 
 556 <xsl:template match="indeks_dolny" mode="inline">
 
 557     <sub><xsl:apply-templates mode="inline" /></sub>
 
 560 <xsl:template match="osoba" mode="inline">
 
 561     <em class="person"><xsl:apply-templates mode="inline" /></em>
 
 564 <xsl:template match="www" mode="inline">
 
 566         <xsl:attribute name="href">
 
 567             <xsl:value-of select="text()"/>
 
 569         <xsl:apply-templates mode="inline" />
 
 573 <!-- ============================================== -->
 
 574 <!-- = STANDALONE TAGS                            = -->
 
 575 <!-- = (cannot contain any other tags)            = -->
 
 576 <!-- ============================================== -->
 
 577 <xsl:template match="sekcja_swiatlo">
 
 578     <hr class="spacer" />
 
 581 <xsl:template match="sekcja_asterysk">
 
 582     <p class="spacer-asterisk">*</p>
 
 585 <xsl:template match="separator_linia">
 
 586     <hr class="spacer-line" />
 
 590 <!-- ================ -->
 
 591 <!-- = SPECIAL TAGS = -->
 
 592 <!-- ================ -->
 
 594 <xsl:template match="begin" mode="inline">
 
 595     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
 
 596     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
 
 597         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
 
 601 <xsl:template match="end" mode="inline">
 
 602     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
 
 605 <xsl:template match="begin|end">
 
 606     <xsl:apply-templates select='.' mode="inline" />
 
 609 <xsl:template match="motyw" mode="inline" />
 
 612 <xsl:template match="nota_red" mode="special">
 
 614         <xsl:apply-templates />
 
 619 <xsl:template name="translators">
 
 620     <xsl:if test="//dc:contributor.translator">
 
 621         <span class="translator">
 
 622             <xsl:text>tłum. </xsl:text>
 
 623             <xsl:for-each select="//dc:contributor.translator">
 
 624                 <xsl:if test="position() != 1">, </xsl:if>
 
 625                 <xsl:apply-templates mode="person" />
 
 631 <xsl:template match="text()" mode="person">
 
 632     <xsl:value-of select="wl:person_name(.)" />
 
 635 <xsl:template match="rownolegle">
 
 636     <xsl:apply-templates mode="rownolegle" />
 
 638 <xsl:template match="*" mode="rownolegle">
 
 641     <xsl:attribute name="class">
 
 642       <xsl:text>rownolegly-blok</xsl:text>
 
 643       <xsl:if test="not(following-sibling::*)">
 
 644         <xsl:text> last</xsl:text>
 
 646       <xsl:if test="not(preceding-sibling::*)">
 
 647         <xsl:text> first</xsl:text>
 
 650     <xsl:attribute name="style">
 
 651       <xsl:text>border-left: 2px solid red; padding-left: .5em;</xsl:text>
 
 652       <xsl:if test="not(following-sibling::*)">
 
 653         <xsl:text> border-radius: 0 0 0 .75em;</xsl:text>
 
 655       <xsl:if test="not(preceding-sibling::*)">
 
 656         <xsl:text> border-radius: .75em 0 0 0;</xsl:text>
 
 659     <xsl:apply-templates match="." />
 
 663 <xsl:template match="tab" mode="inline">
 
 666       <xsl:when test="@szer">
 
 667         <xsl:attribute name="style">display: inline-block; width: <xsl:value-of select="@szer" />em</xsl:attribute>
 
 670         <xsl:attribute name="style">display: inline-block; width: 1em</xsl:attribute>
 
 677 <xsl:template match="werset">
 
 678     <p class="werset paragraph">
 
 679       <xsl:call-template name="block-args" />
 
 680       <xsl:call-template name="section-anchor"/>
 
 681         <xsl:apply-templates mode="inline" />
 
 686 <!-- ================ -->
 
 687 <!-- = IGNORED TAGS = -->
 
 688 <!-- ================ -->
 
 689 <xsl:template match="extra|uwaga" />
 
 690 <xsl:template match="extra|uwaga" mode="inline" />
 
 692 <xsl:template match="nota_red" />
 
 693 <xsl:template match="abstrakt" />
 
 698 <xsl:template match="text()" />
 
 699 <xsl:template match="text()" mode="inline">
 
 700     <xsl:value-of select="wl:substitute_entities(.)" />
 
 706 <xsl:template name="section-anchor">
 
 708        this formula works as follows:
 
 709        - get all ancestors including self
 
 710        - choose the header (third one from root): utwor/book-type/header
 
 711        - get all preceding siblings
 
 713        - create an <a name="sec123"/> tag.
 
 715         <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
 
 718 <xsl:template name="block-args">
 
 720     <xsl:attribute name="id">
 
 721       <xsl:text>wl-</xsl:text>
 
 722       <xsl:value-of select="@id"/>
 
 727 <xsl:template match="numeracja">
 
 728         <span class="numeracja">
 
 729                 <xsl:attribute name="data-start">
 
 730                         <xsl:value-of select="@start" />
 
 732                 <xsl:attribute name="data-link">
 
 733                         <xsl:value-of select="@link" />