Add language tags definition, caret and bubbles in editor.
[redakcja.git] / src / wlxml / templates / wlxml / wl2html.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   section-->
27     <xsl:template match="{{ tags.section|join:"|" }}">
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      div -->
38     <xsl:template match="{{ tags.div|join:"|" }}">
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     {% if tags.verse %}
121     <xsl:template match="{{ tags.verse|join:"|" }}">
122         <xsl:param name="mixed" />
123                 <div x-verse="true">
124                 <xsl:call-template name="standard-attributes" />
125                 <xsl:apply-templates select="child::node()">
126                         <xsl:with-param name="mixed" select="true()" />
127                 </xsl:apply-templates>
128                 </div>
129     </xsl:template>
130     {% endif %}
131
132     <xsl:template match="br"><xsl:text>/</xsl:text></xsl:template>
133
134     {% if tags.span %}
135     <!-- Style znakowe         span -->
136     <xsl:template match="{{ tags.span|join:"|" }}">
137         <xsl:param name="mixed" />
138         <em>
139             <xsl:call-template name="standard-attributes" />
140             <xsl:apply-templates select="child::node()">
141                 <xsl:with-param name="mixed" select="true()" />
142             </xsl:apply-templates>
143         </em>
144     </xsl:template>
145     {% endif %}
146
147     {% if tags.sep %}
148     <!-- Separatory            sep -->
149     <xsl:template match="{{ tags.sep|join:"|" }}">
150         <xsl:param name="mixed" />
151         <hr><xsl:call-template name="standard-attributes" /></hr>
152     </xsl:template>
153     {% endif %}
154
155     {% if tags.aside %}
156     <!-- Przypisy i motywy     aside -->
157     <xsl:template match="{{ tags.aside|join:"|" }}">
158         <span x-editable="true">
159             <xsl:call-template name="standard-attributes">
160                 <xsl:with-param name="extra-class" select="'annotation-inline-box'" />
161             </xsl:call-template>
162             <a name="anchor-{generate-id(.)}" />
163             <!-- the link to the non-inline version -->
164             <a href="#annotation-{generate-id(.)}" class="annotation"></a>
165             <!-- inline contents -->
166             <span x-annotation-box="true" x-pass-thru="true">
167                 <xsl:apply-templates select="node()">
168                     <xsl:with-param name="mixed" select="true()" />
169                 </xsl:apply-templates>
170             </span>
171         </span>
172     </xsl:template>
173     {% endif %}
174
175     <xsl:template match="ref">
176       <span x-editable="true" x-edit-no-format="true" x-edit-attribute="href">
177         <xsl:call-template name="standard-attributes">
178           <xsl:with-param name="extra-class" select="'reference-inline-box'" />
179         </xsl:call-template>
180         <a class="reference">📌</a>
181       </span>
182     </xsl:template>
183     
184     <xsl:template match="begin">        
185         <span>
186             <xsl:call-template name="standard-attributes" />
187             <xsl:attribute name="theme-class">
188                 <xsl:value-of select="substring-after(@id, 'b')" />
189             </xsl:attribute>
190         </span>
191     </xsl:template>
192
193     <xsl:template match="motyw">
194         <span x-editable="true" x-edit-no-format="true">
195             <xsl:call-template name="standard-attributes" />
196             <xsl:attribute name="theme-class">
197                 <xsl:value-of select="substring-after(@id, 'm')" />
198             </xsl:attribute>
199             <span x-pass-thru="true" class="theme-text-list"><xsl:value-of select=".|node()" /></span>
200         </span>
201     </xsl:template>
202
203     <xsl:template match="end">
204         <span>
205             <xsl:call-template name="standard-attributes" />
206             <xsl:attribute name="theme-class">
207                 <xsl:value-of select="substring-after(@id, 'e')" />
208             </xsl:attribute>
209         </span>
210     </xsl:template>
211
212
213     <!-- Tekst -->
214     <xsl:template match="text()">
215       <!-- <xsl:value-of select="." /> -->
216       <xsl:param name="mixed" />
217       <xsl:choose>
218         <xsl:when test="normalize-space(.) = ''">
219           <xsl:value-of select="." />
220         </xsl:when>
221         <xsl:when test="not($mixed)">
222           <span x-node="out-of-flow-text" class="out-of-flow-text" x-editable="true">
223             <xsl:value-of select="." />
224           </span>
225         </xsl:when>
226         <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
227       </xsl:choose>
228     </xsl:template>
229
230     <xsl:template match="comment()">
231         <xsl:comment><xsl:value-of select="." /></xsl:comment>
232     </xsl:template>
233
234     <xsl:template match="*[name() != local-name()]">
235         <span>
236             <xsl:call-template name="standard-attributes" />
237             <xsl:apply-templates select="child::node()">
238                 <xsl:with-param name="mixed" select="true()" />
239             </xsl:apply-templates>
240         </span>
241     </xsl:template>
242         
243     <xsl:template match="*">
244         <span>
245             <xsl:call-template name="standard-attributes">
246                 <xsl:with-param name="extra-class">unknown-tag</xsl:with-param>
247             </xsl:call-template>
248             <xsl:apply-templates select="child::node()">
249                 <xsl:with-param name="mixed" select="true()" />
250             </xsl:apply-templates>        
251         </span>
252     </xsl:template>
253
254     <xsl:template name="standard-attributes">
255         <xsl:param name="extra-class" />
256         <xsl:attribute name="class"><xsl:value-of select="$extra-class" /></xsl:attribute>
257
258         <xsl:attribute name="x-node"><xsl:value-of select="local-name()" /></xsl:attribute>
259
260         <xsl:if test="local-name() != name()">
261             <xsl:attribute name="x-ns"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
262         </xsl:if>
263
264         <xsl:for-each select="@*">
265             <xsl:variable name="id" select="generate-id()" />
266             <xsl:attribute name="x-attr-value-{$id}"><xsl:value-of select="."/></xsl:attribute>
267             <xsl:attribute name="x-attr-name-{$id}"><xsl:value-of select="local-name()"/></xsl:attribute>
268             <xsl:choose>
269                 <xsl:when test="namespace-uri()">
270                 <xsl:attribute name="x-attr-ns-{$id}"><xsl:value-of select="namespace-uri()"/></xsl:attribute>
271                                 </xsl:when>
272                                 <!-- if the element belongs to default namespace and attribut has no namespace -->
273                 <xsl:when test="not(namespace-uri(.))">
274                                 <xsl:attribute name="data-wlf-{local-name()}"><xsl:value-of select="."/></xsl:attribute>
275                                 </xsl:when>
276                         </xsl:choose>               
277         </xsl:for-each>
278     </xsl:template>
279
280     <xsl:template match="alien">
281             <span class="alien" x-pass-thru="true">
282                 <xsl:apply-templates select="node()">
283                     <xsl:with-param name="mixed" select="true()" />
284                 </xsl:apply-templates>
285             </span>
286     </xsl:template>
287
288     <xsl:template match="comment()">
289         <xsl:comment><xsl:value-of select="."/></xsl:comment>
290     </xsl:template>
291 </xsl:stylesheet>