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 Nowoczesna Polska. 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 href="https://static.wolnelektury.pl/css/compressed/book_text.css" rel="stylesheet" type="text/css" />
 
  24                   .animacja {cursor: pointer;}
 
  28               <xsl:call-template name="book-text" />
 
  30               <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 
  31               <script src="http://malsup.github.io/min/jquery.cycle2.min.js"></script>
 
  36             <xsl:call-template name="book-text" />
 
  41 <xsl:template name="book-text">
 
  43         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
  44         <xsl:if test="count(descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)])">
 
  47                 <xsl:for-each select="descendant::*[self::pe or self::pa or self::pr or self::pt][not(parent::extra)]">
 
  49                         <xsl:attribute name="class">fn-<xsl:value-of select="name()" /></xsl:attribute>
 
  50                         <a name="{concat('footnote-', generate-id(.))}" />
 
  51                         <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:when test="count(akap|akap_cd|strofa) = 0">
 
  54                                 <p><xsl:apply-templates select="text()|*" mode="inline" />
 
  55                                 <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
 
  56                                 <xsl:if test="name()='pt'"> [przypis tłumacza]</xsl:if>
 
  57                                 <xsl:if test="name()='pr'"> [przypis redakcyjny]</xsl:if>
 
  58                                 <xsl:if test="name()='pe'"> [przypis edytorski]</xsl:if>
 
  62                                 <xsl:apply-templates select="text()|*" mode="inline" />
 
  73 <!-- ============================================================================== -->
 
  74 <!-- = MASTER TAG                                                                 = -->
 
  75 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
 
  76 <!-- ============================================================================== -->
 
  77 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
 
  78     <xsl:apply-templates select="nota_red" mode="special" />
 
  79     <xsl:if test="nazwa_utworu">
 
  81             <xsl:apply-templates select="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul" mode="header" />
 
  82             <xsl:call-template name="translators" />
 
  85     <xsl:apply-templates />
 
  89 <!-- ==================================================================================== -->
 
  90 <!-- = BLOCK TAGS                                                                       = -->
 
  91 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
 
  92 <!-- ==================================================================================== -->
 
  93 <xsl:template match="nota">
 
  94     <div class="note"><xsl:apply-templates /></div>
 
  97 <xsl:template match="lista_osob">
 
  98     <xsl:call-template name="section-anchor"/>
 
  99     <div class="person-list">
 
 100         <h3><xsl:value-of select="naglowek_listy" /></h3>
 
 102             <xsl:apply-templates select="lista_osoba" />
 
 107 <xsl:template match="dedykacja">
 
 108     <div class="dedication"><xsl:apply-templates /></div>
 
 111 <xsl:template match="ramka">
 
 112     <div class="frame"><xsl:apply-templates /></div>
 
 115 <xsl:template match="kwestia">
 
 116     <div class="kwestia">
 
 117         <xsl:apply-templates select="strofa|akap|didaskalia" />
 
 121 <xsl:template match="dlugi_cytat|poezja_cyt">
 
 122     <blockquote><xsl:apply-templates /></blockquote>
 
 125 <xsl:template match="motto">
 
 126     <xsl:call-template name="section-anchor"/>
 
 127     <div class="motto"><xsl:apply-templates /></div>
 
 130 <xsl:template match="ilustr" mode="inline">
 
 131     <xsl:apply-templates select="."/>
 
 134 <xsl:template match="ilustr">
 
 136         <xsl:attribute name="src">
 
 137             <xsl:value-of select="$gallery" /><xsl:value-of select="@src" />
 
 139         <xsl:attribute name="alt">
 
 140             <xsl:value-of select="@alt" />
 
 142         <xsl:attribute name="title">
 
 143             <xsl:value-of select="@alt" />
 
 148 <xsl:template match="animacja">
 
 149   <div class="animacja cycle-slideshow" data-cycle-pause-on-hover="true" data-cycle-next="> img" data-cycle-fx="fadeout" data-cycle-paused="true">
 
 150     <xsl:apply-templates/>
 
 155 <!-- ========================================== -->
 
 156 <!-- = PARAGRAPH TAGS                         = -->
 
 157 <!-- = (can contain inline and special tags)  = -->
 
 158 <!-- ========================================== -->
 
 160 <xsl:template match="autor_utworu" mode="header">
 
 161     <span class="author"><xsl:apply-templates mode="inline" /></span>
 
 164 <xsl:template match="nazwa_utworu" mode="header">
 
 165     <span class="title"><xsl:apply-templates mode="inline" /></span>
 
 168 <xsl:template match="dzielo_nadrzedne" mode="header">
 
 169     <span class="collection"><xsl:apply-templates mode="inline" /></span>
 
 172 <xsl:template match="podtytul" mode="header">
 
 173     <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
 
 176 <!-- Section headers (included in index)-->
 
 177 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
 
 178   <xsl:call-template name="section-anchor"/>
 
 179     <h2><xsl:apply-templates mode="inline" /></h2>
 
 182 <xsl:template match="naglowek_scena|naglowek_rozdzial">
 
 183     <xsl:call-template name="section-anchor"/>
 
 184     <h3><xsl:apply-templates mode="inline" /></h3>
 
 187 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
 
 188       <xsl:call-template name="section-anchor"/>
 
 189     <h4><xsl:apply-templates mode="inline" /></h4>
 
 192 <!-- Other paragraph tags -->
 
 193 <xsl:template match="miejsce_czas">
 
 194       <xsl:call-template name="section-anchor"/>
 
 195     <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
 
 198 <xsl:template match="didaskalia">
 
 199       <xsl:call-template name="section-anchor"/>
 
 200     <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
 
 203 <xsl:template match="lista_osoba">
 
 204     <li><xsl:apply-templates mode="inline" /></li>
 
 207 <xsl:template match="akap|akap_dialog|akap_cd">
 
 208     <p class="paragraph">
 
 209       <xsl:call-template name="section-anchor"/>
 
 210         <xsl:apply-templates mode="inline" />
 
 214 <xsl:template match="strofa" mode="inline">
 
 215     <xsl:apply-templates select="." />
 
 218 <xsl:template match="strofa">
 
 220       <xsl:call-template name="section-anchor"/>
 
 222             <xsl:when test="count(br) > 0">
 
 223                 <xsl:call-template name="verse">
 
 224                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
 
 225                     <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]" />
 
 227                 <xsl:for-each select="br">              
 
 228                                 <!-- Each BR tag "consumes" text after it -->
 
 229                     <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
 
 230                     <xsl:call-template name="verse">
 
 231                         <xsl:with-param name="verse-content"
 
 232                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
 
 233                         <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]" />
 
 238                 <xsl:call-template name="verse">
 
 239                     <xsl:with-param name="verse-content" select="text() | node()" />
 
 240                     <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej[1]" />
 
 247 <xsl:template name="verse">
 
 248     <xsl:param name="verse-content" />
 
 249     <xsl:param name="verse-type" />
 
 252             <xsl:when test="name($verse-type) = 'wers_akap'">
 
 253                 <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
 
 255             <xsl:when test="name($verse-type) = 'wers_wciety'">
 
 257                     <xsl:when test="$verse-content/@typ">
 
 258                         <xsl:attribute name="style">padding-left: <xsl:value-of select="$verse-content/@typ" />em</xsl:attribute>
 
 261                         <xsl:attribute name="style">padding-left: 1em</xsl:attribute>
 
 265             <xsl:when test="name($verse-type) = 'wers_cd'">
 
 266                 <xsl:attribute name="style">padding-left: 12em</xsl:attribute>
 
 268             <xsl:when test="name($verse-type) = 'wers_do_prawej'">
 
 269                 <xsl:attribute name="style">text-align: right</xsl:attribute>
 
 272         <xsl:apply-templates select="$verse-content" mode="inline" />
 
 276 <xsl:template match="motto_podpis">
 
 277     <xsl:call-template name="section-anchor"/>
 
 278     <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
 
 281 <xsl:template match="tabela|tabelka">
 
 282     <xsl:call-template name="section-anchor"/>
 
 284         <xsl:when test="@ramka = '1'">
 
 285             <table class="border"><xsl:apply-templates /></table>
 
 288             <table><xsl:apply-templates /></table>
 
 292 <xsl:template match="wiersz">
 
 293     <tr><xsl:apply-templates /></tr>
 
 295 <xsl:template match="kol">
 
 296     <td><xsl:apply-templates mode="inline" /></td>
 
 299 <xsl:template match="mat">
 
 300     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
 
 304 <!-- ================================================ -->
 
 305 <!-- = INLINE TAGS                                  = -->
 
 306 <!-- = (contain other inline tags and special tags) = -->
 
 307 <!-- ================================================ -->
 
 309 <xsl:template match="pa|pe|pr|pt" mode="inline">
 
 310     <a name="{concat('anchor-', generate-id(.))}" />
 
 311     <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>
 
 314 <!-- Other inline tags -->
 
 315 <xsl:template match="mat" mode="inline">
 
 316     <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
 
 319 <xsl:template match="didask_tekst" mode="inline">
 
 320     <em class="didaskalia"><xsl:apply-templates mode="inline" /></em>
 
 323 <xsl:template match="slowo_obce" mode="inline">
 
 324     <em class="foreign-word"><xsl:apply-templates mode="inline" /></em>
 
 327 <xsl:template match="tytul_dziela" mode="inline">
 
 328     <em class="book-title">
 
 329         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
 
 333 <xsl:template match="wyroznienie" mode="inline">
 
 334     <em class="author-emphasis"><xsl:apply-templates mode="inline" /></em>
 
 337 <xsl:template match="wieksze_odstepy" mode="inline">
 
 338     <em class="wieksze-odstepy"><xsl:apply-templates mode="inline" /></em>
 
 341 <xsl:template match="indeks_dolny" mode="inline">
 
 342     <sub><xsl:apply-templates mode="inline" /></sub>
 
 345 <xsl:template match="osoba" mode="inline">
 
 346     <em class="person"><xsl:apply-templates mode="inline" /></em>
 
 350 <!-- ============================================== -->
 
 351 <!-- = STANDALONE TAGS                            = -->
 
 352 <!-- = (cannot contain any other tags)            = -->
 
 353 <!-- ============================================== -->
 
 354 <xsl:template match="sekcja_swiatlo">
 
 355     <hr class="spacer" />
 
 358 <xsl:template match="sekcja_asterysk">
 
 359     <p class="spacer-asterisk">*</p>
 
 362 <xsl:template match="separator_linia">
 
 363     <hr class="spacer-line" />
 
 367 <!-- ================ -->
 
 368 <!-- = SPECIAL TAGS = -->
 
 369 <!-- ================ -->
 
 371 <xsl:template match="begin" mode="inline">
 
 372     <xsl:variable name="mnum" select="concat('m', substring(@id, 2))" />
 
 373     <a name="m{substring(@id, 2)}" class="theme-begin" fid="{substring(@id, 2)}">
 
 374         <xsl:value-of select="string(following::motyw[@id=$mnum]/text())" />
 
 378 <xsl:template match="end" mode="inline">
 
 379     <span class="theme-end" fid="{substring(@id, 2)}"> </span>
 
 382 <xsl:template match="begin|end">
 
 383     <xsl:apply-templates select='.' mode="inline" />
 
 386 <xsl:template match="motyw" mode="inline" />
 
 389 <xsl:template match="nota_red" mode="special">
 
 391         <xsl:apply-templates />
 
 396 <xsl:template name="translators">
 
 397     <xsl:if test="//dc:contributor.translator">
 
 398         <span class="translator">
 
 399             <xsl:text>tłum. </xsl:text>
 
 400             <xsl:for-each select="//dc:contributor.translator">
 
 401                 <xsl:if test="position() != 1">, </xsl:if>
 
 402                 <xsl:apply-templates mode="person" />
 
 408 <xsl:template match="text()" mode="person">
 
 409     <xsl:value-of select="wl:person_name(.)" />
 
 413 <!-- ================ -->
 
 414 <!-- = IGNORED TAGS = -->
 
 415 <!-- ================ -->
 
 416 <xsl:template match="extra|uwaga" />
 
 417 <xsl:template match="extra|uwaga" mode="inline" />
 
 419 <xsl:template match="nota_red" />
 
 420 <xsl:template match="abstrakt" />
 
 425 <xsl:template match="text()" />
 
 426 <xsl:template match="text()" mode="inline">
 
 427     <xsl:value-of select="wl:substitute_entities(.)" />
 
 433 <xsl:template name="section-anchor">
 
 435        this formula works as follows:
 
 436        - get all ancestors including self
 
 437        - choose the header (third one from root): utwor/book-type/header
 
 438        - get all preceding siblings
 
 440        - create an <a name="sec123"/> tag.
 
 442         <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />