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