以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  求助!!!关于XML到SVG的转换  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=7118)


--  作者:happyhair
--  发布时间:4/29/2004 11:04:00 AM

--  求助!!!关于XML到SVG的转换
我想用XSL把XML转换为SVG,使得可以在地址栏输入XML文件的路径就能输出SVG图像。
我现在编写了XSL文件和XML文件,但是没有办法显示SVG,怎么办啊?
--  作者:joyce_hua
--  发布时间:5/14/2004 9:27:00 AM

--  
我也很想知道
--  作者:kuanan
--  发布时间:5/29/2004 2:47:00 PM

--  
SVG就是标准的XML文档,为什么转换?

如果数据保存在非SVG格式的XML文档中。可以把数据读出来,然后写成标准的SVG文件


--  作者:wonking
--  发布时间:5/29/2004 3:53:00 PM

--  
怎么搞呢?
--  作者:yanwen
--  发布时间:7/28/2004 9:18:00 AM

--  
不知道大家是不是用 javax.xml.transform.*;?
XML文件只是数据库的数据文件 通过一个XSL文件来把他转换为另外一个SVG文件
sources.xml:
<?xml version='1.0'?>
<testdata>
<test position="1" name="sail1" salary="2500"/>
<test position="2" name="sail2" salary="2500"/>
<test position="3" name="sail3" salary="3500"/>
<test position="3" name="sail3" salary="5500"/>
</testdata>

salary.xsl:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        xmlns="http://www.w3.org/2000/svg">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />


<xsl:template match="/">

  <svg  width="1200px" height="250px" viewBox="-25 -45 575 575" >

   <xsl:apply-templates select="testdata/test" />


</svg>

</xsl:template>

<xsl:variable name="rectwidth" select="(400-count(//test)*2) div count(//test)"/>


<xsl:element name="rect">

    <xsl:attribute name="x"><xsl:value-of
        select="concat((100+$rectwidth * @position+(@position-1)*2)),'px')" /></xsl:attribute>
    
    <xsl:attribute name="y"><xsl:value-of
        select="concat((300-@salary), 'px')" />
    </xsl:attribute>

    <xsl:attribute name="width"><xsl:value-of
        select="concat($rectwidth,'px')" /></xsl:attribute>

    <xsl:attribute name="height"><xsl:value-of
        select="concat((@salary),'px')" /></xsl:attribute>

    <xsl:attribute name="fill">gray</xsl:attribute>
     <xsl:attribute name="stroke">blue</xsl:attribute>
    <xsl:attribute name="stroke-width">1px</xsl:attribute>
   
     
     
</xsl:element> <!-- End of nested svg Element -->


<xsl:element name="text">

    <xsl:attribute name="x"><xsl:value-of
        select="concat((100+$rectwidth * @position+(@position-1)*2),'px')" /></xsl:attribute>
    
    <xsl:attribute name="y"><xsl:value-of
        select="concat(320, 'px')" />
    </xsl:attribute>

    
    <xsl:attribute name="fill">blue</xsl:attribute>
   
  <xsl:value-of
        select="@name)" />
      
   
     
     
</xsl:element>  



</xsl:for-each >


</xsl:template>


</xsl:stylesheet>


--  作者:yanwen
--  发布时间:7/28/2004 9:20:00 AM

--  
不知道大家是不是用 javax.xml.transform.*;?
XML文件只是数据库的数据文件 通过一个XSL文件来把他转换为另外一个SVG文件
sources.xml:
<?xml version='1.0'?>
<testdata>
<test position="1" name="sail1" salary="2500"/>
<test position="2" name="sail2" salary="2500"/>
<test position="3" name="sail3" salary="3500"/>
<test position="3" name="sail3" salary="5500"/>
</testdata>

salary.xsl:
<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        xmlns="http://www.w3.org/2000/svg">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />


<xsl:template match="/">

  <svg  width="1200px" height="250px" viewBox="-25 -45 575 575" >

   <xsl:apply-templates select="testdata/test" />


</svg>

</xsl:template>

<xsl:variable name="rectwidth" select="(400-count(//test)*2) div count(//test)"/>

<xsl:template match="test">
<xsl:for-each select="test">



<xsl:element name="rect">

    <xsl:attribute name="x"><xsl:value-of
        select="concat((100+$rectwidth * @position+(@position-1)*2)),'px')" /></xsl:attribute>
    
    <xsl:attribute name="y"><xsl:value-of
        select="concat((300-@salary), 'px')" />
    </xsl:attribute>

    <xsl:attribute name="width"><xsl:value-of
        select="concat($rectwidth,'px')" /></xsl:attribute>

    <xsl:attribute name="height"><xsl:value-of
        select="concat((@salary),'px')" /></xsl:attribute>

    <xsl:attribute name="fill">gray</xsl:attribute>
     <xsl:attribute name="stroke">blue</xsl:attribute>
    <xsl:attribute name="stroke-width">1px</xsl:attribute>
   
     
     
</xsl:element> <!-- End of nested svg Element -->


<xsl:element name="text">

    <xsl:attribute name="x"><xsl:value-of
        select="concat((100+$rectwidth * @position+(@position-1)*2),'px')" /></xsl:attribute>
    
    <xsl:attribute name="y"><xsl:value-of
        select="concat(320, 'px')" />
    </xsl:attribute>

    
    <xsl:attribute name="fill">blue</xsl:attribute>
   
  <xsl:value-of
        select="@name)" />
      
   
     
     
</xsl:element>  



</xsl:for-each >


</xsl:template>


</xsl:stylesheet>


--  作者:yanwen
--  发布时间:7/28/2004 9:29:00 AM

--  
我在XML里引用XSL 在地址栏里输入XML地址 显示是空白 没有报错?

请那位做过类似的 请赐教?/??/?


--  作者:yanwen
--  发布时间:7/28/2004 9:31:00 AM

--  
import java.io.File;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;

public class ChooseStyleSheet {
   public static void main (String args[]) {
      try {

      TransformerFactory transformerFactory =
                          TransformerFactory.newInstance();

         StreamSource source = new StreamSource("scores.xml");
         StreamResult result = new StreamResult("result.xml");
         StreamSource style = new StreamSource("scores.xsl");

         Transformer transformer =
                       transformerFactory.newTransformer(style);

         transformer.transform(source, result);  

      } catch (Exception e) {
               e.printStackTrace();
      }
   }
}

请问这个转换应该怎么做 求助?????!!!!


--  作者:wenmier
--  发布时间:8/5/2004 3:37:00 PM

--  
请问,您用的是哪些工具呢?推荐下,谢谢
--  作者:hry23
--  发布时间:8/18/2004 9:50:00 AM

--  
以下是引用yanwen在2004-7-28 9:29:31的发言:
我在XML里引用XSL 在地址栏里输入XML地址 显示是空白 没有报错?

请那位做过类似的 请赐教?/??/?


我也有同样的问题,而且你试试在xsl文件中加入<text>内容,它可以显示。怪了。


--  作者:hry23
--  发布时间:8/18/2004 9:52:00 AM

--  
以下是引用wenmier在2004-8-5 15:37:35的发言:
请问,您用的是哪些工具呢?推荐下,谢谢


用IE可以使用<?xml-stylesheet type="text/xsl" href="green.xsl" ?>直接转换,但有的时候不大好用(像我上一楼那贴的问题),所以我也用使用msxsl.exe来转换,可以看到转换过程,或输出文件(我上一楼问题用这个工具能输出正常结果,可以说明转换结果没问题,看来是有点IE不把它当SVG看待的感觉)
--  作者:mxr
--  发布时间:9/30/2005 12:10:00 PM

--  
下载一个svgviewer,把xml文件存成.svg格式就可以用IE打开
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
76.172ms