Add sponsor logos.
[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
109                 <xsl:if test="data-sponsor">
110                     \def\sponsors{
111                         \scriptsize Sfinansowano ze~środków:\\
112                         <xsl:for-each select="data-sponsor">
113                             \includegraphics[height=0.25\textwidth,width=0.25\textwidth,keepaspectratio]{<xsl:value-of select="@src" />}
114                         </xsl:for-each>
115                     }
116                 </xsl:if>
117             </TeXML>
118
119             <cmd name="editorialsection" />
120
121         </env>
122     </TeXML>
123 </xsl:template>
124
125 <xsl:template match="utwor" mode="part">
126     <cmd name="tytul"><parm>
127       <xsl:choose>
128         <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
129             <!-- title in master -->
130             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="title" />
131             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/podtytul" mode="title" />
132         </xsl:when>
133         <xsl:otherwise>
134             <!-- look for title in dc -->
135             <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
136             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode='dctitle' />
137         </xsl:otherwise>
138       </xsl:choose>
139     </parm></cmd>
140
141     <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
142     <xsl:apply-templates select="utwor" mode="part" />
143 </xsl:template>
144
145 <!-- =================== -->
146 <!-- = MAIN TITLE PAGE = -->
147 <!-- = (from DC)       = -->
148 <!-- =================== -->
149
150 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="titlepage">
151     <xsl:apply-templates select="rdf:RDF" mode="titlepage" />
152 </xsl:template>
153
154 <xsl:template match="rdf:RDF" mode="titlepage">
155     <TeXML escape="0">
156         \def\authors{<xsl:call-template name="authors" />}
157         \author{\authors}
158         \title{<xsl:apply-templates select=".//dc:title" mode="inline" />}
159         \def\translatorsline{<xsl:call-template name="translators" />}
160
161         \def\bookurl{<xsl:value-of select=".//dc:identifier.url" />}
162
163         \def\rightsinfo{Ten utwór nie jest objęty majątkowym prawem autorskim i~znajduje się w~domenie
164             publicznej, co oznacza że możesz go swobodnie wykorzystywać, publikować
165             i~rozpowszechniać. Jeśli utwór opatrzony jest dodatkowymi materiałami
166             (przypisy, motywy literackie etc.), które podlegają prawu autorskiemu, to
167             te dodatkowe materiały udostępnione są na licencji
168             \href{http://creativecommons.org/licenses/by-sa/3.0/}{Creative Commons
169             Uznanie Autorstwa – Na Tych Samych Warunkach 3.0 PL}.}
170         <xsl:if test=".//dc:rights.license">
171             \def\rightsinfo{Ten utwór jest udostepniony na licencji
172             \href{<xsl:value-of select=".//dc:rights.license" />}{<xsl:value-of select=".//dc:rights" />}.}
173         </xsl:if>
174
175         \def\sourceinfo{
176             <xsl:if test=".//dc:source">
177                 Tekst opracowany na podstawie: <xsl:apply-templates select=".//dc:source" mode="inline" />
178                 \vspace{.6em}
179             </xsl:if>}
180         \def\description{<xsl:apply-templates select=".//dc:description" mode="inline" />}
181     </TeXML>
182 </xsl:template>
183
184
185 <!-- ============== -->
186 <!-- = BOOK TITLE = -->
187 <!-- = (from DC)  = -->
188 <!-- ============== -->
189
190 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="dctitle">
191     <xsl:apply-templates select="rdf:RDF" mode="dctitle" />
192 </xsl:template>
193
194 <xsl:template match="rdf:RDF" mode="dctitle">
195     <cmd name="nazwapodutworu"><parm>
196         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
197     </parm></cmd>
198 </xsl:template>
199
200 <xsl:template match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" mode="firstdctitle">
201     <xsl:apply-templates select="rdf:RDF" mode="firstdctitle" />
202 </xsl:template>
203
204 <xsl:template match="rdf:RDF" mode="firstdctitle">
205     <cmd name="autorutworu"><parm><cmd name="authors"/></parm></cmd>
206     <cmd name="nazwautworu"><parm>
207         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
208     </parm></cmd>
209     <cmd name="translatorsline" />
210 </xsl:template>
211
212
213 <!-- ============================================================================== -->
214 <!-- = MASTER TAG                                                                 = -->
215 <!-- = (can contain block tags, paragraph tags, standalone tags and special tags) = -->
216 <!-- ============================================================================== -->
217 <!-- ==================================================================================== -->
218 <!-- = BLOCK TAGS                                                                       = -->
219 <!-- = (can contain other block tags, paragraph tags, standalone tags and special tags) = -->
220 <!-- ==================================================================================== -->
221
222 <xsl:template
223     match="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|nota|dedykacja|dlugi_cytat|poezja_cyt|motto">
224     <cmd>
225         <xsl:attribute name="name">
226             <xsl:value-of select="wl:texcommand(name())" />
227         </xsl:attribute>
228         <parm><xsl:apply-templates/></parm>
229     </cmd>
230 </xsl:template>
231
232 <xsl:template match="lista_osob">
233     <cmd name="listaosob">
234         <parm><xsl:apply-templates select="naglowek_listy" /></parm>
235         <parm><xsl:apply-templates select="lista_osoba" /></parm>
236     </cmd>
237 </xsl:template>
238
239 <xsl:template match="kwestia">
240     <cmd name="kwestia">
241         <parm><xsl:apply-templates select="strofa|akap|didaskalia" /></parm>
242     </cmd>
243 </xsl:template>
244
245
246 <!-- ========================================== -->
247 <!-- = PARAGRAPH TAGS                         = -->
248 <!-- = (can contain inline and special tags)  = -->
249 <!-- ========================================== -->
250
251 <!-- only in root -->
252 <xsl:template
253     match="autor_utworu|dzielo_nadrzedne|nazwa_utworu|podtytul"
254     mode="title">
255     <cmd>
256         <xsl:attribute name="name">
257             <xsl:value-of select="wl:texcommand(name())" />
258         </xsl:attribute>
259         <parm><xsl:apply-templates mode="inline"/></parm>
260     </cmd>
261 </xsl:template>
262
263
264 <xsl:template
265     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">
266     <cmd>
267         <xsl:attribute name="name">
268             <xsl:value-of select="wl:texcommand(name())" />
269         </xsl:attribute>
270         <parm><xsl:apply-templates mode="inline"/></parm>
271     </cmd>
272 </xsl:template>
273
274 <xsl:template match="strofa">
275   <cmd name="strofa"><parm>
276     <xsl:choose>
277         <xsl:when test="count(br) > 0">
278             <xsl:call-template name="verse">
279                 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
280                 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
281             </xsl:call-template>
282             <xsl:for-each select="br">
283                 <TeXML escape="0">\\{}</TeXML>
284                 <!-- Each BR tag "consumes" text after it -->
285                 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
286                 <xsl:call-template name="verse">
287                     <xsl:with-param name="verse-content"
288                         select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
289                     <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]" />
290                 </xsl:call-template>
291             </xsl:for-each>
292         </xsl:when>
293         <xsl:otherwise>
294             <xsl:call-template name="verse">
295                 <xsl:with-param name="verse-content" select="text() | node()" />
296                 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
297             </xsl:call-template>
298         </xsl:otherwise>
299     </xsl:choose>
300   </parm></cmd>
301 </xsl:template>
302
303
304 <xsl:template name="verse">
305     <xsl:param name="verse-content" />
306     <xsl:param name="verse-type" />
307
308     <cmd>
309         <xsl:attribute name="name">
310             <xsl:choose>
311                 <xsl:when test="$verse-type != ''">
312                     <xsl:value-of select='wl:texcommand(name($verse-type))' />
313                 </xsl:when>
314                 <xsl:otherwise>wers</xsl:otherwise>
315             </xsl:choose>
316         </xsl:attribute>
317         <xsl:if test="string($verse-content/@typ)">
318             <opt><xsl:value-of select="$verse-content/@typ" />em</opt>
319         </xsl:if>
320         <parm><xsl:apply-templates select="$verse-content" mode="inline"/></parm>
321     </cmd>
322 </xsl:template>
323
324 <!-- ================================================ -->
325 <!-- = INLINE TAGS                                  = -->
326 <!-- = (contain other inline tags and special tags) = -->
327 <!-- ================================================ -->
328
329 <xsl:template mode="inline"
330     match="pa|pe|pr|pt|mat|didask_tekst|slowo_obce|wyroznienie|osoba">
331     <cmd>
332         <xsl:attribute name="name">
333             <xsl:value-of select="wl:texcommand(name())" />
334         </xsl:attribute>
335         <parm><xsl:apply-templates mode="inline"/></parm>
336     </cmd>
337 </xsl:template>
338
339
340
341 <xsl:template match="tytul_dziela" mode="inline">
342     <cmd name="tytuldziela"><parm>
343         <xsl:if test="@typ = '1'">„</xsl:if><xsl:apply-templates mode="inline" /><xsl:if test="@typ = '1'">”</xsl:if>
344     </parm></cmd>
345 </xsl:template>
346
347
348
349 <!-- ============================================== -->
350 <!-- = STANDALONE TAGS                            = -->
351 <!-- = (cannot contain any other tags)            = -->
352 <!-- ============================================== -->
353 <xsl:template
354     match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
355     <cmd>
356         <xsl:attribute name="name">
357             <xsl:value-of select="wl:texcommand(name())" />
358         </xsl:attribute>
359     </cmd>
360 </xsl:template>
361
362
363 <!-- ================ -->
364 <!-- = SPECIAL TAGS = -->
365 <!-- ================ -->
366 <!-- Themes -->
367
368
369 <xsl:template match="begin|end|motyw">
370     <xsl:apply-templates select='.' mode="inline" />
371 </xsl:template>
372
373 <xsl:template match="begin" mode="inline" />
374 <xsl:template match="end" mode="inline" />
375
376 <xsl:template match="motyw" mode="inline">
377     <cmd name="motyw">
378         <xsl:if test="@moved">
379             <opt name="moved"><xsl:value-of select="@moved" /></opt>
380         </xsl:if>
381         <parm><xsl:apply-templates mode="inline" /></parm>
382     </cmd>
383 </xsl:template>
384
385 <xsl:template name="authors">
386     <xsl:for-each select=".//dc:creator_parsed">
387         <xsl:if test="position() != 1">, </xsl:if>
388         <xsl:apply-templates mode="inline" />
389     </xsl:for-each>
390 </xsl:template>
391
392 <xsl:template name="editors">
393     <xsl:if test="@editors">
394         <xsl:text>Opracowanie redakcyjne i przypisy: </xsl:text>
395         <xsl:value-of select="@editors" />
396         <xsl:text>.</xsl:text>
397     </xsl:if>
398 </xsl:template>
399
400 <xsl:template name="translators">
401     <xsl:if test=".//dc:contributor.translator_parsed">
402         <cmd name='translator'><parm>
403             <xsl:for-each select=".//dc:contributor.translator_parsed">
404                 <xsl:if test="position() != 1">, </xsl:if>
405                 <xsl:apply-templates mode="inline" />
406             </xsl:for-each>
407         </parm></cmd>
408     </xsl:if>
409 </xsl:template>
410
411
412 <!-- ============== -->
413 <!-- = ADDED TAGS = -->
414 <!-- ============== -->
415
416
417 <xsl:template match="dywiz" mode="inline">
418     <cmd name="dywiz" />
419 </xsl:template>
420
421 <xsl:template match="nbsp" mode="inline">
422     <spec cat="tilde" />
423 </xsl:template>
424
425 <xsl:template match="alien" mode="inline">
426     <group>
427         <cmd name="alien" />
428         <xsl:apply-templates mode="inline" />
429     </group>
430 </xsl:template>
431
432 <!-- ================ -->
433 <!-- = IGNORED TAGS = -->
434 <!-- ================ -->
435 <xsl:template match="extra|uwaga" />
436 <xsl:template match="extra|uwaga" mode="inline" />
437
438 <xsl:template match="nota_red" />
439
440 <!-- ======== -->
441 <!-- = TEXT = -->
442 <!-- ======== -->
443 <xsl:template match="text()" />
444 <xsl:template match="text()" mode="inline">
445     <xsl:if test="preceding-sibling::node() and wl:starts_white(.)">
446       <xsl:text> </xsl:text>
447     </xsl:if>
448
449     <xsl:value-of select="wl:substitute_entities(wl:strip(.))" />
450
451     <xsl:if test="following-sibling::node() and wl:ends_white(.)">
452       <xsl:text> </xsl:text>
453     </xsl:if>
454 </xsl:template>
455
456
457 </xsl:stylesheet>