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[a4paper, oneside, 11pt]{book}
 
  23             <xsl:when test="@old-morefloats">
 
  25                     \IfFileExists{morefloats.sty}{
 
  26                         \usepackage{morefloats}
 
  32                     \usepackage[maxfloats=64]{morefloats}
 
  37         <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
 
  38         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
 
  41             <cmd name="maketitle" />
 
  44                 <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
 
  45                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/autor_utworu" mode="title" />
 
  46                     <!-- title in master -->
 
  49                     <!-- look for author title in dc -->
 
  50                     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
 
  51                     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='firstdctitle' />
 
  54             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
  55             <xsl:apply-templates select="utwor" mode="part" />
 
  60 <xsl:template match="utwor" mode="part">
 
  61     <!-- title for empty dc -->
 
  63         <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
 
  64             <!-- title in master -->
 
  67             <!-- look for title in dc -->
 
  68             <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
 
  69             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
 
  73     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
 
  74     <xsl:apply-templates select="utwor" mode="part" />
 
  77 <!-- =================== -->
 
  78 <!-- = MAIN TITLE PAGE = -->
 
  79 <!-- = (from DC)       = -->
 
  80 <!-- =================== -->
 
  82 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
 
  83     <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
 
  86 <xsl:template match="rdf:RDF" mode="titlepage">
 
  87     <cmd name='title'><parm>
 
  88         <xsl:value-of select=".//dc:title/text()" />
 
  90     <cmd name='author'><parm>
 
  91         <xsl:value-of select="wl:person_name(.//dc:creator/text())" />
 
  96 <!-- ============== -->
 
  97 <!-- = BOOK TITLE = -->
 
  98 <!-- = (from DC)  = -->
 
  99 <!-- ============== -->
 
 101 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
 
 102     <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
 
 105 <xsl:template match="rdf:RDF" mode="dctitle">
 
 106     <cmd name="section*"><parm>
 
 107         <xsl:value-of select=".//dc:title/text()" />
 
 112 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
 
 113     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
 
 116 <xsl:template match="rdf:RDF" mode="firstdctitle">
 
 117     <cmd name="subsection*"><parm>
 
 118         <xsl:value-of select="wl:person_name(.//dc:creator/text())" />
 
 120     <cmd name="section*"><parm>
 
 121         <xsl:value-of select=".//dc:title/text()" />
 
 126 <!-- ============================================================================== -->
 
 127 <!-- = MASTER TAG                                                                 = -->
 
 128 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
 
 129 <!-- ============================================================================== -->
 
 131 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny">
 
 132     <xsl:apply-templates />
 
 137 <!-- ==================================================================================== -->
 
 138 <!-- = BLOCK TAGS                                                                       = -->
 
 139 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
 
 140 <!-- ==================================================================================== -->
 
 141 <xsl:template match="nota">
 
 143         <parm><xsl:apply-templates /></parm>
 
 147 <xsl:template match="lista_osob">
 
 148     <cmd name="par"><parm>
 
 150             <parm><xsl:value-of select="naglowek_listy" /></parm>
 
 153             <xsl:apply-templates select="lista_osoba" />
 
 158 <xsl:template match="dedykacja">
 
 160         <env name="flushright">
 
 161             <xsl:apply-templates/>
 
 166 <xsl:template match="kwestia">
 
 168         <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
 
 172 <xsl:template match="dlugi_cytat">
 
 173     <env name="quotation">
 
 174         <xsl:apply-templates />
 
 178 <xsl:template match="poezja_cyt">
 
 180         <xsl:apply-templates />
 
 184 <xsl:template match="motto">
 
 186         <xsl:apply-templates mode="inline" />
 
 191 <!-- ========================================== -->
 
 192 <!-- = PARAGRAPH TAGS                         = -->
 
 193 <!-- = (can contain inline and special tags)  = -->
 
 194 <!-- ========================================== -->
 
 196 <!-- only in root -->
 
 197 <xsl:template match="autor_utworu" mode="title">
 
 198     <cmd name="subsection*"><parm>
 
 199         <xsl:apply-templates mode="inline" />
 
 203 <xsl:template match="nazwa_utworu">
 
 204     <cmd name="section*"><parm>
 
 205         <xsl:apply-templates mode="inline" />
 
 209 <!-- Section headers (included in index)-->
 
 210 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
 
 211     <cmd name="subsection*">
 
 212         <parm><xsl:apply-templates mode="inline" /></parm>
 
 216 <xsl:template match="naglowek_scena|naglowek_rozdzial">
 
 217     <cmd name="subsubsection*">
 
 218         <parm><xsl:apply-templates mode="inline" /></parm>
 
 222 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
 
 224         <parm><xsl:apply-templates mode="inline" /></parm>
 
 225     </cmd><cmd name="nopagebreak" />
 
 228 <!-- Other paragraph tags -->
 
 229 <xsl:template match="miejsce_czas">
 
 230     <cmd name="par"><parm>
 
 232             <parm><xsl:apply-templates mode="inline" /></parm>
 
 237 <xsl:template match="didaskalia">
 
 238     <cmd name="par"><parm>
 
 240             <parm><xsl:apply-templates mode="inline" /></parm>
 
 245 <xsl:template match="lista_osoba">
 
 246     <cmd name="item"><parm>
 
 247         <xsl:apply-templates mode="inline" />
 
 251 <xsl:template match="akap|akap_dialog|akap_cd">
 
 252     <cmd name="par"><parm>
 
 253         <xsl:apply-templates mode="inline" />
 
 257 <xsl:template match="strofa">
 
 258 <cmd name="par"><parm><cmd name="noindent"><parm>
 
 260         <xsl:when test="count(br) > 0">
 
 261             <xsl:call-template name="verse">
 
 262                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
 
 263                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
 
 265             <xsl:for-each select="br">
 
 266                 <TeXML escape="0">\\{}</TeXML>
 
 267                 <!-- Each BR tag "consumes" text after it -->
 
 268                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
 
 269                 <xsl:call-template name="verse">
 
 270                     <xsl:with-param name="verse-content"
 
 271                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
 
 272                     <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]" />
 
 277             <xsl:call-template name="verse">
 
 278                 <xsl:with-param name="verse-content" select="text() | node()" />
 
 279                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
 
 283     <cmd name="vspace"><parm>1em</parm></cmd>
 
 284 </parm></cmd></parm></cmd>
 
 288 <xsl:template name="verse">
 
 289     <xsl:param name="verse-content" />
 
 290     <xsl:param name="verse-type" />
 
 291         <xsl:choose><xsl:when test="name($verse-type) = 'wers_akap'"><cmd name="hspace" ><parm>1em</parm></cmd></xsl:when>
 
 292             <xsl:when test="name($verse-type) = 'wers_wciety'">
 
 294                     <xsl:when test="string($verse-content/@typ)">
 
 295                         <cmd name="hspace" ><parm><xsl:value-of select="$verse-content/@typ" />em</parm></cmd>
 
 298                         <cmd name="hspace" ><parm>1em</parm></cmd>
 
 302             <xsl:when test="name($verse-type) = 'wers_cd'">
 
 303                 <cmd name="hspace" ><parm>8em</parm></cmd>
 
 306         <xsl:apply-templates select="$verse-content" mode="inline" />
 
 309 <xsl:template match="motto_podpis">
 
 311         <env name="flushright">
 
 312             <xsl:apply-templates mode="inline"/>
 
 317 <!-- ================================================ -->
 
 318 <!-- = INLINE TAGS                                  = -->
 
 319 <!-- = (contain other inline tags and special tags) = -->
 
 320 <!-- ================================================ -->
 
 323 <xsl:template match="pa|pe|pr|pt" mode="inline">
 
 324     <cmd name="footnote"><parm><xsl:apply-templates mode="inline" /></parm></cmd>
 
 327 <!-- Other inline tags -->
 
 328 <xsl:template match="mat" mode="inline">
 
 329     <math><xsl:apply-templates mode="inline" /></math>
 
 332 <xsl:template match="didask_tekst" mode="inline">
 
 333     <cmd name="emph"><parm><xsl:apply-templates mode="inline" /></parm></cmd>
 
 336 <xsl:template match="slowo_obce" mode="inline">
 
 337     <cmd name="emph"><parm><xsl:apply-templates mode="inline" /></parm></cmd>
 
 340 <xsl:template match="tytul_dziela" mode="inline">
 
 341     <cmd name="emph"><parm>
 
 342         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
 
 346 <xsl:template match="wyroznienie" mode="inline">
 
 347     <cmd name="emph"><parm><xsl:apply-templates mode="inline" /></parm></cmd>
 
 350 <xsl:template match="osoba" mode="inline">
 
 351     <cmd name="textsc"><parm><xsl:apply-templates mode="inline" /></parm></cmd>
 
 355 <!-- ============================================== -->
 
 356 <!-- = STANDALONE TAGS                            = -->
 
 357 <!-- = (cannot contain any other tags)            = -->
 
 358 <!-- ============================================== -->
 
 359 <xsl:template match="sekcja_swiatlo">
 
 360     <cmd name="hspace"><parm>30pt</parm></cmd>
 
 363 <xsl:template match="sekcja_asterysk">
 
 364     <!-- TODO: padding? -->
 
 365     <cmd name="par"><parm>*</parm></cmd>
 
 368 <xsl:template match="separator_linia">
 
 374 <!-- ================ -->
 
 375 <!-- = SPECIAL TAGS = -->
 
 376 <!-- ================ -->
 
 380 <xsl:template match="begin|end|motyw">
 
 381     <xsl:apply-templates select='.' mode="inline" />
 
 384 <xsl:template match="begin" mode="inline" />
 
 385 <xsl:template match="end" mode="inline" />
 
 387 <xsl:template match="motyw" mode="inline">
 
 389     <cmd name="marginpar">
 
 391             <cmd name="vspace"><parm>-8pt</parm></cmd>
 
 392             <xsl:if test="@moved">
 
 393                 <cmd name="vspace"><parm>-<xsl:value-of select="@moved" /><cmd name="baselineskip" /></parm></cmd>
 
 395             <cmd name="raggedright"><parm>
 
 396                 <cmd name="hspace"><parm>0pt</parm></cmd>
 
 397                 <cmd name="footnotesize"><parm>
 
 398                     <cmd name="color"><parm>theme</parm><parm>
 
 399                         <xsl:value-of select="." />
 
 408 <!-- ============== -->
 
 409 <!-- = ADDED TAGS = -->
 
 410 <!-- ============== -->
 
 413 <xsl:template match="dywiz" mode="inline">
 
 417 <xsl:template match="nbsp" mode="inline">
 
 421 <!-- ================ -->
 
 422 <!-- = IGNORED TAGS = -->
 
 423 <!-- ================ -->
 
 424 <xsl:template match="extra|uwaga" />
 
 425 <xsl:template match="extra|uwaga" mode="inline" />
 
 431 <xsl:template match="text()" />
 
 432 <xsl:template match="text()" mode="inline">
 
 433     <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
 
 434       <xsl:text> </xsl:text>
 
 437     <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
 
 439     <xsl:if test="following-sibling::node() and wl:ends_white(.)">
 
 440       <xsl:text> </xsl:text>