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/"
 
  11     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
 
  13 <xsl:output encoding="utf-8" indent="yes" version="2.0" />
 
  15 <xsl:template match="utwor">
 
  16     <TeXML xmlns="http://getfo.sourceforge.net/texml/ns1">
 
  18         \documentclass[<xsl:value-of select="@customizations"/>]{wl}
 
  20         <!-- flags and values set on root -->
 
  22         \newif\ifflaglessadvertising
 
  24         <xsl:for-each select="@*[starts-with(name(), 'flag-')]">
 
  26                 <xsl:attribute name="name"><xsl:value-of select="wl:texcommand(name())" />true</xsl:attribute>
 
  30         <xsl:for-each select="@*[starts-with(name(), 'data-')]">
 
  32                 \def\<xsl:value-of select="wl:texcommand(name())" />{<TeXML escape="1"><xsl:value-of select="."/></TeXML>}
 
  38             <xsl:when test="@morefloats = 'new'">
 
  40                     \usepackage[maxfloats=64]{morefloats}
 
  43             <xsl:when test="@morefloats = 'old'">
 
  45                     \usepackage{morefloats}
 
  48             <xsl:when test="@morefloats = 'none'" />
 
  51                     \IfFileExists{morefloats.sty}{
 
  52                         \usepackage{morefloats}
 
  58         <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
 
  59         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
 
  62             <xsl:if test="@data-cover-width">
 
  63                 <cmd name="makecover">
 
  64                     <parm><xsl:value-of select="210 * @data-cover-width div @data-cover-height" />mm</parm>
 
  68             <cmd name="maketitle" />
 
  70             <cmd name="tytul"><parm>
 
  72                 <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
 
  73                     <!-- title in master -->
 
  74                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/autor_utworu" mode="title" />
 
  75                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/dzielo_nadrzedne" mode="title" />
 
  76                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="title" />
 
  77                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/podtytul" mode="title" />
 
  78                     <!-- dc in master or not -->
 
  79                     <cmd name="translatorsline" />
 
  82                     <!-- look for author title in dc -->
 
  83                     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
 
  84                     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='firstdctitle' />
 
  88             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
  89             <xsl:apply-templates select="utwor" mode="part" />
 
  93                 <xsl:if test="@data-cover-by">Okładka na podstawie: 
 
  95                     <xsl:when test="@data-cover-source">
 
  96                         \href{\datacoversource}{\datacoverby}
 
 106             <cmd name="editorialsection" />
 
 111 <xsl:template match="utwor" mode="part">
 
 112     <cmd name="tytul"><parm>
 
 114         <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
 
 115             <!-- title in master -->
 
 116             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="title" />
 
 117             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/podtytul" mode="title" />
 
 120             <!-- look for title in dc -->
 
 121             <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
 
 122             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
 
 127     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
 128     <xsl:apply-templates select="utwor" mode="part" />
 
 131 <!-- =================== -->
 
 132 <!-- = MAIN TITLE PAGE = -->
 
 133 <!-- = (from DC)       = -->
 
 134 <!-- =================== -->
 
 136 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
 
 137     <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
 
 140 <xsl:template match="rdf:RDF" mode="titlepage">
 
 142         \def\authors{<xsl:call-template name="authors" />}
 
 144         \title{<xsl:apply-templates select=".//dc:title" mode="inline" />}
 
 145         \def\translatorsline{<xsl:call-template name="translators" />}
 
 147         \def\bookurl{<xsl:value-of select=".//dc:identifier.url" />}
 
 149         \def\rightsinfo{Ten utwór nie jest chroniony prawem autorskim i~znajduje się w~domenie
 
 150             publicznej, co oznacza że możesz go swobodnie wykorzystywać, publikować
 
 151             i~rozpowszechniać. Jeśli utwór opatrzony jest dodatkowymi materiałami
 
 152             (przypisy, motywy literackie etc.), które podlegają prawu autorskiemu, to
 
 153             te dodatkowe materiały udostępnione są na licencji
 
 154             \href{http://creativecommons.org/licenses/by-sa/3.0/}{Creative Commons
 
 155             Uznanie Autorstwa – Na Tych Samych Warunkach 3.0 PL}.}
 
 156         <xsl:if test=".//dc:rights.license">
 
 157             \def\rightsinfo{Ten utwór jest udostepniony na licencji
 
 158             \href{<xsl:value-of select=".//dc:rights.license" />}{<xsl:value-of select=".//dc:rights" />}.}
 
 162             <xsl:if test=".//dc:source">
 
 163                 Tekst opracowany na podstawie: <xsl:apply-templates select=".//dc:source" mode="inline" />
 
 166         \def\description{<xsl:apply-templates select=".//dc:description" mode="inline" />}
 
 167         \def\editors{<xsl:call-template name="editors" />}
 
 172 <!-- ============== -->
 
 173 <!-- = BOOK TITLE = -->
 
 174 <!-- = (from DC)  = -->
 
 175 <!-- ============== -->
 
 177 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
 
 178     <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
 
 181 <xsl:template match="rdf:RDF" mode="dctitle">
 
 182     <cmd name="nazwapodutworu"><parm>
 
 183         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
 
 187 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
 
 188     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
 
 191 <xsl:template match="rdf:RDF" mode="firstdctitle">
 
 192     <cmd name="autorutworu"><parm><cmd name="authors"/></parm></cmd>
 
 193     <cmd name="nazwautworu"><parm>
 
 194         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
 
 196     <cmd name="translatorsline" />
 
 200 <!-- ============================================================================== -->
 
 201 <!-- = MASTER TAG                                                                 = -->
 
 202 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
 
 203 <!-- ============================================================================== -->
 
 204 <!-- ==================================================================================== -->
 
 205 <!-- = BLOCK TAGS                                                                       = -->
 
 206 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
 
 207 <!-- ==================================================================================== -->
 
 210     match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|nota|dedykacja|dlugi_cytat|poezja_cyt|motto">
 
 212         <xsl:attribute name="name">
 
 213             <xsl:value-of select="wl:texcommand(name())" />
 
 215         <parm><xsl:apply-templates/></parm>
 
 219 <xsl:template match="lista_osob">
 
 220     <cmd name="listaosob">
 
 221         <parm><xsl:apply-templates select="naglowek_listy" /></parm>
 
 222         <parm><xsl:apply-templates select="lista_osoba" /></parm>
 
 226 <xsl:template match="kwestia">
 
 228         <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
 
 233 <!-- ========================================== -->
 
 234 <!-- = PARAGRAPH TAGS                         = -->
 
 235 <!-- = (can contain inline and special tags)  = -->
 
 236 <!-- ========================================== -->
 
 238 <!-- only in root -->
 
 240     match="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul"
 
 243         <xsl:attribute name="name">
 
 244             <xsl:value-of select="wl:texcommand(name())" />
 
 246         <parm><xsl:apply-templates mode="inline"/></parm>
 
 252     match="naglowek_akt|naglowek_czesc|srodtytul|naglowek_osoba|naglowek_podrozdzial|naglowek_scena|naglowek_rozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_dialog|akap_cd|motto_podpis|naglowek_listy">
 
 254         <xsl:attribute name="name">
 
 255             <xsl:value-of select="wl:texcommand(name())" />
 
 257         <parm><xsl:apply-templates mode="inline"/></parm>
 
 261 <xsl:template match="strofa">
 
 262   <cmd name="strofa"><parm>
 
 264         <xsl:when test="count(br) > 0">
 
 265             <xsl:call-template name="verse">
 
 266                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
 
 267                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
 
 269             <xsl:for-each select="br">
 
 270                 <TeXML escape="0">\\{}</TeXML>
 
 271                 <!-- Each BR tag "consumes" text after it -->
 
 272                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
 
 273                 <xsl:call-template name="verse">
 
 274                     <xsl:with-param name="verse-content"
 
 275                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
 
 276                     <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')][1]" />
 
 281             <xsl:call-template name="verse">
 
 282                 <xsl:with-param name="verse-content" select="text() | node()" />
 
 283                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
 
 291 <xsl:template name="verse">
 
 292     <xsl:param name="verse-content" />
 
 293     <xsl:param name="verse-type" />
 
 296         <xsl:attribute name="name">
 
 298                 <xsl:when test="$verse-type != ''">
 
 299                     <xsl:value-of select='wl:texcommand(name($verse-type))' />
 
 301                 <xsl:otherwise>wers</xsl:otherwise>
 
 304         <xsl:if test="string($verse-content/@typ)">
 
 305             <opt><xsl:value-of select="$verse-content/@typ" />em</opt>
 
 307         <parm><xsl:apply-templates select="$verse-content" mode="inline"/></parm>
 
 311 <!-- ================================================ -->
 
 312 <!-- = INLINE TAGS                                  = -->
 
 313 <!-- = (contain other inline tags and special tags) = -->
 
 314 <!-- ================================================ -->
 
 316 <xsl:template mode="inline"
 
 317     match="pa|pe|pr|pt|mat|didask_tekst|slowo_obce|wyroznienie|osoba">
 
 319         <xsl:attribute name="name">
 
 320             <xsl:value-of select="wl:texcommand(name())" />
 
 322         <parm><xsl:apply-templates mode="inline"/></parm>
 
 328 <xsl:template match="tytul_dziela" mode="inline">
 
 329     <cmd name="tytuldziela"><parm>
 
 330         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
 
 336 <!-- ============================================== -->
 
 337 <!-- = STANDALONE TAGS                            = -->
 
 338 <!-- = (cannot contain any other tags)            = -->
 
 339 <!-- ============================================== -->
 
 341     match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
 
 343         <xsl:attribute name="name">
 
 344             <xsl:value-of select="wl:texcommand(name())" />
 
 350 <!-- ================ -->
 
 351 <!-- = SPECIAL TAGS = -->
 
 352 <!-- ================ -->
 
 356 <xsl:template match="begin|end|motyw">
 
 357     <xsl:apply-templates select='.' mode="inline" />
 
 360 <xsl:template match="begin" mode="inline" />
 
 361 <xsl:template match="end" mode="inline" />
 
 363 <xsl:template match="motyw" mode="inline">
 
 365         <xsl:if test="@moved">
 
 366             <opt name="moved"><xsl:value-of select="@moved" /></opt>
 
 368         <parm><xsl:apply-templates mode="inline" /></parm>
 
 372 <xsl:template name="authors">
 
 373     <xsl:for-each select=".//dc:creator_parsed">
 
 374         <xsl:if test="position() != 1">, </xsl:if>
 
 375         <xsl:apply-templates mode="inline" />
 
 379 <xsl:template name="editors">
 
 380     <xsl:if test="//dc:contributor.editor_parsed|//dc:contributor.technical_editor_parsed">
 
 381         <xsl:text>Opracowanie redakcyjne: </xsl:text>
 
 382         <xsl:for-each select="//dc:contributor.editor_parsed|//dc:contributor.technical_editor_parsed[not(//dc:contributor.editor_parsed/text()=text())]">
 
 383             <xsl:sort select="@sortkey" />
 
 384             <xsl:if test="position() != 1">, </xsl:if>
 
 385             <xsl:apply-templates mode="inline" />
 
 390 <xsl:template name="translators">
 
 391     <xsl:if test=".//dc:contributor.translator_parsed">
 
 392         <cmd name='translator'><parm>
 
 393             <xsl:for-each select=".//dc:contributor.translator_parsed">
 
 394                 <xsl:if test="position() != 1">, </xsl:if>
 
 395                 <xsl:apply-templates mode="inline" />
 
 402 <!-- ============== -->
 
 403 <!-- = ADDED TAGS = -->
 
 404 <!-- ============== -->
 
 407 <xsl:template match="dywiz" mode="inline">
 
 411 <xsl:template match="nbsp" mode="inline">
 
 415 <xsl:template match="alien" mode="inline">
 
 418         <xsl:apply-templates mode="inline" />
 
 422 <!-- ================ -->
 
 423 <!-- = IGNORED TAGS = -->
 
 424 <!-- ================ -->
 
 425 <xsl:template match="extra|uwaga" />
 
 426 <xsl:template match="extra|uwaga" mode="inline" />
 
 428 <xsl:template match="nota_red" />
 
 433 <xsl:template match="text()" />
 
 434 <xsl:template match="text()" mode="inline">
 
 435     <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
 
 436       <xsl:text> </xsl:text>
 
 439     <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
 
 441     <xsl:if test="following-sibling::node() and wl:ends_white(.)">
 
 442       <xsl:text> </xsl:text>