6882a7538f83d7868cdb7820311219854185d8ee
[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:subject.curriculum.new|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">
96                 <xsl:if test="@name">
97                     <xsl:attribute name="nazwa"><xsl:value-of select="@name"/></xsl:attribute>
98                 </xsl:if>
99                 <xsl:if test="@dest">
100                     <xsl:attribute name="cel"><xsl:value-of select="@dest"/></xsl:attribute>
101                 </xsl:if>
102                 <xsl:apply-templates />
103             </lista>
104         </xsl:when>
105         <xsl:when test="@class = 'list.itemized'">
106             <lista typ="punkt"><xsl:apply-templates /></lista>
107         </xsl:when>
108         <xsl:when test="@class = 'list.orderable'">
109             <lista typ="punkt"><xsl:apply-templates /></lista>
110         </xsl:when>
111         <xsl:when test="@class = 'list.enum'">
112             <lista typ="num"><xsl:apply-templates /></lista>
113         </xsl:when>
114         <xsl:when test="@class = 'list.definitions'">
115             <xsl:choose>
116                 <xsl:when test="@src = ''">
117                     <lista typ="slowniczek"><xsl:apply-templates /></lista>
118                 </xsl:when>
119                 <xsl:otherwise>
120                     <lista typ="slowniczek" src="{@src}"><xsl:apply-templates /></lista>
121                 </xsl:otherwise>
122             </xsl:choose>
123         </xsl:when>
124         <xsl:when test="@class = 'list.bibliography'">
125             <lista typ="czytelnia"><xsl:apply-templates /></lista>
126         </xsl:when>
127         <xsl:when test="@class = 'item'">
128             <punkt><xsl:apply-templates /></punkt>
129         </xsl:when>
130         <xsl:when test="@class = 'item.category'">
131             <punkt nazwa="{@name}"><xsl:apply-templates /></punkt>
132         </xsl:when>
133         <xsl:when test="@class = 'item.answer'">
134             <punkt>
135                 <xsl:attribute name="rozw">
136                     <xsl:choose>
137                         <xsl:when test="@answer = 'true'">prawda</xsl:when>
138                         <xsl:when test="@answer = 'false'">falsz</xsl:when>
139                         <xsl:otherwise><xsl:value-of select="@answer" /></xsl:otherwise>
140                     </xsl:choose>
141                 </xsl:attribute>
142                 <xsl:apply-templates />
143             </punkt>
144         </xsl:when>
145         <xsl:when test="@class = 'question'">
146             <pytanie>
147                 <xsl:for-each select="div">
148                     <xsl:choose>
149                         <xsl:when test="@class = 'p'">
150                             <xsl:apply-templates />
151                         </xsl:when>
152                         <xsl:otherwise>
153                             <xsl:apply-templates select="."/>
154                         </xsl:otherwise>
155                     </xsl:choose>
156                 </xsl:for-each>
157             </pytanie>
158         </xsl:when>
159         <xsl:when test="@class = 'defined'">
160             <xsl:choose>
161                 <xsl:when test="count(ancestor::*) = 4 ">
162                     <definiendum><xsl:apply-templates /></definiendum>
163                 </xsl:when>
164                 <xsl:otherwise>
165                 </xsl:otherwise>
166             </xsl:choose>
167         </xsl:when>
168         <xsl:when test="@class = 'exercise.order'">
169             <cwiczenie typ="uporzadkuj">
170                 <xsl:call-template name="cwiczenie"/>
171             </cwiczenie>
172         </xsl:when>
173         <xsl:when test="@class = 'exercise.choice.true-or-false'">
174             <cwiczenie typ="prawdafalsz">
175                 <xsl:call-template name="cwiczenie"/>
176             </cwiczenie>
177         </xsl:when>
178         <xsl:when test="@class = 'exercise.choice' or @class = 'exercise.choice.single'">
179             <cwiczenie typ="wybor">
180                 <xsl:call-template name="cwiczenie"/>
181             </cwiczenie>
182         </xsl:when>
183         <xsl:when test="@class = 'exercise.match'">
184             <cwiczenie typ="przyporzadkuj">
185                 <xsl:call-template name="cwiczenie"/>
186             </cwiczenie>
187         </xsl:when>
188         <xsl:when test="@class = 'exercise.gap'">
189             <cwiczenie typ="luki">
190                 <opis><akap>Uzupełnij luki:</akap></opis>
191                 <xsl:apply-templates/>
192             </cwiczenie>
193         </xsl:when>
194         <xsl:when test="@class = 'exercise.replace'">
195             <cwiczenie typ="zastap">
196                 <opis><akap>Znajdź i zamień niepasujące słowa w zdaniach na następujące:</akap></opis>
197                 <xsl:apply-templates/>
198             </cwiczenie>
199         </xsl:when>
200         <xsl:otherwise>
201             <NIEZNANY_DIV><xsl:value-of select="@class" /></NIEZNANY_DIV>
202         </xsl:otherwise>
203     </xsl:choose>
204 </xsl:template>
205
206 <xsl:template match="div" mode="opis">
207     <xsl:choose>
208         <xsl:when test="@class = 'p'">
209             <akap><xsl:apply-templates /></akap>
210         </xsl:when>
211         <xsl:when test="@class = 'list'">
212             <lista typ="punkt"><xsl:apply-templates /></lista>
213         </xsl:when>
214         <xsl:when test="@class = 'list.itemized'">
215             <lista typ="punkt"><xsl:apply-templates /></lista>
216         </xsl:when>
217         <xsl:when test="@class = 'item'">
218             <punkt><xsl:apply-templates /></punkt>
219         </xsl:when>
220     </xsl:choose>
221 </xsl:template>
222
223 <xsl:template match="div" mode="aktywnosc">
224     <xsl:choose>
225         <xsl:when test="@class = 'list.definitions'">
226             <xsl:apply-templates mode="defs" />
227         </xsl:when>
228     </xsl:choose>
229 </xsl:template>
230
231
232 <xsl:template match="div" mode="defs">
233     <xsl:choose>
234         <xsl:when test="div/text() = 'Czas'"><czas><xsl:apply-templates /></czas></xsl:when>
235         <xsl:when test="div/text() = 'Metoda'"><forma><xsl:apply-templates /></forma></xsl:when>
236         <xsl:when test="div/text() = 'Pomoce'"><pomoce><xsl:apply-templates /></pomoce></xsl:when>
237     </xsl:choose>
238 </xsl:template>
239
240 <xsl:template match="span">
241     <xsl:choose>
242         <xsl:when test="@class = 'link'">
243             <link>
244                 <xsl:choose>
245                     <xsl:when test="starts-with(@href, 'file://')">
246                         <xsl:attribute name="material">
247                             <xsl:value-of select="wl:rmext(substring(@href, 8))" />
248                         </xsl:attribute>
249                     </xsl:when>
250                     <xsl:when test="starts-with(@href, 'http')">
251                         <xsl:attribute name="url">
252                             <xsl:value-of select="@href" />
253                         </xsl:attribute>
254                     </xsl:when>
255                     <xsl:otherwise>
256                         <xsl:attribute name="url">
257                             <xsl:value-of select="." />
258                         </xsl:attribute>
259                     </xsl:otherwise>
260                 </xsl:choose>
261                 <xsl:apply-templates />
262             </link>
263         </xsl:when>
264         <xsl:when test="@class = 'emp'">
265             <wyroznienie><xsl:apply-templates /></wyroznienie>
266         </xsl:when>
267         <xsl:when test="@class = 'cite'">
268             <dlugi_cytat><xsl:apply-templates /></dlugi_cytat>
269         </xsl:when>
270         <xsl:when test="@class = 'answer'">
271             <zastap rozw="{@answer}"><xsl:apply-templates/></zastap>
272         </xsl:when>
273         <xsl:otherwise>
274             <NIEZNANY_SPAN><xsl:value-of select="@class" /></NIEZNANY_SPAN>
275         </xsl:otherwise>
276     </xsl:choose>
277 </xsl:template>
278
279 <xsl:template match="section" mode="error">
280     NIEZNANA_SEKCJA
281 </xsl:template>
282
283 <xsl:template name="cwiczenie">
284     <xsl:for-each select="div">
285         <xsl:choose>
286             <xsl:when test="@class = 'p'">
287                 <opis><xsl:apply-templates select="."/></opis>
288                 <!-- https://stackoverflow.com/questions/27374493/grouping-the-consecutive-elements-in-xslt -->
289             </xsl:when>
290             <xsl:otherwise>
291                 <xsl:apply-templates select="."/>
292             </xsl:otherwise>
293         </xsl:choose>
294     </xsl:for-each>
295 </xsl:template>
296
297 </xsl:stylesheet>