日期:2011-05-28 浏览次数:21516 次
代码如下:
<%
'生成xsl样式
str = chr(13)&chr(10)&chr(9)
xslt="<?xml version=""1.0""?>" & chr(13)&chr(10) & "<xsl:stylesheet version=""1.0"""_
&" xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"""_
&" xmlns:s=""uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"""_
&" xmlns:dt=""uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"""_
&" xmlns:rs=""urn:schemas-microsoft-com:rowset"""_
&" xmlns:z=""#RowsetSchema"">"& str_
& "<xsl:output omit-xml-declaration=""yes""/>"&str_
& "<xsl:template match=""/"">"& str&chr(9)_
& "<xsl:element name=""xml"">"& str&chr(9)&chr(9)_
&"<xsl:for-each select=""/xml/rs:data/z:row"">"& str&chr(9)&chr(9)&chr(9)_
&"<xsl:element name=""row"">"& str&chr(9)&chr(9)&chr(9)&chr(9)_
&"<xsl:for-each select=""@*"">"& str&chr(9)&chr(9)&chr(9)&chr(9)&chr(9)_
& "<xsl:element name=""{name()}"">"& str&chr(9)&chr(9)&chr(9)&chr(9)&chr(9)&chr(9)_
& "<xsl:value-of select="".""/>"& str&chr(9)&chr(9)&chr(9)&chr(9)&chr(9)_
&"</xsl:element>"& str&chr(9)&chr(9)&chr(9)&chr(9)_
& "</xsl:for-each>"& str&chr(9)&chr(9)&chr(9)_
& "</xsl:element>"& str&chr(9)&chr(9)_
&"</xsl:for-each>"& str&chr(9)_
&"</xsl:element>"& str_
&"</xsl:template>"& chr(13)&chr(10)_
&"</xsl:stylesheet>"
'读取数据库
curDir = Server.MapPath("data.mdb")
set conn=server.createobject("adodb.connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & curDir
set rs=conn.Execute("select * from admins")
Dim objXMLDOM
Set objXMLDOM = Server.CreateObject("MSXML2.DOMDocument.3.0")
'将recordset对象保存到dom里
rs.save objXMLDOM, 1
Set rs = Nothing
Dim strCleanXML, objXMLDOM_XSLT
Set objXMLDOM_XSLT = CreateObject("MSXML2.DOMDocument")
objXMLDOM_XSLT.loadXml(xslt)
'用xsl格式化数据
strCleanXML = objXMLDOM.transformNode(objXMLDOM_XSLT)
Set objXMLDOM = Nothing
Set objXMLDOM_XSLT = Nothing
'输出数据
Response.Write strCleanXML
%>
因为xml是跨平台的,所以呢不论是asp还是jsp或者客户端都可以通过该接口获得数据,然后用自己的样式来显示数据。比如,在客户端我们可以使用javascript操作xmlhttp来获得www.xxxx.com上某个mdb的数据:
<script language="javascript">
function req(){
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("GET", "