styles/vym2xhtml.xsl
author insilmaril
Wed, 08 Mar 2006 12:59:08 +0000
changeset 238 c15affaf86a8
parent 219 a860efcaac4c
child 245 27b71695d690
permissions -rw-r--r--
Fixed Image Preview in FileDialog
     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.7'"/>
    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 
   128 <xsl:variable name="default.css.stylesheet">
   129    <xsl:text>
   130 h1 {border-width: 1; border: solid; text-align: center}
   131 div.imagemap { align: center; border: 0; }
   132    </xsl:text>
   133 </xsl:variable>
   134 
   135 
   136 <!-- ====================================================================== -->
   137 <xsl:template name="generate.head">
   138    <head>
   139       <title><xsl:value-of select="$head.title"/></title>
   140       <xsl:if test="$use.default.css.stylesheet">
   141          <style type="text/css">
   142             <xsl:value-of select="$default.css.stylesheet"/>
   143          </style>
   144       </xsl:if>
   145       <xsl:if test="vymmap/@author!=''">
   146          <meta name="author" content="{vymmap/@author}"/>
   147       </xsl:if>
   148       <xsl:if test="vymmap/@comment!=''">
   149          <meta name="comment" content="{vymmap/@comment}"/>
   150       </xsl:if>
   151       <meta name="generator" content="vym"/>
   152       <xsl:if test="$css.stylesheet!=''">
   153          <link rel="stylesheet" id="css.stylesheet" href="{$css.stylesheet}"/>
   154       </xsl:if>
   155    </head>
   156 </xsl:template>
   157 
   158 
   159 <xsl:template name="check.vym.version">
   160    <xsl:if test="$checkvym.version">
   161       <xsl:if test="not(/vymmap/@version=$vym.version)">
   162          <xsl:message>
   163             <xsl:text>&#10;</xsl:text>
   164             <xsl:text>  WARNING:</xsl:text>
   165             <xsl:text> This stylesheet applies to VYM XML format v.</xsl:text>
   166             <xsl:value-of select="$vym.version"/>
   167             <xsl:text>.&#10;  Your XML format has v</xsl:text>
   168             <xsl:value-of select="/vymmap/@version"/>
   169             <xsl:text>.&#10;  Check your HTML output!</xsl:text>
   170             <xsl:text>&#10;&#10;</xsl:text>
   171          </xsl:message>
   172       </xsl:if>
   173    </xsl:if>
   174 </xsl:template>
   175 
   176 
   177 <!-- ====================================================================== -->
   178 <xsl:template match="*">
   179    <xsl:message>
   180       <xsl:text>WARNING: Unknown tag "</xsl:text>
   181       <xsl:value-of select="local-name(.)"/>
   182       <xsl:text>": </xsl:text>
   183       <xsl:value-of select="normalize-space(.)"/>
   184       <xsl:text>&#10;</xsl:text>
   185    </xsl:message>
   186 </xsl:template>
   187 
   188 
   189 <xsl:template match="/">
   190    <xsl:call-template name="check.vym.version"/>
   191 
   192    <html xmlns="&xhtmlns;">
   193       <xsl:call-template name="generate.head"/>
   194       <body>
   195          <xsl:apply-templates/>
   196          <xsl:call-template name="generate.footer"/>
   197 
   198       </body>
   199    </html>
   200 </xsl:template>
   201 
   202 
   203 <xsl:template match="vymmap">
   204    <div class="vymmap">
   205       <xsl:apply-templates/>
   206    </div>
   207 </xsl:template>
   208 
   209 
   210 <xsl:template match="mapcenter">
   211    <div class="mapcenter">
   212       <xsl:apply-templates/>
   213    </div>
   214 </xsl:template>
   215 
   216 
   217 <xsl:template match="mapcenter/heading">
   218    <div class="vym-header">
   219 	   <xsl:apply-templates/>
   220    </div>
   221  
   222       <xsl:if test="$use.imagemap=1">
   223          <div class="vym-imagemap">
   224             <img src="{$imagemap}"
   225                alt="Imagemap"
   226                class="imagemap"
   227                usemap="#vym_imagemap"/>
   228          </div>
   229          <map name="vym_imagemap">
   230             <xsl:apply-templates select="../branch" mode="imagemap"/>
   231          </map>
   232       </xsl:if>
   233 </xsl:template>
   234 
   235 
   236 <xsl:template match="mapcenter/branch">
   237    <hr/>
   238    <ul class="branch">
   239       <xsl:apply-templates/>
   240    </ul>
   241 </xsl:template>
   242 
   243 
   244 <xsl:template match="branch">
   245    <ul class="branch">
   246       <xsl:apply-templates/>
   247    </ul>
   248 </xsl:template>
   249 
   250 
   251 <xsl:template match="heading">
   252    <li class="heading">
   253 	  <span id="{generate-id(..)}">
   254       <xsl:if test="@textColor!='' and $use.textcolor=1">
   255          <xsl:attribute name="style" >color: <xsl:value-of select="@textColor" />
   256 		 </xsl:attribute>
   257       </xsl:if>
   258       <xsl:choose>
   259          <xsl:when test="../@url">
   260             <xsl:variable name="url" select="../@url"/>
   261 
   262             <!-- Check, how links should be generated -->
   263             <xsl:choose>
   264                <xsl:when test="$link.style = 'name'">
   265                    <a href="{$url}">
   266 						<img src="{concat($image.flags.path,'url-16x16.png')}" border="0" alt="URL"/>
   267 						<xsl:text> </xsl:text>
   268 						<xsl:apply-templates/>
   269 					</a>
   270                </xsl:when>
   271                <xsl:when test="$link.style = 'url'">
   272 					<a href="{$url}">
   273 						<img src="{concat($image.flags.path,'url-16x16.png')}" border="0" alt="URL"/>
   274 						<xsl:text> </xsl:text>
   275 						<xsl:value-of select="$url"/>
   276 					</a>
   277                </xsl:when>
   278                <xsl:when test="$link.style = 'both'">
   279                   <a href="{$url}">
   280 						<img src="{concat($image.flags.path,'url-16x16.png')}" border="0" alt="URL"/>
   281 						<xsl:text> </xsl:text>
   282 						<xsl:apply-templates/> (<xsl:value-of select="$url"/>)
   283 					</a>
   284                </xsl:when>
   285                <xsl:otherwise>
   286                   <xsl:message>
   287                      <xsl:text>WARNING: Parameter link.style doesn't contain the correct</xsl:text>
   288                      <xsl:text> value (name|url|both)</xsl:text>
   289                      <xsl:text>&#10; was "</xsl:text>
   290                      <xsl:value-of select="$link.style"/>
   291                      <xsl:text>"</xsl:text>
   292                   </xsl:message>
   293                   <a href="{$url}"><xsl:apply-templates/></a>
   294                </xsl:otherwise>
   295             </xsl:choose>
   296 
   297          </xsl:when>
   298          <xsl:otherwise>
   299 						<xsl:call-template name="gettitle" >
   300 							<xsl:with-param name="txt" select="." />
   301 						</xsl:call-template>
   302 						
   303          </xsl:otherwise>
   304       </xsl:choose>
   305 
   306       <xsl:for-each select="following-sibling::standardflag">
   307          <xsl:apply-templates select="current()" mode="standardflag"/><xsl:text> </xsl:text>
   308       </xsl:for-each>
   309       </span>
   310    </li>
   311 </xsl:template>
   312 
   313 
   314 <xsl:template match="floatimage">
   315    <xsl:variable name="filename">
   316       <xsl:choose>
   317          <xsl:when test="contains(@href,':')">
   318             <xsl:value-of select="substring-after(@href,':')"/>
   319          </xsl:when>
   320          <xsl:otherwise>
   321             <xsl:value-of select="@href"/>
   322          </xsl:otherwise>
   323       </xsl:choose>
   324    </xsl:variable>
   325    
   326   <xsl:if test="@floatExport='true'">
   327       <span><img src="{$filename}" alt="{$filename}"/></span>
   328   </xsl:if>
   329 </xsl:template>
   330 
   331 
   332 <xsl:template match="standardflag"/><!-- Do nothing in normal mode -->
   333 
   334 <xsl:template match="standardflag" mode="standardflag">
   335    <span class="standardflag">
   336       <xsl:element name="img">
   337          <xsl:variable name="_srcimg">
   338          <xsl:choose>
   339             <xsl:when test="$image.flags.path">
   340                <xsl:value-of select="concat($image.flags.path,
   341                   .,
   342                   $image.extension)"/>
   343             </xsl:when>
   344             <xsl:otherwise>
   345                <xsl:value-of select="concat(., $image.extension)"/>
   346             </xsl:otherwise>
   347          </xsl:choose>
   348          </xsl:variable>
   349          <xsl:attribute name="src">
   350             <xsl:value-of select="$_srcimg"/>
   351          </xsl:attribute>
   352          <xsl:attribute name="alt">
   353             <xsl:value-of select="$_srcimg"/>
   354          </xsl:attribute>
   355       </xsl:element>
   356    </span>
   357 </xsl:template>
   358 
   359 <!-- Do nothing! -->
   360 <xsl:template match="select"/>
   361 <xsl:template match="setting"/>
   362 
   363 
   364 <xsl:template match="htmlnote">
   365    <div class="vym-htmlnote">
   366 			<xsl:choose>
   367 				<xsl:when test="$use.diffnotes=1">
   368 	      	<xsl:copy-of select="."/>
   369 				</xsl:when>
   370 				<xsl:otherwise>
   371 					<xsl:apply-templates select=".//body/*"/><!-- Select only body elements -->
   372 				</xsl:otherwise>
   373 			</xsl:choose>
   374    </div>
   375 </xsl:template>
   376 
   377 <!-- Do nothing! We don't need some informational elements -->
   378 <xsl:template match="htmlnote/html/*"/>
   379 
   380 <xsl:template match="htmlnote/html/body">
   381    <xsl:copy-of select="."/>
   382 </xsl:template>
   383 
   384 <xsl:template match="htmlnote/html/body/*">
   385    <xsl:copy-of select="."/>
   386 </xsl:template>
   387 
   388 
   389 <!-- ====================================================================== -->
   390 <xsl:template match="branch" mode="imagemap"> 
   391    <xsl:param name="node"/> 
   392    <xsl:variable name="title"> 
   393       <xsl:apply-templates mode="imagemap"/> 
   394    </xsl:variable> 
   395  
   396    <xsl:if test="$debug=1"> 
   397       <xsl:message> 
   398       branch/heading = "<xsl:value-of select="normalize-space($title)"/>" 
   399       </xsl:message> 
   400    </xsl:if> 
   401  
   402    <area shape="rect"> 
   403       <xsl:attribute name="href"> 
   404          <xsl:choose><!-- Fix begin (!) --> 
   405             <xsl:when test="$imagemap != ''"> 
   406                <xsl:value-of select="concat('#', generate-id(.))"/> 
   407             </xsl:when> 
   408             <xsl:when test="$imagemap and @url"> 
   409                <xsl:value-of select="@url"/> 
   410             </xsl:when> 
   411             <xsl:when test="$imagemap and @vymLink"> 
   412                <xsl:value-of select="concat( substring-before(@vymLink, 
   413 '.vym'), '.html')"/> 
   414             </xsl:when> 
   415          </xsl:choose><!-- Fix end --> 
   416       </xsl:attribute> 
   417       <xsl:attribute name="alt"> 
   418 				 <xsl:call-template name="gettitle" >
   419 				 	<xsl:with-param name="txt" select="heading" />
   420 				 </xsl:call-template>
   421       </xsl:attribute> 
   422       <xsl:attribute name="title"> 
   423 				<xsl:call-template name="gettitle" >
   424 				 	<xsl:with-param name="txt" select="heading" />
   425 				</xsl:call-template>
   426       </xsl:attribute> 
   427       <xsl:attribute name="coords"> 
   428          <xsl:choose> 
   429             <xsl:when test="@x1!='' and @x2!='' and @y1!='' and @y2!=''"> 
   430                <xsl:value-of select="@x1"/> 
   431                <xsl:text>,</xsl:text> 
   432                <xsl:value-of select="@y1"/> 
   433                <xsl:text>,</xsl:text> 
   434                <xsl:value-of select="@x2"/> 
   435                <xsl:text>,</xsl:text> 
   436                <xsl:value-of select="@y2"/> 
   437             </xsl:when> 
   438             <xsl:otherwise> 
   439                <!-- 
   440                <xsl:message> 
   441                   <xsl:text>ERROR: Some coordinates in branch are 
   442 missing!&#10;</xsl:text> 
   443                   <xsl:text>       See branch with </xsl:text> 
   444                   <xsl:value-of select="normalize-space($title)"/> 
   445                </xsl:message>
   446                //--> 
   447             </xsl:otherwise> 
   448          </xsl:choose> 
   449       </xsl:attribute> 
   450    </area> 
   451    <xsl:apply-templates select="./branch" mode="imagemap"/> 
   452 </xsl:template> 
   453 
   454 
   455 <xsl:template match="heading" mode="imagemap">
   456 		<xsl:call-template name="gettitle" >
   457 			<xsl:with-param name="txt" select="." />
   458 		</xsl:call-template>
   459 		<!--<xsl:message>title2: <xsl:value-of select="$title" /></xsl:message>-->
   460 
   461     <xsl:apply-templates mode="imagemap"/>
   462 </xsl:template>
   463 
   464 
   465 <xsl:template match="xlink">
   466 		<xsl:element name="a">
   467 			<xsl:attribute name="name">
   468 				<xsl:value-of select="translate(@beginBranch, ':,', '')"/>
   469 			</xsl:attribute>
   470 		</xsl:element>
   471 
   472 		<div class="xlink">
   473 			<xsl:text>See: </xsl:text>
   474 			<xsl:element name="a">
   475 				<xsl:attribute name="href">
   476 					<xsl:text>#</xsl:text><!--<xsl:value-of select="translate(@endBranch, ':,', '')"/>-->
   477 				</xsl:attribute>
   478 				<!--<xsl:value-of select="translate(@endBranch, ':,', '')"/>-->reference
   479 			</xsl:element>
   480 				<!--<xsl:apply-templates/>-->
   481 				<!--<xsl:message>->xlink: <xsl:value-of select="concat(@endBranch, ' ', position())" /></xsl:message>-->
   482    </div>
   483 </xsl:template>
   484 
   485 
   486 <xsl:template name="gettitle">
   487 		<xsl:param name="txt" select="." />
   488 		
   489 		<xsl:variable name="br">
   490 			<xsl:text disable-output-escaping="yes">&lt;br&gt;</xsl:text>
   491 		</xsl:variable>
   492 		
   493 		<xsl:choose>
   494 			<xsl:when test="contains($txt, $br)" >
   495 				<xsl:variable name="right" select="substring-after($txt, $br)" />
   496 				<xsl:variable name="left" select="substring-before($txt, $br)" />
   497 				<xsl:variable name="txt" select="concat( $left, ' ', $right )" />
   498 					<xsl:call-template name="gettitle" >
   499 						<xsl:with-param name="txt" select="$txt" />
   500 					</xsl:call-template>
   501 			</xsl:when>
   502 			<xsl:otherwise>
   503 				<xsl:value-of select="$txt" />
   504 			</xsl:otherwise>
   505 		</xsl:choose>
   506 
   507 </xsl:template>
   508 
   509 
   510 </xsl:stylesheet>