0

I have a very simple taxonomy I'm editing in freemind, and want to visualize it in protovis as a sunburst visualisation. The depth of the taxonomy is unknown.

I've produced an attempt to built a XLST transformation that can be used with Freemind's export via xsl script functionality - to output data in the exact JSON format needed by Protovis to produce a sunburst - the idea being no further transforms are needed in javascript.

An example of the output JSON format I'm looking for is here: http://mbostock.github.com/protovis/ex/sunburst.html

Effectively the freemind .mm file format is the input.

Running my alpha code (shown below) in stylus studio builds up a json format (badly formatted but seems legal) which feeds protovis ok when I save the output generated from stylus studio directly to a .js file manually. For some reason Freemind doesn't seem to export data using this code though...

Is there something I'm missing? Any help appreciated.

Many thanks, Andrew

===========UPDATE=============

I've corrected the code, the problem was that some of my xsl wasn't supported by the xslt engine used by freemind. I corrected the code and moved it to github under a liberal license and removed it from here.

The adaptor is available here: https://github.com/minkymorgan/Freemind2JSON#readme

  • Andrew
VividD
  • 10,456
  • 6
  • 64
  • 111
Minkymorgan
  • 479
  • 4
  • 9

2 Answers2

0

In case it's of interest ... I've just pushed an XSLT script for converting FreeMind to JSON. My script is a bit simpler and does not yet support Javascript escaping.

It's also not designed for use in Protovis

Tony O'Hagan
  • 21,638
  • 3
  • 67
  • 78
0

Here is my attempt. I based it of your version, and added a few more features.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="text"/>

    <xsl:template match="/map">
        <xsl:text>var Map = {
</xsl:text>
        <xsl:apply-templates select="node">
            <xsl:with-param name="indent">
                <xsl:text>    </xsl:text>
            </xsl:with-param>
        </xsl:apply-templates>
        <xsl:text>
};
</xsl:text>
    </xsl:template>

    <xsl:template match="node">
        <xsl:param name="indent"/>
        <xsl:if test="position() != 1">
            <xsl:text>,
</xsl:text>
        </xsl:if>
        <xsl:value-of select="$indent"/>
        <xsl:text>"</xsl:text>
        <xsl:call-template name="escape-javascript">
            <xsl:with-param name="string"
                select="descendant-or-self::node/@TEXT"/>
        </xsl:call-template>
        <xsl:text>": </xsl:text>
        <xsl:choose>
            <xsl:when test="node">
                <xsl:text>{
</xsl:text>
                <xsl:apply-templates select="node">
                    <xsl:with-param name="indent">
                        <xsl:value-of select="$indent"/>
                        <xsl:text>    </xsl:text>
                    </xsl:with-param>
                </xsl:apply-templates>
                <xsl:text>
</xsl:text>
                <xsl:value-of select="$indent"/>
                <xsl:text>}</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>10</xsl:text>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <!--
        Javascript string escape template by Jeni Tennison
        Source: http://holytshirt.blogspot.com/2008/06/xslt-javascript-escaping.html
        Author page: http://www.jenitennison.com/
    -->
    <xsl:template name="escape-javascript">
        <xsl:param name="string" />
        <xsl:choose>
            <xsl:when test='contains($string, "&apos;")'>
                <xsl:call-template name="escape-javascript">
                    <xsl:with-param name="string"
                        select='substring-before($string, "&apos;")' />
                </xsl:call-template>
                <xsl:text>\'</xsl:text>
                <xsl:call-template name="escape-javascript">
                    <xsl:with-param name="string"
                        select='substring-after($string, "&apos;")' />
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="contains($string, '&#xA;')">
                <xsl:call-template name="escape-javascript">
                    <xsl:with-param name="string"
                        select="substring-before($string, '&#xA;')" />
                </xsl:call-template>
                <xsl:text>\n</xsl:text>
                <xsl:call-template name="escape-javascript">
                    <xsl:with-param name="string"
                        select="substring-after($string, '&#xA;')" />
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="contains($string, '\')">
                <xsl:value-of select="substring-before($string, '\')" />
                <xsl:text>\\</xsl:text>
                <xsl:call-template name="escape-javascript">
                    <xsl:with-param name="string"
                        select="substring-after($string, '\')" />
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>

If run on the Freemind test file, it produces the following output:

var Map = {
    "Notetest": {
        "Notetest": 10,
        "This is a node": {
            "with a linbreak \n subnode": 10,
            "and another subnode": 10,
            "and some folded subnodes": {
                "fold1": 10,
                "fold2": 10,
                "fold3": 10
            }
        },
        "Attributes": 10
    }
};
Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
  • Hi MizardX, I did some tests. While your code looks so much better than mine, I've still not got it to render Protvis graphics, where my rudimentary effort is rendering with it. Not sure why yet, but will look into it further. Bear in mind I learned XLST yesterday, so take a little time for me to figure out your code works. – Minkymorgan Feb 04 '12 at 22:23
  • How did it go with this? Did you find the problem? – Markus Jarderot Feb 12 '12 at 11:43
  • I think so. The issue isn't your conversion as much as the protovis code I'm using. Adjustments could be made in either place. As long as protovis can read the json you can manipulate the data there. – Minkymorgan Feb 25 '12 at 09:53
  • (sorry clipped my comment here's the rest of my thought) ... in javascript. So your conversion is a great one for anyone building new protovis, d3.js templates, as the output will be cleaner than my effort. My rudimentary effort is working too with the bog standard sunburst layout, and I was getting what I needed, so I've not had the need to really go further with it. But thanks for you help and input as I learned a lot reading your xlst. – Minkymorgan Feb 25 '12 at 10:00