1 <?xml version="1.0" encoding="utf-8"?>
4 This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
5 Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
8 <xsl:stylesheet version="1.0"
9 xmlns="http://nowoczesnapolska.org.pl/ML/Lektury/1.1"
11 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
12 xmlns:wlf="http://wolnelektury.pl/functions"
14 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
15 xmlns:dc="http://purl.org/dc/elements/1.1/"
17 exclude-result-prefixes="wlf xsl"
20 <!-- Normalization Stylsheet for Wolne Lektury XML -->
21 <xsl:output method="xml" encoding="utf-8" indent="yes" />
23 <xsl:strip-space elements="rdf:RDF rdf:Description meta doc main-text strofa stanza drama-line wlml:*" />
25 <xsl:param name="normalize-text" select="boolean(1)" />
27 <!-- Main entry point -->
28 <xsl:template match="/">
31 <xsl:apply-templates select="//rdf:RDF" mode="meta"/>
34 <xsl:variable name="body" select="/utwor/*[local-name() = name()]" />
36 <main-text class="{name($body)}">
37 <xsl:apply-templates select="$body/node()" />
41 <xsl:apply-templates select="//pr|pt|pe|pa" mode="annotations" />
46 <xsl:template match="strofa">
47 <xsl:element name="stanza" namespace="http://nowoczesnapolska.org.pl/ML/Lektury/1.1">
48 <!-- normalize verses -->
50 <xsl:when test="count(br) > 0">
51 <!-- First, collect all the tags up to first BR -->
52 <xsl:call-template name="verse">
53 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::node()" />
54 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
57 <!-- Collect the rest of verses -->
58 <xsl:for-each select="br">
59 <!-- Each BR tag "consumes" text after it -->
60 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
61 <xsl:call-template name="verse">
62 <xsl:with-param name="verse-content"
63 select="following-sibling::node()[count(preceding-sibling::br) = $lnum+1 and name() != 'br']" />
64 <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]" />
69 <!-- No BR's - collect the whole content -->
71 <xsl:call-template name="verse">
72 <xsl:with-param name="verse-content" select="child::node()" />
73 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
81 <xsl:template name="verse">
82 <xsl:param name="verse-content" />
83 <xsl:param name="verse-type" />
86 <xsl:when test="not($verse-type)">
87 <xsl:element name="v" namespace="http://nowoczesnapolska.org.pl/ML/Lektury/1.1">
88 <xsl:apply-templates select="$verse-content" />
93 <xsl:apply-templates select="$verse-content" />
100 <xsl:template match="akap">
101 <xsl:element name="p">
102 <xsl:apply-templates select="@*|node()" />
106 <xsl:template match="akap_cd">
107 <xsl:element name="pc">
108 <xsl:apply-templates select="@*|node()" />
112 <xsl:template match="akap_dialog">
113 <xsl:element name="pd">
114 <xsl:variable name="prolog" select="./text()[1]" />
115 <xsl:value-of select="wlf:fix-dialog-line($prolog)" />
116 <xsl:apply-templates select="@*|*|text()[. != $prolog]" />
121 <xsl:template match="wers_cd">
122 <xsl:element name="vc">
123 <xsl:apply-templates select="@*|node()" />
127 <xsl:template match="wers_akap">
128 <xsl:element name="vi">
129 <xsl:attribute name="size">p</xsl:attribute>
130 <xsl:apply-templates select="@*|node()" />
134 <xsl:template match="wers_wciety">
135 <xsl:element name="vi">
137 <xsl:attribute name="size"><xsl:value-of select="@typ" /></xsl:attribute>
139 <xsl:apply-templates select="@*[name() != 'typ']|node()" />
143 <xsl:template match="zastepnik_wersu">
144 <xsl:element name="verse-skip">
146 <xsl:when test="starts-with(., '.')">
147 <xsl:attribute name="type">dot</xsl:attribute>
153 <!-- Przypisy i motywy -->
154 <xsl:template match="begin">
155 <xsl:element name="mark">
156 <xsl:attribute name="starts">
157 <xsl:value-of select="substring(@id, 2)" />
159 <xsl:attribute name="themes">
160 <xsl:value-of select="following-sibling::motyw[1]/text()" />
165 <xsl:template match="motyw" />
167 <xsl:template match="end">
168 <xsl:element name="mark">
169 <xsl:attribute name="ends">
170 <xsl:value-of select="substring(@id, 2)" />
175 <xsl:template match="pa|pe|pr|pt">
176 <mark id="{generate-id(.)}" />
180 <xsl:template match="pa|pe|pr|pt" mode="annotations">
181 <annotation refs="{generate-id(.)}" type="{name(.)}">
182 <xsl:apply-templates select="@*|node()" />
188 <xsl:template match="autor_utworu">
189 <xsl:element name="author">
190 <xsl:apply-templates select="@*|node()" />
194 <xsl:template match="nazwa_utworu">
195 <xsl:element name="title">
196 <xsl:apply-templates select="@*|node()" />
200 <xsl:template match="naglowek_czesc">
202 <xsl:apply-templates select="@*|node()" />
206 <xsl:template match="naglowek_akt">
208 <xsl:apply-templates select="@*|node()" />
212 <xsl:template match="naglowek_scena">
214 <xsl:apply-templates select="@*|node()" />
218 <xsl:template match="podtytul">
220 <xsl:apply-templates select="@*|node()" />
224 <xsl:template match="srodtytul">
226 <xsl:apply-templates select="@*|node()" />
230 <!-- elementy dramatu -->
231 <xsl:template match="miejsce_czas">
232 <xsl:element name="time-and-date">
233 <xsl:apply-templates select="@*|node()" />
238 <xsl:template match="didaskalia|didask_tekst">
239 <xsl:element name="stage-directions">
240 <xsl:apply-templates select="@*|node()" />
244 <xsl:template match="motto">
245 <xsl:element name="motto">
246 <xsl:apply-templates select="@*|node()" />
248 <xsl:variable name="sign" select="following-sibling::*[1][name() = 'motto_podpis']" />
250 <xsl:apply-templates select="$sign/node()" />
255 <xsl:template match="motto_podpis[preceding-sibling::*[1][name() = 'motto']]" />
257 <xsl:template match="lista_osob">
259 <xsl:apply-templates select="@*|node()" />
263 <xsl:template match="naglowek_listy">
265 <xsl:apply-templates select="@*|node()" />
269 <xsl:template match="lista_osoba">
271 <xsl:apply-templates select="@*|node()" />
275 <!-- Odstępy i prześwity -->
276 <xsl:template match="sekcja_swiatlo">
280 <xsl:template match="sekcja_asterysk">
281 <vertical-space type="asterisk" />
284 <xsl:template match="sekcja_asterysk">
285 <vertical-space type="line" />
288 <!-- pozostałe elementy blokowe -->
289 <xsl:template match="dlugi_cytat">
291 <xsl:apply-templates select="@*|node()" />
295 <xsl:template match="poezja_cyt">
297 <xsl:apply-templates select="@*|node()" />
301 <xsl:template match="kwestia">
302 <xsl:variable name="person" select="preceding-sibling::*[1][name() = 'naglowek_osoba']" />
305 <xsl:apply-templates select="$person/node()" />
307 <xsl:apply-templates select="node()[. != $person]" />
311 <xsl:template match="naglowek_osoba[following-sibling::*[1][name() = 'kwestia']]" />
314 <xsl:template match="osoba">
315 <xsl:element name="person-ref">
316 <xsl:apply-templates select="@*|node()" />
320 <xsl:template match="slowo_obce">
321 <xsl:element name="df">
322 <xsl:apply-templates select="@*|node()" />
326 <xsl:template match="wyroznienie">
327 <xsl:element name="em">
328 <xsl:apply-templates select="@*|node()" />
332 <xsl:template match="mat">
333 <xsl:element name="math">
334 <xsl:apply-templates select="@*|node()" />
338 <!-- oznaczenie tytulu innego utworu, wymienionego w tym -->
339 <xsl:template match="tytul_dziela">
340 <xsl:element name="book-ref">
341 <xsl:apply-templates select="@*|node()" />
345 <xsl:template match="extra">
346 <xsl:element name="comment">
347 <xsl:apply-templates select="@*|node()" />
351 <xsl:template match="uwaga">
352 <xsl:element name="edit-comment">
353 <xsl:apply-templates select="@*|node()" />
357 <!-- Copy attributes -->
358 <xsl:template match="@*|comment()">
362 <!-- Inside RDF meta-data, leave the text unchanged -->
363 <xsl:template match="rdf:RDF//text()">
364 <xsl:value-of select="." />
367 <!-- Normalize text in other nodes -->
368 <xsl:template match="text()">
370 <xsl:when test="$normalize-text">
371 <xsl:value-of select="wlf:normalize-text(.)" />
374 <xsl:value-of select="." />
379 <!-- Ignoruj RDF poza meta -->
380 <xsl:template match="rdf:*|dc:*" />
382 <xsl:template match="@*|node()" mode="meta">
384 <xsl:apply-templates match="@*|node()" mode="meta" />
388 <!-- Warn about non-matched elements -->
389 <xsl:template match="node()">
391 <xsl:text>Nieprzetworzony węzeł:</xsl:text>
392 <xsl:value-of select="." />
395 <xsl:copy-of select="." />