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/>.
27 xmlns="http://www.w3.org/1999/xhtml"
28 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29 xmlns:wl="http://wolnelektury.pl/functions"
31 exclude-result-prefixes="wl" >
33 <xsl:variable name="config" select="document('config.xml')" />
35 <xsl:output method="xml"
38 omit-xml-declaration = "yes" />
41 Dokument ten opisuje podstawowe przekształcenia potrzebne
42 do zamiany dokumentu WLML 1.0 na poprawnie sformatowany
47 <xsl:template name="generic-attributes">
48 <xsl:param name="element" />
49 <xsl:param name="mypath" />
50 <xsl:variable name="tag" select="name($element)" />
52 <xsl:if test="$with-paths">
53 <xsl:attribute name="x-pointer">
54 <xsl:value-of select="$mypath" />
58 <xsl:if test="$config//editable/*[name() = $tag]">
59 <xsl:attribute name="x-editable">editable</xsl:attribute>
62 <xsl:attribute name="class">
63 <xsl:value-of select="$tag"/>
67 <xsl:template name="generic-descent">
68 <xsl:param name="element" />
69 <xsl:param name="mypath" />
70 <xsl:param name="mixed" />
72 <xsl:for-each select="child::node()">
73 <xsl:apply-templates select="." mode="element-tag">
74 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
75 <xsl:with-param name="parent-path" select="$mypath" />
76 <xsl:with-param name="mixed" select="$mixed" />
77 </xsl:apply-templates>
81 <xsl:template name="generic-content">
82 <xsl:param name="element" />
83 <xsl:param name="mypath" />
84 <xsl:param name="mixed" />
86 <xsl:call-template name="generic-attributes">
87 <xsl:with-param name="element" select="$element" />
88 <xsl:with-param name="mypath" select="$mypath" />
91 <xsl:call-template name="generic-descent">
92 <xsl:with-param name="element" select="$element" />
93 <xsl:with-param name="mypath" select="$mypath" />
94 <xsl:with-param name="mixed" select="$mixed" />
98 <!-- Generyczne szablony -->
99 <xsl:template name="generic" >
100 <xsl:param name="element" />
101 <xsl:param name="mypath" />
102 <xsl:param name="offset" />
104 <!-- <xsl:param name="parent-type" select="'block'" /> -->
106 <xsl:variable name="tag" select="name($element)" />
107 <xsl:variable name="group" select="$config//types/*[@element and child::*[local-name() = $tag]]" />
110 <!-- ignore namespaced elements -->
111 <xsl:when test="namespace-uri()" />
112 <xsl:when test="$group/@element">
114 <xsl:element name="{$group/@element}" namespace="http://www.w3.org/1999/xhtml">
115 <xsl:apply-templates select="$element" mode="element-content" >
116 <xsl:with-param name="mypath" select="$mypath" />
117 <xsl:with-param name="mixed" select="boolean($group/@mixed)" />
118 </xsl:apply-templates>
130 <xsl:template match="pr|pa|pe|pt" mode="element-tag">
131 <a href="#annotation-{generate-id(.)}"><span class="annotation"/></a><a name="anchor-{generate-id(.)}" />
134 <xsl:template match="dlugi_cytat|poezja_cyt" mode="element-tag">
135 <xsl:param name="offset" />
136 <xsl:param name="parent-path" />
137 <xsl:variable name="mypath"
138 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
140 <xsl:element name="blockquote" >
141 <xsl:call-template name="generic-attributes">
142 <xsl:with-param name="element" select="current()" />
143 <xsl:with-param name="mypath" select="$mypath" />
145 <xsl:call-template name="generic-descent">
146 <xsl:with-param name="element" select="current()" />
147 <xsl:with-param name="mypath" select="$mypath" />
148 <xsl:with-param name="mixed" select="true" />
154 <xsl:template match="lista_osob" mode="element-tag">
155 <xsl:param name="offset" />
156 <xsl:param name="parent-path" />
157 <xsl:variable name="mypath"
158 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
160 <xsl:element name="div" >
161 <xsl:call-template name="generic-attributes">
162 <xsl:with-param name="element" select="current()" />
163 <xsl:with-param name="mypath" select="$mypath" />
166 <xsl:apply-templates select="./naglowek-listy" mode="element-tag" />
168 <xsl:for-each select="./lista_osoba">
169 <xsl:apply-templates select="." mode="element-tag">
170 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
171 <xsl:with-param name="parent-path" select="$mypath" />
172 <xsl:with-param name="mixed" select="false" />
173 </xsl:apply-templates>
179 <xsl:template match="lista_osoba" mode="element-tag">
180 <xsl:param name="offset" />
181 <xsl:param name="parent-path" />
182 <xsl:variable name="mypath"
183 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
185 <xsl:element name="li" >
186 <xsl:call-template name="generic-attributes">
187 <xsl:with-param name="element" select="current()" />
188 <xsl:with-param name="mypath" select="$mypath" />
190 <xsl:call-template name="generic-descent">
191 <xsl:with-param name="element" select="current()" />
192 <xsl:with-param name="mypath" select="$mypath" />
193 <xsl:with-param name="mixed" select="true" />
198 <xsl:template match="separator_linia" mode="element-tag">
199 <xsl:param name="offset" />
200 <xsl:param name="parent-path" />
201 <xsl:variable name="mypath"
202 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
204 <xsl:element name="hr" >
205 <xsl:call-template name="generic-attributes">
206 <xsl:with-param name="element" select="current()" />
207 <xsl:with-param name="mypath" select="$mypath" />
212 <xsl:template match="sekcja_swiatlo" mode="element-tag">
213 <xsl:param name="offset" />
214 <xsl:param name="parent-path" />
215 <xsl:variable name="mypath"
216 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
218 <xsl:element name="br" >
219 <xsl:call-template name="generic-attributes">
220 <xsl:with-param name="element" select="current()" />
221 <xsl:with-param name="mypath" select="$mypath" />
226 <xsl:template match="sekcja_asterysk" 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="p" >
233 <xsl:call-template name="generic-attributes">
234 <xsl:with-param name="element" select="current()" />
235 <xsl:with-param name="mypath" select="$mypath" />
241 <xsl:template match="zastepnik_wersu|wers_akap|wers_cd|wers_wciety" mode="element-tag">
242 <xsl:param name="offset" />
243 <xsl:param name="parent-path" />
245 <xsl:variable name="mypath"
246 select="concat($parent-path, '/', name(), '[',string($offset),']')" />
248 <xsl:call-template name="generic-descent">
249 <xsl:with-param name="element" select="current()" />
250 <xsl:with-param name="mypath" select="$mypath" />
251 <xsl:with-param name="mixed" select="boolean(1)" />
256 <xsl:template match="strofa" mode="element-tag">
257 <xsl:param name="offset" />
258 <xsl:param name="parent-path" />
260 <xsl:variable name="mypath"
261 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
263 <xsl:element name="div" >
264 <xsl:call-template name="generic-attributes">
265 <xsl:with-param name="element" select="current()" />
266 <xsl:with-param name="mypath" select="$mypath" />
270 <xsl:when test="count(br) > 0">
271 <xsl:call-template name="verse">
272 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
273 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
274 <xsl:with-param name="mypath" select="$mypath" />
276 <xsl:for-each select="br">
277 <!-- Each BR tag "consumes" text after it -->
278 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
279 <xsl:call-template name="verse">
280 <xsl:with-param name="verse-content"
281 select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
282 <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]" />
283 <xsl:with-param name="mypath" select="$mypath" />
288 <xsl:call-template name="verse">
289 <xsl:with-param name="verse-content" select="child::node()" />
290 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
291 <xsl:with-param name="mypath" select="$mypath" />
298 <xsl:template name="verse">
299 <xsl:param name="verse-content" />
300 <xsl:param name="verse-type" />
301 <xsl:param name="mypath" />
303 <xsl:element name="p">
304 <xsl:attribute name="class">
305 <xsl:value-of select="name($verse-type)" />
307 <xsl:for-each select="$verse-content">
308 <xsl:apply-templates select="." mode="element-tag">
309 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
310 <xsl:with-param name="parent-path" select="$mypath" />
311 <xsl:with-param name="mixed" select="boolean(1)" />
312 </xsl:apply-templates>
318 <!-- default content processing -->
319 <xsl:template match="*" mode="element-content">
320 <xsl:param name="mypath" />
321 <xsl:param name="mixed" />
323 <xsl:call-template name="generic-content">
324 <xsl:with-param name="element" select="current()"/>
325 <xsl:with-param name="mypath" select="$mypath"/>
326 <xsl:with-param name="mixed" select="$mixed"/>
330 <xsl:template match="*" mode="element-tag" >
331 <xsl:param name="offset" />
332 <xsl:param name="parent-path" />
333 <xsl:param name="mixed" />
335 <xsl:variable name="mypath"
336 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
338 <xsl:call-template name="generic">
339 <xsl:with-param name="element" select="current()" />
340 <xsl:with-param name="offset" select="$offset" />
341 <xsl:with-param name="mypath" select="$mypath" />
342 <xsl:with-param name="mixed" select="$mixed"/>
346 <xsl:template match="text()" mode="element-tag">
347 <xsl:param name="mixed" />
351 <xsl:when test="not($mixed)">
353 <xsl:when test="not(normalize-space(.))" />
354 <xsl:when test="normalize-space(.) = ''"/>
357 <div class="parse-warning">
358 <p class="message">Uwaga! Tekst poza paragrafem</p>
359 <p>#<xsl:copy-of select="." />#</p>
366 <xsl:value-of select="wl:substitute_entities(.)">
368 <xsl:value-of select="." />
377 <xsl:template match="node()" />