styles/mmap2vym.xsl
author insilmaril
Tue Feb 21 16:18:23 2006 +0000 (2006-02-21)
changeset 217 375be2baa976
child 218 160459d924a1
permissions -rw-r--r--
rudimentary mmap import
     1 <?xml version="1.0" encoding="iso-8859-1"?>
     2 
     3 <!--
     4 	Document   : mmap2vym.xsl
     5 	Created on : 20051120
     6 	Modified   : 20051128
     7 	Version    : 0.1.2
     8 	Author     : Clemens Kraus (http://www.clemens-kraus.de)
     9 	
    10 	Description: transforms exported MindManager-files (version x5/6) into vym-format.
    11 	Bugs       : First Version, work still in progress!
    12 	Todo       : - xlinks still to be implemented
    13 	             - codes/symbols still to be implemented
    14 							 - Multimap links (.mmap) still to be implemented
    15 -->
    16 
    17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    18 	xmlns:xlink="http://www.w3.org/1999/xlink"
    19   xmlns:ap="http://schemas.mindjet.com/MindManager/Application/2003"
    20 	xmlns:exsl="http://exslt.org/common" extension-element-prefixes="exsl math func"
    21 	xmlns:math="http://exslt.org/math"
    22 	xmlns:func="http://exslt.org/functions"
    23 	version="1.0">
    24 
    25 <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    26   <xsl:param name="filenamep" />
    27   <xsl:variable name="filename" select="$filenamep"/>
    28   <!--<xsl:variable name="maxxCoord"><xsl:value-of select="math:max(map//xCoord)" /></xsl:variable>-->
    29   <xsl:variable name="maxxCoord"><xsl:value-of select="600" /></xsl:variable>
    30   <xsl:variable name="maxyCoord"><xsl:value-of select="800" /></xsl:variable>
    31   <xsl:variable name="minxCoord"><xsl:value-of select="0" /></xsl:variable>
    32   <xsl:variable name="minyCoord"><xsl:value-of select="0" /></xsl:variable>
    33 
    34 
    35   <!-- root element -->	
    36 	<xsl:template match="/">
    37 	
    38    	<xsl:element name="vymmap">
    39 			<!-- default settings: -->
    40 			<xsl:attribute name="comment">Generated with mmap2vym (V0.1.2) - MindManager to vym converter. More infos: www.clemens-kraus.de</xsl:attribute>
    41 			<xsl:attribute name="backgroundColor">#ffffff</xsl:attribute>
    42 			<xsl:attribute name="linkStyle">StyleLine</xsl:attribute>
    43 			<xsl:attribute name="linkColor">#00007f</xsl:attribute>
    44 			<xsl:attribute name="linkColorHint">HeadingColor</xsl:attribute>
    45 			<xsl:attribute name="defXLinkColor">#e6e6e6</xsl:attribute>
    46 			<xsl:attribute name="defXLinkWidth">1</xsl:attribute>
    47 
    48 			<xsl:variable name="author" select="concat(/ap:Map/ap:DocumentGroup/ap:Author/@UserName, ' ', /ap:Map/ap:DocumentGroup/ap:Author/@UserEmail)" />
    49 			<xsl:if test="$author">
    50 				<xsl:attribute name="author"><xsl:value-of select="$author"/></xsl:attribute>
    51 			</xsl:if>
    52 			
    53 			<xsl:element name="mapcenter">
    54 				<!--xsl:attribute name="absPosX"><xsl:value-of select="300"/></xsl:attribute-->
    55 				<!--xsl:attribute name="absPosY"><xsl:value-of select="400"/></xsl:attribute-->
    56 				<!--xsl:attribute name="absPosX"><xsl:value-of select="- floor($minxCoord * 0.6) - 30"/></xsl:attribute-->
    57 				<!--xsl:attribute name="absPosY"><xsl:value-of select="floor($maxyCoord * 0.6)"/></xsl:attribute-->
    58 				<!-- xsl:message>absPos: <xsl:value-of select="-
    59 				floor($minxCoord * 0.6) - 30"/></xsl:message -->
    60 
    61 					<!-- recurse to map title node ... -->
    62 					<xsl:apply-templates select="ap:Map/ap:OneTopic/ap:Topic/ap:Text"/>
    63 				
    64 				<xsl:apply-templates select="ap:Map/ap:OneTopic/ap:Topic/ap:SubTopics" />
    65 				
    66 			</xsl:element>
    67 	
    68 		</xsl:element>
    69 	</xsl:template>
    70 
    71   <xsl:template match="ap:Topic/ap:Text">
    72 		<xsl:element name="heading">
    73 			<xsl:value-of select="@PlainText" />
    74 		</xsl:element>
    75 	</xsl:template>
    76 
    77 	
    78   <xsl:template match="ap:Topic">
    79 	
    80 		<xsl:element name="branch">
    81 	  	<xsl:call-template name="position" />
    82 
    83 			<!-- =============================== hyperlink ================================ -->
    84 			<xsl:variable name="url" select="ap:Hyperlink" />
    85 			<xsl:if test="$url">
    86 				<xsl:attribute name="url"><xsl:value-of select="ap:Hyperlink/@Url"/></xsl:attribute>
    87 			</xsl:if>
    88 			
    89 			<xsl:variable name="rect" select="ap:SubTopicShape/@SubTopicShape" />
    90 			<xsl:if test="contains($rect, 'Rectangle')">
    91 				<xsl:attribute name="frameType">Rectangle</xsl:attribute>
    92 				<!--<xsl:message><xsl:text>Rectangle</xsl:text><xsl:value-of select="$rect"/></xsl:message>-->
    93 			</xsl:if>
    94 			
    95 			<!-- =============================== closed ================================ -->
    96 			<!-- is branch closed? -->
    97 			<xsl:variable name="collapsed" select="ap:TopicViewGroup/Collapsed/@Collapsed" />
    98 			<xsl:if test="$collapsed = 'true'">
    99 				<xsl:attribute name="scrolled">
   100 					<xsl:value-of select="yes"/>
   101 				</xsl:attribute>
   102 			</xsl:if>
   103 
   104 			<xsl:element name="heading">
   105 				 <xsl:if test="ap:Text/ap:Font/@Color">
   106 					 <xsl:attribute name="textColor">
   107 						 <xsl:value-of select="concat('#', substring(ap:Text/ap:Font/@Color, 3, 6))" />
   108 					 </xsl:attribute>
   109 				 </xsl:if>
   110 				 <xsl:value-of select="ap:Text/@PlainText" />
   111 				 
   112 				 <!-- <xsl:variable name="OId" select="@OId" />
   113 				 <xsl:variable name="relation" select="/ap:Map/ap:Relationships/ap:Relationship[ap:ConnectionGroup[@Index=0]/ap:Connection/ap:ObjectReference/@OIdRef=$OId]" />
   114 				 <xsl:if test="$relation">
   115 					 <xsl:variable name="toId" select="$relation/ap:ConnectionGroup[@Index=1]/ap:Connection/ap:ObjectReference/@OIdRef" />
   116 					 <xsl:element name="arrowlink">
   117 						 <xsl:attribute name="ENDARROW">Default</xsl:attribute>
   118 						 <xsl:attribute name="DESTINATION">
   119 							 <xsl:value-of select="$relation/ap:ConnectionGroup[@Index=1]/ap:Connection/ap:ObjectReference/@OIdRef" />
   120 						 </xsl:attribute>
   121 						 <xsl:attribute name="STARTARROW">None</xsl:attribute>
   122 					 </xsl:element>
   123 				 </xsl:if>
   124 				 <xsl:variable name="toId" select="/ap:Map/ap:Relationships/ap:Relationship/ap:ConnectionGroup[@Index=1]/ap:Connection/ap:ObjectReference[@OIdRef=$OId]/@OIdRef" />
   125 				 <xsl:if test="$toId">
   126 					 <xsl:attribute name="ID">
   127 						 <xsl:value-of select="$toId" />
   128 					 </xsl:attribute>
   129 				 </xsl:if> -->
   130 				 
   131 			 </xsl:element>
   132 			 
   133 			<!-- =============================== createnote ================================ -->
   134  			<xsl:variable name="note" select="ap:NotesGroup" />
   135 			<xsl:if test="$note">
   136 				<xsl:element name="htmlnote">
   137 					<xsl:attribute name="fonthint">var</xsl:attribute>
   138 						<xsl:copy-of select="ap:NotesGroup/ap:NotesXhtmlData/*"/>
   139 				</xsl:element>
   140 			</xsl:if>
   141 			 
   142 			 <xsl:apply-templates select="ap:SubTopics"/>
   143 			</xsl:element>
   144 			
   145    </xsl:template>
   146 
   147 
   148   <!-- =============================== position ================================ -->
   149   <!-- for position -->
   150   <xsl:template name="position">
   151 	
   152     <xsl:attribute name="absPosX">
   153 		<!-- if CX != "" -->
   154       <xsl:value-of select="floor( (ap:Offset/@CX - $minxCoord) * 0.8  + 10 )"/>
   155 			<!--xsl:message>absPosX: <xsl:value-of select="floor( (ap:Offset/@CX - $minxCoord) * 0.8  + 10 )"/></xsl:message-->
   156     </xsl:attribute>
   157     <xsl:attribute name="absPosY">
   158       	<xsl:value-of select="floor( (- ap:Offset/@CY + $maxyCoord) * 0.6 + 10 )"/>
   159 				<!-- xsl:message>absPosY: <xsl:value-of select="floor( (- ap:Offset/@CY + $maxyCoord) * 0.6 + 10)"/></xsl:message-->
   160     </xsl:attribute>
   161 		
   162   </xsl:template>
   163 
   164 
   165   <!-- ========================== symbol (floatimage) =========================== -->
   166   <!-- any floatimage? -->
   167   <xsl:template match="symbol">
   168   
   169 	<xsl:if test="string-length(./url) &gt; 0">
   170 	  <xsl:variable name="imagename" >
   171 		<xsl:call-template name="getfn" >
   172 			<xsl:with-param name="txt" select="substring-before( translate( normalize-space( current() ), '\', '/' ), '.' )" />
   173 		</xsl:call-template>
   174 	  </xsl:variable>
   175 
   176 	  <xsl:element name="floatimage">
   177 		<xsl:attribute name="relPosX">
   178 			<xsl:value-of select="'20'"/>
   179 		</xsl:attribute>
   180 		<xsl:attribute name="relPosY">
   181 			<xsl:value-of select="'-50'"/>
   182 		</xsl:attribute>
   183 		<xsl:attribute name="useOrientation">
   184 			<xsl:text>true</xsl:text>
   185 		</xsl:attribute>
   186 		<xsl:attribute name="saveInMap">
   187 			<xsl:text>true</xsl:text>
   188 		</xsl:attribute>
   189 		
   190 		<xsl:attribute name="href">
   191 		  <xsl:value-of select="concat('file:', $filename, '-image-', $imagename, '.png')"/>
   192 		</xsl:attribute>
   193 	  </xsl:element>
   194 	</xsl:if>
   195 	
   196   </xsl:template>
   197   
   198   
   199   <!-- =============================== hyperlink ================================ -->
   200   <xsl:template match="xhyperLink">
   201 
   202   <xsl:choose>
   203 	<xsl:when test="substring(., 1, 4)='http'">
   204 	  <xsl:attribute name="url">
   205 		<xsl:value-of select="."/>
   206 	  </xsl:attribute>
   207 	</xsl:when>
   208 	
   209 	<xsl:when test="contains(., '.mmp')">
   210 	  <xsl:attribute name="vymLink">
   211 	  	<!-- Aus .mmp .vym machen und '\' durch '/' ersetzen -->
   212 		<xsl:value-of select="translate( concat(substring-before(current(),'.mmp'), '.vym'), '\', '/')"/>
   213 	  </xsl:attribute>
   214 	</xsl:when>
   215 	
   216 	<xsl:otherwise>
   217 	 <!-- <xsl:message terminate="yes">Test: <xsl:value-of select="."/></xsl:message> -->
   218 	  <xsl:attribute name="url">
   219 		<xsl:value-of select="concat( 'file:/', translate(current(), '\', '/') )"/>
   220 	  </xsl:attribute>
   221 	</xsl:otherwise>
   222   </xsl:choose>
   223   
   224   
   225 <!--   	<xsl:if test="substring(., 1, 4)='http'">
   226 	  <xsl:attribute name="url">
   227 		<xsl:value-of select="."/>
   228 	  </xsl:attribute>
   229 	 </xsl:if>
   230 	 
   231   	<xsl:if test="contains(., '.mmp')">
   232 	  <xsl:attribute name="vymLink">
   233 		<xsl:value-of select="translate( concat(substring-before(current(),'.mmp'), '.vym'), '\', '/')"/>
   234 	  </xsl:attribute>
   235 	</xsl:if> -->
   236 	
   237   </xsl:template>
   238 
   239 	
   240   <!-- ================================= getfn ================================== -->
   241   <!-- get the filename (without the path) -->
   242   
   243   <xsl:template name="getfn">
   244 	  <xsl:param name="txt" select="." />
   245 	  
   246 	  <xsl:choose>
   247 		  <xsl:when test="contains($txt, '/')" >
   248 		  	<xsl:variable name="right" select="substring-after($txt, '/')" />
   249 			<xsl:if test="string-length($right)>1" >
   250 			  <xsl:call-template name="getfn" >
   251 				  <xsl:with-param name="txt" select="$right" />
   252 			  </xsl:call-template>
   253 			</xsl:if>
   254 		  </xsl:when>
   255 		  <xsl:otherwise>
   256 			  <xsl:value-of select="$txt" />
   257 		  </xsl:otherwise>
   258 	  </xsl:choose>
   259 	  
   260   </xsl:template>
   261   
   262 
   263   <!-- =============================== codes ================================ -->
   264   <xsl:template match="codes">
   265 
   266   	<!-- file:/home/clemens/CLEMENS/MM/Tools/Open Interface Reference Guide/doc/enum-mmcode.html -->
   267 	<xsl:element name="standardFlag">
   268 	  <xsl:choose>
   269 		<xsl:when test="code = '1'">lamp</xsl:when>
   270 		<xsl:when test="code = '2'">arrow-up</xsl:when>
   271 		<xsl:when test="code = '3'">arrow-down</xsl:when>
   272 		<!-- <xsl:when test="code = ">scrolled-right</xsl:when> -->
   273 		<xsl:when test="code = '5'">hook-green</xsl:when>
   274 		<xsl:when test="code = '6'">questionmark</xsl:when>
   275 		<xsl:when test="code = '7'">smiley-good</xsl:when>
   276 		<xsl:when test="code = '8'">smiley-sad</xsl:when>
   277 		<xsl:when test="code = '11'">stopsign</xsl:when>
   278 		<xsl:when test="code = '13'">clock</xsl:when>
   279 		<xsl:when test="code = '15'">clock</xsl:when>
   280 		<xsl:when test="code = '17'">cross-red</xsl:when>
   281 		<xsl:when test="code = '41'">cross-red</xsl:when>
   282 		<xsl:when test="code = '20'">exclamationmark</xsl:when>
   283 		<xsl:when test="code = '29'">thumb-up</xsl:when>
   284 		<!-- <xsl:when test="code = '9'">note</xsl:when>
   285 		<xsl:when test="code = '32'">note</xsl:when> -->
   286 		<xsl:otherwise>heart</xsl:otherwise>
   287 	  </xsl:choose>
   288 	  <!-- Fuer spaetere Erweiterung um eigene Codes: z.B. MindManager-Codes "code-9.png"
   289 	  <xsl:value-of select="concat( 'code-', current() )"/> -->
   290 	</xsl:element>
   291 
   292   </xsl:template>
   293 
   294   
   295   <!-- =============================== color ================================ -->
   296   <xsl:template match="color">
   297     <xsl:attribute name="textColor">
   298       <!-- switch from BBGGRR to #RRGGBB representation -->
   299       <xsl:text>#</xsl:text>
   300       <xsl:value-of select="substring( ., 5, 2 )"/>
   301       <xsl:value-of select="substring( ., 3, 2 )"/>
   302       <xsl:value-of select="substring( ., 1, 2 )"/>
   303     </xsl:attribute>
   304   </xsl:template>
   305 
   306 
   307   <!-- =============================== for future use ================================ -->
   308   <xsl:template match="Name">
   309     <xsl:attribute name="NAME">
   310       <xsl:value-of select="."/>
   311     </xsl:attribute>
   312   </xsl:template>
   313 
   314   <xsl:template match="Size">
   315       <xsl:attribute name="SIZE">
   316         <xsl:value-of select="."/>
   317       </xsl:attribute>
   318   </xsl:template>
   319 
   320   <xsl:template match="Bold">
   321       <xsl:attribute name="BOLD">
   322         <xsl:value-of select="."/>
   323       </xsl:attribute>
   324   </xsl:template>
   325 
   326   <xsl:template match="Italic">
   327       <xsl:attribute name="ITALIC">
   328         <xsl:value-of select="."/>
   329       </xsl:attribute>
   330   </xsl:template>
   331 
   332   <xsl:template match="Underline">
   333       <xsl:attribute name="UNDERLINE">
   334         <xsl:value-of select="."/>
   335       </xsl:attribute>
   336   </xsl:template>
   337 
   338   <xsl:template match="Strikethrough">
   339       <xsl:attribute name="Strikethrough">
   340         <xsl:value-of select="."/>
   341       </xsl:attribute>
   342   </xsl:template>
   343 
   344   <!-- template extracting a subset of font attributes -->
   345   <xsl:template match="ap:font">
   346     <xsl:apply-templates select="@Name"/>
   347     <xsl:apply-templates select="@Size"/>
   348     <xsl:apply-templates select="@Bold"/>
   349     <xsl:apply-templates select="@Italic"/>
   350     <xsl:apply-templates select="@Underline"/>
   351     <xsl:apply-templates select="@Strikethrough"/>
   352   </xsl:template>
   353   
   354 </xsl:stylesheet>
   355 
   356