9716e19fc6d83ed86aca400e77f8f35b092d4364
[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     <xsl:template match="numeracja">
61       <div>
62         <xsl:call-template name="standard-attributes" />
63         <div>
64           <xsl:attribute name="data-start">
65             <xsl:value-of select="@start" />
66           </xsl:attribute>
67           <xsl:attribute name="data-link">
68             <xsl:value-of select="@link" />
69           </xsl:attribute>
70         </div>
71       </div>
72     </xsl:template>
73
74     <!--
75         ********
76         STROFA
77         ********
78     -->
79     <xsl:template match="strofa">
80         <div x-editable="true">
81             <xsl:call-template name="standard-attributes" />
82          
83             <xsl:choose>
84                 <xsl:when test="count(br) > 0">
85                     <xsl:variable name="first-verse" select="br[1]/preceding-sibling::node()" />                    
86                     <xsl:call-template name="verse">
87                         <xsl:with-param name="verse-content" select="$first-verse" />                        
88                     </xsl:call-template>
89                     <xsl:for-each select="br">
90                         <xsl:variable name="lnum" select="count(preceding-sibling::br)" />
91                         <!-- select all nodes up to the next br or end of stanza -->
92                         <xsl:variable name="current-verse"
93                             select="following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />                        
94                         <xsl:call-template name="verse">
95                             <xsl:with-param name="verse-content" select="$current-verse" />                            
96                         </xsl:call-template>
97                     </xsl:for-each>
98                 </xsl:when>
99                 <xsl:otherwise>
100                     <xsl:call-template name="verse">
101                         <xsl:with-param name="verse-content" select="child::node()" />                        
102                     </xsl:call-template>
103                 </xsl:otherwise>
104             </xsl:choose>
105         </div>
106     </xsl:template>
107
108     <xsl:template name="verse">
109         <!-- the verse contents including the last br (if any) -->
110         <xsl:param name="verse-content" />
111         <xsl:variable name="first-tag-name" select="name($verse-content/self::*)" />
112         <!-- name of text nodes is '' == false -->
113
114         <!-- THIS IS A HORROR!!! -->
115         <!-- Possible variants: -->
116         <xsl:choose>
117             <!-- Simple verse == not wers_ tags anywhere until the ending br -->
118             <xsl:when test="not($verse-content[starts-with(name(), 'wers')])">
119                 <div class="wers" x-node="wers" x-verse="true" x-auto-node="true">
120                 <xsl:apply-templates select="$verse-content[local-name(.) != 'br']">
121                     <xsl:with-param name="mixed" select="true()" />
122                 </xsl:apply-templates>
123                 </div>
124             </xsl:when>
125
126             <xsl:otherwise>
127             <xsl:apply-templates select="$verse-content[local-name(.) != 'br']">
128                 <xsl:with-param name="mixed" select="false()" />
129             </xsl:apply-templates>
130             </xsl:otherwise>
131         </xsl:choose>
132     </xsl:template>
133
134     {% if tags.verse %}
135     <xsl:template match="{{ tags.verse|join:"|" }}">
136         <xsl:param name="mixed" />
137                 <div x-verse="true">
138                 <xsl:call-template name="standard-attributes" />
139                 <xsl:apply-templates select="child::node()">
140                         <xsl:with-param name="mixed" select="true()" />
141                 </xsl:apply-templates>
142                 </div>
143     </xsl:template>
144     {% endif %}
145
146     <xsl:template match="br"><xsl:text>/</xsl:text></xsl:template>
147
148     {% if tags.span %}
149     <!-- Style znakowe         span -->
150     <xsl:template match="{{ tags.span|join:"|" }}">
151         <xsl:param name="mixed" />
152         <em>
153             <xsl:call-template name="standard-attributes" />
154             <xsl:apply-templates select="child::node()">
155                 <xsl:with-param name="mixed" select="true()" />
156             </xsl:apply-templates>
157         </em>
158     </xsl:template>
159     {% endif %}
160
161     {% if tags.sep %}
162     <!-- Separatory            sep -->
163     <xsl:template match="{{ tags.sep|join:"|" }}">
164         <xsl:param name="mixed" />
165         <hr><xsl:call-template name="standard-attributes" /></hr>
166     </xsl:template>
167     {% endif %}
168
169     {% if tags.aside %}
170     <!-- Przypisy i motywy     aside -->
171     <xsl:template match="{{ tags.aside|join:"|" }}">
172         <span x-editable="true">
173             <xsl:call-template name="standard-attributes">
174                 <xsl:with-param name="extra-class" select="'annotation-inline-box'" />
175             </xsl:call-template>
176             <a name="anchor-{generate-id(.)}" />
177             <!-- the link to the non-inline version -->
178             <a href="#annotation-{generate-id(.)}" class="annotation"></a>
179             <!-- inline contents -->
180             <span x-annotation-box="true" x-pass-thru="true">
181                 <xsl:apply-templates select="node()">
182                     <xsl:with-param name="mixed" select="true()" />
183                 </xsl:apply-templates>
184             </span>
185         </span>
186     </xsl:template>
187     {% endif %}
188
189     <xsl:template match="ref">
190       <span x-editable="true" x-edit-no-format="true" x-edit-attribute="href">
191         <xsl:call-template name="standard-attributes">
192           <xsl:with-param name="extra-class" select="'reference-inline-box'" />
193         </xsl:call-template>
194         <a class="reference">📌</a>
195         <span x-preview="true" x-pass-thru="true">
196           <a target="wiki" title="?">
197             <xsl:attribute name="href">
198               <xsl:value-of select="@href" />
199             </xsl:attribute>
200             <xsl:value-of select="@href" />
201           </a>
202         </span>
203       </span>
204     </xsl:template>
205     
206     <xsl:template match="begin">        
207         <span>
208             <xsl:call-template name="standard-attributes" />
209             <xsl:attribute name="theme-class">
210                 <xsl:value-of select="substring-after(@id, 'b')" />
211             </xsl:attribute>
212         </span>
213     </xsl:template>
214
215     <xsl:template match="motyw">
216         <span x-editable="true" x-edit-no-format="true">
217             <xsl:call-template name="standard-attributes" />
218             <xsl:attribute name="theme-class">
219                 <xsl:value-of select="substring-after(@id, 'm')" />
220             </xsl:attribute>
221             <span x-pass-thru="true" class="theme-text-list"><xsl:value-of select=".|node()" /></span>
222         </span>
223     </xsl:template>
224
225     <xsl:template match="end">
226         <span>
227             <xsl:call-template name="standard-attributes" />
228             <xsl:attribute name="theme-class">
229                 <xsl:value-of select="substring-after(@id, 'e')" />
230             </xsl:attribute>
231         </span>
232     </xsl:template>
233
234
235     <!-- Tekst -->
236     <xsl:template match="text()">
237       <!-- <xsl:value-of select="." /> -->
238       <xsl:param name="mixed" />
239       <xsl:choose>
240         <xsl:when test="normalize-space(.) = ''">
241           <xsl:value-of select="." />
242         </xsl:when>
243         <xsl:when test="not($mixed)">
244           <span x-node="out-of-flow-text" class="out-of-flow-text" x-editable="true">
245             <xsl:value-of select="." />
246           </span>
247         </xsl:when>
248         <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
249       </xsl:choose>
250     </xsl:template>
251
252     <xsl:template match="comment()">
253         <xsl:comment><xsl:value-of select="." /></xsl:comment>
254     </xsl:template>
255
256     <xsl:template match="*[name() != local-name()]">
257         <span>
258             <xsl:call-template name="standard-attributes" />
259             <xsl:apply-templates select="child::node()">
260                 <xsl:with-param name="mixed" select="true()" />
261             </xsl:apply-templates>
262         </span>
263     </xsl:template>
264         
265     <xsl:template match="*">
266         <span>
267             <xsl:call-template name="standard-attributes">
268                 <xsl:with-param name="extra-class">unknown-tag</xsl:with-param>
269             </xsl:call-template>
270             <xsl:apply-templates select="child::node()">
271                 <xsl:with-param name="mixed" select="true()" />
272             </xsl:apply-templates>        
273         </span>
274     </xsl:template>
275
276     <xsl:template name="standard-attributes">
277         <xsl:param name="extra-class" />
278         <xsl:attribute name="class"><xsl:value-of select="$extra-class" /></xsl:attribute>
279
280         <xsl:attribute name="x-node"><xsl:value-of select="local-name()" /></xsl:attribute>
281
282         <xsl:if test="local-name() != name()">
283             <xsl:attribute name="x-ns"><xsl:value-of select="namespace-uri()" /></xsl:attribute>
284         </xsl:if>
285
286         <xsl:for-each select="@*">
287
288           <xsl:choose>
289             {% for namespace, prefix in namespaces.items %}
290             <xsl:when test="namespace-uri() =  '{{ namespace }}'">
291               <xsl:attribute name="x-a-{{ prefix }}-{local-name()}">
292                 <xsl:value-of select="."/>
293               </xsl:attribute>
294             </xsl:when>
295             {% endfor %}
296
297             <xsl:otherwise>
298               <xsl:variable name="id" select="generate-id()" />
299               <xsl:attribute name="x-attr-value-{$id}"><xsl:value-of select="."/></xsl:attribute>
300               <xsl:attribute name="x-attr-name-{$id}"><xsl:value-of select="local-name()"/></xsl:attribute>
301               <xsl:attribute name="x-attr-ns-{$id}"><xsl:value-of select="namespace-uri()"/></xsl:attribute>
302             </xsl:otherwise>
303           </xsl:choose>               
304
305         </xsl:for-each>
306     </xsl:template>
307
308     <xsl:template match="alien">
309             <span class="alien" x-pass-thru="true">
310                 <xsl:apply-templates select="node()">
311                     <xsl:with-param name="mixed" select="true()" />
312                 </xsl:apply-templates>
313             </span>
314     </xsl:template>
315
316     <xsl:template match="comment()">
317         <xsl:comment><xsl:value-of select="."/></xsl:comment>
318     </xsl:template>
319 </xsl:stylesheet>