欢迎光临

木子屋

标题: ASP调用XSLTemplate对象将XML转换为HTML示例

作者: dnawo

日期: 2010-09-11 10:35 AM

分类: Web编程

内容: 复制内容到剪贴板 程序代码<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>ASP调用XSLTemplate对象将XML转换为HTML示例-Mzwu.Com</title>
</head>
<body>
<%
'msxml版本
Const MsxmlVersion = ".3.0"
'通用函数
Function CreateAXObject(str)
Set CreateAXObject = CreateObject(str)
End Function
Function CreateXMLDoc(str)
Set CreateXmlDoc = CreateAXObject(str)
CreateXMLDoc.Async = False
End Function
Function TransFormNode(strXML, strXSL)
Set XMLDom = CreateXMLDoc("msxml2.FreeThreadedDOMDocument"& MsxmlVersion)
Set XSLTemplate=CreateAXObject("Msxml2.XSLTemplate" & MsxmlVersion)
Set XMLStyle=CreateXmlDoc("msxml2.FreeThreadedDOMDocument"& MsxmlVersion)

On Error Resume Next
If XMLDom.loadxml(strXML) Then
If XMLStyle.loadxml(strXSL) Then
XSLTemplate.stylesheet=XMLStyle
Set proc = XSLTemplate.createProcessor()
proc.input = XMLDom
proc.transform()
TransFormNode = proc.output
Set proc=Nothing
Else
TransFormNode = "载入xsl错误..."
End If
Else
TransFormNode = "载入xml错误..."
End If
If Err Then
TransFormNode = "未知错误..."
Err.Clear
End If

Set iXMLDom=Nothing
Set XSLTemplate=Nothing
Set XMLStyle=Nothing
End Function
'xml和xsl字符串
Dim strXML : strXML = "<?xml version=""1.0"" encoding=""gb2312""?><xml><website><name>木子屋</name><url>http://www.mzwu.com/</url></website><website><name>竹炭产品专卖</name><url>http://ztcp.taobao.com/</url></website></xml>"
Dim strXSL : strXSL = "<?xml version=""1.0"" encoding=""gb2312""?><xsl:stylesheet version=""1.0"" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform""><xsl:template match=""/""><xsl:for-each select=""xml/website""><xsl:value-of select=""name"" />,<xsl:value-of select=""url"" /><br/></xsl:for-each></xsl:template></xsl:stylesheet>"
Response.Write TransFormNode(strXML, strXSL)
%>
</body>
</html>
代码参考自新云CMS4.0SP2。

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.078 ms

返回

标题: ASP调用XSLTemplate对象将XML转换为HTML示例

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.078 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 1.125 ms

返回