initial import
[vym] / styles / vym2xhtml.xsl
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE xsl:stylesheet
3 [
4    <!-- Namespace for XHTML -->
5    <!ENTITY xhtmlns "http://www.w3.org/1999/xhtml">
6 ]>
7
8 <!--
9     Document    : vym2xhtml.xsl
10     Created     : 20040818
11         Changed         : 20051123
12     License     : GPL
13     Version     : 0.4.0
14     VYM version : 1.7.5
15     Author      : Thomas Schraitle <tom_schr@web.de>
16                                   modified by Clemens Kraus (http://www.clemens-kraus.de)
17     Description : transforms vym-files into XHTML.
18     Bugs        : Many. ;) Produces at the moment not valid XHTML
19                   Needs to checked.
20                                                                         - li/ul structure not ok
21                 Changes                 : - <br>s in headings removed
22                                                                         - error fixed in "alt" and "title"
23 -->
24
25 <xsl:stylesheet version="1.0"
26     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
27     xmlns:date="http://exslt.org/dates-and-times"
28     extension-element-prefixes="date"
29     xmlns="&xhtmlns;">
30
31
32 <xsl:output method="xml"
33     doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
34     doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
35     encoding="UTF-8"
36     indent="yes"
37     media-type="application/xhtml+xml"/>
38
39
40
41 <!-- ====================================================================== -->
42 <!-- 1 = true, 0 = false -->
43
44 <!-- URL to CSS stylesheet -->
45 <xsl:param name="css.stylesheet" select="'vym.css'"/>
46
47 <!-- Should a default CSS stylesheet be used? -->
48 <xsl:param name="use.default.css.stylesheet" select="1"/>
49
50 <!-- Should textcolors be used? -->
51 <xsl:param name="use.textcolor" select="0"/>
52
53 <!-- Should an imagemap be generated? -->
54 <xsl:param name="use.imagemap" select="1"/>
55
56 <!-- URL to image for imagemap -->
57 <xsl:param name="imagemap" select="''"/>
58
59 <!-- This stylesheet is able to process the following VYM version -->
60 <xsl:param name="vym.version" select="'1.7.10'"/>
61
62 <!-- Should the VYM XML format be checked -->
63 <xsl:param name="checkvym.version" select="1"/>
64
65 <!-- Which is the image extension? -->
66 <xsl:param name="image.extension" select="'.png'"/>
67
68 <!-- Where are the flags? -->
69 <xsl:param name="image.flags.path" select="'flags/'"/>
70
71 <!-- Filename of the XML document -->
72 <xsl:param name="mapname" />
73
74 <!-- Should a footer be generated? -->
75 <xsl:param name="use.footer" select="1"/>
76
77 <!-- How should Links generated:
78     name : Use only the name of the branch (default)
79     url  : Use only the URL of the branch
80     both : Use both
81 -->
82 <xsl:param name="link.style" select="'name'"/>
83
84 <!-- Accept different html-notes? 
85                 Only for imported MindManager maps! -->
86 <xsl:param name="use.diffnotes" select="0"/>
87
88 <!-- Debuggin on/off? -->
89 <xsl:param name="debug" select="0"/>
90
91
92 <xsl:template name="generate.footer">
93   <xsl:if test="$use.footer">
94       <hr/>
95       <table class="vym-footer">
96          <tr >
97          <td class="vym-footerL"><xsl:value-of select="$mapname"/></td>
98          <td class="vym-footerC"><xsl:value-of select="vymmap/@date"/> </td>
99          <!--<td class="vym-footerC"><xsl:value-of select="date:date()"/></td>-->
100          <td class="vym-footerR">vym <xsl:value-of select="vymmap/@version"/></td>
101          </tr>
102       </table>
103   </xsl:if>
104 </xsl:template>
105
106
107
108
109
110 <!-- ====================================================================== -->
111 <xsl:variable name="head.title">
112    <xsl:choose>
113       <xsl:when test="/vymmap/mapcenter/heading">
114                         
115                                 <xsl:variable name="title">
116                                         <xsl:call-template name="gettitle" >
117                                                 <xsl:with-param name="txt" select="/vymmap/mapcenter/heading" />
118                                         </xsl:call-template>
119                                 </xsl:variable>
120
121         <xsl:value-of select="$title"/>
122       </xsl:when>
123       <xsl:otherwise></xsl:otherwise>
124    </xsl:choose>
125 </xsl:variable>
126
127 <xsl:variable name="default.css.stylesheet">
128    <xsl:text>
129 h1 {border-width: 1; border: solid; text-align: center}
130 div.imagemap { align: center; border: 0; }
131    </xsl:text>
132 </xsl:variable>
133
134
135 <!-- ====================================================================== -->
136 <xsl:template name="generate.head">
137    <head>
138       <title><xsl:value-of select="$head.title"/></title>
139       <xsl:if test="$use.default.css.stylesheet">
140          <style type="text/css">
141             <xsl:value-of select="$default.css.stylesheet"/>
142          </style>
143       </xsl:if>
144       <xsl:if test="vymmap/@author!=''">
145          <meta name="author" content="{vymmap/@author}"/>
146       </xsl:if>
147       <xsl:if test="vymmap/@comment!=''">
148          <meta name="comment" content="{vymmap/@comment}"/>
149       </xsl:if>
150       <meta name="generator" content="vym"/>
151       <xsl:if test="$css.stylesheet!=''">
152          <link rel="stylesheet" id="css.stylesheet" href="{$css.stylesheet}"/>
153       </xsl:if>
154    </head>
155 </xsl:template>
156
157
158 <xsl:template name="check.vym.version">
159    <xsl:if test="$checkvym.version">
160       <xsl:if test="not(/vymmap/@version=$vym.version)">
161          <xsl:message>
162             <xsl:text>&#10;</xsl:text>
163             <xsl:text>  WARNING:</xsl:text>
164             <xsl:text> This stylesheet applies to VYM XML format v.</xsl:text>
165             <xsl:value-of select="$vym.version"/>
166             <xsl:text>.&#10;  Your XML format has v</xsl:text>
167             <xsl:value-of select="/vymmap/@version"/>
168             <xsl:text>.&#10;  Check your HTML output!</xsl:text>
169             <xsl:text>&#10;&#10;</xsl:text>
170          </xsl:message>
171       </xsl:if>
172    </xsl:if>
173 </xsl:template>
174
175
176 <!-- ====================================================================== -->
177 <xsl:template match="*">
178    <xsl:message>
179       <xsl:text>WARNING: Unknown tag "</xsl:text>
180       <xsl:value-of select="local-name(.)"/>
181       <xsl:text>": </xsl:text>
182       <xsl:value-of select="normalize-space(.)"/>
183       <xsl:text>&#10;</xsl:text>
184    </xsl:message>
185 </xsl:template>
186
187
188 <xsl:template match="/">
189    <xsl:call-template name="check.vym.version"/>
190
191    <html xmlns="&xhtmlns;">
192       <xsl:call-template name="generate.head"/>
193       <body>
194          <xsl:apply-templates/>
195          <xsl:call-template name="generate.footer"/>
196       </body>
197    </html>
198 </xsl:template>
199
200
201 <xsl:template match="vymmap">
202    <div class="vymmap">
203       <xsl:apply-templates/>
204    </div>
205 </xsl:template>
206
207
208 <xsl:template match="mapcenter">
209    <div class="mapcenter">
210       <xsl:apply-templates/>
211    </div>
212 </xsl:template>
213
214
215 <xsl:template match="mapcenter/heading">
216    <div class="vym-header">
217            <xsl:apply-templates/>
218    </div>
219  
220       <xsl:if test="$use.imagemap=1">
221          <div class="vym-imagemap">
222             <img src="{$imagemap}"
223                alt="Imagemap"
224                class="imagemap"
225                usemap="#vym_imagemap"/>
226          </div>
227          <map name="vym_imagemap">
228             <xsl:apply-templates select="../branch" mode="imagemap"/>
229          </map>
230       </xsl:if>
231 </xsl:template>
232
233
234 <xsl:template match="mapcenter/branch">
235    <hr/>
236    <ul class="branch">
237       <xsl:apply-templates/>
238    </ul>
239 </xsl:template>
240
241
242 <xsl:template match="branch">
243    <ul class="branch">
244       <xsl:apply-templates/>
245    </ul>
246 </xsl:template>
247
248
249 <xsl:template match="heading">
250    <li class="heading">
251           <span id="{generate-id(..)}">
252       <xsl:if test="@textColor!='' and $use.textcolor=1">
253          <xsl:attribute name="style" >color: <xsl:value-of select="@textColor" />
254                  </xsl:attribute>
255       </xsl:if>
256       <xsl:choose>
257          <xsl:when test="../@url">
258             <xsl:variable name="url" select="../@url"/>
259
260             <!-- Check, how links should be generated -->
261             <xsl:choose>
262                <xsl:when test="$link.style = 'name'">
263                    <a href="{$url}">
264                                                 <img src="{concat($image.flags.path,'flag-url-16x16.png')}" border="0" alt="URL"/>
265                                                 <xsl:text> </xsl:text>
266                                                 <xsl:apply-templates/>
267                                         </a>
268                </xsl:when>
269                <xsl:when test="$link.style = 'url'">
270                                         <a href="{$url}">
271                                                 <img src="{concat($image.flags.path,'flag-url-16x16.png')}" border="0" alt="URL"/>
272                                                 <xsl:text> </xsl:text>
273                                                 <xsl:value-of select="$url"/>
274                                         </a>
275                </xsl:when>
276                <xsl:when test="$link.style = 'both'">
277                   <a href="{$url}">
278                                                 <img src="{concat($image.flags.path,'flag-url-16x16.png')}" border="0" alt="URL"/>
279                                                 <xsl:text> </xsl:text>
280                                                 <xsl:apply-templates/> (<xsl:value-of select="$url"/>)
281                                         </a>
282                </xsl:when>
283                <xsl:otherwise>
284                   <xsl:message>
285                      <xsl:text>WARNING: Parameter link.style doesn't contain the correct</xsl:text>
286                      <xsl:text> value (name|url|both)</xsl:text>
287                      <xsl:text>&#10; was "</xsl:text>
288                      <xsl:value-of select="$link.style"/>
289                      <xsl:text>"</xsl:text>
290                   </xsl:message>
291                   <a href="{$url}"><xsl:apply-templates/></a>
292                </xsl:otherwise>
293             </xsl:choose>
294
295          </xsl:when>
296          <xsl:otherwise>
297                                                 <xsl:call-template name="gettitle" >
298                                                         <xsl:with-param name="txt" select="." />
299                                                 </xsl:call-template>
300                                                 
301          </xsl:otherwise>
302       </xsl:choose>
303
304       <xsl:for-each select="following-sibling::standardflag">
305          <xsl:apply-templates select="current()" mode="standardflag"/><xsl:text> </xsl:text>
306       </xsl:for-each>
307       </span>
308    </li>
309 </xsl:template>
310
311
312 <xsl:template match="floatimage">
313    <xsl:variable name="filename">
314       <xsl:choose>
315          <xsl:when test="contains(@href,':')">
316             <xsl:value-of select="substring-after(@href,':')"/>
317          </xsl:when>
318          <xsl:otherwise>
319             <xsl:value-of select="@href"/>
320          </xsl:otherwise>
321       </xsl:choose>
322    </xsl:variable>
323    
324   <xsl:if test="@floatExport='true'">
325       <span><img src="{$filename}" alt="{$filename}"/></span>
326   </xsl:if>
327 </xsl:template>
328
329
330 <xsl:template match="standardflag"/><!-- Do nothing in normal mode -->
331
332 <xsl:template match="standardflag" mode="standardflag">
333    <span class="standardflag">
334       <xsl:element name="img">
335          <xsl:variable name="_srcimg">
336          <xsl:choose>
337             <xsl:when test="$image.flags.path">
338                <xsl:value-of select="concat($image.flags.path,
339                   .,
340                   $image.extension)"/>
341             </xsl:when>
342             <xsl:otherwise>
343                <xsl:value-of select="concat(., $image.extension)"/>
344             </xsl:otherwise>
345          </xsl:choose>
346          </xsl:variable>
347          <xsl:attribute name="src">
348             <xsl:value-of select="$_srcimg"/>
349          </xsl:attribute>
350          <xsl:attribute name="alt">
351             <xsl:value-of select="$_srcimg"/>
352          </xsl:attribute>
353       </xsl:element>
354    </span>
355 </xsl:template>
356
357 <!-- Do nothing! -->
358 <xsl:template match="select"/>
359 <xsl:template match="setting"/>
360
361
362 <xsl:template match="htmlnote">
363    <div class="vym-htmlnote">
364                         <xsl:choose>
365                                 <xsl:when test="$use.diffnotes=1">
366                 <xsl:copy-of select="."/>
367                                 </xsl:when>
368                                 <xsl:otherwise>
369                                         <xsl:apply-templates select=".//body/*"/><!-- Select only body elements -->
370                                 </xsl:otherwise>
371                         </xsl:choose>
372    </div>
373 </xsl:template>
374
375 <!-- Do nothing! We don't need some informational elements -->
376 <xsl:template match="htmlnote/html/*"/>
377
378 <xsl:template match="htmlnote/html/body">
379    <xsl:copy-of select="."/>
380 </xsl:template>
381
382 <xsl:template match="htmlnote/html/body/*">
383    <xsl:copy-of select="."/>
384 </xsl:template>
385
386
387 <!-- ====================================================================== -->
388 <xsl:template match="branch" mode="imagemap"> 
389    <xsl:param name="node"/> 
390    <xsl:variable name="title"> 
391       <xsl:apply-templates mode="imagemap"/> 
392    </xsl:variable> 
393  
394    <xsl:if test="$debug=1"> 
395       <xsl:message> 
396       branch/heading = "<xsl:value-of select="normalize-space($title)"/>" 
397       </xsl:message> 
398    </xsl:if> 
399  
400    <area shape="rect"> 
401       <xsl:attribute name="href"> 
402          <xsl:choose><!-- Fix begin (!) --> 
403             <xsl:when test="$imagemap != ''"> 
404                <xsl:value-of select="concat('#', generate-id(.))"/> 
405             </xsl:when> 
406             <xsl:when test="$imagemap and @url"> 
407                <xsl:value-of select="@url"/> 
408             </xsl:when> 
409             <xsl:when test="$imagemap and @vymLink"> 
410                <xsl:value-of select="concat( substring-before(@vymLink, 
411 '.vym'), '.html')"/> 
412             </xsl:when> 
413          </xsl:choose><!-- Fix end --> 
414       </xsl:attribute> 
415       <xsl:attribute name="alt"> 
416                                  <xsl:call-template name="gettitle" >
417                                         <xsl:with-param name="txt" select="heading" />
418                                  </xsl:call-template>
419       </xsl:attribute> 
420       <xsl:attribute name="title"> 
421                                 <xsl:call-template name="gettitle" >
422                                         <xsl:with-param name="txt" select="heading" />
423                                 </xsl:call-template>
424       </xsl:attribute> 
425       <xsl:attribute name="coords"> 
426          <xsl:choose> 
427             <xsl:when test="@x1!='' and @x2!='' and @y1!='' and @y2!=''"> 
428                <xsl:value-of select="@x1"/> 
429                <xsl:text>,</xsl:text> 
430                <xsl:value-of select="@y1"/> 
431                <xsl:text>,</xsl:text> 
432                <xsl:value-of select="@x2"/> 
433                <xsl:text>,</xsl:text> 
434                <xsl:value-of select="@y2"/> 
435             </xsl:when> 
436             <xsl:otherwise> 
437                <!-- 
438                <xsl:message> 
439                   <xsl:text>ERROR: Some coordinates in branch are 
440 missing!&#10;</xsl:text> 
441                   <xsl:text>       See branch with </xsl:text> 
442                   <xsl:value-of select="normalize-space($title)"/> 
443                </xsl:message>
444                //--> 
445             </xsl:otherwise> 
446          </xsl:choose> 
447       </xsl:attribute> 
448    </area> 
449    <xsl:apply-templates select="./branch" mode="imagemap"/> 
450 </xsl:template> 
451
452
453 <xsl:template match="heading" mode="imagemap">
454                 <xsl:call-template name="gettitle" >
455                         <xsl:with-param name="txt" select="." />
456                 </xsl:call-template>
457                 <!--<xsl:message>title2: <xsl:value-of select="$title" /></xsl:message>-->
458
459     <xsl:apply-templates mode="imagemap"/>
460 </xsl:template>
461
462
463 <xsl:template match="xlink">
464                 <xsl:element name="a">
465                         <xsl:attribute name="name">
466                                 <xsl:value-of select="translate(@beginBranch, ':,', '')"/>
467                         </xsl:attribute>
468                 </xsl:element>
469
470                 <div class="xlink">
471                         <xsl:text>See: </xsl:text>
472                         <xsl:element name="a">
473                                 <xsl:attribute name="href">
474                                         <xsl:text>#</xsl:text><!--<xsl:value-of select="translate(@endBranch, ':,', '')"/>-->
475                                 </xsl:attribute>
476                                 <!--<xsl:value-of select="translate(@endBranch, ':,', '')"/>-->reference
477                         </xsl:element>
478                                 <!--<xsl:apply-templates/>-->
479                                 <!--<xsl:message>->xlink: <xsl:value-of select="concat(@endBranch, ' ', position())" /></xsl:message>-->
480    </div>
481 </xsl:template>
482
483
484 <xsl:template name="gettitle">
485                 <xsl:param name="txt" select="." />
486                 
487                 <xsl:variable name="br">
488                         <xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
489                 </xsl:variable>
490                 
491                 <xsl:choose>
492                         <xsl:when test="contains($txt, $br)" >
493                                 <xsl:variable name="right" select="substring-after($txt, $br)" />
494                                 <xsl:variable name="left" select="substring-before($txt, $br)" />
495                                 <xsl:variable name="txt" select="concat( $left, ' ', $right )" />
496                                         <xsl:call-template name="gettitle" >
497                                                 <xsl:with-param name="txt" select="$txt" />
498                                         </xsl:call-template>
499                         </xsl:when>
500                         <xsl:otherwise>
501                                 <xsl:value-of select="$txt" />
502                         </xsl:otherwise>
503                 </xsl:choose>
504 </xsl:template>
505
506
507 </xsl:stylesheet>