2016-11-02 22 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