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"/>]{<xsl:value-of select="@documentclass"/>}
 
  20         <!-- flags and values set on root -->
 
  22         \newif\ifflaglessadvertising
 
  23         <xsl:for-each select="@*[starts-with(name(), 'flag-')]">
 
  25                 <xsl:attribute name="name"><xsl:value-of select="wl:texcommand(name())" />true</xsl:attribute>
 
  29         <xsl:for-each select="@*[starts-with(name(), 'data-')]">
 
  31                 \def\<xsl:value-of select="wl:texcommand(name())" />{<TeXML escape="1"><xsl:value-of select="."/></TeXML>}
 
  36 <!-- WHAT. THE. FUCK. -->
 
  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' />
 
  65                 <xsl:when test="//dc:contributor">Thank you for your contribution, <xsl:value-of select="//dc:contributor"/>!</xsl:when>
 
  66                 <xsl:otherwise>Thank you for all your contributions!</xsl:otherwise>
 
  70             <!-- XXX fix this not to hardcode width -->
 
  71             <!--<xsl:if test="@data-cover-width">
 
  72                 <cmd name="makecover">
 
  74                     <parm><xsl:value-of select="210 * @data-cover-height div @data-cover-width" />mm</parm>
 
  77             <cmd name="makecover" />
 
  78             <cmd name="maketitle" />
 
  82                 <xsl:if test="@data-cover-by">Obraz na okładce:
 
  84                     <xsl:when test="@data-cover-source">
 
  85                         \href{\datacoversource}{\datacoverby}.
 
  95             <cmd name="editorialsection" />
 
  96             <cmd name="spistresci" />
 
  98             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
  99             <xsl:apply-templates select="utwor" mode="part" />
 
 105 <xsl:template match="utwor" mode="part">
 
 106     <cmd name="newpage" />
 
 107     <cmd name="tytul"><parm>
 
 110     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/motyw" mode="inline"/>
 
 113         <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
 
 114             <!-- title in master -->
 
 115             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/dzielo_nadrzedne" mode="title" />
 
 116             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/autor_utworu" mode="title" />
 
 117             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="title" />
 
 118             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/podtytul" mode="title" />
 
 121             <!-- look for title in dc -->
 
 122             <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
 
 123             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
 
 128     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
 129     <xsl:apply-templates select="utwor" mode="part" />
 
 132 <!-- =================== -->
 
 133 <!-- = MAIN TITLE PAGE = -->
 
 134 <!-- = (from DC)       = -->
 
 135 <!-- =================== -->
 
 137 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
 
 138     <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
 
 141 <xsl:template match="rdf:RDF" mode="titlepage">
 
 143         \def\authors{<xsl:call-template name="authors" />}
 
 145         \title{<xsl:apply-templates select=".//dc:title" mode="inline" />}
 
 147         \let\theauthor\@author
 
 151         \def\translatorsline{<xsl:call-template name="translators" />}
 
 153         \def\bookurl{<xsl:value-of select=".//dc:identifier.url" />}
 
 155         \def\rightsinfo{Ten utwór nie jest chroniony prawem autorskim i~znajduje się w~domenie
 
 156             publicznej, co oznacza że możesz go swobodnie wykorzystywać, publikować
 
 157             i~rozpowszechniać. Jeśli utwór opatrzony jest dodatkowymi materiałami
 
 158             (przypisy, motywy literackie etc.), które podlegają prawu autorskiemu, to
 
 159             te dodatkowe materiały udostępnione są na licencji
 
 160             \href{http://creativecommons.org/licenses/by-sa/3.0/}{Creative Commons
 
 161             Uznanie Autorstwa – Na Tych Samych Warunkach 3.0 PL}.}
 
 162         <xsl:if test=".//dc:rights.license">
 
 163             \def\rightsinfo{Ta książka jest udostpęniona na licencji
 
 164             \href{<xsl:value-of select=".//dc:rights.license" />}{<xsl:value-of select=".//dc:rights" />}.}
 
 168             <xsl:if test=".//dc:source">
 
 169                 Tekst opracowany na podstawie: <xsl:apply-templates select=".//dc:source" mode="inline" />
 
 172         \def\description{<xsl:apply-templates select=".//dc:description" mode="inline" />}
 
 173         \def\editors{<xsl:call-template name="editors" />}
 
 178 <!-- ============== -->
 
 179 <!-- = BOOK TITLE = -->
 
 180 <!-- = (from DC)  = -->
 
 181 <!-- ============== -->
 
 183 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
 
 184     <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
 
 187 <xsl:template match="rdf:RDF" mode="dctitle">
 
 188     <cmd name="nazwapodutworu"><parm>
 
 189         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
 
 193 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
 
 194     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
 
 197 <xsl:template match="rdf:RDF" mode="firstdctitle">
 
 198     <cmd name="autorutworu"><parm><cmd name="authors"/></parm></cmd>
 
 199     <cmd name="nazwautworu"><parm>
 
 200         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
 
 202     <cmd name="translatorsline" />
 
 206 <!-- ============================================================================== -->
 
 207 <!-- = MASTER TAG                                                                 = -->
 
 208 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
 
 209 <!-- ============================================================================== -->
 
 210 <!-- ==================================================================================== -->
 
 211 <!-- = BLOCK TAGS                                                                       = -->
 
 212 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
 
 213 <!-- ==================================================================================== -->
 
 216     match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|nota|dedykacja|dlugi_cytat|poezja_cyt|motto">
 
 218         <xsl:attribute name="name">
 
 219             <xsl:value-of select="wl:texcommand(name())" />
 
 221         <parm><xsl:apply-templates/></parm>
 
 225 <xsl:template match="lista_osob">
 
 226     <cmd name="listaosob">
 
 227         <parm><xsl:apply-templates select="naglowek_listy" /></parm>
 
 228         <parm><xsl:apply-templates select="lista_osoba" /></parm>
 
 232 <xsl:template match="kwestia">
 
 234         <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
 
 239 <!-- ========================================== -->
 
 240 <!-- = PARAGRAPH TAGS                         = -->
 
 241 <!-- = (can contain inline and special tags)  = -->
 
 242 <!-- ========================================== -->
 
 244 <!-- only in root -->
 
 246     match="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul"
 
 249         <xsl:attribute name="name">
 
 250             <xsl:value-of select="wl:texcommand(name())" />
 
 252         <parm><xsl:apply-templates mode="inline"/></parm>
 
 256 <xsl:template match="autor_rozdzialu">
 
 260     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|lista|nota_red">
 
 261   <xsl:if test="name(following-sibling::*[1])='autor_rozdzialu'">
 
 262     <cmd name="autorrozdzialu"><parm><xsl:value-of select="following-sibling::*[1]/text()"/></parm></cmd>
 
 265         <xsl:attribute name="name">
 
 266             <xsl:value-of select="wl:texcommand(name())" />
 
 268         <parm><xsl:apply-templates mode="inline"/></parm>
 
 272 <xsl:template match="strofa">
 
 273   <cmd name="strofa"><parm>
 
 275         <xsl:when test="count(br) > 0">
 
 276             <xsl:call-template name="verse">
 
 277                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
 
 278                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
 
 280             <xsl:for-each select="br">
 
 281                 <TeXML escape="0">\\{}</TeXML>
 
 282                 <!-- Each BR tag "consumes" text after it -->
 
 283                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
 
 284                 <xsl:call-template name="verse">
 
 285                     <xsl:with-param name="verse-content"
 
 286                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
 
 287                     <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]" />
 
 292             <xsl:call-template name="verse">
 
 293                 <xsl:with-param name="verse-content" select="text() | node()" />
 
 294                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
 
 302 <xsl:template match="link">
 
 304     <parm><xsl:value-of select="@url"/></parm>
 
 305     <parm><xsl:apply-templates mode="inline"/></parm>
 
 310 <xsl:template name="verse">
 
 311     <xsl:param name="verse-content" />
 
 312     <xsl:param name="verse-type" />
 
 315         <xsl:attribute name="name">
 
 317                 <xsl:when test="$verse-type != ''">
 
 318                     <xsl:value-of select='wl:texcommand(name($verse-type))' />
 
 320                 <xsl:otherwise>wers</xsl:otherwise>
 
 323         <xsl:if test="string($verse-content/@typ)">
 
 324             <opt><xsl:value-of select="$verse-content/@typ" />em</opt>
 
 326         <parm><xsl:apply-templates select="$verse-content" mode="inline"/></parm>
 
 330 <!-- ================================================ -->
 
 331 <!-- = INLINE TAGS                                  = -->
 
 332 <!-- = (contain other inline tags and special tags) = -->
 
 333 <!-- ================================================ -->
 
 335 <xsl:template mode="inline"
 
 336     match="pa|pe|pr|pt|mat|didask_tekst|slowo_obce|wyroznienie|osoba|punkt|www|nota_red">
 
 338         <xsl:attribute name="name">
 
 339             <xsl:value-of select="wl:texcommand(name())" />
 
 341         <parm><xsl:apply-templates mode="inline"/></parm>
 
 345 <xsl:template mode="inline"
 
 348         <xsl:attribute name="name">
 
 349             <xsl:value-of select="wl:texcommand(name())" />
 
 351         <xsl:apply-templates mode="inline"/>
 
 355     match="wyimek_extra">
 
 357         <xsl:attribute name="name">
 
 358             <xsl:value-of select="wl:texcommand(name())" />
 
 360         <xsl:apply-templates mode="inline"/>
 
 367 <xsl:template match="tytul_dziela" mode="inline">
 
 368     <cmd name="tytuldziela"><parm>
 
 369         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
 
 375 <!-- ============================================== -->
 
 376 <!-- = STANDALONE TAGS                            = -->
 
 377 <!-- = (cannot contain any other tags)            = -->
 
 378 <!-- ============================================== -->
 
 380     match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
 
 382         <xsl:attribute name="name">
 
 383             <xsl:value-of select="wl:texcommand(name())" />
 
 388 <xsl:strip-space elements="ilustr"/>
 
 389 <xsl:template match="ilustr">
 
 391         <xsl:attribute name="name">
 
 392             <xsl:value-of select="wl:texcommand(name())" />
 
 395           <opt><TeXML ecape="0"><xsl:value-of select="normalize-space(@opt)" /></TeXML></opt>
 
 397         <parm><TeXML escape="0"><xsl:value-of select="normalize-space(@src)" /></TeXML></parm>
 
 398         <parm><xsl:apply-templates mode="inline" /></parm>
 
 402 <xsl:template match="@*|node()" mode="identity">
 
 404     <xsl:apply-templates select="@*|node()" mode="identity"/>
 
 410 <xsl:template match="dmath">
 
 412     <xsl:apply-templates mode="identity"/>
 
 416 <xsl:template match="math" mode="inline">
 
 418     <xsl:apply-templates mode="identity"/>
 
 422 <xsl:template match="latex">
 
 424     <xsl:for-each select="text()">
 
 425       <xsl:value-of select="normalize-space(.)"/>
 
 430 <xsl:template match="latex" mode="inline">
 
 432     <xsl:for-each select="text()">
 
 433       <xsl:value-of select="normalize-space(.)"/>
 
 439 <xsl:template match="tablewrap">
 
 440   <cmd name="begin"><parm>table</parm><opt>h!</opt></cmd>
 
 441   <xsl:apply-templates select="table"/>
 
 443   <cmd name="caption*"><parm>
 
 444     <xsl:apply-templates select="akap"/>
 
 446   <cmd name="end"><parm>table</parm></cmd>
 
 449 <xsl:template match="table">
 
 450   <xsl:if test="@caption">
 
 452       <cmd name="caption*"><parm>
 
 454         <cmd name="Large"/><xsl:value-of select="@caption"/>
 
 457     <env name="tabularx">
 
 458       <parm><cmd name="textwidth"/></parm>
 
 459         <parm><xsl:value-of select="@spec"/></parm>
 
 460         <xsl:apply-templates />
 
 464 <xsl:template match="r">
 
 465     <xsl:apply-templates />
 
 466     <spec cat="esc"/><spec cat="esc"/>
 
 468 <xsl:template match="c">
 
 469     <cmd name="footnotesize"/>
 
 470     <xsl:apply-templates mode="inline"/>
 
 471     <xsl:if test="position() < last()-1">
 
 475 <xsl:template match="hr">
 
 479 <!-- ================ -->
 
 480 <!-- = SPECIAL TAGS = -->
 
 481 <!-- ================ -->
 
 485 <xsl:template match="begin|end|motyw">
 
 486     <xsl:apply-templates select='.' mode="inline" />
 
 489 <xsl:template match="begin" mode="inline" />
 
 490 <xsl:template match="end" mode="inline" />
 
 492 <xsl:template match="motyw" mode="inline">
 
 494         <xsl:if test="@moved">
 
 495             <opt name="moved"><xsl:value-of select="@moved" /></opt>
 
 497         <parm><xsl:apply-templates mode="inline" /></parm>
 
 501 <xsl:template name="authors">
 
 502     <xsl:for-each select=".//dc:creator_parsed">
 
 503         <xsl:if test="position() != 1">, </xsl:if>
 
 504         <xsl:apply-templates mode="inline" />
 
 508 <xsl:template name="editors">
 
 509     <xsl:if test=".//dc:contributor.editor_parsed|.//dc:contributor.technical_editor_parsed">
 
 510         <xsl:text>Redakcja techniczna: </xsl:text>
 
 511         <xsl:for-each select=".//dc:contributor.editor_parsed|.//dc:contributor.technical_editor_parsed[not(.//dc:contributor.editor_parsed/text()=text())]">
 
 512             <!--xsl:sort select="@sortkey" /-->
 
 513             <xsl:if test="position() != 1">, </xsl:if>
 
 514             <xsl:apply-templates mode="inline" />
 
 519 <xsl:template name="translators">
 
 520     <xsl:if test=".//dc:contributor.translator_parsed">
 
 521         <cmd name='translator'><parm>
 
 522             <xsl:for-each select=".//dc:contributor.translator_parsed">
 
 523                 <xsl:if test="position() != 1">, </xsl:if>
 
 524                 <xsl:apply-templates mode="inline" />
 
 531 <!-- ============== -->
 
 532 <!-- = ADDED TAGS = -->
 
 533 <!-- ============== -->
 
 536 <xsl:template match="dywiz" mode="inline">
 
 540 <xsl:template match="nbsp" mode="inline">
 
 544 <xsl:template match="alien" mode="inline">
 
 547         <xsl:apply-templates mode="inline" />
 
 551 <!-- ================ -->
 
 552 <!-- = IGNORED TAGS = -->
 
 553 <!-- ================ -->
 
 554 <xsl:template match="extra|uwaga" />
 
 555 <xsl:template match="extra|uwaga" mode="inline" />
 
 557 <!-- make it a command: <xsl:template match="nota_red" />-->
 
 563 <xsl:template match="text()" />
 
 564 <xsl:template match="text()" mode="inline">
 
 565     <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
 
 566       <xsl:text> </xsl:text>
 
 569     <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
 
 571     <xsl:if test="following-sibling::node() and wl:ends_white(.)">
 
 572       <xsl:text> </xsl:text>