styles/vym2html.xsl
author convert-repo
Fri, 23 Jul 2010 16:43:49 +0000
changeset 849 988f1908a7c4
parent 37 df767ed748f3
permissions -rw-r--r--
update tags
     1 <?xml version="1.0" encoding="UTF-8" ?>
     2 
     3 <!--
     4     Document   : vym2html.xsl
     5     Created on : 20040313
     6 	Modified   : 20040512,20040622	Uwe Drechsel
     7 	Version    : 0.7
     8     Author     : Clemens Kraus (http://www.clemens-kraus.de)
     9     Description: transforms vym-files into html format.
    10     
    11 	Hint:
    12 	tm.xsl and cm.xsl were taken from Alexander Johannesen's 
    13 	beautiful xSiteable content management system: 
    14 		http://xsiteable.org
    15 	and are used with kind permission
    16 -->
    17 
    18 	
    19 
    20 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    21 
    22 	<!-- Include external stylesheets -->
    23 	<xsl:include href="tm.xsl" />
    24 	<xsl:include href="cm.xsl" />
    25   
    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"/> 
    43 
    44 	<xsl:variable name="level" select="'0'"/>			
    45 	<xsl:variable name="contentlist" select="false()"/> 
    46 
    47   
    48 	<xsl:variable name="fn" >
    49 		<xsl:call-template name="getfn" >
    50 			<xsl:with-param name="txt" select="$filename" />
    51 		</xsl:call-template>
    52 	</xsl:variable>
    53 
    54 	<xsl:variable name="path" >
    55 	  <xsl:value-of select="normalize-space( substring($filename, 1, number(string-length($filename)-string-length($fn))) )" />
    56 	</xsl:variable>
    57 
    58 	<xsl:variable name="stylesheetn" >
    59 	<xsl:call-template name="getfn" >
    60 		<xsl:with-param name="txt" select="$stylesheet" />
    61 	</xsl:call-template>
    62 	</xsl:variable><!-- path -->
    63 
    64 
    65 
    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" />
    72 		</xsl:call-template>
    73 	</xsl:variable><!-- header -->
    74 		
    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">]]>&#xA;</xsl:text>
    77 	<html><xsl:text>&#xA;</xsl:text>
    78 		<head><xsl:text>&#xA;</xsl:text>
    79 			<title><xsl:value-of select="$header"/></title>
    80 			<xsl:text disable-output-escaping="yes">&#xA;<![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[">]]>&#xA;</xsl:text>
    85 			<meta name="generator" content="vym (http://www.insilmaril.de/vym/) and vym2html.xsl (http://www.clemens-kraus.de)"/><xsl:text>&#xA;</xsl:text>
    86 		</head>
    87 		<xsl:text>&#xA;</xsl:text>
    88 
    89 		<!-- Write body of HTML document -->  
    90 		<body>
    91 			<!-- vym title box at top of page -->
    92 			<xsl:text>&#xA;</xsl:text>
    93 			<div class="vymTitleBox">
    94 				<xsl:value-of select="$header"/>
    95 			</div>
    96 
    97 			<!-- Include image of map, if wanted -->
    98 			<xsl:if test="$genimage != ''">
    99 				<xsl:variable name="image" select="concat($fn, '.png')" />
   100 
   101 				<div class="vymImageMap">
   102 					<img src="images/{$image}" 
   103 						border="0" 
   104 						usemap="#vymmap"
   105 						alt="vymmap">
   106 					</img>
   107 				</div>
   108 				<xsl:text>&#xA;</xsl:text>
   109 
   110 				<!-- Generate image map by a first walk through all branches -->
   111 				<map name="vymmap">
   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>
   116 				</map>
   117 
   118 				<xsl:text>&#xA;</xsl:text>
   119 			</xsl:if>
   120 
   121 			<!-- Include note of mapcenter here -->
   122 			<xsl:apply-templates select="vymmap/mapcenter/note/@href"/>
   123 
   124 
   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>
   132 			</xsl:if>
   133 
   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"/>
   139 				</div>
   140 			</div>
   141 
   142 			<!-- Footer containing filename, date, selfpromotion -->
   143 			<table class="vymFooter">
   144 				<tr>
   145 					<td class="vymFooterL">
   146 						<xsl:value-of select="$fn"/>.vym
   147 					</td>
   148 					<td class="vymFooterC">
   149 						<xsl:value-of select="vymmap/@date"/>
   150 					</td>
   151 					<td class="vymFooterR">
   152 						vym <xsl:value-of select="$mapversion"/> 
   153 					</td>  
   154 				</tr>
   155 			</table>
   156 
   157 		</body>&#xA;
   158 	</html>&#xA;
   159 	</xsl:template><!-- Beginning of tranformation, "/" template -->
   160 
   161 	
   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" />
   175 					</xsl:call-template>
   176 				</xsl:variable>
   177 
   178 				<xsl:if test="($imageonly and @url) or ($imageonly and @vymLink) or $imageonly=''">
   179 					<area>
   180 					<xsl:attribute name="shape">
   181 						<xsl:text>rect</xsl:text>
   182 					</xsl:attribute>
   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"/>
   191 					</xsl:attribute>
   192 					<xsl:attribute name="href">
   193 						<xsl:if test="$imageonly = ''">
   194 							<xsl:text>#</xsl:text>
   195 							<xsl:value-of select="generate-id(.)"/>
   196 						</xsl:if>
   197 						<xsl:if test="$imageonly and @url">
   198 							<xsl:value-of select="@url"/>
   199 						</xsl:if>
   200 						<xsl:if test="$imageonly and @vymLink">
   201 							<xsl:value-of select="concat( substring-before(@vymLink, '.vym'), '.html')"/>
   202 						</xsl:if>
   203 					</xsl:attribute>
   204 					<xsl:attribute name="alt">
   205 						<xsl:value-of select="$header"/>
   206 					</xsl:attribute>
   207 					<xsl:attribute name="title">
   208 						<xsl:value-of select="$header"/>
   209 					</xsl:attribute>
   210 					</area>
   211 					<xsl:text>&#xA;</xsl:text>
   212 				</xsl:if>
   213 			</xsl:if> <!--generating id's and anchors -->
   214 
   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-->
   221 
   222 		
   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"/>
   227 				</xsl:call-template>
   228 				<xsl:text>&#xA;</xsl:text>
   229 			</xsl:if>
   230 		</xsl:if>
   231 	</xsl:template><!--branch-->
   232 
   233 
   234 
   235 	<xsl:template name="anchor">
   236 		<xsl:param name="depth"/>
   237 		<xsl:if test="$depth=0"> 
   238 			<hr />
   239 			<xsl:call-template name="gen-anchor-tag">
   240 				<xsl:with-param name="depth" select="$depth"/>
   241 			</xsl:call-template>
   242 				<xsl:if test="count(descendant::branch)">
   243 					<ul>
   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>
   248 					</ul>
   249 				</xsl:if>	
   250 		</xsl:if>
   251 
   252 	<xsl:if test="$depth > 0">
   253 			<li>
   254 				<xsl:call-template name="gen-anchor-tag">
   255 					<xsl:with-param name="depth" select="$depth"/>
   256 				</xsl:call-template>
   257 				<xsl:if test="count(descendant::branch)">
   258 					<ul>
   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>
   263 					</ul>
   264 				</xsl:if>	
   265 			</li>
   266 		</xsl:if>
   267 	</xsl:template><!--anchor-->
   268 
   269 
   270 	<xsl:template name="gen-anchor-tag">
   271 		<xsl:param name="depth"/>
   272 
   273 		<xsl:variable name="header">
   274 			<xsl:call-template name="getheading" >
   275 			<xsl:with-param name="txt" select="heading" />
   276 			</xsl:call-template>
   277 		</xsl:variable><!--header-->
   278 
   279 		<div class="vymBranch{$depth}">
   280 			<xsl:if test="not($genimage = '')">
   281 				<a name="{generate-id(.)}"></a>
   282 			</xsl:if>
   283 
   284 			<!-- start header -->
   285 			<xsl:value-of select="$header"/>
   286 
   287 			<!-- Include flags -->
   288 			<xsl:apply-templates select="./standardFlag" />
   289 
   290 			<!-- URL to external document  -->
   291 			<xsl:if test="@url != ''">
   292 				<p class="vymURL">
   293 				<xsl:element name="a">
   294 					<xsl:attribute name="href">
   295 						<xsl:value-of select="@url"/>
   296 					</xsl:attribute>
   297 					<xsl:if test="$urlImage= 'yes'">
   298 						<img src="flags/url.png" 
   299 							border="0" 
   300 							valign="middle"
   301 							alt="URL">
   302 						</img>
   303 					</xsl:if>
   304 					<xsl:if test="$urlImage!= 'yes'">
   305 						<xsl:text>&gt; </xsl:text>
   306 					</xsl:if>
   307 					<xsl:if test="$urlHeading = 'yes'">
   308 						<xsl:value-of select="$header"/>
   309 					</xsl:if>
   310 					<xsl:if test="$urlHeading != 'yes'">
   311 						<xsl:value-of select="@url"/>
   312 					</xsl:if>
   313 				</xsl:element>
   314 				</p>
   315 			</xsl:if><!-- URL to ext. doc -->
   316 			<xsl:text>&#xA;</xsl:text>
   317 		</div>
   318 
   319 		<xsl:apply-templates select="note/@href"/>
   320 
   321 		<xsl:text>&#xA;</xsl:text>
   322 	</xsl:template><!--gen-anchor-tag-->
   323 
   324 
   325 	<xsl:template match="standardFlag">
   326 		<xsl:variable name="flag" select="concat(., '.png')" />
   327 		<img src="flags/{$flag}" valign="middle" border="0" alt="{$flag}">
   328 		</img>
   329 
   330 	</xsl:template><!--standardFlag-->
   331 
   332 
   333 	<xsl:template match="note/@href">
   334 		<div class="vymNote">
   335 		<xsl:variable name="actualnotename">
   336 			<xsl:value-of select="substring-after(current(),':')"/>
   337 		</xsl:variable>
   338 
   339 		<xsl:variable name="note-name">
   340 			<xsl:if test="$path = ''">
   341 				<xsl:value-of select="$actualnotename"/>
   342 			</xsl:if>
   343 			<xsl:if test="not($path = '')">
   344 				<xsl:value-of select="concat($path, '/', $actualnotename)"/>
   345 			</xsl:if>
   346 		</xsl:variable><!--note-name-->
   347 
   348 
   349 		<xsl:if test="../@fonthint = 'fixed'">
   350 			<xsl:text disable-output-escaping="yes">&lt;pre></xsl:text>
   351 		</xsl:if>
   352 
   353 		<xsl:variable name="currentID" select="@id" />
   354 
   355 		<xsl:apply-templates select="document($note-name)/note">
   356 			<xsl:with-param name="currentID" select="$currentID" />
   357 		</xsl:apply-templates>
   358 
   359 		<xsl:if test="../@fonthint = 'fixed'">
   360 			<xsl:text disable-output-escaping="yes">&lt;/pre></xsl:text>
   361 		</xsl:if>
   362 
   363 		</div>
   364 	</xsl:template><!--note/@href-->
   365 
   366 
   367   
   368 <!--	Wiki-style notation overview:
   369   		Lines:
   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
   378 		# clues
   379 		
   380 		Links:
   381 		use "{...}" or {(Clemens homepage) http://www.clemens-kraus.de/} for external links.
   382 		
   383 		Markup:
   384 		|This is bold| text, while |/this text is italic|, |*this is pre-formatted|, and |!this is a note|
   385 	-->
   386   
   387 	<xsl:template match="note">
   388 		<xsl:param name="currentID"/>
   389 
   390 
   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"/>
   394 		</xsl:call-template>
   395 	</xsl:template><!--note-->
   396 
   397 	  
   398   
   399   
   400   
   401 	<xsl:template name="getfn">
   402 		<xsl:param name="txt" select="." />
   403 
   404 		<xsl:choose>
   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" />
   410 					</xsl:call-template>
   411 				</xsl:if>
   412 			</xsl:when>
   413 			<xsl:otherwise>
   414 				<xsl:value-of select="$txt" />
   415 			</xsl:otherwise>
   416 		</xsl:choose>
   417 	</xsl:template><!--getfn-->
   418 
   419   
   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">&lt;br&gt;</xsl:text>
   425 		</xsl:variable>
   426 		<xsl:choose>
   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 )" />
   431 			</xsl:when>
   432 			<xsl:otherwise>
   433 				<xsl:value-of select="$txt" />
   434 			</xsl:otherwise>
   435 		</xsl:choose>
   436 	</xsl:template><!--getheading-->
   437   
   438 </xsl:stylesheet>
   439