首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Freemind到JSON到Protovis xlst变换草案

从Freemind到JSON到Protovis xlst变换草案
EN

Stack Overflow用户
提问于 2012-02-03 14:20:09
回答 2查看 799关注 0票数 0

我在freemind中编辑了一个非常简单的分类学,我想把它可视化为太阳暴晒可视化。分类的深度尚不清楚。

我已经尝试构建了一个XLST转换,它可以通过xsl脚本功能与Freemind的导出一起使用--以Protovis所需的确切JSON格式输出数据,从而产生阳光暴晒-- javascript中不需要进行进一步的转换。

我正在寻找的输出JSON格式的一个例子是:http://mbostock.github.com/protovis/ex/sunburst.html

实际上,freemind .mm文件格式是输入。

在手写笔工作室中运行我的alpha代码(如下图所示)将生成一种json格式(格式很差,但似乎是合法的),当我将从手写工作室生成的输出直接保存到一个.js文件中时,这种格式就会生成protovis ok。但是,由于某种原因,Freemind似乎没有使用此代码导出数据.

我遗漏了什么吗?任何帮助都很感激。

非常感谢,安德鲁

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

我已经更正了代码,问题是freemind使用的xslt引擎不支持我的xsl。我更正了代码,并在自由许可下将其移至github,并将其从这里删除。

适配器在这里可用:https://github.com/minkymorgan/Freemind2JSON#readme

  • 安德鲁
EN

回答 2

Stack Overflow用户

发布于 2012-02-04 18:50:03

这是我的尝试。我的基础是您的版本,并添加了一些更多的功能。

代码语言:javascript
复制
<?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>

如果在Freemind测试文件上运行,它将产生以下输出:

代码语言:javascript
复制
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
    }
};
票数 0
EN

Stack Overflow用户

发布于 2012-12-01 16:36:51

万一有兴趣..。我刚刚推出了一个XSLT脚本,用于将FreeMind转换为JSON。我的脚本有点简单,还不支持Javascript转义。

它也不是为Protovis而设计的

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9130063

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档