5 xmlns="http://www.w3.org/1999/xhtml"
6 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7 xmlns:wl="http://wolnelektury.pl/functions"
9 exclude-result-prefixes="wl" >
11 <xsl:variable name="config" select="document('config.xml')" />
13 <xsl:output method="xml"
16 omit-xml-declaration = "yes" />
19 Dokument ten opisuje podstawowe przeksztaĆcenia potrzebne
20 do zamiany dokumentu WLML 1.0 na poprawnie sformatowany
25 <xsl:template name="generic-attributes">
26 <xsl:param name="element" />
27 <xsl:param name="mypath" />
28 <xsl:variable name="tag" select="name($element)" />
30 <xsl:if test="$with-paths">
31 <xsl:attribute name="x-pointer">
32 <xsl:value-of select="$mypath" />
36 <xsl:if test="$config//editable/*[name() = $tag]">
37 <xsl:attribute name="x-editable">editable</xsl:attribute>
40 <xsl:attribute name="class">
41 <xsl:value-of select="$tag"/>
45 <xsl:template name="generic-descent">
46 <xsl:param name="element" />
47 <xsl:param name="mypath" />
48 <xsl:param name="mixed" />
50 <xsl:for-each select="child::node()">
51 <xsl:apply-templates select="." mode="element-tag">
52 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
53 <xsl:with-param name="parent-path" select="$mypath" />
54 <xsl:with-param name="mixed" select="$mixed" />
55 </xsl:apply-templates>
59 <xsl:template name="generic-content">
60 <xsl:param name="element" />
61 <xsl:param name="mypath" />
62 <xsl:param name="mixed" />
64 <xsl:call-template name="generic-attributes">
65 <xsl:with-param name="element" select="$element" />
66 <xsl:with-param name="mypath" select="$mypath" />
69 <xsl:call-template name="generic-descent">
70 <xsl:with-param name="element" select="$element" />
71 <xsl:with-param name="mypath" select="$mypath" />
72 <xsl:with-param name="mixed" select="$mixed" />
76 <!-- Generyczne szablony -->
77 <xsl:template name="generic" >
78 <xsl:param name="element" />
79 <xsl:param name="mypath" />
80 <xsl:param name="offset" />
82 <!-- <xsl:param name="parent-type" select="'block'" /> -->
84 <xsl:variable name="tag" select="name($element)" />
85 <xsl:variable name="group" select="$config//types/*[@element and child::*[local-name() = $tag]]" />
88 <!-- ignore namespaced elements -->
89 <xsl:when test="namespace-uri()" />
90 <xsl:when test="$group/@element">
92 <xsl:element name="{$group/@element}" namespace="http://www.w3.org/1999/xhtml">
93 <xsl:apply-templates select="$element" mode="element-content" >
94 <xsl:with-param name="mypath" select="$mypath" />
95 <xsl:with-param name="mixed" select="boolean($group/@mixed)" />
96 </xsl:apply-templates>
108 <xsl:template match="pr|pa|pe|pt" mode="element-tag">
109 <a href="#annotation-{generate-id(.)}"><span class="annotation"/></a><a name="anchor-{generate-id(.)}" />
112 <xsl:template match="dlugi_cytat|poezja_cyt" mode="element-tag">
113 <xsl:param name="offset" />
114 <xsl:param name="parent-path" />
115 <xsl:variable name="mypath"
116 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
118 <xsl:element name="blockquote" >
119 <xsl:call-template name="generic-attributes">
120 <xsl:with-param name="element" select="current()" />
121 <xsl:with-param name="mypath" select="$mypath" />
123 <xsl:call-template name="generic-descent">
124 <xsl:with-param name="element" select="current()" />
125 <xsl:with-param name="mypath" select="$mypath" />
126 <xsl:with-param name="mixed" select="true" />
132 <xsl:template match="lista_osob" mode="element-tag">
133 <xsl:param name="offset" />
134 <xsl:param name="parent-path" />
135 <xsl:variable name="mypath"
136 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
138 <xsl:element name="div" >
139 <xsl:call-template name="generic-attributes">
140 <xsl:with-param name="element" select="current()" />
141 <xsl:with-param name="mypath" select="$mypath" />
144 <xsl:apply-templates select="./naglowek-listy" mode="element-tag" />
146 <xsl:for-each select="./lista_osoba">
147 <xsl:apply-templates select="." mode="element-tag">
148 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
149 <xsl:with-param name="parent-path" select="$mypath" />
150 <xsl:with-param name="mixed" select="false" />
151 </xsl:apply-templates>
157 <xsl:template match="lista_osoba" mode="element-tag">
158 <xsl:param name="offset" />
159 <xsl:param name="parent-path" />
160 <xsl:variable name="mypath"
161 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
163 <xsl:element name="li" >
164 <xsl:call-template name="generic-attributes">
165 <xsl:with-param name="element" select="current()" />
166 <xsl:with-param name="mypath" select="$mypath" />
168 <xsl:call-template name="generic-descent">
169 <xsl:with-param name="element" select="current()" />
170 <xsl:with-param name="mypath" select="$mypath" />
171 <xsl:with-param name="mixed" select="true" />
176 <xsl:template match="separator_linia" mode="element-tag">
177 <xsl:param name="offset" />
178 <xsl:param name="parent-path" />
179 <xsl:variable name="mypath"
180 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
182 <xsl:element name="hr" >
183 <xsl:call-template name="generic-attributes">
184 <xsl:with-param name="element" select="current()" />
185 <xsl:with-param name="mypath" select="$mypath" />
190 <xsl:template match="sekcja_swiatlo" mode="element-tag">
191 <xsl:param name="offset" />
192 <xsl:param name="parent-path" />
193 <xsl:variable name="mypath"
194 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
196 <xsl:element name="br" >
197 <xsl:call-template name="generic-attributes">
198 <xsl:with-param name="element" select="current()" />
199 <xsl:with-param name="mypath" select="$mypath" />
204 <xsl:template match="sekcja_asterysk" mode="element-tag">
205 <xsl:param name="offset" />
206 <xsl:param name="parent-path" />
207 <xsl:variable name="mypath"
208 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
210 <xsl:element name="p" >
211 <xsl:call-template name="generic-attributes">
212 <xsl:with-param name="element" select="current()" />
213 <xsl:with-param name="mypath" select="$mypath" />
219 <xsl:template match="zastepnik_wersu|wers_akap|wers_cd|wers_wciety" mode="element-tag">
220 <xsl:param name="offset" />
221 <xsl:param name="parent-path" />
223 <xsl:variable name="mypath"
224 select="concat($parent-path, '/', name(), '[',string($offset),']')" />
226 <xsl:call-template name="generic-descent">
227 <xsl:with-param name="element" select="current()" />
228 <xsl:with-param name="mypath" select="$mypath" />
229 <xsl:with-param name="mixed" select="boolean(1)" />
234 <xsl:template match="strofa" mode="element-tag">
235 <xsl:param name="offset" />
236 <xsl:param name="parent-path" />
238 <xsl:variable name="mypath"
239 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
241 <xsl:element name="div" >
242 <xsl:call-template name="generic-attributes">
243 <xsl:with-param name="element" select="current()" />
244 <xsl:with-param name="mypath" select="$mypath" />
248 <xsl:when test="count(br) > 0">
249 <xsl:call-template name="verse">
250 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
251 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
252 <xsl:with-param name="mypath" select="$mypath" />
254 <xsl:for-each select="br">
255 <!-- Each BR tag "consumes" text after it -->
256 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
257 <xsl:call-template name="verse">
258 <xsl:with-param name="verse-content"
259 select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
260 <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]" />
261 <xsl:with-param name="mypath" select="$mypath" />
266 <xsl:call-template name="verse">
267 <xsl:with-param name="verse-content" select="child::node()" />
268 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
269 <xsl:with-param name="mypath" select="$mypath" />
276 <xsl:template name="verse">
277 <xsl:param name="verse-content" />
278 <xsl:param name="verse-type" />
279 <xsl:param name="mypath" />
281 <xsl:element name="p">
282 <xsl:attribute name="class">
283 <xsl:value-of select="name($verse-type)" />
285 <xsl:for-each select="$verse-content">
286 <xsl:apply-templates select="." mode="element-tag">
287 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
288 <xsl:with-param name="parent-path" select="$mypath" />
289 <xsl:with-param name="mixed" select="boolean(1)" />
290 </xsl:apply-templates>
296 <!-- default content processing -->
297 <xsl:template match="*" mode="element-content">
298 <xsl:param name="mypath" />
299 <xsl:param name="mixed" />
301 <xsl:call-template name="generic-content">
302 <xsl:with-param name="element" select="current()"/>
303 <xsl:with-param name="mypath" select="$mypath"/>
304 <xsl:with-param name="mixed" select="$mixed"/>
308 <xsl:template match="*" mode="element-tag" >
309 <xsl:param name="offset" />
310 <xsl:param name="parent-path" />
311 <xsl:param name="mixed" />
313 <xsl:variable name="mypath"
314 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
316 <xsl:call-template name="generic">
317 <xsl:with-param name="element" select="current()" />
318 <xsl:with-param name="offset" select="$offset" />
319 <xsl:with-param name="mypath" select="$mypath" />
320 <xsl:with-param name="mixed" select="$mixed"/>
324 <xsl:template match="text()" mode="element-tag">
325 <xsl:param name="mixed" />
329 <xsl:when test="not($mixed)">
331 <xsl:when test="not(normalize-space(.))" />
332 <xsl:when test="normalize-space(.) = ''"/>
335 <div class="parse-warning">
336 <p class="message">Uwaga! Tekst poza paragrafem</p>
337 <p>#<xsl:copy-of select="." />#</p>
344 <xsl:value-of select="wl:substitute_entities(.)">
346 <xsl:value-of select="." />
355 <xsl:template match="node()" />