<?xml version="1.0" encoding="utf-8"?>
<!-- pmap2fm.xslt version 1.1 Copyright 2005 JKRB Software -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="urn:my-scripts" xmlns:it="urn:icontranslation" exclude-result-prefixes="user msxsl it">
  <xsl:output method="xml" indent="no" encoding="utf-8" omit-xml-declaration="yes" />
  <xsl:strip-space elements="XHTML html"/>

  <msxsl:script language="JScript" implements-prefix="user">
    function convdate(d)
    {
    var a = d.split(" ");
    var b = a[0];
    var s = b.replace(/^(\d+)-(\d+)-(\d+)/, "$2/$3/$1");
    b = a[1];
    var t = b.replace(/^(\d+):(\d+):(\d+)/, "$1:$2:$3");
    s += " " + t;
    var n = new Date(s);
    return n.valueOf();
    }
  </msxsl:script>
  <it:icons>
    <it:icon NameFM="help" NamePMM="7"/>
    <it:icon NameFM="messagebox_warning" NamePMM="23"/>
    <it:icon NameFM="idea" NamePMM="68"/>
    <it:icon NameFM="button_ok" NamePMM="12"/>
    <it:icon NameFM="button_cancel" NamePMM="79"/>
    <it:icon NameFM="full-1" NamePMM=""/>
    <it:icon NameFM="full-2" NamePMM=""/>
    <it:icon NameFM="full-3" NamePMM=""/>
    <it:icon NameFM="full-4" NamePMM=""/>
    <it:icon NameFM="full-5" NamePMM=""/>
    <it:icon NameFM="full-6" NamePMM=""/>
    <it:icon NameFM="full-7" NamePMM=""/>
    <it:icon NameFM="back" NamePMM="3"/>
    <it:icon NameFM="forward" NamePMM="2"/>
    <it:icon NameFM="attach" NamePMM="74"/>
    <it:icon NameFM="ksmiletris" NamePMM="8"/>
    <it:icon NameFM="clanbomber" NamePMM=""/>
    <it:icon NameFM="desktop_new" NamePMM="82"/>
    <it:icon NameFM="flag" NamePMM="35"/>
    <it:icon NameFM="gohome" NamePMM="70"/>
    <it:icon NameFM="kaddressbook" NamePMM="72"/>
    <it:icon NameFM="knotify" NamePMM="46"/>
    <it:icon NameFM="korn" NamePMM="26"/>
    <it:icon NameFM="Mail" NamePMM="29"/>
    <it:icon NameFM="password" NamePMM="81"/>
    <it:icon NameFM="pencil" NamePMM="75"/>
    <it:icon NameFM="stop" NamePMM="22"/>
    <it:icon NameFM="wizard" NamePMM=""/>
    <it:icon NameFM="xmag" NamePMM="17"/>
    <it:icon NameFM="bell" NamePMM="80"/>
    <it:icon NameFM="bookmark" NamePMM=""/>
    <it:icon NameFM="penguin" NamePMM=""/>
    <it:icon NameFM="licq" NamePMM=""/>
  </it:icons>
  <xsl:key name="kDistinctCustProps" match="CustomProperty" use="@Name"/>
  <xsl:key name="kNodeList" match="Node" use="@id"/>
  <xsl:template match="/">
    <map version="0.8.FA Alpha 5a">
      <xsl:apply-templates select="PocketMindMap[@Version='1.4']"/>
    </map>
  </xsl:template>

  <xsl:template match="Style">
    <!-- do nothing -->
  </xsl:template>
  <xsl:template match="References">
    <!-- do nothing -->
  </xsl:template>

  <xsl:template match="Node">
    <xsl:choose>
      <xsl:when test="ancestor::FloatingNodes">
      </xsl:when>
      <xsl:otherwise>
	<xsl:choose>
	  <xsl:when test="Map">
	    <xsl:apply-templates select="Map"/>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:element name="node">
	      <xsl:attribute name="CREATED">
		<xsl:call-template name="fmt_date">
		  <xsl:with-param name="date" select="@Created"/>
		</xsl:call-template>
	      </xsl:attribute>
	      <xsl:attribute name="ID">
		<xsl:value-of select="@id" />
	      </xsl:attribute>
	      <xsl:attribute name="MODIFIED">
		<xsl:call-template name="fmt_date">
		  <xsl:with-param name="date" select="@Modified"/>
		</xsl:call-template>
	      </xsl:attribute>
	      <xsl:attribute name="TEXT">
		<xsl:variable name="disp" select="translate(@Display, '|', '&#xa;')"/>
		<xsl:value-of select="$disp"/>
	      </xsl:attribute>
	      <xsl:if test="Font/@Color">
		<xsl:attribute name="COLOR">
		  <xsl:call-template name="convcolor">
		    <xsl:with-param name="color" select="Font/@Color"/>
		  </xsl:call-template>
		</xsl:attribute>
	      </xsl:if>
	      <xsl:if test="@XPos != -1">
		<xsl:attribute name="POSITION">
		  <xsl:if test="@XPos >= 0">
		    <xsl:value-of select="'right'"/>
		  </xsl:if>
		  <xsl:if test="@XPos &lt; 0">
		    <xsl:value-of select="'left'"/>
		  </xsl:if>
		</xsl:attribute>
	      </xsl:if>
	      <xsl:if test="name(../..) = 'Map'">
		<xsl:if test="name(../../..) != 'Maps'">
		  <xsl:attribute name="FOLDED">true</xsl:attribute>
		</xsl:if>
	      </xsl:if>
	      <xsl:if test="@HideSubNodes = 'true'">
		<xsl:attribute name="FOLDED">true</xsl:attribute>
	      </xsl:if>
	      <xsl:if test="@href">
		<xsl:attribute name="LINK">
		  <xsl:choose>
		    <xsl:when test="starts-with(@href, '#')">
		      <xsl:variable name="destid" select="translate(@href,'#/', '')"/>
		      <xsl:variable name="destnode" select="//Node[generate-id() = generate-id(key('kNodeList',$destid))]"/>
		      <xsl:choose>
			<xsl:when test="$destnode/Map">
			  <xsl:value-of select="concat('#', $destnode/Map/Nodes/Node/@id)"/>
			</xsl:when>
			<xsl:otherwise>
			  <xsl:value-of select="concat('#', $destid)"/>
			</xsl:otherwise>
		      </xsl:choose>
		    </xsl:when>
		    <xsl:otherwise>
		      <xsl:value-of select="translate(@href,'\', '/')"/>
		    </xsl:otherwise>
		  </xsl:choose>
		</xsl:attribute>
	      </xsl:if>
	      <xsl:if test="name(../..) = 'Map'">
		<xsl:if test="name(../../..) != 'Maps'">
		  <xsl:element name="cloud">
		    <xsl:if test="../../Background[@Color]">
		      <xsl:attribute name="COLOR">
			<xsl:call-template name="convcolor">
			  <xsl:with-param name="color" select="../../Background/@Color"/>
			</xsl:call-template>
		      </xsl:attribute>
		    </xsl:if>
		  </xsl:element>
		</xsl:if>
	      </xsl:if>
	      <xsl:apply-templates select="Border"/>
	      <xsl:if test="name(../../..) = 'Maps'">
		<hook NAME="accessories/plugins/CreationModificationPlugin_new.properties"/>
	      </xsl:if>
	      <xsl:variable name="href" select="concat('#/',@id)" />
	      <xsl:variable name="ref" select="/PocketMindMap/References/Reference[@Source=$href]" />
	      <xsl:if test="$ref">
		<xsl:apply-templates select="$ref"/>
	      </xsl:if>
	      <xsl:apply-templates select="Symbols|TaskInfo"/>
	      <xsl:apply-templates select="Font|Text|XHTML|Nodes"/>
	    </xsl:element>
	  </xsl:otherwise>
	</xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="CustomProperties">
    <!-- just ignore -->
  </xsl:template>

  <xsl:template match="CustomProperty">
    <!-- just ignore -->
  </xsl:template>

  <xsl:template match="Border">
    <xsl:if test="@FillColor">
      <xsl:attribute name="BACKGROUND_COLOR">
        <xsl:call-template name="convcolor">
          <xsl:with-param name="color" select="@FillColor"/>
        </xsl:call-template>
      </xsl:attribute>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Reference">
    <xsl:variable name="reftype" select="/PocketMindMap/ReferenceTypes/ReferenceType[@Name=current()/@Type]"/>
    <xsl:element name="arrowlink">
      <xsl:attribute name="ID">
        <xsl:value-of select="@id"/>
      </xsl:attribute>
      <xsl:attribute name="COLOR">
        <xsl:call-template name="convcolor">
          <xsl:with-param name="color" select="$reftype/@Color"/>
        </xsl:call-template>
      </xsl:attribute>
      <xsl:attribute name="DESTINATION">
        <xsl:value-of select="substring-after(@Target, '#/')"/>
      </xsl:attribute>
      <xsl:attribute name="STARTARROW">
        <xsl:choose>
          <xsl:when test="@BiDir='true'">Default</xsl:when>
          <xsl:otherwise>None</xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xsl:attribute name="ENDARROW">Default</xsl:attribute>
      <xsl:attribute name="STARTINCLINATION"><xsl:value-of select="@RefRelativeX1"/>;<xsl:value-of select="@RefRelativeY1"/>;</xsl:attribute>
      <xsl:attribute name="ENDINCLINATION"><xsl:value-of select="@RefRelativeX2"/>;<xsl:value-of select="@RefRelativeY2"/>;</xsl:attribute>
    </xsl:element>
  </xsl:template>

  <xsl:template match="TaskInfo">
    <xsl:if test="@Priority &gt; 0">
      <xsl:element name="icon">
        <xsl:attribute name="BUILTIN">
          <xsl:value-of select="concat('full-', @Priority)"/>
        </xsl:attribute>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Symbols">
    <xsl:for-each select="Symbol">
      <xsl:variable name="sym" select="document('')//it:icons/it:icon[@NamePMM=current()/@Index]/@NameFM"/>
      <xsl:if test="$sym">
        <xsl:element name="icon">
          <xsl:attribute name="BUILTIN">
            <xsl:value-of select="$sym"/>
          </xsl:attribute>
        </xsl:element>
      </xsl:if>
    </xsl:for-each>
  </xsl:template>

  <xsl:template match="Font">
    <xsl:if test="@Family|@Size">
      <xsl:element name="font">
	<xsl:if test="@Family">
	  <xsl:attribute name="NAME">
	    <xsl:value-of select="@Family"/>
	  </xsl:attribute>
	</xsl:if>
	<xsl:if test="@Size">
	  <xsl:attribute name="SIZE">
	    <xsl:value-of select="@Size"/>
	  </xsl:attribute>
	</xsl:if>
      </xsl:element>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Nodes">
    <xsl:apply-templates select="Node"/>
  </xsl:template>

  <xsl:template match="Text">
    <hook NAME="accessories/plugins/NodeNote.properties">
      <text>
        <xsl:value-of select="."/>
      </text>
    </hook>
  </xsl:template>

  <xsl:template match="XHTML">
    <hook NAME="accessories/plugins/NodeNote.properties">
      <text>
        <xsl:value-of select="translate(., '&#9;', '')"/>
      </text>
    </hook>
  </xsl:template>

  <xsl:template name="fmt_date">
    <xsl:param name="date" />
    <xsl:variable name="dt" select="translate($date, 'T', ' ')"/>
    <xsl:value-of select="user:convdate($dt)" />
  </xsl:template>

  <xsl:template name="convcolor">
    <xsl:param name="color"/>
    <xsl:value-of select="concat('#', substring($color, 3))"/>
  </xsl:template>

</xsl:stylesheet>

