1 <?xml version="1.0" encoding="utf-8"?>
4 # This file is part of Librarian.
6 # Copyright © 2008,2009,2010 Fundacja Nowoczesna Polska <fundacja@nowoczesnapolska.org.pl>
8 # For full list of contributors see AUTHORS file.
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Affero General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Affero General Public License for more details.
20 # You should have received a copy of the GNU Affero General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 <xsl:stylesheet version="1.0"
25 xmlns="http://nowoczesnapolska.org.pl/ML/Lektury/1.1"
27 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
28 xmlns:wlf="http://wolnelektury.pl/functions"
30 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
31 xmlns:dc="http://purl.org/dc/elements/1.1/"
33 exclude-result-prefixes="wlf xsl"
36 <!-- Normalization Stylsheet for Wolne Lektury XML -->
37 <xsl:output method="xml" encoding="utf-8" indent="yes" />
39 <xsl:strip-space elements="rdf:RDF rdf:Description meta doc main-text strofa stanza drama-line wlml:*" />
41 <xsl:param name="normalize-text" select="boolean(1)" />
43 <!-- Main entry point -->
44 <xsl:template match="/">
47 <xsl:apply-templates select="//rdf:RDF" mode="meta"/>
50 <xsl:variable name="body" select="/utwor/*[local-name() = name()]" />
52 <main-text class="{name($body)}">
53 <xsl:apply-templates select="$body/node()" />
57 <xsl:apply-templates select="//pr|pt|pe|pa" mode="annotations" />
62 <xsl:template match="strofa">
63 <xsl:element name="stanza" namespace="http://nowoczesnapolska.org.pl/ML/Lektury/1.1">
64 <!-- normalize verses -->
66 <xsl:when test="count(br) > 0">
67 <!-- First, collect all the tags up to first BR -->
68 <xsl:call-template name="verse">
69 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::node()" />
70 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
73 <!-- Collect the rest of verses -->
74 <xsl:for-each select="br">
75 <!-- Each BR tag "consumes" text after it -->
76 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
77 <xsl:call-template name="verse">
78 <xsl:with-param name="verse-content"
79 select="following-sibling::node()[count(preceding-sibling::br) = $lnum+1 and name() != 'br']" />
80 <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]" />
85 <!-- No BR's - collect the whole content -->
87 <xsl:call-template name="verse">
88 <xsl:with-param name="verse-content" select="child::node()" />
89 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
97 <xsl:template name="verse">
98 <xsl:param name="verse-content" />
99 <xsl:param name="verse-type" />
102 <xsl:when test="not($verse-type)">
103 <xsl:element name="v" namespace="http://nowoczesnapolska.org.pl/ML/Lektury/1.1">
104 <xsl:apply-templates select="$verse-content" />
109 <xsl:apply-templates select="$verse-content" />
116 <xsl:template match="akap">
117 <xsl:element name="p">
118 <xsl:apply-templates select="@*|node()" />
122 <xsl:template match="akap_cd">
123 <xsl:element name="pc">
124 <xsl:apply-templates select="@*|node()" />
128 <xsl:template match="akap_dialog">
129 <xsl:element name="pd">
130 <xsl:variable name="prolog" select="./text()[1]" />
131 <xsl:value-of select="wlf:fix-dialog-line($prolog)" />
132 <xsl:apply-templates select="@*|*|text()[. != $prolog]" />
137 <xsl:template match="wers_cd">
138 <xsl:element name="vc">
139 <xsl:apply-templates select="@*|node()" />
143 <xsl:template match="wers_akap">
144 <xsl:element name="vi">
145 <xsl:attribute name="size">p</xsl:attribute>
146 <xsl:apply-templates select="@*|node()" />
150 <xsl:template match="wers_wciety">
151 <xsl:element name="vi">
153 <xsl:attribute name="size"><xsl:value-of select="@typ" /></xsl:attribute>
155 <xsl:apply-templates select="@*[name() != 'typ']|node()" />
159 <xsl:template match="zastepnik_wersu">
160 <xsl:element name="verse-skip">
162 <xsl:when test="starts-with(., '.')">
163 <xsl:attribute name="type">dot</xsl:attribute>
169 <!-- Przypisy i motywy -->
170 <xsl:template match="begin">
171 <xsl:element name="mark">
172 <xsl:attribute name="starts">
173 <xsl:value-of select="substring(@id, 2)" />
175 <xsl:attribute name="themes">
176 <xsl:value-of select="following-sibling::motyw[1]/text()" />
181 <xsl:template match="motyw" />
183 <xsl:template match="end">
184 <xsl:element name="mark">
185 <xsl:attribute name="ends">
186 <xsl:value-of select="substring(@id, 2)" />
191 <xsl:template match="pa|pe|pr|pt">
192 <mark id="{generate-id(.)}" />
196 <xsl:template match="pa|pe|pr|pt" mode="annotations">
197 <annotation refs="{generate-id(.)}" type="{name(.)}">
198 <xsl:apply-templates select="@*|node()" />
204 <xsl:template match="autor_utworu">
205 <xsl:element name="author">
206 <xsl:apply-templates select="@*|node()" />
210 <xsl:template match="nazwa_utworu">
211 <xsl:element name="title">
212 <xsl:apply-templates select="@*|node()" />
216 <xsl:template match="naglowek_czesc">
218 <xsl:apply-templates select="@*|node()" />
222 <xsl:template match="naglowek_akt">
224 <xsl:apply-templates select="@*|node()" />
228 <xsl:template match="naglowek_scena">
230 <xsl:apply-templates select="@*|node()" />
234 <xsl:template match="podtytul">
236 <xsl:apply-templates select="@*|node()" />
240 <xsl:template match="srodtytul">
242 <xsl:apply-templates select="@*|node()" />
246 <!-- elementy dramatu -->
247 <xsl:template match="miejsce_czas">
248 <xsl:element name="time-and-date">
249 <xsl:apply-templates select="@*|node()" />
254 <xsl:template match="didaskalia|didask_tekst">
255 <xsl:element name="stage-directions">
256 <xsl:apply-templates select="@*|node()" />
260 <xsl:template match="motto">
261 <xsl:element name="motto">
262 <xsl:apply-templates select="@*|node()" />
264 <xsl:variable name="sign" select="following-sibling::*[1][name() = 'motto_podpis']" />
266 <xsl:apply-templates select="$sign/node()" />
271 <xsl:template match="motto_podpis[preceding-sibling::*[1][name() = 'motto']]" />
273 <xsl:template match="lista_osob">
275 <xsl:apply-templates select="@*|node()" />
279 <xsl:template match="naglowek_listy">
281 <xsl:apply-templates select="@*|node()" />
285 <xsl:template match="lista_osoba">
287 <xsl:apply-templates select="@*|node()" />
291 <!-- Odstępy i prześwity -->
292 <xsl:template match="sekcja_swiatlo">
296 <xsl:template match="sekcja_asterysk">
297 <vertical-space type="asterisk" />
300 <xsl:template match="sekcja_asterysk">
301 <vertical-space type="line" />
304 <!-- pozostałe elementy blokowe -->
305 <xsl:template match="dlugi_cytat">
307 <xsl:apply-templates select="@*|node()" />
311 <xsl:template match="poezja_cyt">
313 <xsl:apply-templates select="@*|node()" />
317 <xsl:template match="kwestia">
318 <xsl:variable name="person" select="preceding-sibling::*[1][name() = 'naglowek_osoba']" />
321 <xsl:apply-templates select="$person/node()" />
323 <xsl:apply-templates select="node()[. != $person]" />
327 <xsl:template match="naglowek_osoba[following-sibling::*[1][name() = 'kwestia']]" />
330 <xsl:template match="osoba">
331 <xsl:element name="person-ref">
332 <xsl:apply-templates select="@*|node()" />
336 <xsl:template match="slowo_obce">
337 <xsl:element name="df">
338 <xsl:apply-templates select="@*|node()" />
342 <xsl:template match="wyroznienie">
343 <xsl:element name="em">
344 <xsl:apply-templates select="@*|node()" />
348 <xsl:template match="mat">
349 <xsl:element name="math">
350 <xsl:apply-templates select="@*|node()" />
354 <!-- oznaczenie tytulu innego utworu, wymienionego w tym -->
355 <xsl:template match="tytul_dziela">
356 <xsl:element name="book-ref">
357 <xsl:apply-templates select="@*|node()" />
361 <xsl:template match="extra">
362 <xsl:element name="comment">
363 <xsl:apply-templates select="@*|node()" />
367 <xsl:template match="uwaga">
368 <xsl:element name="edit-comment">
369 <xsl:apply-templates select="@*|node()" />
373 <!-- Copy attributes -->
374 <xsl:template match="@*|comment()">
378 <!-- Inside RDF meta-data, leave the text unchanged -->
379 <xsl:template match="rdf:RDF//text()">
380 <xsl:value-of select="." />
383 <!-- Normalize text in other nodes -->
384 <xsl:template match="text()">
386 <xsl:when test="$normalize-text">
387 <xsl:value-of select="wlf:normalize-text(.)" />
390 <xsl:value-of select="." />
395 <!-- Ignoruj RDF poza meta -->
396 <xsl:template match="rdf:*|dc:*" />
398 <xsl:template match="@*|node()" mode="meta">
400 <xsl:apply-templates match="@*|node()" mode="meta" />
404 <!-- Warn about non-matched elements -->
405 <xsl:template match="node()">
407 <xsl:text>Nieprzetworzony węzeł:</xsl:text>
408 <xsl:value-of select="." />
411 <xsl:copy-of select="." />