1 <?xml version="1.0" encoding="utf-8"?>
2 <xsl:stylesheet version="1.0"
3 xmlns="http://nowoczesnapolska.org.pl/ML/Lektury/1.1"
5 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
6 xmlns:wlf="http://wolnelektury.pl/functions"
8 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
9 xmlns:dc="http://purl.org/dc/elements/1.1/"
11 exclude-result-prefixes="wlf xsl"
14 <!-- Normalization Stylsheet for Wolne Lektury XML -->
15 <xsl:output method="xml" encoding="utf-8" indent="yes" />
17 <xsl:strip-space elements="rdf:RDF rdf:Description meta doc main-text strofa stanza drama-line wlml:*" />
19 <xsl:param name="normalize-text" select="boolean(1)" />
21 <!-- Main entry point -->
22 <xsl:template match="/">
25 <xsl:apply-templates select="//rdf:RDF" mode="meta"/>
28 <xsl:variable name="body" select="/utwor/*[local-name() = name()]" />
30 <main-text class="{name($body)}">
31 <xsl:apply-templates select="$body/node()" />
35 <xsl:apply-templates select="//pr|pt|pe|pa" mode="annotations" />
40 <xsl:template match="strofa">
41 <xsl:element name="stanza" namespace="http://nowoczesnapolska.org.pl/ML/Lektury/1.1">
42 <!-- normalize verses -->
44 <xsl:when test="count(br) > 0">
45 <!-- First, collect all the tags up to first BR -->
46 <xsl:call-template name="verse">
47 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::node()" />
48 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
51 <!-- Collect the rest of verses -->
52 <xsl:for-each select="br">
53 <!-- Each BR tag "consumes" text after it -->
54 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
55 <xsl:call-template name="verse">
56 <xsl:with-param name="verse-content"
57 select="following-sibling::node()[count(preceding-sibling::br) = $lnum+1 and name() != 'br']" />
58 <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]" />
63 <!-- No BR's - collect the whole content -->
65 <xsl:call-template name="verse">
66 <xsl:with-param name="verse-content" select="child::node()" />
67 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
75 <xsl:template name="verse">
76 <xsl:param name="verse-content" />
77 <xsl:param name="verse-type" />
80 <xsl:when test="not($verse-type)">
81 <xsl:element name="v" namespace="http://nowoczesnapolska.org.pl/ML/Lektury/1.1">
82 <xsl:apply-templates select="$verse-content" />
87 <xsl:apply-templates select="$verse-content" />
94 <xsl:template match="akap">
95 <xsl:element name="p">
96 <xsl:apply-templates select="@*|node()" />
100 <xsl:template match="akap_cd">
101 <xsl:element name="pc">
102 <xsl:apply-templates select="@*|node()" />
106 <xsl:template match="akap_dialog">
107 <xsl:element name="pd">
108 <xsl:variable name="prolog" select="./text()[1]" />
109 <xsl:value-of select="wlf:fix-dialog-line($prolog)" />
110 <xsl:apply-templates select="@*|*|text()[. != $prolog]" />
115 <xsl:template match="wers_cd">
116 <xsl:element name="vc">
117 <xsl:apply-templates select="@*|node()" />
121 <xsl:template match="wers_akap">
122 <xsl:element name="vi">
123 <xsl:attribute name="size">p</xsl:attribute>
124 <xsl:apply-templates select="@*|node()" />
128 <xsl:template match="wers_wciety">
129 <xsl:element name="vi">
131 <xsl:attribute name="size"><xsl:value-of select="@typ" /></xsl:attribute>
133 <xsl:apply-templates select="@*[name() != 'typ']|node()" />
137 <xsl:template match="zastepnik_wersu">
138 <xsl:element name="verse-skip">
140 <xsl:when test="starts-with(., '.')">
141 <xsl:attribute name="type">dot</xsl:attribute>
147 <!-- Przypisy i motywy -->
148 <xsl:template match="begin">
149 <xsl:element name="mark">
150 <xsl:attribute name="starts">
151 <xsl:value-of select="substring(@id, 2)" />
153 <xsl:attribute name="themes">
154 <xsl:value-of select="following-sibling::motyw[1]/text()" />
159 <xsl:template match="motyw" />
161 <xsl:template match="end">
162 <xsl:element name="mark">
163 <xsl:attribute name="ends">
164 <xsl:value-of select="substring(@id, 2)" />
169 <xsl:template match="pa|pe|pr|pt">
170 <mark id="{generate-id(.)}" />
174 <xsl:template match="pa|pe|pr|pt" mode="annotations">
175 <annotation refs="{generate-id(.)}" type="{name(.)}">
176 <xsl:apply-templates select="@*|node()" />
182 <xsl:template match="autor_utworu">
183 <xsl:element name="author">
184 <xsl:apply-templates select="@*|node()" />
188 <xsl:template match="nazwa_utworu">
189 <xsl:element name="title">
190 <xsl:apply-templates select="@*|node()" />
194 <xsl:template match="naglowek_czesc">
196 <xsl:apply-templates select="@*|node()" />
200 <xsl:template match="naglowek_akt">
202 <xsl:apply-templates select="@*|node()" />
206 <xsl:template match="naglowek_scena">
208 <xsl:apply-templates select="@*|node()" />
212 <xsl:template match="podtytul">
214 <xsl:apply-templates select="@*|node()" />
218 <xsl:template match="srodtytul">
220 <xsl:apply-templates select="@*|node()" />
224 <!-- elementy dramatu -->
225 <xsl:template match="miejsce_czas">
226 <xsl:element name="time-and-date">
227 <xsl:apply-templates select="@*|node()" />
232 <xsl:template match="didaskalia|didask_tekst">
233 <xsl:element name="stage-directions">
234 <xsl:apply-templates select="@*|node()" />
238 <xsl:template match="motto">
239 <xsl:element name="motto">
240 <xsl:apply-templates select="@*|node()" />
242 <xsl:variable name="sign" select="following-sibling::*[1][name() = 'motto_podpis']" />
244 <xsl:apply-templates select="$sign/node()" />
249 <xsl:template match="motto_podpis[preceding-sibling::*[1][name() = 'motto']]" />
251 <xsl:template match="lista_osob">
253 <xsl:apply-templates select="@*|node()" />
257 <xsl:template match="naglowek_listy">
259 <xsl:apply-templates select="@*|node()" />
263 <xsl:template match="lista_osoba">
265 <xsl:apply-templates select="@*|node()" />
269 <!-- Odstępy i prześwity -->
270 <xsl:template match="sekcja_swiatlo">
274 <xsl:template match="sekcja_asterysk">
275 <vertical-space type="asterisk" />
278 <xsl:template match="sekcja_asterysk">
279 <vertical-space type="line" />
282 <!-- pozostałe elementy blokowe -->
283 <xsl:template match="dlugi_cytat">
285 <xsl:apply-templates select="@*|node()" />
289 <xsl:template match="poezja_cyt">
291 <xsl:apply-templates select="@*|node()" />
295 <xsl:template match="kwestia">
296 <xsl:variable name="person" select="preceding-sibling::*[1][name() = 'naglowek_osoba']" />
299 <xsl:apply-templates select="$person/node()" />
301 <xsl:apply-templates select="node()[. != $person]" />
305 <xsl:template match="naglowek_osoba[following-sibling::*[1][name() = 'kwestia']]" />
308 <xsl:template match="osoba">
309 <xsl:element name="person-ref">
310 <xsl:apply-templates select="@*|node()" />
314 <xsl:template match="slowo_obce">
315 <xsl:element name="df">
316 <xsl:apply-templates select="@*|node()" />
320 <xsl:template match="wyroznienie">
321 <xsl:element name="em">
322 <xsl:apply-templates select="@*|node()" />
326 <xsl:template match="mat">
327 <xsl:element name="math">
328 <xsl:apply-templates select="@*|node()" />
332 <!-- oznaczenie tytulu innego utworu, wymienionego w tym -->
333 <xsl:template match="tytul_dziela">
334 <xsl:element name="book-ref">
335 <xsl:apply-templates select="@*|node()" />
339 <xsl:template match="extra">
340 <xsl:element name="comment">
341 <xsl:apply-templates select="@*|node()" />
345 <xsl:template match="uwaga">
346 <xsl:element name="edit-comment">
347 <xsl:apply-templates select="@*|node()" />
351 <!-- Copy attributes -->
352 <xsl:template match="@*|comment()">
356 <!-- Inside RDF meta-data, leave the text unchanged -->
357 <xsl:template match="rdf:RDF//text()">
358 <xsl:value-of select="." />
361 <!-- Normalize text in other nodes -->
362 <xsl:template match="text()">
364 <xsl:when test="$normalize-text">
365 <xsl:value-of select="wlf:normalize-text(.)" />
368 <xsl:value-of select="." />
373 <!-- Ignoruj RDF poza meta -->
374 <xsl:template match="rdf:*|dc:*" />
376 <xsl:template match="@*|node()" mode="meta">
378 <xsl:apply-templates match="@*|node()" mode="meta" />
382 <!-- Warn about non-matched elements -->
383 <xsl:template match="node()">
385 <xsl:text>Nieprzetworzony węzeł:</xsl:text>
386 <xsl:value-of select="." />
389 <xsl:copy-of select="." />