reversion
[redakcja.git] / src / redakcja / static / xsl / wl2html_client.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <xsl:stylesheet version="1.0"    
3     xmlns="http://www.w3.org/1999/xhtml"    
4     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
5     <xsl:output method="html" omit-xml-declaration="yes" encoding="utf-8" indent="no" />
6
7     <!--
8         Base tag for rendering a fragment of text
9     -->
10     <xsl:template match="chunk">        
11         <xsl:apply-templates select="child::node()">            
12             <xsl:with-param name="mixed" select="true()" />
13         </xsl:apply-templates>        
14     </xsl:template>
15     
16     <xsl:template match="utwor">
17         <div>
18             <xsl:call-template name="standard-attributes" />
19             <xsl:apply-templates select="child::node()">
20                 <xsl:with-param name="mixed" select="false()" />
21             </xsl:apply-templates>
22         </div>
23     </xsl:template>    
24
25
26     <!-- nieedytowany - zawiera bloki -->
27     <xsl:template match="opowiadanie|powiesc|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny|wywiad|nota|nota_red|dedykacja|ramka|lista_osob|dlugi_cytat|poezja_cyt|kwestia|wywiad_pyt|wywiad_odp|motto">
28         <xsl:param name="mixed" />
29         <div>
30             <xsl:call-template name="standard-attributes" />
31             <xsl:apply-templates select="child::node()">
32                 <xsl:with-param name="mixed" select="false()" />
33             </xsl:apply-templates>
34         </div>
35     </xsl:template>
36
37     <!-- edytowalny - zawiera tekst -->
38     <xsl:template match="didaskalia|naglowek_podrozdzial|naglowek_osoba|podtytul|naglowek_scena|naglowek_rozdzial|autor_utworu|dzielo_nadrzedne|naglowek_czesc|srodtytul|naglowek_akt|nazwa_utworu|naglowek_listy|lista_osoba|miejsce_czas|akap|akap_cd|akap_dialog|motto_podpis|uwaga|extra">
39         <xsl:param name="mixed" />
40         <div x-editable="true">
41             <xsl:call-template name="standard-attributes" />
42             <xsl:apply-templates select="child::node()">
43                 <xsl:with-param name="mixed" select="true()" />
44             </xsl:apply-templates>
45         </div>
46     </xsl:template>
47
48     <xsl:template match="ilustr">
49       <div>
50         <xsl:call-template name="standard-attributes" />
51         <img>
52           <xsl:attribute name="src">
53             <xsl:value-of select="@src" />
54           </xsl:attribute>
55         </img>
56         <p class="alt"><xsl:value-of select="@alt"/></p>
57       </div>
58     </xsl:template>
59
60     <!--
61         ********
62         STROFA
63         ********
64     -->
65     <xsl:template match="strofa">
66         <div x-editable="true">
67             <xsl:call-template name="standard-attributes" />
68          
69             <xsl:choose>
70                 <xsl:when test="count(br) > 0">
71                     <xsl:variable name="first-verse" select="br[1]/preceding-sibling::node()" />                    
72                     <xsl:call-template name="verse">
73                         <xsl:with-param name="verse-content" select="$first-verse" />                        
74                     </xsl:call-template>
75                     <xsl:for-each select="br">
76                         <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
77                         <!-- select all nodes up to the next br or end of stanza -->
78                         <xsl:variable name="current-verse"
79                             select="following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />                        
80                         <xsl:call-template name="verse">
81                             <xsl:with-param name="verse-content" select="$current-verse" />                            
82                         </xsl:call-template>
83                     </xsl:for-each>
84                 </xsl:when>
85                 <xsl:otherwise>
86                     <xsl:call-template name="verse">
87                         <xsl:with-param name="verse-content" select="child::node()" />                        
88                     </xsl:call-template>
89                 </xsl:otherwise>
90             </xsl:choose>
91         </div>
92     </xsl:template>
93
94     <xsl:template name="verse">
95         <!-- the verse contents including the last br (if any) -->
96         <xsl:param name="verse-content" />
97         <xsl:variable name="first-tag-name" select="name($verse-content/self::*)" />
98         <!-- name of text nodes is '' == false -->
99
100         <!-- THIS IS A HORROR!!! -->
101         <!-- Possible variants: -->
102         <xsl:choose>
103             <!-- Simple verse == not wers_ tags anywhere until the ending br -->
104             <xsl:when test="not($verse-content[starts-with(name(), 'wers')])">
105                 <div class="wers" x-node="wers" x-verse="true" x-auto-node="true">
106                 <xsl:apply-templates select="$verse-content[local-name(.) != 'br']">
107                     <xsl:with-param name="mixed" select="true()" />
108                 </xsl:apply-templates>
109                 </div>
110             </xsl:when>
111
112             <xsl:otherwise>
113             <xsl:apply-templates select="$verse-content[local-name(.) != 'br']">
114                 <xsl:with-param name="mixed" select="false()" />
115             </xsl:apply-templates>
116             </xsl:otherwise>
117         </xsl:choose>
118     </xsl:template>
119
120     <xsl:template match="wers_cd|wers_akap|wers_wciety|wers_do_prawej|wers">
121         <xsl:param name="mixed" />
122                 <div x-verse="true">
123                 <xsl:call-template name="standard-attributes" />
124                 <xsl:apply-templates select="child::node()">
125                         <xsl:with-param name="mixed" select="true()" />
126                 </xsl:apply-templates>
127                 </div>
128     </xsl:template>
129
130     <xsl:template match="br"><xsl:text>/</xsl:text></xsl:template>
131
132     <!-- Style znakowe -->
133     <xsl:template match="tytul_dziela|wyroznienie|slowo_obce|mat|didask_tekst|osoba|wyp_osoba|www|wieksze_odstepy|indeks_dolny|zastepnik_wersu">
134         <xsl:param name="mixed" />
135         <em>
136             <xsl:call-template name="standard-attributes" />
137             <xsl:apply-templates select="child::node()">
138                 <xsl:with-param name="mixed" select="true()" />
139             </xsl:apply-templates>
140         </em>
141     </xsl:template>
142
143     <!-- Separatory -->
144     <xsl:template match="sekcja_swiatlo|sekcja_asterysk|separator_linia">
145         <xsl:param name="mixed" />
146         <hr><xsl:call-template name="standard-attributes" /></hr>
147     </xsl:template>
148
149     <!-- Przypisy i motywy -->
150     <xsl:template match="pr|pa|pe|pt">       
151         <span x-editable="true">
152             <xsl:call-template name="standard-attributes">
153                 <xsl:with-param name="extra-class" select="'annotation-inline-box'" />
154             </xsl:call-template>
155             <a name="anchor-{generate-id(.)}" />
156             <!-- the link to the non-inline version -->
157             <a href="#annotation-{generate-id(.)}" class="annotation"></a>
158             <!-- inline contents -->
159             <span x-annotation-box="true" x-pass-thru="true">
160                 <xsl:apply-templates select="node()">
161                     <xsl:with-param name="mixed" select="true()" />
162                 </xsl:apply-templates>
163             </span>
164         </span>
165     </xsl:template>
166
167     <xsl:template match="ref">
168       <span x-editable="true" x-edit-no-format="true" x-edit-attribute="href">
169         <xsl:call-template name="standard-attributes">
170           <xsl:with-param name="extra-class" select="'reference-inline-box'" />
171         </xsl:call-template>
172         <a class="reference">📌</a>
173       </span>
174     </xsl:template>
175     
176     <xsl:template match="begin">        
177         <span>
178             <xsl:call-template name="standard-attributes" />
179             <xsl:attribute name="theme-class">
180                 <xsl:value-of select="substring-after(@id, 'b')" />
181             </xsl:attribute>
182         </span>
183     </xsl:template>
184
185     <xsl:template match="motyw">
186         <span x-editable="true" x-edit-no-format="true">
187             <xsl:call-template name="standard-attributes" />
188             <xsl:attribute name="theme-class">
189                 <xsl:value-of select="substring-after(@id, 'm')" />
190             </xsl:attribute>
191             <span x-pass-thru="true" class="theme-text-list"><xsl:value-of select=".|node()" /></span>
192         </span>
193     </xsl:template>
194
195     <xsl:template match="end">
196         <span>
197             <xsl:call-template name="standard-attributes" />
198             <xsl:attribute name="theme-class">
199                 <xsl:value-of select="substring-after(@id, 'e')" />
200             </xsl:attribute>
201         </span>
202     </xsl:template>
203
204
205     <!-- Tekst -->
206     <xsl:template match="text()">
207       <!-- <xsl:value-of select="." /> -->
208       <xsl:param name="mixed" />
209       <xsl:choose>
210         <xsl:when test="normalize-space(.) = ''">
211           <xsl:value-of select="." />
212         </xsl:when>
213         <xsl:when test="not($mixed)">
214           <span x-node="out-of-flow-text" class="out-of-flow-text" x-editable="true">
215             <xsl:value-of select="." />
216           </span>
217         </xsl:when>
218         <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
219       </xsl:choose>
220     </xsl:template>
221
222     <xsl:template match="comment()">
223         <xsl:comment><xsl:value-of select="." /></xsl:comment>
224     </xsl:template>
225
226     <xsl:template match="*[name() != local-name()]">
227         <span>
228             <xsl:call-template name="standard-attributes" />
229             <xsl:apply-templates select="child::node()">
230                 <xsl:with-param name="mixed" select="true()" />
231             </xsl:apply-templates>
232         </span>
233     </xsl:template>
234         
235     <xsl:template match="*">
236         <span>
237             <xsl:call-template name="standard-attributes">
238                 <xsl:with-param name="extra-class">unknown-tag</xsl:with-param>
239             </xsl:call-template>
240             <xsl:apply-templates select="child::node()">
241                 <xsl:with-param name="mixed" select="true()" />
242             </xsl:apply-templates>        
243         </span>
244     </xsl:template>
245
246     <xsl:template name="standard-attributes">
247         <xsl:param name="extra-class" />
248         <xsl:attribute name="class"><xsl:value-of select="local-name()" /><xsl:text>&#x0020;</xsl:text><xsl:value-of select="$extra-class" /></xsl:attribute>
249
250         <xsl:attribute name="x-node"><xsl:value-of select="local-name()" /></xsl:attribute>
251
252         <xsl:if test="local-name() != name()">
253             <xsl:attribute name="x-ns"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
254         </xsl:if>
255
256         <xsl:for-each select="@*">
257             <xsl:variable name="id" select="generate-id()" />
258             <xsl:attribute name="x-attr-value-{$id}"><xsl:value-of select="."/></xsl:attribute>
259             <xsl:attribute name="x-attr-name-{$id}"><xsl:value-of select="local-name()"/></xsl:attribute>
260             <xsl:choose>
261                 <xsl:when test="namespace-uri()">
262                 <xsl:attribute name="x-attr-ns-{$id}"><xsl:value-of select="namespace-uri()"/></xsl:attribute>
263                                 </xsl:when>
264                                 <!-- if the element belongs to default namespace and attribut has no namespace -->
265                 <xsl:when test="not(namespace-uri(.))">
266                                 <xsl:attribute name="data-wlf-{local-name()}"><xsl:value-of select="."/></xsl:attribute>
267                                 </xsl:when>
268                         </xsl:choose>               
269         </xsl:for-each>
270     </xsl:template>
271
272     <xsl:template match="alien">
273             <span class="alien" x-pass-thru="true">
274                 <xsl:apply-templates select="node()">
275                     <xsl:with-param name="mixed" select="true()" />
276                 </xsl:apply-templates>
277             </span>
278     </xsl:template>
279
280     <xsl:template match="comment()">
281         <xsl:comment><xsl:value-of select="."/></xsl:comment>
282     </xsl:template>
283 </xsl:stylesheet>