2016-11-02 25 views
-1

我有xml-like格式的自定义图形格式。我想要按原样安排节点textviewedge。我的方法是使用从xmlsvgXSL转换。我是svg格式的新手,但在xsl之前工作过一点。我想知道yEd这个任务是否已经解决了graphml to svg功能。有没有一些方便的方法来进行这样的转换?如何通过XSLT将自定义图形格式转换为SVG图形视图?

<?xml version="1.0" encoding="windows-1251"?> 
<project version="1.2"> 
    <calc allowworktime="false" cutoff="0"/> 
    <sfc> 
    <graphview> 
     <nodeview idref="1"> 
     <properties> 
      <color value="#FF000000" name="outline.color"/> 
      <rectangle left="165" top="85" right="195" bottom="115" name="bounds"/> 
      <color value="#FFFFFFFF" name="fill.color"/> 
     </properties> 
     </nodeview> 
     <edgeview idref="1"> 
     <properties> 
      <color value="#FF000000" name="outline.color"/> 
     </properties> 
     </edgeview> 
     <textview> 
     <properties> 
      <color value="#00000000" name="outline.color"/> 
      <color value="#FF000000" name="label.font.color"/> 
      <integer value="8" name="label.font.size"/> 
      <rectangle left="176" top="63" right="194" bottom="78" name="bounds"/> 
      <string value="Tahoma" name="label.font.family"/> 
      <color value="#00000000" name="fill.color"/> 
      <integer value="0" name="label.font.style"/> 
      <string value="Ë1" name="label.text"/> 
     </properties> 
     </textview> 
    </graphview> 
    </sfc> 
</project> 

我刚刚创建的样本xslt,可以改变nodeviews到rects,但在Inkscape中打开时,SVG不以某种方式呈现。

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:local="local" 
    exclude-result-prefixes="xs" 
    version="2.0" 
    xmlns:svg="http://www.w3.org/2000/svg"> 
    <xsl:output indent="yes"/> 

    <xsl:template match="/"> 
     <svg> 
     <xsl:apply-templates select="@* | node()"/> 
       </svg> 

      </xsl:template> 

    <xsl:template match="//graphview/nodeview"> 
     <xsl:variable name="nodeleft" select="properties/rectangle/@left"/> 
     <xsl:variable name="noderight" select="properties/rectangle/@right"/> 
     <xsl:variable name="nodetop" select="properties/rectangle/@top"/> 
     <xsl:variable name="nodebottom" select="properties/rectangle/@bottom"/> 
     <!-- adding svg group item --> 
     <g> 
      <xsl:element name="rect"> 
       <xsl:attribute name="x"><xsl:value-of select="$nodeleft"/></xsl:attribute> 
       <xsl:attribute name="width"><xsl:value-of select="($noderight - $nodeleft)"/></xsl:attribute> 
       <xsl:attribute name="height"><xsl:value-of select="($nodetop - $nodebottom)"/></xsl:attribute> 
       <xsl:attribute name="y"><xsl:value-of select="($nodetop)"/></xsl:attribute> 
      </xsl:element> 
     </g> 
    </xsl:template> 
</xsl:stylesheet> 

回答

3

您的样式表的主要问题是您创建的元素不在SVG名称空间中。您可以通过使SVG命名空间中的样式表的默认命名空间解决这个问题很容易 - 督察,改变这种:

xmlns:svg="http://www.w3.org/2000/svg" 

到:

xmlns="http://www.w3.org/2000/svg" 

的另一件事是,你计算返回负的高度,这在SVG中是不允许的。

+0

我已经改变了它,元素现在在svg ns中,但图形已经隐藏了。但我可以通过inkscape中的xml编辑器查看它。 – Juriy

+0

@Juriy我不确定你想说什么。 –

+1

@Juriy:这个答案涵盖了你的两个主要问题。考虑[**接受它](http://meta.stackoverflow.com/q/5234/234215),然后对于其他问题,请尝试首先手动创建SVG,以实现您想要的结果。然后,通过XSLT定位SVG将变得更加容易。 – kjhughes