5 xmlns="http://www.w3.org/1999/xhtml"
6 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7 xmlns:wl2o="http://nowoczesnapolska.org.pl/WL/2.0/Overlay"
8 xmlns:wl="http://wolnelektury.pl/functions"
10 exclude-result-prefixes="wl" >
12 <xsl:variable name="config" select="document('config.xml')" />
14 <xsl:output method="xml"
17 omit-xml-declaration = "yes" />
19 <xsl:strip-space elements = "strofa utwor kwestia liryka_l liryka_lp powiesc opowiadanie dramat_wierszowany_lp" />
21 Dokument ten opisuje podstawowe przeksztaĆcenia potrzebne
22 do zamiany dokumentu WLML 1.0 na poprawnie sformatowany
27 <xsl:template name="generic-attributes">
28 <xsl:param name="element" />
29 <xsl:param name="mypath" />
30 <xsl:variable name="tag" select="name($element)" />
32 <xsl:if test="$with-paths">
33 <xsl:attribute name="wl2o:path">
34 <xsl:value-of select="$mypath" />
38 <xsl:if test="$config//editable/*[name() = $tag]">
39 <xsl:attribute name="wl2o:editable">editable</xsl:attribute>
42 <xsl:attribute name="class">
43 <xsl:value-of select="$tag"/>
47 <xsl:template name="generic-descent">
48 <xsl:param name="element" />
49 <xsl:param name="mypath" />
51 <xsl:for-each select="child::node()">
52 <xsl:apply-templates select="." mode="element-tag">
53 <xsl:with-param name="offset" select="position()" />
54 <xsl:with-param name="parent-path" select="$mypath" />
55 </xsl:apply-templates>
59 <xsl:template name="generic-content">
60 <xsl:param name="element" />
61 <xsl:param name="mypath" />
63 <xsl:call-template name="generic-attributes">
64 <xsl:with-param name="element" select="$element" />
65 <xsl:with-param name="mypath" select="$mypath" />
68 <xsl:call-template name="generic-descent">
69 <xsl:with-param name="element" select="$element" />
70 <xsl:with-param name="mypath" select="$mypath" />
74 <!-- Generyczne szablony -->
75 <xsl:template name="generic" >
76 <xsl:param name="element" />
77 <xsl:param name="mypath" />
78 <xsl:param name="offset" />
80 <!-- <xsl:param name="parent-type" select="'block'" /> -->
82 <xsl:variable name="tag" select="name($element)" />
85 <!-- ignore namespaced elements -->
86 <xsl:when test="namespace-uri()" />
88 <xsl:when test="$config//block-elements/*[local-name() = $tag]">
89 <xsl:element name="div" namespace="http://www.w3.org/1999/xhtml">
90 <xsl:apply-templates select="$element" mode="element-content" >
91 <xsl:with-param name="mypath" select="$mypath"/>
92 </xsl:apply-templates>
96 <xsl:when test="$config//paragraph-elements/*[local-name() = $tag]">
97 <xsl:element name="p" namespace="http://www.w3.org/1999/xhtml">
98 <xsl:apply-templates select="$element" mode="element-content" >
99 <xsl:with-param name="mypath" select="$mypath"/>
100 </xsl:apply-templates>
104 <xsl:when test="$config//inline-elements/*[local-name() = $tag]">
105 <xsl:element name="span" namespace="http://www.w3.org/1999/xhtml">
106 <xsl:apply-templates select="$element" mode="element-content" >
107 <xsl:with-param name="mypath" select="$mypath"/>
108 </xsl:apply-templates>
112 <xsl:when test="$config//header-1-elements/*[local-name() = $tag]">
113 <xsl:element name="h1" namespace="http://www.w3.org/1999/xhtml">
114 <xsl:apply-templates select="$element" mode="element-content" >
115 <xsl:with-param name="mypath" select="$mypath"/>
116 </xsl:apply-templates>
120 <xsl:when test="$config//header-2-elements/*[local-name() = $tag]">
121 <xsl:element name="h2" namespace="http://www.w3.org/1999/xhtml">
122 <xsl:apply-templates select="$element" mode="element-content" >
123 <xsl:with-param name="mypath" select="$mypath"/>
124 </xsl:apply-templates>
128 <xsl:when test="$config//header-3-elements/*[local-name() = $tag]">
129 <xsl:element name="h3" namespace="http://www.w3.org/1999/xhtml">
130 <xsl:apply-templates select="$element" mode="element-content" >
131 <xsl:with-param name="mypath" select="$mypath"/>
132 </xsl:apply-templates>
136 <xsl:when test="$config//header-4-elements/*[local-name() = $tag]">
137 <xsl:element name="h4" namespace="http://www.w3.org/1999/xhtml">
138 <xsl:apply-templates select="$element" mode="element-content" >
139 <xsl:with-param name="mypath" select="$mypath"/>
140 </xsl:apply-templates>
144 <xsl:when test="$config//no-show-elements/*[local-name() = $tag]" />
147 <xsl:message terminate="yes">
148 Nieznany tag '<xsl:value-of select="$tag" />' :(.
165 <xsl:template match="dlugi_cytat|poezja_cyt" mode="element-tag">
166 <xsl:param name="offset" />
167 <xsl:param name="parent-path" />
168 <xsl:variable name="mypath"
169 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
171 <xsl:element name="blockquote" >
172 <xsl:call-template name="generic-attributes">
173 <xsl:with-param name="element" select="current()" />
174 <xsl:with-param name="mypath" select="$mypath" />
176 <xsl:call-template name="generic-descent">
177 <xsl:with-param name="element" select="current()" />
178 <xsl:with-param name="mypath" select="$mypath" />
184 <xsl:template match="lista_osob" mode="element-tag">
185 <xsl:param name="offset" />
186 <xsl:param name="parent-path" />
187 <xsl:variable name="mypath"
188 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
190 <xsl:element name="div" >
191 <xsl:call-template name="generic-attributes">
192 <xsl:with-param name="element" select="current()" />
193 <xsl:with-param name="mypath" select="$mypath" />
196 <xsl:apply-templates select="./naglowek-listy" mode="element-tag" />
198 <xsl:for-each select="./lista_osoba">
199 <xsl:apply-templates select="." mode="element-tag">
200 <xsl:with-param name="offset" select="position()" />
201 <xsl:with-param name="parent-path" select="$mypath" />
202 </xsl:apply-templates>
208 <xsl:template match="lista_osoba" mode="element-tag">
209 <xsl:param name="offset" />
210 <xsl:param name="parent-path" />
211 <xsl:variable name="mypath"
212 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
214 <xsl:element name="li" >
215 <xsl:call-template name="generic-attributes">
216 <xsl:with-param name="element" select="current()" />
217 <xsl:with-param name="mypath" select="$mypath" />
219 <xsl:call-template name="generic-descent">
220 <xsl:with-param name="element" select="current()" />
221 <xsl:with-param name="mypath" select="$mypath" />
226 <xsl:template match="separator_linia" mode="element-tag">
227 <xsl:param name="offset" />
228 <xsl:param name="parent-path" />
229 <xsl:variable name="mypath"
230 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
232 <xsl:element name="hr" >
233 <xsl:call-template name="generic-attributes">
234 <xsl:with-param name="element" select="current()" />
235 <xsl:with-param name="mypath" select="$mypath" />
240 <xsl:template match="sekcja_swiatlo" mode="element-tag">
241 <xsl:param name="offset" />
242 <xsl:param name="parent-path" />
243 <xsl:variable name="mypath"
244 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
246 <xsl:element name="br" >
247 <xsl:call-template name="generic-attributes">
248 <xsl:with-param name="element" select="current()" />
249 <xsl:with-param name="mypath" select="$mypath" />
254 <xsl:template match="sekcja_asterysk" mode="element-tag">
255 <xsl:param name="offset" />
256 <xsl:param name="parent-path" />
257 <xsl:variable name="mypath"
258 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
260 <xsl:element name="p" >
261 <xsl:call-template name="generic-attributes">
262 <xsl:with-param name="element" select="current()" />
263 <xsl:with-param name="mypath" select="$mypath" />
269 <xsl:template match="zastepnik_wersu|wers_akap|wers_cd|wers_wciety" mode="element-tag">
270 <xsl:param name="offset" />
271 <xsl:param name="parent-path" />
273 <xsl:variable name="mypath"
274 select="concat($parent-path, '/', name(), '[',string($offset),']')" />
276 <xsl:call-template name="generic-descent">
277 <xsl:with-param name="element" select="current()" />
278 <xsl:with-param name="mypath" select="$mypath" />
283 <xsl:template match="strofa" mode="element-tag">
284 <xsl:param name="offset" />
285 <xsl:param name="parent-path" />
287 <xsl:variable name="mypath"
288 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
290 <xsl:element name="div" >
291 <xsl:call-template name="generic-attributes">
292 <xsl:with-param name="element" select="current()" />
293 <xsl:with-param name="mypath" select="$mypath" />
297 <xsl:when test="count(br) > 0">
298 <xsl:call-template name="verse">
299 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
300 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
301 <xsl:with-param name="mypath" select="$mypath" />
303 <xsl:for-each select="br">
304 <!-- Each BR tag "consumes" text after it -->
305 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
306 <xsl:call-template name="verse">
307 <xsl:with-param name="verse-content"
308 select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
309 <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]" />
310 <xsl:with-param name="mypath" select="$mypath" />
315 <xsl:call-template name="verse">
316 <xsl:with-param name="verse-content" select="child::node()" />
317 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
318 <xsl:with-param name="mypath" select="$mypath" />
325 <xsl:template name="verse">
326 <xsl:param name="verse-content" />
327 <xsl:param name="verse-type" />
328 <xsl:param name="mypath" />
330 <xsl:element name="p">
331 <xsl:attribute name="class">
332 <xsl:value-of select="name($verse-type)" />
334 <xsl:for-each select="$verse-content">
335 <xsl:apply-templates select="." mode="element-tag">
336 <xsl:with-param name="offset" select="position()" />
337 <xsl:with-param name="parent-path" select="$mypath" />
338 </xsl:apply-templates>
344 <!-- default content processing -->
345 <xsl:template match="*" mode="element-content">
346 <xsl:param name="mypath" />
347 <xsl:call-template name="generic-content">
348 <xsl:with-param name="element" select="current()"/>
349 <xsl:with-param name="mypath" select="$mypath"/>
353 <xsl:template match="*" mode="element-tag" >
354 <xsl:param name="offset" />
355 <xsl:param name="parent-path" />
357 <xsl:variable name="mypath"
358 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
360 <xsl:call-template name="generic">
361 <xsl:with-param name="element" select="current()" />
362 <xsl:with-param name="offset" select="$offset" />
363 <xsl:with-param name="mypath" select="$mypath" />
367 <xsl:template match="text()" mode="element-tag">
369 <xsl:value-of select="wl:substitute_entities(.)" />
371 <!--<xsl:value-of select="." /> -->
374 <xsl:template match="node()" />