以下為引用的內容:
<%@ 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方式安裝.
新聞熱點
疑難解答