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