以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 SVG/GML/VRML/X3D/XAML 』  (http://bbs.xml.org.cn/list.asp?boardid=21)
----  服务器端利用xslt技术将xml转换为svg  (http://bbs.xml.org.cn/dispbbs.asp?boardid=21&rootid=&id=33138)


--  作者:wanghai00
--  发布时间:5/26/2006 10:02:00 PM

--  服务器端利用xslt技术将xml转换为svg
example.xml

<?xml version="1.0" encoding="gb2312"?>
<data>
  <datum>23</datum>
  <datum>94</datum>
  <datum>55</datum>
</data>

example.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- 定义XSLT转换后输出的文件的格式,这里输出为XML格式的文件内容 -->
<xsl:output method="xml" indent="yes" encoding="UTF-8" version="1.0" standalone="no" media-type="image/svg+xml"/>
  <xsl:template match="/">
    <svg xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 {10*(count(data/datum)+1)} 100">
      <xsl:for-each select="data/datum">
        <rect x="{10*position()}" y="{100- .}" width="10" height="{.}" fill="red" stroke="black"/>        
      </xsl:for-each>
      </svg>
  </xsl:template>
</xsl:stylesheet>

svg.asp

<%@ Language="VBScript"%>
<Meta Name="Author" Content="greaterthanme">
<Meta Name="WebSite" Content="超越自我">
<Meta Name="WebSite" Content="http://greaterthanme.blog.hexun.com">
<Meta Name="CopyRight" Content="超越自我">
<%
Response.Clear
Response.Buffer = True
Dim xmlDom, xslDom, strResult
Set xmlDom = Server.CreateObject("Msxml2.DOMDocument")
Set xslDom = Server.CreateObject("Msxml2.FreeThreadedDOMDocument")
xmlDom.async = False
xslDom.async = False

xmlDom.load Server.MapPath("example.xml")
xslDom.load Server.MapPath("example.xsl")
Response.ContentType = "image/svg+xml"

strResult = xmlDom.transformNode(xslDom)
'' 在不支持UTF-16编码的饿平台上,替换成UTF-8
strResult = Replace(strResult,"UTF-16","UTF-8")
Response.Write strResult
%>  


--  作者:gyinlbomer
--  发布时间:5/27/2006 12:48:00 PM

--  
好啊!感谢ing...
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
39.063ms