styles/vym2xhtml.xsl
author insilmaril
Tue, 14 Jun 2005 09:41:37 +0000
changeset 106 4083860dd82e
parent 38 24c0b959c738
child 179 d1d6d9c29f9f
permissions -rw-r--r--
fixed import into empty map
     1 <?xml version="1.0" encoding="ISO-8859-1"?>
     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     License     : GPL
    12     Version     : 0.3.4
    13     VYM version : 1.6.0
    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
    17                   Needs to checked.
    18 -->
    19 
    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"
    24     xmlns="&xhtmlns;">
    25 
    26 
    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"
    30     encoding="UTF-8"
    31     indent="yes"
    32     media-type="application/xhtml+xml"/>
    33 
    34 
    35 
    36 <!-- ====================================================================== -->
    37 <!-- 1 = true, 0 = false -->
    38 
    39 <!-- URL to CSS stylesheet -->
    40 <xsl:param name="css.stylesheet" select="'vym.css'"/>
    41 
    42 <!-- Should a default CSS stylesheet be used? -->
    43 <xsl:param name="use.default.css.stylesheet" select="1"/>
    44 
    45 <!-- Should textcolors be used? -->
    46 <xsl:param name="use.textcolor" select="0"/>
    47 
    48 <!-- Should an imagemap be generated? -->
    49 <xsl:param name="use.imagemap" select="1"/>
    50 
    51 <!-- URL to image for imagemap -->
    52 <xsl:param name="imagemap" select="''"/>
    53 
    54 <!-- This stylesheet is able to process the following VYM version -->
    55 <xsl:param name="vym.version" select="'1.6.0'"/>
    56 
    57 <!-- Should the VYM XML format be checked -->
    58 <xsl:param name="checkvym.version" select="1"/>
    59 
    60 <!-- Which is the image extension? -->
    61 <xsl:param name="image.extension" select="'.png'"/>
    62 
    63 <!-- Where are the flags? -->
    64 <xsl:param name="image.flags.path" select="'flags/'"/>
    65 
    66 <!-- Filename of the XML document -->
    67 <xsl:param name="mapname" />
    68 
    69 <!-- Should a footer be generated? -->
    70 <xsl:param name="use.footer" select="1"/>
    71 
    72 <!-- How should Links generated:
    73     name : Use only the name of the branch (default)
    74     url  : Use only the URL of the branch
    75     both : Use both
    76 -->
    77 <xsl:param name="link.style" select="'name'"/>
    78 
    79 
    80 
    81 <!-- Debuggin on/off? -->
    82 <xsl:param name="debug" select="0"/>
    83 <xsl:template name="generate.footer">
    84   <xsl:if test="$use.footer">
    85       <hr/>
    86       <table class="vym-footer">
    87          <tr >
    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>
    92          </tr>
    93       </table>
    94   </xsl:if>
    95 </xsl:template>
    96 
    97 
    98 
    99 
   100 
   101 <!-- ====================================================================== -->
   102 <xsl:variable name="head.title">
   103    <xsl:choose>
   104       <xsl:when test="/vymmap/mapcenter/heading">
   105          <xsl:value-of select="normalize-space(/vymmap/mapcenter/heading)"/>
   106       </xsl:when>
   107       <xsl:otherwise></xsl:otherwise>
   108    </xsl:choose>
   109 </xsl:variable>
   110 
   111 
   112 <xsl:variable name="default.css.stylesheet">
   113    <xsl:text>
   114 h1 {border-width: 1; border: solid; text-align: center}
   115 div.imagemap { align: center; border: 0; }
   116    </xsl:text>
   117 </xsl:variable>
   118 
   119 
   120 <!-- ====================================================================== -->
   121 <xsl:template name="generate.head">
   122    <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"/>
   127          </style>
   128       </xsl:if>
   129       <xsl:if test="vymmap/@author!=''">
   130          <meta name="author" content="{vymmap/@author}"/>
   131       </xsl:if>
   132       <xsl:if test="vymmap/@comment!=''">
   133          <meta name="comment" content="{vymmap/@comment}"/>
   134       </xsl:if>
   135       <meta name="generator" content="vym"/>
   136       <xsl:if test="$css.stylesheet!=''">
   137          <link rel="stylesheet" id="css.stylesheet" href="{$css.stylesheet}"/>
   138       </xsl:if>
   139    </head>
   140 </xsl:template>
   141 
   142 
   143 <xsl:template name="check.vym.version">
   144    <xsl:if test="$checkvym.version">
   145       <xsl:if test="not(/vymmap/@version=$vym.version)">
   146          <xsl:message>
   147             <xsl:text>&#10;</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>.&#10;  Your XML format has v</xsl:text>
   152             <xsl:value-of select="/vymmap/@version"/>
   153             <xsl:text>.&#10;  Check your HTML output!</xsl:text>
   154             <xsl:text>&#10;&#10;</xsl:text>
   155          </xsl:message>
   156       </xsl:if>
   157    </xsl:if>
   158 </xsl:template>
   159 
   160 
   161 <!-- ====================================================================== -->
   162 <xsl:template match="*">
   163    <xsl:message>
   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>&#10;</xsl:text>
   169    </xsl:message>
   170 </xsl:template>
   171 
   172 
   173 <xsl:template match="/">
   174    <xsl:call-template name="check.vym.version"/>
   175 
   176    <html xmlns="&xhtmlns;">
   177       <xsl:call-template name="generate.head"/>
   178       <body>
   179          <xsl:apply-templates/>
   180          <xsl:call-template name="generate.footer"/>
   181 
   182       </body>
   183    </html>
   184 </xsl:template>
   185 
   186 
   187 <xsl:template match="vymmap">
   188    <div class="vymmap">
   189       <xsl:apply-templates/>
   190    </div>
   191 </xsl:template>
   192 
   193 
   194 <xsl:template match="mapcenter">
   195    <div class="mapcenter">
   196       <xsl:apply-templates/>
   197    </div>
   198 </xsl:template>
   199 
   200 
   201 <xsl:template match="mapcenter/heading">
   202    <div class="vym-header">
   203 	   <xsl:apply-templates/>
   204    </div>
   205  
   206       <xsl:if test="$use.imagemap=1">
   207          <div class="vym-imagemap">
   208             <img src="{$imagemap}"
   209                alt="Imagemap"
   210                class="imagemap"
   211                usemap="#vym_imagemap"/>
   212          </div>
   213          <map name="vym_imagemap">
   214             <xsl:apply-templates select="../branch" mode="imagemap"/>
   215          </map>
   216       </xsl:if>
   217 </xsl:template>
   218 
   219 
   220 <xsl:template match="mapcenter/branch">
   221    <hr/>
   222    <ul class="branch">
   223       <xsl:apply-templates/>
   224    </ul>
   225 </xsl:template>
   226 
   227 
   228 <xsl:template match="branch">
   229    <ul class="branch">
   230       <xsl:apply-templates/>
   231    </ul>
   232 </xsl:template>
   233 
   234 
   235 <xsl:template match="heading">
   236    <li class="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" />
   240 		 </xsl:attribute>
   241       </xsl:if>
   242       <xsl:choose>
   243          <xsl:when test="../@url">
   244             <xsl:variable name="url" select="../@url"/>
   245 
   246             <!-- Check, how links should be generated -->
   247             <xsl:choose>
   248                <xsl:when test="$link.style = 'name'">
   249                    <a href="{$url}">
   250 						<img src="{concat($image.flags.path,'url.png')}" border="0" valign="middle" alt="URL"/>
   251 						<xsl:apply-templates/>
   252 					</a>
   253                </xsl:when>
   254                <xsl:when test="$link.style = 'url'">
   255 					<a href="{$url}">
   256 						<img src="{concat($image.flags.path,'url.png')}" border="0" valign="middle" alt="URL"/>
   257 						<xsl:value-of select="$url"/>
   258 					</a>
   259                </xsl:when>
   260                <xsl:when test="$link.style = 'both'">
   261                   <a href="{$url}">
   262 						<img src="{concat($image.flags.path,'url.png')}" border="0" valign="middle" alt="URL"/>
   263 						<xsl:apply-templates/> ( <xsl:value-of select="$url"/>)
   264 					</a>
   265                </xsl:when>
   266                <xsl:otherwise>
   267                   <xsl:message>
   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>&#10; was "</xsl:text>
   271                      <xsl:value-of select="$link.style"/>
   272                      <xsl:text>"</xsl:text>
   273                   </xsl:message>
   274                   <a href="{$url}"><xsl:apply-templates/></a>
   275                </xsl:otherwise>
   276             </xsl:choose>
   277 
   278          </xsl:when>
   279          <xsl:otherwise>
   280             <xsl:apply-templates/>
   281          </xsl:otherwise>
   282       </xsl:choose>
   283 
   284       <xsl:for-each select="following-sibling::standardflag">
   285          <xsl:apply-templates select="current()" mode="standardflag"/>
   286       </xsl:for-each>
   287       </span>
   288    </li>
   289 </xsl:template>
   290 
   291 
   292 <xsl:template match="floatimage">
   293    <xsl:variable name="filename">
   294       <xsl:choose>
   295          <xsl:when test="contains(@href,':')">
   296             <xsl:value-of select="substring-after(@href,':')"/>
   297          </xsl:when>
   298          <xsl:otherwise>
   299             <xsl:value-of select="@href"/>
   300          </xsl:otherwise>
   301       </xsl:choose>
   302    </xsl:variable>
   303    
   304   <xsl:if test="@floatExport='true'">
   305       <span><img src="{$filename}" alt="{$filename}"/></span>
   306   </xsl:if>
   307 </xsl:template>
   308 
   309 
   310 <xsl:template match="standardflag"/><!-- Do nothing in normal mode -->
   311 
   312 <xsl:template match="standardflag" mode="standardflag">
   313    <span class="standardflag">
   314       <xsl:element name="img">
   315          <xsl:variable name="_srcimg">
   316          <xsl:choose>
   317             <xsl:when test="$image.flags.path">
   318                <xsl:value-of select="concat($image.flags.path,
   319                   .,
   320                   $image.extension)"/>
   321             </xsl:when>
   322             <xsl:otherwise>
   323                <xsl:value-of select="concat(., $image.extension)"/>
   324             </xsl:otherwise>
   325          </xsl:choose>
   326          </xsl:variable>
   327          <xsl:attribute name="src">
   328             <xsl:value-of select="$_srcimg"/>
   329          </xsl:attribute>
   330          <xsl:attribute name="alt">
   331             <xsl:value-of select="$_srcimg"/>
   332          </xsl:attribute>
   333       </xsl:element>
   334    </span>
   335 </xsl:template>
   336 
   337 <!-- Do nothing! -->
   338 <xsl:template match="select"/>
   339 <xsl:template match="setting"/>
   340 
   341 
   342 <xsl:template match="htmlnote">
   343    <div class="vym-htmlnote" >
   344       <xsl:apply-templates select=".//body/*"/><!-- Select only body elements -->
   345    </div>
   346 </xsl:template>
   347 
   348 <!-- Do nothing! We don't need some informational elements -->
   349 <xsl:template match="htmlnote/html/*"/>
   350 
   351 <xsl:template match="htmlnote/html/body">
   352    <xsl:copy-of select="."/>
   353 </xsl:template>
   354 
   355 <xsl:template match="htmlnote/html/body/*">
   356    <xsl:copy-of select="."/>
   357 </xsl:template>
   358 
   359 
   360 <!-- ====================================================================== -->
   361 <xsl:template match="branch" mode="imagemap"> 
   362    <xsl:param name="node"/> 
   363    <xsl:variable name="title"> 
   364       <xsl:apply-templates mode="imagemap"/> 
   365    </xsl:variable> 
   366  
   367    <xsl:if test="$debug=1"> 
   368       <xsl:message> 
   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)"/> 
   372       </xsl:message> 
   373    </xsl:if> 
   374  
   375    <area shape="rect"> 
   376       <xsl:attribute name="href"> 
   377          <xsl:choose><!-- Fix begin (!) --> 
   378             <xsl:when test="$imagemap != ''"> 
   379                <xsl:value-of select="concat('#', generate-id(.))"/> 
   380             </xsl:when> 
   381             <xsl:when test="$imagemap and @url"> 
   382                <xsl:value-of select="@url"/> 
   383             </xsl:when> 
   384             <xsl:when test="$imagemap and @vymLink"> 
   385                <xsl:value-of select="concat( substring-before(@vymLink, 
   386 '.vym'), '.html')"/> 
   387             </xsl:when> 
   388          </xsl:choose><!-- Fix end --> 
   389       </xsl:attribute> 
   390       <xsl:attribute name="alt"> 
   391          <xsl:value-of select="normalize-space($title)"/> 
   392       </xsl:attribute> 
   393       <xsl:attribute name="title"> 
   394          <xsl:value-of select="normalize-space($title)"/> 
   395       </xsl:attribute> 
   396       <xsl:attribute name="coords"> 
   397          <xsl:choose> 
   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"/> 
   406             </xsl:when> 
   407             <xsl:otherwise> 
   408                <!-- 
   409                <xsl:message> 
   410                   <xsl:text>ERROR: Some coordinates in branch are 
   411 missing!&#10;</xsl:text> 
   412                   <xsl:text>       See branch with </xsl:text> 
   413                   <xsl:value-of select="normalize-space($title)"/> 
   414                </xsl:message> 
   415                //--> 
   416             </xsl:otherwise> 
   417          </xsl:choose> 
   418       </xsl:attribute> 
   419    </area> 
   420    <xsl:apply-templates select="./branch" mode="imagemap"/> 
   421 </xsl:template> 
   422 
   423 
   424 
   425 <xsl:template match="heading" mode="imagemap">
   426    <xsl:apply-templates mode="imagemap"/>
   427 </xsl:template>
   428 
   429 
   430 </xsl:stylesheet>