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