1 <?xml version="1.0" encoding="UTF-8" ?>
4 Document : vym2html.xsl
6 Modified : 20040512,20040622 Uwe Drechsel
8 Author : Clemens Kraus (http://www.clemens-kraus.de)
9 Description: transforms vym-files into html format.
12 tm.xsl and cm.xsl were taken from Alexander Johannesen's
13 beautiful xSiteable content management system:
15 and are used with kind permission
20 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
22 <!-- Include external stylesheets -->
23 <xsl:include href="tm.xsl" />
24 <xsl:include href="cm.xsl" />
26 <!-- Settings and parameters -->
27 <xsl:output method="html" indent="no" encoding="UTF-8"/>
28 <xsl:param name="filenamep" />
29 <xsl:param name="wikistylep" />
30 <xsl:param name="genimagep" />
31 <xsl:param name="imageonlyp" />
32 <xsl:param name="stylesheetp" />
33 <xsl:param name="urlHeadingp" />
34 <xsl:param name="urlImagep" />
35 <xsl:variable name="filename" select="$filenamep"/>
36 <xsl:variable name="wikistyle" select="$wikistylep"/>
37 <xsl:variable name="genimage" select="$genimagep"/>
38 <xsl:variable name="imageonly" select="$imageonlyp"/>
39 <xsl:variable name="stylesheet" select="$stylesheetp"/>
40 <xsl:variable name="topics" select="//item" />
41 <xsl:variable name="urlHeading" select="$urlHeadingp"/>
42 <xsl:variable name="urlImage" select="$urlImagep"/>
44 <xsl:variable name="level" select="'0'"/>
45 <xsl:variable name="contentlist" select="false()"/>
48 <xsl:variable name="fn" >
49 <xsl:call-template name="getfn" >
50 <xsl:with-param name="txt" select="$filename" />
54 <xsl:variable name="path" >
55 <xsl:value-of select="normalize-space( substring($filename, 1, number(string-length($filename)-string-length($fn))) )" />
58 <xsl:variable name="stylesheetn" >
59 <xsl:call-template name="getfn" >
60 <xsl:with-param name="txt" select="$stylesheet" />
62 </xsl:variable><!-- path -->
66 <!-- Beginning of transformation here -->
67 <xsl:template match="/">
68 <xsl:variable name="mapversion" select="vymmap/@version"/>
69 <xsl:variable name="header" >
70 <xsl:call-template name="getheading" >
71 <xsl:with-param name="txt" select="vymmap/mapcenter/heading" />
73 </xsl:variable><!-- header -->
75 <!-- Write head of HTML document -->
76 <xsl:text disable-output-escaping="yes"><![CDATA[<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">]]>
</xsl:text>
77 <html><xsl:text>
</xsl:text>
78 <head><xsl:text>
</xsl:text>
79 <title><xsl:value-of select="$header"/></title>
80 <xsl:text disable-output-escaping="yes">
<![CDATA[<link href="]]></xsl:text>
81 <xsl:value-of select="$stylesheetn"/>
82 <xsl:text disable-output-escaping="yes"><![CDATA[" rel="stylesheet" id="]]></xsl:text>
83 <xsl:value-of select="$stylesheetn"/>
84 <xsl:text disable-output-escaping="yes"><![CDATA[">]]>
</xsl:text>
85 <meta name="generator" content="vym (http://www.insilmaril.de/vym/) and vym2html.xsl (http://www.clemens-kraus.de)"/><xsl:text>
</xsl:text>
87 <xsl:text>
</xsl:text>
89 <!-- Write body of HTML document -->
91 <!-- vym title box at top of page -->
92 <xsl:text>
</xsl:text>
93 <div class="vymTitleBox">
94 <xsl:value-of select="$header"/>
97 <!-- Include image of map, if wanted -->
98 <xsl:if test="$genimage != ''">
99 <xsl:variable name="image" select="concat($fn, '.png')" />
101 <div class="vymImageMap">
102 <img src="images/{$image}"
108 <xsl:text>
</xsl:text>
110 <!-- Generate image map by a first walk through all branches -->
112 <xsl:apply-templates select="vymmap/mapcenter/branch">
113 <xsl:with-param name="genarea" select="true()"/>
114 <xsl:with-param name="imageonly" select="$imageonly"/>
115 </xsl:apply-templates>
118 <xsl:text>
</xsl:text>
121 <!-- Include note of mapcenter here -->
122 <xsl:apply-templates select="vymmap/mapcenter/note/@href"/>
125 <!-- Include all the branches, if not only image is wanted-->
126 <xsl:if test="$imageonly = ''">
127 <xsl:apply-templates select="vymmap/mapcenter/branch">
128 <xsl:with-param name="genarea" select="false()"/>
129 <xsl:with-param name="imageonly" select="$imageonly"/>
130 <xsl:with-param name="depth" select="0"/>
131 </xsl:apply-templates>
134 <!-- Box at bottom of page, containing comment and author -->
135 <div class="vymBoxBottom">
136 <xsl:value-of select="vymmap/@comment"/>
137 <div class="vymBoxBottomR">
138 <xsl:value-of select="vymmap/@author"/>
142 <!-- Footer containing filename, date, selfpromotion -->
143 <table class="vymFooter">
145 <td class="vymFooterL">
146 <xsl:value-of select="$fn"/>.vym
148 <td class="vymFooterC">
149 <xsl:value-of select="vymmap/@date"/>
151 <td class="vymFooterR">
152 vym <xsl:value-of select="$mapversion"/>
159 </xsl:template><!-- Beginning of tranformation, "/" template -->
162 <!-- Main Function generating a branch -->
163 <xsl:template match="branch">
164 <!-- Work a branch twice: a) make id for anchors, b) make output -->
165 <xsl:param name="genarea"/>
166 <xsl:param name="imageonly"/>
167 <xsl:param name="depth"/>
168 <xsl:if test="$genarea">
169 <!-- Generate id's and anchors, no output yet -->
170 <xsl:if test="(@x1 != '' and @y1 != '' and @x2 != '' and @y2 != '') and not(../@scrolled = 'yes')">
171 <!-- Heading is used in ALT field of anchor -->
172 <xsl:variable name="header">
173 <xsl:call-template name="getheading" >
174 <xsl:with-param name="txt" select="heading" />
178 <xsl:if test="($imageonly and @url) or ($imageonly and @vymLink) or $imageonly=''">
180 <xsl:attribute name="shape">
181 <xsl:text>rect</xsl:text>
183 <xsl:attribute name="coords">
184 <xsl:value-of select="@x1"/>
185 <xsl:text>,</xsl:text>
186 <xsl:value-of select="@y1"/>
187 <xsl:text>,</xsl:text>
188 <xsl:value-of select="@x2"/>
189 <xsl:text>,</xsl:text>
190 <xsl:value-of select="@y2"/>
192 <xsl:attribute name="href">
193 <xsl:if test="$imageonly = ''">
194 <xsl:text>#</xsl:text>
195 <xsl:value-of select="generate-id(.)"/>
197 <xsl:if test="$imageonly and @url">
198 <xsl:value-of select="@url"/>
200 <xsl:if test="$imageonly and @vymLink">
201 <xsl:value-of select="concat( substring-before(@vymLink, '.vym'), '.html')"/>
204 <xsl:attribute name="alt">
205 <xsl:value-of select="$header"/>
207 <xsl:attribute name="title">
208 <xsl:value-of select="$header"/>
211 <xsl:text>
</xsl:text>
213 </xsl:if> <!--generating id's and anchors -->
215 <xsl:apply-templates select="branch">
216 <xsl:with-param name="genarea" select="true()"/>
217 <xsl:with-param name="imageonly" select="$imageonly"/>
218 <xsl:with-param name="depth" select="$depth +1"/>
219 </xsl:apply-templates>
220 </xsl:if><!--genarea-->
223 <xsl:if test="$imageonly = ''">
224 <xsl:if test="not($genarea)">
225 <xsl:call-template name="anchor">
226 <xsl:with-param name="depth" select="$depth"/>
228 <xsl:text>
</xsl:text>
231 </xsl:template><!--branch-->
235 <xsl:template name="anchor">
236 <xsl:param name="depth"/>
237 <xsl:if test="$depth=0">
239 <xsl:call-template name="gen-anchor-tag">
240 <xsl:with-param name="depth" select="$depth"/>
242 <xsl:if test="count(descendant::branch)">
244 <xsl:apply-templates select="branch">
245 <xsl:with-param name="genarea" select="false()"/>
246 <xsl:with-param name="depth" select="$depth+1"/>
247 </xsl:apply-templates>
252 <xsl:if test="$depth > 0">
254 <xsl:call-template name="gen-anchor-tag">
255 <xsl:with-param name="depth" select="$depth"/>
257 <xsl:if test="count(descendant::branch)">
259 <xsl:apply-templates select="branch">
260 <xsl:with-param name="genarea" select="false()"/>
261 <xsl:with-param name="depth" select="$depth+1"/>
262 </xsl:apply-templates>
267 </xsl:template><!--anchor-->
270 <xsl:template name="gen-anchor-tag">
271 <xsl:param name="depth"/>
273 <xsl:variable name="header">
274 <xsl:call-template name="getheading" >
275 <xsl:with-param name="txt" select="heading" />
277 </xsl:variable><!--header-->
279 <div class="vymBranch{$depth}">
280 <xsl:if test="not($genimage = '')">
281 <a name="{generate-id(.)}"></a>
284 <!-- start header -->
285 <xsl:value-of select="$header"/>
287 <!-- Include flags -->
288 <xsl:apply-templates select="./standardFlag" />
290 <!-- URL to external document -->
291 <xsl:if test="@url != ''">
293 <xsl:element name="a">
294 <xsl:attribute name="href">
295 <xsl:value-of select="@url"/>
297 <xsl:if test="$urlImage= 'yes'">
298 <img src="flags/url.png"
304 <xsl:if test="$urlImage!= 'yes'">
305 <xsl:text>> </xsl:text>
307 <xsl:if test="$urlHeading = 'yes'">
308 <xsl:value-of select="$header"/>
310 <xsl:if test="$urlHeading != 'yes'">
311 <xsl:value-of select="@url"/>
315 </xsl:if><!-- URL to ext. doc -->
316 <xsl:text>
</xsl:text>
319 <xsl:apply-templates select="note/@href"/>
321 <xsl:text>
</xsl:text>
322 </xsl:template><!--gen-anchor-tag-->
325 <xsl:template match="standardFlag">
326 <xsl:variable name="flag" select="concat(., '.png')" />
327 <img src="flags/{$flag}" valign="middle" border="0" alt="{$flag}">
330 </xsl:template><!--standardFlag-->
333 <xsl:template match="note/@href">
334 <div class="vymNote">
335 <xsl:variable name="actualnotename">
336 <xsl:value-of select="substring-after(current(),':')"/>
339 <xsl:variable name="note-name">
340 <xsl:if test="$path = ''">
341 <xsl:value-of select="$actualnotename"/>
343 <xsl:if test="not($path = '')">
344 <xsl:value-of select="concat($path, '/', $actualnotename)"/>
346 </xsl:variable><!--note-name-->
349 <xsl:if test="../@fonthint = 'fixed'">
350 <xsl:text disable-output-escaping="yes"><pre></xsl:text>
353 <xsl:variable name="currentID" select="@id" />
355 <xsl:apply-templates select="document($note-name)/note">
356 <xsl:with-param name="currentID" select="$currentID" />
357 </xsl:apply-templates>
359 <xsl:if test="../@fonthint = 'fixed'">
360 <xsl:text disable-output-escaping="yes"></pre></xsl:text>
364 </xsl:template><!--note/@href-->
368 <!-- Wiki-style notation overview:
370 + Big headlines start with the '+' character.
371 - Small headlines start with the '-' character.
372 Normal text doesn't have any starting notation.
373 ! Notes start with an exclamation.
374 . Indented text starts with a dot.
375 ? Questions start with a question-mark, and
376 = Answers starts with the equal-sign.
377 * Points for a item-list
381 use "{...}" or {(Clemens homepage) http://www.clemens-kraus.de/} for external links.
384 |This is bold| text, while |/this text is italic|, |*this is pre-formatted|, and |!this is a note|
387 <xsl:template match="note">
388 <xsl:param name="currentID"/>
391 <xsl:call-template name="doLine">
392 <xsl:with-param name="content" select="concat(translate(.,$crlf,$controlCharacter), $controlCharacter)"/>
393 <xsl:with-param name="currentID" select="$currentID"/>
395 </xsl:template><!--note-->
401 <xsl:template name="getfn">
402 <xsl:param name="txt" select="." />
405 <xsl:when test="contains($txt, '/')" >
406 <xsl:variable name="right" select="substring-after($txt, '/')" />
407 <xsl:if test="string-length($right)>1" >
408 <xsl:call-template name="getfn" >
409 <xsl:with-param name="txt" select="$right" />
414 <xsl:value-of select="$txt" />
417 </xsl:template><!--getfn-->
420 <!-- Take care of br's (WHY?) -->
421 <xsl:template name="getheading">
422 <xsl:param name="txt" select="." />
423 <xsl:variable name="br">
424 <xsl:text disable-output-escaping="yes"><br></xsl:text>
427 <xsl:when test="contains($txt, $br)" >
428 <xsl:variable name="right" select="substring-after($txt, $br)" />
429 <xsl:variable name="left" select="substring-before($txt, $br)" />
430 <xsl:value-of select="concat( $left, ' ', $right )" />
433 <xsl:value-of select="$txt" />
436 </xsl:template><!--getheading-->