added modifier modes (color,link,copy). Not fully functional yet
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE xsl:stylesheet
4 <!-- Namespace for XHTML -->
5 <!ENTITY xhtmlns "http://www.w3.org/1999/xhtml">
9 Document : vym2xhtml.xsl
14 Author : Thomas Schraitle <tom_schr@web.de>
15 Description : transforms vym-files into XHTML.
16 Bugs : Many. ;) Produces at the moment not valid XHTML
20 <xsl:stylesheet version="1.0"
21 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
22 xmlns:date="http://exslt.org/dates-and-times"
23 extension-element-prefixes="date"
27 <xsl:output method="xml"
28 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
29 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
32 media-type="application/xhtml+xml"/>
36 <!-- ====================================================================== -->
37 <!-- 1 = true, 0 = false -->
39 <!-- URL to CSS stylesheet -->
40 <xsl:param name="css.stylesheet" select="'vym.css'"/>
42 <!-- Should a default CSS stylesheet be used? -->
43 <xsl:param name="use.default.css.stylesheet" select="1"/>
45 <!-- Should textcolors be used? -->
46 <xsl:param name="use.textcolor" select="0"/>
48 <!-- Should an imagemap be generated? -->
49 <xsl:param name="use.imagemap" select="1"/>
51 <!-- URL to image for imagemap -->
52 <xsl:param name="imagemap" select="''"/>
54 <!-- This stylesheet is able to process the following VYM version -->
55 <xsl:param name="vym.version" select="'1.6.0'"/>
57 <!-- Should the VYM XML format be checked -->
58 <xsl:param name="checkvym.version" select="1"/>
60 <!-- Which is the image extension? -->
61 <xsl:param name="image.extension" select="'.png'"/>
63 <!-- Where are the flags? -->
64 <xsl:param name="image.flags.path" select="'flags/'"/>
66 <!-- Filename of the XML document -->
67 <xsl:param name="mapname" />
69 <!-- Should a footer be generated? -->
70 <xsl:param name="use.footer" select="1"/>
72 <!-- How should Links generated:
73 name : Use only the name of the branch (default)
74 url : Use only the URL of the branch
77 <xsl:param name="link.style" select="'name'"/>
81 <!-- Debuggin on/off? -->
82 <xsl:param name="debug" select="0"/>
83 <xsl:template name="generate.footer">
84 <xsl:if test="$use.footer">
86 <table class="vym-footer">
88 <td class="vym-footerL"><xsl:value-of select="$mapname"/></td>
89 <td class="vym-footerC"><xsl:value-of select="vymmap/@date"/> </td>
90 <!--<td class="vym-footerC"><xsl:value-of select="date:date()"/></td>-->
91 <td class="vym-footerR">vym <xsl:value-of select="vymmap/@version"/></td>
101 <!-- ====================================================================== -->
102 <xsl:variable name="head.title">
104 <xsl:when test="/vymmap/mapcenter/heading">
105 <xsl:value-of select="normalize-space(/vymmap/mapcenter/heading)"/>
107 <xsl:otherwise></xsl:otherwise>
112 <xsl:variable name="default.css.stylesheet">
114 h1 {border-width: 1; border: solid; text-align: center}
115 div.imagemap { align: center; border: 0; }
120 <!-- ====================================================================== -->
121 <xsl:template name="generate.head">
123 <title><xsl:value-of select="$head.title"/></title>
124 <xsl:if test="$use.default.css.stylesheet">
125 <style type="text/css">
126 <xsl:value-of select="$default.css.stylesheet"/>
129 <xsl:if test="vymmap/@author!=''">
130 <meta name="author" content="{vymmap/@author}"/>
132 <xsl:if test="vymmap/@comment!=''">
133 <meta name="comment" content="{vymmap/@comment}"/>
135 <meta name="generator" content="vym"/>
136 <xsl:if test="$css.stylesheet!=''">
137 <link rel="stylesheet" id="css.stylesheet" href="{$css.stylesheet}"/>
143 <xsl:template name="check.vym.version">
144 <xsl:if test="$checkvym.version">
145 <xsl:if test="not(/vymmap/@version=$vym.version)">
147 <xsl:text> </xsl:text>
148 <xsl:text> WARNING:</xsl:text>
149 <xsl:text> This stylesheet applies to VYM XML format v.</xsl:text>
150 <xsl:value-of select="$vym.version"/>
151 <xsl:text>. Your XML format has v</xsl:text>
152 <xsl:value-of select="/vymmap/@version"/>
153 <xsl:text>. Check your HTML output!</xsl:text>
154 <xsl:text> </xsl:text>
161 <!-- ====================================================================== -->
162 <xsl:template match="*">
164 <xsl:text>WARNING: Unknown tag "</xsl:text>
165 <xsl:value-of select="local-name(.)"/>
166 <xsl:text>": </xsl:text>
167 <xsl:value-of select="normalize-space(.)"/>
168 <xsl:text> </xsl:text>
173 <xsl:template match="/">
174 <xsl:call-template name="check.vym.version"/>
176 <html xmlns="&xhtmlns;">
177 <xsl:call-template name="generate.head"/>
179 <xsl:apply-templates/>
180 <xsl:call-template name="generate.footer"/>
187 <xsl:template match="vymmap">
189 <xsl:apply-templates/>
194 <xsl:template match="mapcenter">
195 <div class="mapcenter">
196 <xsl:apply-templates/>
201 <xsl:template match="mapcenter/heading">
202 <div class="vym-header">
203 <xsl:apply-templates/>
206 <xsl:if test="$use.imagemap=1">
207 <div class="vym-imagemap">
208 <img src="{$imagemap}"
211 usemap="#vym_imagemap"/>
213 <map name="vym_imagemap">
214 <xsl:apply-templates select="../branch" mode="imagemap"/>
220 <xsl:template match="mapcenter/branch">
223 <xsl:apply-templates/>
228 <xsl:template match="branch">
230 <xsl:apply-templates/>
235 <xsl:template match="heading">
237 <span id="{generate-id(..)}">
238 <xsl:if test="@textColor!='' and $use.textcolor=1">
239 <xsl:attribute name="style" >color: <xsl:value-of select="@textColor" />
243 <xsl:when test="../@url">
244 <xsl:variable name="url" select="../@url"/>
246 <!-- Check, how links should be generated -->
248 <xsl:when test="$link.style = 'name'">
250 <img src="{concat($image.flags.path,'url.png')}" border="0" valign="middle" alt="URL"/>
251 <xsl:apply-templates/>
254 <xsl:when test="$link.style = 'url'">
256 <img src="{concat($image.flags.path,'url.png')}" border="0" valign="middle" alt="URL"/>
257 <xsl:value-of select="$url"/>
260 <xsl:when test="$link.style = 'both'">
262 <img src="{concat($image.flags.path,'url.png')}" border="0" valign="middle" alt="URL"/>
263 <xsl:apply-templates/> ( <xsl:value-of select="$url"/>)
268 <xsl:text>WARNING: Parameter link.style doesn't contain the correct</xsl:text>
269 <xsl:text> value (name|url|both)</xsl:text>
270 <xsl:text> was "</xsl:text>
271 <xsl:value-of select="$link.style"/>
272 <xsl:text>"</xsl:text>
274 <a href="{$url}"><xsl:apply-templates/></a>
280 <xsl:apply-templates/>
284 <xsl:for-each select="following-sibling::standardflag">
285 <xsl:apply-templates select="current()" mode="standardflag"/>
292 <xsl:template match="floatimage">
293 <xsl:variable name="filename">
295 <xsl:when test="contains(@href,':')">
296 <xsl:value-of select="substring-after(@href,':')"/>
299 <xsl:value-of select="@href"/>
304 <xsl:if test="@floatExport='true'">
305 <span><img src="{$filename}" alt="{$filename}"/></span>
310 <xsl:template match="standardflag"/><!-- Do nothing in normal mode -->
312 <xsl:template match="standardflag" mode="standardflag">
313 <span class="standardflag">
314 <xsl:element name="img">
315 <xsl:variable name="_srcimg">
317 <xsl:when test="$image.flags.path">
318 <xsl:value-of select="concat($image.flags.path,
323 <xsl:value-of select="concat(., $image.extension)"/>
327 <xsl:attribute name="src">
328 <xsl:value-of select="$_srcimg"/>
330 <xsl:attribute name="alt">
331 <xsl:value-of select="$_srcimg"/>
338 <xsl:template match="select"/>
339 <xsl:template match="setting"/>
342 <xsl:template match="htmlnote">
343 <div class="vym-htmlnote" >
344 <xsl:apply-templates select=".//body/*"/><!-- Select only body elements -->
348 <!-- Do nothing! We don't need some informational elements -->
349 <xsl:template match="htmlnote/html/*"/>
351 <xsl:template match="htmlnote/html/body">
352 <xsl:copy-of select="."/>
355 <xsl:template match="htmlnote/html/body/*">
356 <xsl:copy-of select="."/>
360 <!-- ====================================================================== -->
361 <xsl:template match="branch" mode="imagemap">
362 <xsl:param name="node"/>
363 <xsl:variable name="title">
364 <xsl:apply-templates mode="imagemap"/>
367 <xsl:if test="$debug=1">
369 branch/heading = "<xsl:value-of select="normalize-space($title)"/>"
370 x1, x2 = <xsl:value-of select="concat(@x1, '/', @x2)"/>
371 y1, y2 = <xsl:value-of select="concat(@y1, '/', @y2)"/>
376 <xsl:attribute name="href">
377 <xsl:choose><!-- Fix begin (!) -->
378 <xsl:when test="$imagemap != ''">
379 <xsl:value-of select="concat('#', generate-id(.))"/>
381 <xsl:when test="$imagemap and @url">
382 <xsl:value-of select="@url"/>
384 <xsl:when test="$imagemap and @vymLink">
385 <xsl:value-of select="concat( substring-before(@vymLink,
388 </xsl:choose><!-- Fix end -->
390 <xsl:attribute name="alt">
391 <xsl:value-of select="normalize-space($title)"/>
393 <xsl:attribute name="title">
394 <xsl:value-of select="normalize-space($title)"/>
396 <xsl:attribute name="coords">
398 <xsl:when test="@x1!='' and @x2!='' and @y1!='' and @y2!=''">
399 <xsl:value-of select="@x1"/>
400 <xsl:text>,</xsl:text>
401 <xsl:value-of select="@y1"/>
402 <xsl:text>,</xsl:text>
403 <xsl:value-of select="@x2"/>
404 <xsl:text>,</xsl:text>
405 <xsl:value-of select="@y2"/>
410 <xsl:text>ERROR: Some coordinates in branch are
411 missing! </xsl:text>
412 <xsl:text> See branch with </xsl:text>
413 <xsl:value-of select="normalize-space($title)"/>
420 <xsl:apply-templates select="./branch" mode="imagemap"/>
425 <xsl:template match="heading" mode="imagemap">
426 <xsl:apply-templates mode="imagemap"/>