-- 作者: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 %>
|