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.
11 xmlns="http://www.w3.org/1999/xhtml"
12 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
13 xmlns:wl="http://wolnelektury.pl/functions"
15 exclude-result-prefixes="wl" >
17 <xsl:variable name="config" select="document('config.xml')" />
19 <xsl:output method="xml"
22 omit-xml-declaration = "yes" />
25 Dokument ten opisuje podstawowe przekształcenia potrzebne
26 do zamiany dokumentu WLML 1.0 na poprawnie sformatowany
31 <xsl:template name="generic-attributes">
32 <xsl:param name="element" />
33 <xsl:param name="mypath" />
34 <xsl:variable name="tag" select="name($element)" />
36 <xsl:if test="$with-paths">
37 <xsl:attribute name="x-pointer">
38 <xsl:value-of select="$mypath" />
42 <xsl:if test="$config//editable/*[name() = $tag]">
43 <xsl:attribute name="x-editable">editable</xsl:attribute>
46 <xsl:attribute name="class">
47 <xsl:value-of select="$tag"/>
51 <xsl:template name="generic-descent">
52 <xsl:param name="element" />
53 <xsl:param name="mypath" />
54 <xsl:param name="mixed" />
56 <xsl:for-each select="child::node()">
57 <xsl:apply-templates select="." mode="element-tag">
58 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
59 <xsl:with-param name="parent-path" select="$mypath" />
60 <xsl:with-param name="mixed" select="$mixed" />
61 </xsl:apply-templates>
65 <xsl:template name="generic-content">
66 <xsl:param name="element" />
67 <xsl:param name="mypath" />
68 <xsl:param name="mixed" />
70 <xsl:call-template name="generic-attributes">
71 <xsl:with-param name="element" select="$element" />
72 <xsl:with-param name="mypath" select="$mypath" />
75 <xsl:call-template name="generic-descent">
76 <xsl:with-param name="element" select="$element" />
77 <xsl:with-param name="mypath" select="$mypath" />
78 <xsl:with-param name="mixed" select="$mixed" />
82 <!-- Generyczne szablony -->
83 <xsl:template name="generic" >
84 <xsl:param name="element" />
85 <xsl:param name="mypath" />
86 <xsl:param name="offset" />
88 <!-- <xsl:param name="parent-type" select="'block'" /> -->
90 <xsl:variable name="tag" select="name($element)" />
91 <xsl:variable name="group" select="$config//types/*[@element and child::*[local-name() = $tag]]" />
94 <!-- ignore namespaced elements -->
95 <xsl:when test="namespace-uri()" />
96 <xsl:when test="$group/@element">
98 <xsl:element name="{$group/@element}" namespace="http://www.w3.org/1999/xhtml">
99 <xsl:apply-templates select="$element" mode="element-content" >
100 <xsl:with-param name="mypath" select="$mypath" />
101 <xsl:with-param name="mixed" select="boolean($group/@mixed)" />
102 </xsl:apply-templates>
114 <xsl:template match="pr|pa|pe|pt" mode="element-tag">
115 <a href="#annotation-{generate-id(.)}"><span class="annotation"/></a><a name="anchor-{generate-id(.)}" />
118 <xsl:template match="dlugi_cytat|poezja_cyt" mode="element-tag">
119 <xsl:param name="offset" />
120 <xsl:param name="parent-path" />
121 <xsl:variable name="mypath"
122 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
124 <xsl:element name="blockquote" >
125 <xsl:call-template name="generic-attributes">
126 <xsl:with-param name="element" select="current()" />
127 <xsl:with-param name="mypath" select="$mypath" />
129 <xsl:call-template name="generic-descent">
130 <xsl:with-param name="element" select="current()" />
131 <xsl:with-param name="mypath" select="$mypath" />
132 <xsl:with-param name="mixed" select="true" />
138 <xsl:template match="lista_osob" mode="element-tag">
139 <xsl:param name="offset" />
140 <xsl:param name="parent-path" />
141 <xsl:variable name="mypath"
142 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
144 <xsl:element name="div" >
145 <xsl:call-template name="generic-attributes">
146 <xsl:with-param name="element" select="current()" />
147 <xsl:with-param name="mypath" select="$mypath" />
150 <xsl:apply-templates select="./naglowek-listy" mode="element-tag" />
152 <xsl:for-each select="./lista_osoba">
153 <xsl:apply-templates select="." mode="element-tag">
154 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
155 <xsl:with-param name="parent-path" select="$mypath" />
156 <xsl:with-param name="mixed" select="false" />
157 </xsl:apply-templates>
163 <xsl:template match="lista_osoba" mode="element-tag">
164 <xsl:param name="offset" />
165 <xsl:param name="parent-path" />
166 <xsl:variable name="mypath"
167 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
169 <xsl:element name="li" >
170 <xsl:call-template name="generic-attributes">
171 <xsl:with-param name="element" select="current()" />
172 <xsl:with-param name="mypath" select="$mypath" />
174 <xsl:call-template name="generic-descent">
175 <xsl:with-param name="element" select="current()" />
176 <xsl:with-param name="mypath" select="$mypath" />
177 <xsl:with-param name="mixed" select="true" />
182 <xsl:template match="separator_linia" mode="element-tag">
183 <xsl:param name="offset" />
184 <xsl:param name="parent-path" />
185 <xsl:variable name="mypath"
186 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
188 <xsl:element name="hr" >
189 <xsl:call-template name="generic-attributes">
190 <xsl:with-param name="element" select="current()" />
191 <xsl:with-param name="mypath" select="$mypath" />
196 <xsl:template match="sekcja_swiatlo" mode="element-tag">
197 <xsl:param name="offset" />
198 <xsl:param name="parent-path" />
199 <xsl:variable name="mypath"
200 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
202 <xsl:element name="br" >
203 <xsl:call-template name="generic-attributes">
204 <xsl:with-param name="element" select="current()" />
205 <xsl:with-param name="mypath" select="$mypath" />
210 <xsl:template match="sekcja_asterysk" mode="element-tag">
211 <xsl:param name="offset" />
212 <xsl:param name="parent-path" />
213 <xsl:variable name="mypath"
214 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
216 <xsl:element name="p" >
217 <xsl:call-template name="generic-attributes">
218 <xsl:with-param name="element" select="current()" />
219 <xsl:with-param name="mypath" select="$mypath" />
225 <xsl:template match="zastepnik_wersu|wers_akap|wers_cd|wers_wciety" mode="element-tag">
226 <xsl:param name="offset" />
227 <xsl:param name="parent-path" />
229 <xsl:variable name="mypath"
230 select="concat($parent-path, '/', name(), '[',string($offset),']')" />
232 <xsl:call-template name="generic-descent">
233 <xsl:with-param name="element" select="current()" />
234 <xsl:with-param name="mypath" select="$mypath" />
235 <xsl:with-param name="mixed" select="boolean(1)" />
240 <xsl:template match="strofa" mode="element-tag">
241 <xsl:param name="offset" />
242 <xsl:param name="parent-path" />
244 <xsl:variable name="mypath"
245 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
247 <xsl:element name="div" >
248 <xsl:call-template name="generic-attributes">
249 <xsl:with-param name="element" select="current()" />
250 <xsl:with-param name="mypath" select="$mypath" />
254 <xsl:when test="count(br) > 0">
255 <xsl:call-template name="verse">
256 <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
257 <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd'][1]" />
258 <xsl:with-param name="mypath" select="$mypath" />
260 <xsl:for-each select="br">
261 <!-- Each BR tag "consumes" text after it -->
262 <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
263 <xsl:call-template name="verse">
264 <xsl:with-param name="verse-content"
265 select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
266 <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]" />
267 <xsl:with-param name="mypath" select="$mypath" />
272 <xsl:call-template name="verse">
273 <xsl:with-param name="verse-content" select="child::node()" />
274 <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd[1]" />
275 <xsl:with-param name="mypath" select="$mypath" />
282 <xsl:template name="verse">
283 <xsl:param name="verse-content" />
284 <xsl:param name="verse-type" />
285 <xsl:param name="mypath" />
287 <xsl:element name="p">
288 <xsl:attribute name="class">
289 <xsl:value-of select="name($verse-type)" />
291 <xsl:for-each select="$verse-content">
292 <xsl:apply-templates select="." mode="element-tag">
293 <xsl:with-param name="offset" select="count(preceding-sibling::*)" />
294 <xsl:with-param name="parent-path" select="$mypath" />
295 <xsl:with-param name="mixed" select="boolean(1)" />
296 </xsl:apply-templates>
302 <!-- default content processing -->
303 <xsl:template match="*" mode="element-content">
304 <xsl:param name="mypath" />
305 <xsl:param name="mixed" />
307 <xsl:call-template name="generic-content">
308 <xsl:with-param name="element" select="current()"/>
309 <xsl:with-param name="mypath" select="$mypath"/>
310 <xsl:with-param name="mixed" select="$mixed"/>
314 <xsl:template match="*" mode="element-tag" >
315 <xsl:param name="offset" />
316 <xsl:param name="parent-path" />
317 <xsl:param name="mixed" />
319 <xsl:variable name="mypath"
320 select="concat($parent-path, '/', name(), '[', string($offset),']')" />
322 <xsl:call-template name="generic">
323 <xsl:with-param name="element" select="current()" />
324 <xsl:with-param name="offset" select="$offset" />
325 <xsl:with-param name="mypath" select="$mypath" />
326 <xsl:with-param name="mixed" select="$mixed"/>
330 <xsl:template match="text()" mode="element-tag">
331 <xsl:param name="mixed" />
335 <xsl:when test="not($mixed)">
337 <xsl:when test="not(normalize-space(.))" />
338 <xsl:when test="normalize-space(.) = ''"/>
341 <div class="parse-warning">
342 <p class="message">Uwaga! Tekst poza paragrafem</p>
343 <p>#<xsl:copy-of select="." />#</p>
350 <xsl:value-of select="wl:substitute_entities(.)">
352 <xsl:value-of select="." />
361 <xsl:template match="node()" />