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