transform choice exercise to WL1 + refactor
[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 <xsl:output encoding="utf-8" indent="yes" omit-xml-declaration = "yes" version="2.0" />
6
7 <xsl:template match="section">
8     <xsl:choose>
9         <xsl:when test="not(ancestor::*)">
10         <utwor xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wl="http://wolnelektury.pl/functions">
11         <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
12         <rdf:Description>
13             <xsl:attribute name="rdf:about">
14                 <xsl:text>http://redakcja.edukacjamedialna.edu.pl/documents/book/</xsl:text>
15                 <xsl:value-of select="@redslug" />
16                 <xsl:text>/</xsl:text>
17             </xsl:attribute>
18             <dc:title xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"><xsl:apply-templates select="header/text()" /></dc:title>
19             <dc:identifier.url xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">
20                 <xsl:text>http://edukacjamedialna.edu.pl/lekcje/</xsl:text>
21                 <xsl:value-of select="@wlslug" />
22                 <xsl:text>/</xsl:text>
23             </dc:identifier.url>
24
25             <!--dc:creator.expert xml:lang="pl" ></dc:creator.expert>
26             <dc:creator.methodologist xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"></dc:creator.methodologist>
27             <dc:creator.scenario xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"></dc:creator.scenario>
28             <dc:creator.textbook xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"></dc:creator.textbook-->
29
30             <xsl:apply-templates select="metadata" mode="meta" />
31
32             <dc:publisher xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">Fundacja Nowoczesna Polska</dc:publisher>
33             <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>
34             <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>
35             <dc:format xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">xml</dc:format>
36             <!--dc:type xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">added-var</dc:type-->
37             <dc:date xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">2015-01-12</dc:date>
38             <!--dc:audience xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/"><!- -liceum - -><xsl:value-of select="//dc:audience/text()" /></dc:audience-->
39             <dc:language xml:lang="pl" xmlns:dc="http://purl.org/dc/elements/1.1/">pol</dc:language>
40         </rdf:Description>
41         </rdf:RDF>
42         <powiesc>
43             <xsl:apply-templates />
44         </powiesc>
45         </utwor>
46         </xsl:when>
47         <xsl:when test="count(ancestor::*) = 3">
48             <aktywnosc>
49                 <opis><xsl:apply-templates select="header" /><xsl:apply-templates select="div" mode="opis" /></opis>
50                 <xsl:apply-templates select="div" mode="aktywnosc" />
51                 <xsl:apply-templates select="section" mode="error" />
52             </aktywnosc>
53         </xsl:when>
54         <xsl:otherwise><xsl:apply-templates /></xsl:otherwise>
55     </xsl:choose>
56 </xsl:template>
57
58 <!-- TODO language-dependent: description, audience, requires (subject.competence?) -->
59 <xsl:template match="dc:creator.expert|dc:creator.scenario|dc:creator.textbook|dc:description|dc:subject.curriculum|dc:creator.methodologist|dc:subject.competence|dc:audience|dc:type|dc:requires" mode="meta">
60     <xsl:copy><xsl:apply-templates /></xsl:copy>
61 </xsl:template>
62
63 <xsl:template match="metadata"/>
64 <xsl:template match="aside">
65     <xsl:if test="@class = 'gap'">
66         <luka><xsl:apply-templates/></luka>
67     </xsl:if>
68 </xsl:template>
69
70
71 <xsl:template match="header">
72     <xsl:choose>
73         <xsl:when test="count(ancestor::*) = 1">
74             <nazwa_utworu><xsl:apply-templates /></nazwa_utworu>
75         </xsl:when>
76         <xsl:when test="count(ancestor::*) = 2">
77             <naglowek_rozdzial><xsl:apply-templates /></naglowek_rozdzial>
78         </xsl:when>
79         <xsl:when test="count(ancestor::*) = 3">
80             <naglowek_podrozdzial><xsl:apply-templates /></naglowek_podrozdzial>
81         </xsl:when>
82         <xsl:when test="count(ancestor::*) = 4">
83             <akap><xsl:apply-templates /></akap>
84         </xsl:when>
85     </xsl:choose>
86 </xsl:template>
87
88
89 <xsl:template match="div">
90     <xsl:choose>
91         <xsl:when test="@class = 'p'">
92             <akap><xsl:apply-templates /></akap>
93         </xsl:when>
94         <xsl:when test="@class = 'list'">
95             <lista typ="punkt"><xsl:apply-templates /></lista>
96         </xsl:when>
97         <xsl:when test="@class = 'list.itemized'">
98             <lista typ="punkt"><xsl:apply-templates /></lista>
99         </xsl:when>
100         <xsl:when test="@class = 'list.orderable'">
101             <lista typ="punkt"><xsl:apply-templates /></lista>
102         </xsl:when>
103         <xsl:when test="@class = 'list.enum'">
104             <lista typ="num"><xsl:apply-templates /></lista>
105         </xsl:when>
106         <xsl:when test="@class = 'list.definitions'">
107             <xsl:choose>
108                 <xsl:when test="@src = ''">
109                     <lista typ="slowniczek"><xsl:apply-templates /></lista>
110                 </xsl:when>
111                 <xsl:otherwise>
112                     <lista typ="slowniczek" src="{@src}"><xsl:apply-templates /></lista>
113                 </xsl:otherwise>
114             </xsl:choose>
115         </xsl:when>
116         <xsl:when test="@class = 'list.bibliography'">
117             <lista typ="czytelnia"><xsl:apply-templates /></lista>
118         </xsl:when>
119         <xsl:when test="@class = 'item'">
120             <punkt><xsl:apply-templates /></punkt>
121         </xsl:when>
122         <xsl:when test="@class = 'item.answer'">
123             <xsl:element name="punkt">
124                 <xsl:attribute name="rozw">
125                     <xsl:choose>
126                         <xsl:when test="@answer = 'true'">prawda</xsl:when>
127                         <xsl:when test="@answer = 'false'">falsz</xsl:when>
128                         <xsl:otherwise><xsl:value-of select="@answer" /></xsl:otherwise>
129                     </xsl:choose>
130                 </xsl:attribute>
131                 <xsl:apply-templates />
132             </xsl:element>
133         </xsl:when>
134         <xsl:when test="@class = 'defined'">
135             <xsl:choose>
136                 <xsl:when test="count(ancestor::*) = 4 ">
137                     <definiendum><xsl:apply-templates /></definiendum>
138                 </xsl:when>
139                 <xsl:otherwise>
140                 </xsl:otherwise>
141             </xsl:choose>
142         </xsl:when>
143         <xsl:when test="@class = 'exercise.order'">
144             <cwiczenie typ="uporzadkuj">
145                 <xsl:call-template name="cwiczenie"/>
146             </cwiczenie>
147         </xsl:when>
148         <xsl:when test="@class = 'exercise.choice.true-or-false'">
149             <cwiczenie typ="prawdafalsz">
150                 <xsl:call-template name="cwiczenie"/>
151             </cwiczenie>
152         </xsl:when>
153         <xsl:when test="@class = 'exercise.choice' or @class = 'exercise.choice.single'">
154             <cwiczenie typ="wybor">
155                 <opis><akap>[opis]</akap></opis>
156                 <lista typ="num">
157                     <punkt>
158                         <pytanie>
159                             <xsl:for-each select="div">
160                                 <xsl:choose>
161                                     <xsl:when test="@class = 'p'">
162                                         <xsl:apply-templates />
163                                     </xsl:when>
164                                     <xsl:otherwise>
165                                         <xsl:apply-templates select="."/>
166                                     </xsl:otherwise>
167                                 </xsl:choose>
168                             </xsl:for-each>
169                         </pytanie>
170                     </punkt>
171                 </lista>
172             </cwiczenie>
173         </xsl:when>
174         <xsl:when test="@class = 'exercise.gap'">
175             <cwiczenie typ="luki">
176                 <opis><akap>Uzupełnij luki:</akap></opis>
177                 <xsl:apply-templates/>
178             </cwiczenie>
179         </xsl:when>
180         <xsl:when test="@class = 'exercise.replace'">
181             <cwiczenie typ="zastap">
182                 <opis><akap>Znajdź i zamień niepasujące słowa w zdaniach na następujące:</akap></opis>
183                 <xsl:apply-templates/>
184             </cwiczenie>
185         </xsl:when>
186         <xsl:otherwise>
187             <NIEZNANY_DIV><xsl:value-of select="@class" /></NIEZNANY_DIV>
188         </xsl:otherwise>
189     </xsl:choose>
190 </xsl:template>
191
192 <xsl:template match="div" mode="opis">
193     <xsl:choose>
194         <xsl:when test="@class = 'p'">
195             <akap><xsl:apply-templates /></akap>
196         </xsl:when>
197         <xsl:when test="@class = 'list'">
198             <lista typ="punkt"><xsl:apply-templates /></lista>
199         </xsl:when>
200         <xsl:when test="@class = 'list.itemized'">
201             <lista typ="punkt"><xsl:apply-templates /></lista>
202         </xsl:when>
203         <xsl:when test="@class = 'item'">
204             <punkt><xsl:apply-templates /></punkt>
205         </xsl:when>
206     </xsl:choose>
207 </xsl:template>
208
209 <xsl:template match="div" mode="aktywnosc">
210     <xsl:choose>
211         <xsl:when test="@class = 'list.definitions'">
212             <xsl:apply-templates mode="defs" />
213         </xsl:when>
214     </xsl:choose>
215 </xsl:template>
216
217
218 <xsl:template match="div" mode="defs">
219     <xsl:choose>
220         <xsl:when test="div/text() = 'Czas'"><czas><xsl:apply-templates /></czas></xsl:when>
221         <xsl:when test="div/text() = 'Metoda'"><forma><xsl:apply-templates /></forma></xsl:when>
222         <xsl:when test="div/text() = 'Pomoce'"><pomoce><xsl:apply-templates /></pomoce></xsl:when>
223     </xsl:choose>
224 </xsl:template>
225
226 <xsl:template match="span">
227     <xsl:choose>
228         <xsl:when test="@class = 'link'">
229             <link>
230                 <xsl:choose>
231                     <xsl:when test="starts-with(@href, 'file://')">
232                         <xsl:attribute name="material">
233                             <xsl:value-of select="wl:rmext(substring(@href, 8))" />
234                         </xsl:attribute>
235                     </xsl:when>
236                     <xsl:when test="starts-with(@href, 'http')">
237                         <xsl:attribute name="url">
238                             <xsl:value-of select="@href" />
239                         </xsl:attribute>
240                     </xsl:when>
241                     <xsl:otherwise>
242                         <xsl:attribute name="url">
243                             <xsl:value-of select="." />
244                         </xsl:attribute>
245                     </xsl:otherwise>
246                 </xsl:choose>
247                 <xsl:apply-templates />
248             </link>
249         </xsl:when>
250         <xsl:when test="@class = 'emp'">
251             <wyroznienie><xsl:apply-templates /></wyroznienie>
252         </xsl:when>
253         <xsl:when test="@class = 'cite'">
254             <dlugi_cytat><xsl:apply-templates /></dlugi_cytat>
255         </xsl:when>
256         <xsl:when test="@class = 'answer'">
257             <zastap rozw="{@answer}"><xsl:apply-templates/></zastap>
258         </xsl:when>
259         <xsl:otherwise>
260             <NIEZNANY_SPAN><xsl:value-of select="@class" /></NIEZNANY_SPAN>
261         </xsl:otherwise>
262     </xsl:choose>
263 </xsl:template>
264
265 <xsl:template match="section" mode="error">
266     NIEZNANA_SEKCJA
267 </xsl:template>
268
269 <xsl:template name="cwiczenie">
270     <xsl:for-each select="div">
271         <xsl:choose>
272             <xsl:when test="@class = 'p'">
273                 <opis><xsl:apply-templates select="."/></opis>
274             </xsl:when>
275             <xsl:otherwise>
276                 <xsl:apply-templates select="."/>
277             </xsl:otherwise>
278         </xsl:choose>
279     </xsl:for-each>
280 </xsl:template>
281
282 </xsl:stylesheet>