82fd2b4ac29367b162453a5e7a55e02f47abef4f
[redakcja.git] / redakcja / xslt / wl2to1.xslt
1 <?xml version="1.0" encoding="utf-8"?>
2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3     xmlns:wl="http://wolnelektury.pl/functions"
4     xmlns:dc="http://purl.org/dc/elements/1.1/"
5     exclude-result-prefixes="wl dc"><!-- nie jestem pewien czy tak ma być -->
6 <xsl:output encoding="utf-8" indent="yes" omit-xml-declaration = "yes" version="2.0" />
7
8 <xsl:template match="section">
9     <xsl:choose>
10         <xsl:when test="not(ancestor::*)">
11         <utwor xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wl="http://wolnelektury.pl/functions">
12         <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
13         <rdf:Description>
14             <xsl:attribute name="rdf:about">
15                 <xsl:text>http://redakcja.edukacjamedialna.edu.pl/documents/book/</xsl:text>
16                 <xsl:value-of select="@redslug" />
17                 <xsl:text>/</xsl:text>
18             </xsl:attribute>
19             <dc:title xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"><xsl:apply-templates select="header/text()" /></dc:title>
20             <dc:identifier.url xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">
21                 <xsl:text>http://edukacjamedialna.edu.pl/lekcje/</xsl:text>
22                 <xsl:value-of select="@wlslug" />
23                 <xsl:text>/</xsl:text>
24             </dc:identifier.url>
25
26             <!--dc:creator.expert xml:lang="pl" ></dc:creator.expert>
27             <dc:creator.methodologist xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"></dc:creator.methodologist>
28             <dc:creator.scenario xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"></dc:creator.scenario>
29             <dc:creator.textbook xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"></dc:creator.textbook-->
30
31             <xsl:apply-templates select="metadata" mode="meta" />
32
33             <xsl:if test="not(//dc:publisher)">
34                 <dc:publisher xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">Fundacja Nowoczesna Polska</dc:publisher>
35             </xsl:if>
36             <dc:rights xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">Creative Commons Uznanie autorstwa - Na tych samych warunkach 3.0</dc:rights>
37             <dc:rights.license xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">http://creativecommons.org/licenses/by-sa/3.0/</dc:rights.license>
38             <dc:format xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">xml</dc:format>
39             <!--dc:type xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">added-var</dc:type-->
40             <xsl:if test="not(//dc:date)">
41                 <dc:date xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">2015-01-12</dc:date>
42             </xsl:if>
43             <!--dc:audience xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"><!- -liceum - -><xsl:value-of select="//dc:audience/text()" /></dc:audience-->
44             <dc:language xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">pol</dc:language>
45         </rdf:Description>
46         </rdf:RDF>
47         <powiesc>
48             <xsl:apply-templates />
49         </powiesc>
50         </utwor>
51         </xsl:when>
52         <xsl:when test="count(ancestor::*) = 3">
53             <aktywnosc>
54                 <opis><xsl:apply-templates select="header" /><xsl:apply-templates select="div" mode="opis" /></opis>
55                 <xsl:apply-templates select="div" mode="aktywnosc" />
56                 <xsl:apply-templates select="section" mode="error" />
57             </aktywnosc>
58         </xsl:when>
59         <xsl:otherwise><xsl:apply-templates /></xsl:otherwise>
60     </xsl:choose>
61 </xsl:template>
62
63 <!-- TODO language-dependent: description, audience, requires (subject.competence?) -->
64 <xsl:template match="dc:creator.expert|dc:creator.scenario|dc:creator.textbook|dc:description|dc:subject.curriculum|dc:subject.curriculum.new|dc:creator.methodologist|dc:subject.competence|dc:audience|dc:type|dc:requires|dc:relation|dc:subject|dc:date|dc:publisher" mode="meta">
65     <xsl:copy><xsl:apply-templates /></xsl:copy>
66 </xsl:template>
67
68 <xsl:template match="metadata"/>
69 <xsl:template match="aside">
70     <xsl:if test="@class = 'gap'">
71         <luka><xsl:apply-templates/></luka>
72     </xsl:if>
73 </xsl:template>
74
75
76 <xsl:template match="header">
77     <xsl:choose>
78         <xsl:when test="count(ancestor::*) = 1">
79             <nazwa_utworu><xsl:apply-templates /></nazwa_utworu>
80         </xsl:when>
81         <xsl:when test="count(ancestor::*) = 2">
82             <naglowek_rozdzial><xsl:apply-templates /></naglowek_rozdzial>
83         </xsl:when>
84         <xsl:when test="count(ancestor::*) = 3">
85             <naglowek_podrozdzial><xsl:apply-templates /></naglowek_podrozdzial>
86         </xsl:when>
87         <xsl:when test="count(ancestor::*) = 4">
88             <akap><xsl:apply-templates /></akap>
89         </xsl:when>
90     </xsl:choose>
91 </xsl:template>
92
93
94 <xsl:template match="div">
95     <xsl:choose>
96         <xsl:when test="@class = 'p'">
97             <akap><xsl:apply-templates /></akap>
98         </xsl:when>
99         <xsl:when test="@class = 'list'">
100             <lista typ="punkt">
101                 <xsl:if test="@name">
102                     <xsl:attribute name="nazwa"><xsl:value-of select="@name"/></xsl:attribute>
103                 </xsl:if>
104                 <xsl:if test="@dest">
105                     <xsl:attribute name="cel"><xsl:value-of select="@dest"/></xsl:attribute>
106                 </xsl:if>
107                 <xsl:if test="@handles">
108                     <xsl:attribute name="uchwyty"><xsl:value-of select="@handles"/></xsl:attribute>
109                 </xsl:if>
110                 <xsl:if test="@short">
111                     <xsl:attribute name="krotkie"><xsl:value-of select="@short"/></xsl:attribute>
112                 </xsl:if>
113                 <xsl:apply-templates />
114             </lista>
115         </xsl:when>
116         <xsl:when test="@class = 'list.itemized'">
117             <lista typ="punkt"><xsl:apply-templates /></lista>
118         </xsl:when>
119         <xsl:when test="@class = 'list.orderable'">
120             <lista typ="punkt"><xsl:apply-templates /></lista>
121         </xsl:when>
122         <xsl:when test="@class = 'list.enum'">
123             <lista typ="num"><xsl:apply-templates /></lista>
124         </xsl:when>
125         <xsl:when test="@class = 'list.definitions'">
126             <lista typ="slowniczek">
127                 <xsl:if test="@src">
128                     <xsl:attribute name="src"><xsl:value-of select="@src"/></xsl:attribute>
129                 </xsl:if>
130                 <xsl:apply-templates />
131             </lista>
132         </xsl:when>
133         <xsl:when test="@class = 'list.bibliography'">
134             <lista typ="czytelnia"><xsl:apply-templates /></lista>
135         </xsl:when>
136         <xsl:when test="@class = 'item'">
137             <punkt><xsl:apply-templates /></punkt>
138         </xsl:when>
139         <xsl:when test="@class = 'item.category'">
140             <punkt nazwa="{@name}"><xsl:apply-templates /></punkt>
141         </xsl:when>
142         <xsl:when test="@class = 'item.answer'">
143             <punkt>
144                 <xsl:attribute name="rozw">
145                     <xsl:choose>
146                         <xsl:when test="@answer = 'true'">prawda</xsl:when>
147                         <xsl:when test="@answer = 'false'">falsz</xsl:when>
148                         <xsl:otherwise><xsl:value-of select="@answer" /></xsl:otherwise>
149                     </xsl:choose>
150                 </xsl:attribute>
151                 <xsl:apply-templates />
152             </punkt>
153         </xsl:when>
154         <xsl:when test="@class = 'question'">
155             <pytanie>
156                 <xsl:for-each select="div">
157                     <xsl:choose>
158                         <xsl:when test="@class = 'p'">
159                             <xsl:apply-templates />
160                         </xsl:when>
161                         <xsl:otherwise>
162                             <xsl:apply-templates select="."/>
163                         </xsl:otherwise>
164                     </xsl:choose>
165                 </xsl:for-each>
166             </pytanie>
167         </xsl:when>
168         <xsl:when test="@class = 'defined'">
169             <xsl:choose>
170                 <xsl:when test="count(ancestor::*) = 4 ">
171                     <definiendum><xsl:apply-templates /></definiendum>
172                 </xsl:when>
173                 <xsl:otherwise>
174                 </xsl:otherwise>
175             </xsl:choose>
176         </xsl:when>
177         <xsl:when test="@class = 'img'">
178             <obraz nazwa="{@name}" alt="{@alt}"/>
179         </xsl:when>
180         <xsl:when test="@class = 'video'">
181             <video url="{@src}"/>
182         </xsl:when>
183         <xsl:when test="@class = 'label'">
184             <podpis>
185                 <xsl:apply-templates/>
186             </podpis>
187         </xsl:when>
188         <xsl:when test="@class = 'solution.comment'">
189             <rozw_kom>
190                 <xsl:apply-templates/>
191             </rozw_kom>
192         </xsl:when>
193         <xsl:when test="@class = 'important'">
194             <dlugi_cytat>
195                 <xsl:apply-templates/>
196             </dlugi_cytat>
197         </xsl:when>
198         <xsl:when test="@class = 'exercise.order'">
199             <cwiczenie typ="uporzadkuj">
200                 <xsl:call-template name="cwiczenie"/>
201             </cwiczenie>
202         </xsl:when>
203         <xsl:when test="@class = 'exercise.choice.true-or-false'">
204             <cwiczenie typ="prawdafalsz">
205                 <xsl:call-template name="cwiczenie"/>
206             </cwiczenie>
207         </xsl:when>
208         <xsl:when test="@class = 'exercise.choice' or @class = 'exercise.choice.single'">
209             <cwiczenie typ="wybor">
210                 <xsl:call-template name="cwiczenie"/>
211             </cwiczenie>
212         </xsl:when>
213         <xsl:when test="@class = 'exercise.match'">
214             <cwiczenie typ="przyporzadkuj">
215                 <xsl:call-template name="cwiczenie"/>
216             </cwiczenie>
217         </xsl:when>
218         <xsl:when test="@class = 'exercise.gap'">
219             <cwiczenie typ="luki">
220                 <xsl:choose>
221                     <xsl:when test="div[1]/aside[@class = 'gap']">
222                         <opis><akap>Uzupełnij luki:</akap></opis>
223                         <xsl:apply-templates/>
224                     </xsl:when>
225                     <xsl:otherwise>
226                         <opis><xsl:apply-templates select="*[1]"/></opis>
227                         <xsl:apply-templates select="*[position() > 1]"/>
228                     </xsl:otherwise>
229                 </xsl:choose>
230             </cwiczenie>
231         </xsl:when>
232         <xsl:when test="@class = 'exercise.replace'">
233             <cwiczenie typ="zastap">
234                 <xsl:choose>
235                     <xsl:when test="div[1]/aside[@class = 'gap']">
236                         <opis><akap>Znajdź i zamień niepasujące słowa w zdaniach na następujące:</akap></opis>
237                         <xsl:apply-templates/>
238                     </xsl:when>
239                     <xsl:otherwise>
240                         <opis><xsl:apply-templates select="*[1]"/></opis>
241                         <xsl:apply-templates select="*[position() > 1]"/>
242                     </xsl:otherwise>
243                 </xsl:choose>
244             </cwiczenie>
245         </xsl:when>
246         <xsl:when test="@class = 'table'">
247             <tabela ramki="0">
248                 <xsl:apply-templates/>
249             </tabela>
250         </xsl:when>
251         <xsl:when test="@class = 'table.row'">
252             <wiersz><xsl:apply-templates/></wiersz>
253         </xsl:when>
254         <xsl:when test="@class = 'table.cell'">
255             <kol><xsl:apply-templates/></kol>
256         </xsl:when>
257         <xsl:when test="@class = 'verse'">
258             <strofa><xsl:apply-templates/></strofa>
259         </xsl:when>
260         <xsl:otherwise>
261             <NIEZNANY_DIV><xsl:value-of select="@class" /></NIEZNANY_DIV>
262         </xsl:otherwise>
263     </xsl:choose>
264 </xsl:template>
265
266 <xsl:template match="div" mode="opis">
267     <xsl:choose>
268         <xsl:when test="@class != 'list.definitions'">
269             <xsl:apply-templates select="." />
270         </xsl:when>
271     </xsl:choose>
272 </xsl:template>
273
274 <xsl:template match="div" mode="aktywnosc">
275     <xsl:choose>
276         <xsl:when test="@class = 'list.definitions'">
277             <xsl:apply-templates mode="defs" />
278         </xsl:when>
279     </xsl:choose>
280 </xsl:template>
281
282
283 <xsl:template match="div" mode="defs">
284     <xsl:choose>
285         <xsl:when test="div/text() = 'Czas'"><czas><xsl:apply-templates /></czas></xsl:when>
286         <xsl:when test="div/text() = 'Metoda'"><forma><xsl:apply-templates /></forma></xsl:when>
287         <xsl:when test="div/text() = 'Pomoce'"><pomoce><xsl:apply-templates /></pomoce></xsl:when>
288     </xsl:choose>
289 </xsl:template>
290
291 <xsl:template match="span">
292     <xsl:choose>
293         <xsl:when test="@class = 'link'">
294             <link>
295                 <xsl:choose>
296                     <xsl:when test="starts-with(@href, 'file://')">
297                         <xsl:attribute name="material">
298                             <xsl:value-of select="wl:rmext(substring(@href, 8))" />
299                         </xsl:attribute>
300                     </xsl:when>
301                     <xsl:when test="starts-with(@href, 'http') or starts-with(@href, '#')">
302                         <xsl:attribute name="url">
303                             <xsl:value-of select="@href" />
304                         </xsl:attribute>
305                     </xsl:when>
306                     <xsl:otherwise>
307                         <xsl:attribute name="url">
308                             <xsl:value-of select="." />
309                         </xsl:attribute>
310                     </xsl:otherwise>
311                 </xsl:choose>
312                 <xsl:apply-templates />
313             </link>
314         </xsl:when>
315         <xsl:when test="@class = 'emp'">
316             <wyroznienie><xsl:apply-templates /></wyroznienie>
317         </xsl:when>
318         <xsl:when test="@class = 'cite'">
319             <tytul_dziela><xsl:apply-templates /></tytul_dziela>
320         </xsl:when>
321         <xsl:when test="@class = 'answer'">
322             <zastap rozw="{@answer}"><xsl:apply-templates/></zastap>
323         </xsl:when>
324         <xsl:otherwise>
325             <NIEZNANY_SPAN><xsl:value-of select="@class" /></NIEZNANY_SPAN>
326         </xsl:otherwise>
327     </xsl:choose>
328 </xsl:template>
329
330 <xsl:template match="section" mode="error">
331     NIEZNANA_SEKCJA
332 </xsl:template>
333
334 <xsl:template name="cwiczenie">
335     <xsl:for-each select="div">
336         <xsl:choose>
337             <xsl:when test="@class = 'p'">
338                 <opis><xsl:apply-templates select="."/></opis>
339                 <!-- https://stackoverflow.com/questions/27374493/grouping-the-consecutive-elements-in-xslt -->
340             </xsl:when>
341             <xsl:otherwise>
342                 <xsl:apply-templates select="."/>
343             </xsl:otherwise>
344         </xsl:choose>
345     </xsl:for-each>
346 </xsl:template>
347
348 </xsl:stylesheet>