<%@ LANGUAGE = JScript %>
<%
// Set the source and style sheet locations here
var sourceFile = Server.MapPath("test.xml");
var styleFile = Server.MapPath("test.xsl");
// Load the XML
var source = Server.CreateObject("Microsoft.XMLDOM");
source.async = false;
source.load(sourceFile);
// Load the XSL
var style = Server.CreateObject("Microsoft.XMLDOM");
style.async = false;
style.load(styleFile);
Response.Write(source.transformNode(style));
%>
一般以MSXML为开发环境的都要建立安装新的解析器,如MSXML 3或者MSXML 4 Technology Preview,
在以replace方式装了MSXML 3后,我们可以使用以下的代码
<%@ LANGUAGE = JScript %>
<%
// Set the source and style sheet locations here
var sourceFile = Server.MapPath("test.xml");
var styleFile = Server.MapPath("test.xsl");
// Load the XML
var source = Server.CreateObject("Msxml2.DOMDocument");
source.async = false;
source.load(sourceFile);
// Load the XSL
var style = Server.CreateObject("Msxml2.DOMDocument");
style.async = false;
style.load(styleFile);
Response.Write(source.transformNode(style));
%>
这样我们获得了MSXML 3的开发环境,但如果我们不想破坏原来的环境,又要测试我们基于MSXML 3的例子呢,虽然用replace方式安装提供了向后兼容方式来支持XSL元素,函数和XSL命名空间。
其实使用版本无关progIDs(version-dependent progIDs)来创建对象实例可以更好的完成工作,我们不需要用replace方式安装,用side-by-side方式即可,我们看下面的代码:
<%@ LANGUAGE = JScript %>
<%
// Set the source and style sheet locations here
var sourceFile = Server.MapPath("test.xml");
var styleFile = Server.MapPath("test.xsl");
// Load the XML
var source = Server.CreateObject("Msxml2.DOMDocument.3.0");
source.async = false;
source.load(sourceFile);
// Load the XSL
var style = Server.CreateObject("Msxml2.DOMDocument.3.0");
style.async = false;
style.load(styleFile);
Response.Write(source.transformNode(style));
%>
只需要在Msxml2.DOMDocument后面加上版本号3.0,即可使用MSXML 3的东东了,MSXML 4呢,依次类推。
在客户端的环境也是一样的,用js创建DOM对象是一样的。
function test(){
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
var currNode;
xmlDoc.async = false;
xmlDoc.load("test.xml");
currNode = xmlDoc.documentElement.firstChild;
alert(currNode.xml);
}
最后,XSLT样式单side-by-side方式下在Internet Explorer 5.0及以后版本不支持。如果你要使用IE 5来打开XSLT样式单,需要用replace方式安装。
进入讨论组讨论。相关专题
- XHTML 代码规范 (530次浏览)
- XML之CSS和XSL精解(1) (314次浏览)
- 利用Digester把XML转换成为Java对象 (143次浏览)
- XML SOAP应用简介 (131次浏览)
- W3C XML Schema 与文档类型定义 (116次浏览)
- XML、DataSet、DataGrid结合写成广告管理程 (109次浏览)
- dotText源码阅读(4)--DTO和数据访问 (108次浏览)
- Publishing Pages with PUT (65次浏览)
- 如何用MSXML2操作XML配置文件 (14次浏览)



