<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ap="http://schemas.mindjet.com/MindManager/Application/2003"
>

<!-- From http://freemind.sourceforge.net/wiki/index.php/Import_and_export_to_other_applications#Direct_MindManager_X5_to_FreeMind_conversion -->
<!-- MindManager X5 files are zip files that contain XML -->

      <xsl:output
      method="xml"
      version="1.0"
      encoding="iso-8859-1"
      omit-xml-declaration="yes"
      indent="yes"
      />     
  <xsl:template match="/">
    <xsl:element name="map">
      <xsl:attribute name="version">0.7.1</xsl:attribute>
      <xsl:apply-templates select="ap:Map/ap:OneTopic/ap:Topic" />
    </xsl:element>
  </xsl:template>
  <xsl:template match="ap:Topic">
    <xsl:element name="node">
      <xsl:attribute name="TEXT">
        <xsl:value-of select="ap:Text/@PlainText" />
      </xsl:attribute>        <xsl:if test="ap:Text/ap:Font/@Color">
        <xsl:attribute name="COLOR">
          <xsl:value-of select="concat(#, substring(ap:Text/ap:Font/@Color, 3, 6))" />
        </xsl:attribute>
      </xsl:if>
      <xsl:variable name="OId" select="@OId" />
      <xsl:variable name="relation" select="/ap:Map/ap:Relationships/ap:Relationship[ap:ConnectionGroup[@Index=0]/ap:Connection/ap:ObjectReference/@OIdRef=$OId]" />
      <xsl:if test="$relation">
        <xsl:variable name="toId" select="$relation/ap:ConnectionGroup[@Index=1]/ap:Connection/ap:ObjectReference/@OIdRef" />
        <xsl:element name="arrowlink">
          <xsl:attribute name="ENDARROW">Default</xsl:attribute>
          <xsl:attribute name="DESTINATION">
            <xsl:value-of select="$relation/ap:ConnectionGroup[@Index=1]/ap:Connection/ap:ObjectReference/@OIdRef" />
          </xsl:attribute>
          <xsl:attribute name="STARTARROW">None</xsl:attribute>
        </xsl:element>
      </xsl:if>
      <xsl:variable name="toId" select="/ap:Map/ap:Relationships/ap:Relationship/ap:ConnectionGroup[@Index=1]/ap:Connection/ap:ObjectReference[@OIdRef=$OId]/@OIdRef" />
      <xsl:if test="$toId">
        <xsl:attribute name="ID">
          <xsl:value-of select="$toId" />
        </xsl:attribute>
      </xsl:if>
      <xsl:apply-templates select="ap:SubTopics"/>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>