Add funders info.
[librarian.git] / librarian / pdf / wl2tex.xslt
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3
4    This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
5    Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6
7 -->
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#" >
12
13 <xsl:output encoding="utf-8" indent="yes" version="2.0" />
14
15 <xsl:template match="utwor">
16     <TeXML xmlns="http://getfo.sourceforge.net/texml/ns1">
17         <TeXML escape="0">
18         \documentclass[<xsl:value-of select="@customizations"/>]{wl}
19
20         <!-- flags and values set on root -->
21
22         \newif\ifflaglessadvertising
23         <xsl:for-each select="@*[starts-with(name(), 'flag-')]">
24             <cmd>
25                 <xsl:attribute name="name"><xsl:value-of select="wl:texcommand(name())" />true</xsl:attribute>
26             </cmd>
27         </xsl:for-each>
28
29         <xsl:for-each select="@*[starts-with(name(), 'data-')]">
30             <TeXML escape="0">
31                 \def\<xsl:value-of select="wl:texcommand(name())" />{<TeXML escape="1"><xsl:value-of select="."/></TeXML>}
32             </TeXML>
33         </xsl:for-each>
34         </TeXML>
35
36         <xsl:choose>
37             <xsl:when test="@morefloats = 'new'">
38                 <TeXML escape="0">
39                     \usepackage[maxfloats=64]{morefloats}
40                 </TeXML>
41             </xsl:when>
42             <xsl:when test="@morefloats = 'old'">
43                 <TeXML escape="0">
44                     \usepackage{morefloats}
45                 </TeXML>
46             </xsl:when>
47             <xsl:when test="@morefloats = 'none'" />
48             <xsl:otherwise>
49                 <TeXML escape="0">
50                     \IfFileExists{morefloats.sty}{
51                         \usepackage{morefloats}
52                     }{}
53                 </TeXML>
54             </xsl:otherwise>
55         </xsl:choose>
56
57         <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
58         <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='titlepage' />
59
60         <env name="document">
61             <xsl:if test="@data-cover-width">
62                 <cmd name="makecover">
63                     <parm><xsl:value-of select="210 * @data-cover-width div @data-cover-height" />mm</parm>
64                     <parm>210mm</parm>
65                 </cmd>
66             </xsl:if>
67             <cmd name="maketitle" />
68
69             <cmd name="tytul"><parm>
70               <xsl:choose>
71                 <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
72                     <!-- title in master -->
73                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/autor_utworu" mode="title" />
74                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/dzielo_nadrzedne" mode="title" />
75                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="title" />
76                     <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/podtytul" mode="title" />
77                     <!-- dc in master or not -->
78                     <cmd name="translatorsline" />
79                 </xsl:when>
80                 <xsl:otherwise>
81                     <!-- look for author title in dc -->
82                     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
83                     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='firstdctitle' />
84                 </xsl:otherwise>
85               </xsl:choose>
86             </parm></cmd>
87             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
88             <xsl:apply-templates select="utwor" mode="part" />
89
90             <TeXML escape="0">
91                 <xsl:if test="@data-cover-by">
92                 \def\coverby{Okładka na podstawie:
93                     <xsl:choose>
94                     <xsl:when test="@data-cover-source">
95                         \href{\datacoversource}{\datacoverby}
96                     </xsl:when>
97                     <xsl:otherwise>
98                         \datacoverby{}
99                     </xsl:otherwise>
100                     </xsl:choose>
101                 }
102                 </xsl:if>
103                 \def\editors{<TeXML escape="1"><xsl:call-template name="editors" /></TeXML>}
104                 <xsl:if test="@funders">
105                     \def\funders{Publikację ufundowali i ufundowały:
106                         <TeXML escape="1"><xsl:value-of select="@funders" /></TeXML>.}
107                 </xsl:if>
108             </TeXML>
109
110             <cmd name="editorialsection" />
111
112         </env>
113     </TeXML>
114 </xsl:template>
115
116 <xsl:template match="utwor" mode="part">
117     <cmd name="tytul"><parm>
118       <xsl:choose>
119         <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
120             <!-- title in master -->
121             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="title" />
122             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/podtytul" mode="title" />
123         </xsl:when>
124         <xsl:otherwise>
125             <!-- look for title in dc -->
126             <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
127             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
128         </xsl:otherwise>
129       </xsl:choose>
130     </parm></cmd>
131
132     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
133     <xsl:apply-templates select="utwor" mode="part" />
134 </xsl:template>
135
136 <!-- =================== -->
137 <!-- = MAIN TITLE PAGE = -->
138 <!-- = (from DC)       = -->
139 <!-- =================== -->
140
141 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
142     <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
143 </xsl:template>
144
145 <xsl:template match="rdf:RDF" mode="titlepage">
146     <TeXML escape="0">
147         \def\authors{<xsl:call-template name="authors" />}
148         \author{\authors}
149         \title{<xsl:apply-templates select=".//dc:title" mode="inline" />}
150         \def\translatorsline{<xsl:call-template name="translators" />}
151
152         \def\bookurl{<xsl:value-of select=".//dc:identifier.url" />}
153
154         \def\rightsinfo{Ten utwór nie jest chroniony prawem autorskim i~znajduje się w~domenie
155             publicznej, co oznacza że możesz go swobodnie wykorzystywać, publikować
156             i~rozpowszechniać. Jeśli utwór opatrzony jest dodatkowymi materiałami
157             (przypisy, motywy literackie etc.), które podlegają prawu autorskiemu, to
158             te dodatkowe materiały udostępnione są na licencji
159             \href{http://creativecommons.org/licenses/by-sa/3.0/}{Creative Commons
160             Uznanie Autorstwa – Na Tych Samych Warunkach 3.0 PL}.}
161         <xsl:if test=".//dc:rights.license">
162             \def\rightsinfo{Ten utwór jest udostepniony na licencji
163             \href{<xsl:value-of select=".//dc:rights.license" />}{<xsl:value-of select=".//dc:rights" />}.}
164         </xsl:if>
165
166         \def\sourceinfo{
167             <xsl:if test=".//dc:source">
168                 Tekst opracowany na podstawie: <xsl:apply-templates select=".//dc:source" mode="inline" />
169                 \vspace{.6em}
170             </xsl:if>}
171         \def\description{<xsl:apply-templates select=".//dc:description" mode="inline" />}
172     </TeXML>
173 </xsl:template>
174
175
176 <!-- ============== -->
177 <!-- = BOOK TITLE = -->
178 <!-- = (from DC)  = -->
179 <!-- ============== -->
180
181 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
182     <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
183 </xsl:template>
184
185 <xsl:template match="rdf:RDF" mode="dctitle">
186     <cmd name="nazwapodutworu"><parm>
187         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
188     </parm></cmd>
189 </xsl:template>
190
191 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
192     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
193 </xsl:template>
194
195 <xsl:template match="rdf:RDF" mode="firstdctitle">
196     <cmd name="autorutworu"><parm><cmd name="authors"/></parm></cmd>
197     <cmd name="nazwautworu"><parm>
198         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
199     </parm></cmd>
200     <cmd name="translatorsline" />
201 </xsl:template>
202
203
204 <!-- ============================================================================== -->
205 <!-- = MASTER TAG                                                                 = -->
206 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
207 <!-- ============================================================================== -->
208 <!-- ==================================================================================== -->
209 <!-- = BLOCK TAGS                                                                       = -->
210 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
211 <!-- ==================================================================================== -->
212
213 <xsl:template
214     match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|nota|dedykacja|dlugi_cytat|poezja_cyt|motto">
215     <cmd>
216         <xsl:attribute name="name">
217             <xsl:value-of select="wl:texcommand(name())" />
218         </xsl:attribute>
219         <parm><xsl:apply-templates/></parm>
220     </cmd>
221 </xsl:template>
222
223 <xsl:template match="lista_osob">
224     <cmd name="listaosob">
225         <parm><xsl:apply-templates select="naglowek_listy" /></parm>
226         <parm><xsl:apply-templates select="lista_osoba" /></parm>
227     </cmd>
228 </xsl:template>
229
230 <xsl:template match="kwestia">
231     <cmd name="kwestia">
232         <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
233     </cmd>
234 </xsl:template>
235
236
237 <!-- ========================================== -->
238 <!-- = PARAGRAPH TAGS                         = -->
239 <!-- = (can contain inline and special tags)  = -->
240 <!-- ========================================== -->
241
242 <!-- only in root -->
243 <xsl:template
244     match="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul"
245     mode="title">
246     <cmd>
247         <xsl:attribute name="name">
248             <xsl:value-of select="wl:texcommand(name())" />
249         </xsl:attribute>
250         <parm><xsl:apply-templates mode="inline"/></parm>
251     </cmd>
252 </xsl:template>
253
254
255 <xsl:template
256     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">
257     <cmd>
258         <xsl:attribute name="name">
259             <xsl:value-of select="wl:texcommand(name())" />
260         </xsl:attribute>
261         <parm><xsl:apply-templates mode="inline"/></parm>
262     </cmd>
263 </xsl:template>
264
265 <xsl:template match="strofa">
266   <cmd name="strofa"><parm>
267     <xsl:choose>
268         <xsl:when test="count(br) > 0">
269             <xsl:call-template name="verse">
270                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
271                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
272             </xsl:call-template>
273             <xsl:for-each select="br">
274                 <TeXML escape="0">\\{}</TeXML>
275                 <!-- Each BR tag "consumes" text after it -->
276                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
277                 <xsl:call-template name="verse">
278                     <xsl:with-param name="verse-content"
279                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
280                     <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>
282             </xsl:for-each>
283         </xsl:when>
284         <xsl:otherwise>
285             <xsl:call-template name="verse">
286                 <xsl:with-param name="verse-content" select="text() | node()" />
287                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
288             </xsl:call-template>
289         </xsl:otherwise>
290     </xsl:choose>
291   </parm></cmd>
292 </xsl:template>
293
294
295 <xsl:template name="verse">
296     <xsl:param name="verse-content" />
297     <xsl:param name="verse-type" />
298
299     <cmd>
300         <xsl:attribute name="name">
301             <xsl:choose>
302                 <xsl:when test="$verse-type != ''">
303                     <xsl:value-of select='wl:texcommand(name($verse-type))' />
304                 </xsl:when>
305                 <xsl:otherwise>wers</xsl:otherwise>
306             </xsl:choose>
307         </xsl:attribute>
308         <xsl:if test="string($verse-content/@typ)">
309             <opt><xsl:value-of select="$verse-content/@typ" />em</opt>
310         </xsl:if>
311         <parm><xsl:apply-templates select="$verse-content" mode="inline"/></parm>
312     </cmd>
313 </xsl:template>
314
315 <!-- ================================================ -->
316 <!-- = INLINE TAGS                                  = -->
317 <!-- = (contain other inline tags and special tags) = -->
318 <!-- ================================================ -->
319
320 <xsl:template mode="inline"
321     match="pa|pe|pr|pt|mat|didask_tekst|slowo_obce|wyroznienie|osoba">
322     <cmd>
323         <xsl:attribute name="name">
324             <xsl:value-of select="wl:texcommand(name())" />
325         </xsl:attribute>
326         <parm><xsl:apply-templates mode="inline"/></parm>
327     </cmd>
328 </xsl:template>
329
330
331
332 <xsl:template match="tytul_dziela" mode="inline">
333     <cmd name="tytuldziela"><parm>
334         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
335     </parm></cmd>
336 </xsl:template>
337
338
339
340 <!-- ============================================== -->
341 <!-- = STANDALONE TAGS                            = -->
342 <!-- = (cannot contain any other tags)            = -->
343 <!-- ============================================== -->
344 <xsl:template
345     match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
346     <cmd>
347         <xsl:attribute name="name">
348             <xsl:value-of select="wl:texcommand(name())" />
349         </xsl:attribute>
350     </cmd>
351 </xsl:template>
352
353
354 <!-- ================ -->
355 <!-- = SPECIAL TAGS = -->
356 <!-- ================ -->
357 <!-- Themes -->
358
359
360 <xsl:template match="begin|end|motyw">
361     <xsl:apply-templates select='.' mode="inline" />
362 </xsl:template>
363
364 <xsl:template match="begin" mode="inline" />
365 <xsl:template match="end" mode="inline" />
366
367 <xsl:template match="motyw" mode="inline">
368     <cmd name="motyw">
369         <xsl:if test="@moved">
370             <opt name="moved"><xsl:value-of select="@moved" /></opt>
371         </xsl:if>
372         <parm><xsl:apply-templates mode="inline" /></parm>
373     </cmd>
374 </xsl:template>
375
376 <xsl:template name="authors">
377     <xsl:for-each select=".//dc:creator_parsed">
378         <xsl:if test="position() != 1">, </xsl:if>
379         <xsl:apply-templates mode="inline" />
380     </xsl:for-each>
381 </xsl:template>
382
383 <xsl:template name="editors">
384     <xsl:if test="@editors">
385         <xsl:text>Opracowanie redakcyjne i przypisy: </xsl:text>
386         <xsl:value-of select="@editors" />
387         <xsl:text>.</xsl:text>
388     </xsl:if>
389 </xsl:template>
390
391 <xsl:template name="translators">
392     <xsl:if test=".//dc:contributor.translator_parsed">
393         <cmd name='translator'><parm>
394             <xsl:for-each select=".//dc:contributor.translator_parsed">
395                 <xsl:if test="position() != 1">, </xsl:if>
396                 <xsl:apply-templates mode="inline" />
397             </xsl:for-each>
398         </parm></cmd>
399     </xsl:if>
400 </xsl:template>
401
402
403 <!-- ============== -->
404 <!-- = ADDED TAGS = -->
405 <!-- ============== -->
406
407
408 <xsl:template match="dywiz" mode="inline">
409     <cmd name="dywiz" />
410 </xsl:template>
411
412 <xsl:template match="nbsp" mode="inline">
413     <spec cat="tilde" />
414 </xsl:template>
415
416 <xsl:template match="alien" mode="inline">
417     <group>
418         <cmd name="alien" />
419         <xsl:apply-templates mode="inline" />
420     </group>
421 </xsl:template>
422
423 <!-- ================ -->
424 <!-- = IGNORED TAGS = -->
425 <!-- ================ -->
426 <xsl:template match="extra|uwaga" />
427 <xsl:template match="extra|uwaga" mode="inline" />
428
429 <xsl:template match="nota_red" />
430
431 <!-- ======== -->
432 <!-- = TEXT = -->
433 <!-- ======== -->
434 <xsl:template match="text()" />
435 <xsl:template match="text()" mode="inline">
436     <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
437       <xsl:text> </xsl:text>
438     </xsl:if>
439
440     <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
441
442     <xsl:if test="following-sibling::node() and wl:ends_white(.)">
443       <xsl:text> </xsl:text>
444     </xsl:if>
445 </xsl:template>
446
447
448 </xsl:stylesheet>