×î½üʹÓÃFirefox½øÐÐÍøÒ³µÄµ÷ÊÔ,·¢ÏÖÓÐЩJavascript XSLT´¦ÀíXMLµÄÓï¾ä½ö½öÖ§³ÖIEä¯ÀÀÆ÷¡£¶øÍøÂçÖеÄһЩ½éÉÜjavascript XSLT ´¦ÀíXMLµÄÎÄÕ»ù±¾É϶¼ÊÇÒÀ¾ÝAJAXÀ´×öµÄ¡£
ÎÞÄÎÖÐ,×Ô¼ºÐ´ÁËÒ»¸öJavascript XSLT´¦ÀíXMLÕ¹ÏÖÒ³ÃæµÄС¹¦ÄÜ¡£ÏÖÔÚÌû³öÀ´ºÍ´ó¼Ò¹²Ïí£¬Ï£Íû´ó¼Ò¸øµã¸Ä½øÒâ¼û¡£
ÔÚFirefoxÖÐʹÓÃXSLTProcessor¶ÔÏó´¦ÀíXML£¬Ö÷ҪʹÓøöÔÏóµÄÁ½¸ö·½·¨£º
Ò»¡¢transformToFragment()¡£
¶þ¡¢transformToDocument()¡£
ÏÂÃæµÄ´úÂë½ö½öʹÓÃtransformToFragment()·½·¨À´ÊµÏÖ¶ÔXMLÎļþ´¦Àí,Èç¹ûÄã¶ÔÔÚFirefoxÖÐʹÓà Javascript XSLT ´¦ÀíXMLÎļþ¸ÐÐËȤµÄ»°²»·ÁÊÔ׎«ÒÔÏ´úÂë¸Äд³ÉʹÓÃtransformToDocument()·½·¨À´ÊµÏֵĴ¦Àí¹¦ÄÜ¡£
Javascript ´úÂëÈçÏ£º
function initialize() {
var xmlDoc;
var xslDoc;
// ÅжÏä¯ÀÀÆ÷µÄÀàÐÍ
if(document.implementation && document.implementation.createDocument)
{
// Ö§³ÖMozillaä¯ÀÀÆ÷
try
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load("guestbook/guestbook.xml");
}
catch(e)
{
alert("error:001");
}
try
{
xslDoc = document.implementation.createDocument("", "", null);
xslDoc.async = false;
xslDoc.load("guestbook/guestbook.xsl");
}
catch(e)
{
alert("error:002");
}
try
{
// ¶¨ÒåXSLTProcessor¶ÔÏó
var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xslDoc);
var oResultFragment = xsltProcessor.transformToFragment(xmlDoc,document);
// ½«½âÎö¹ýµÄÎı¾Êä³öµ½Ò³Ãæ
var oDiv = document.getElementById("guestbookPanel");
oDiv.appendChild(oResultFragment);
}
catch(e)
{
alert("error:003");
}
}
else if(typeof window.ActiveXObject != 'undefined')
{
//var xmlDoc=Server.CreateObject("Msxml2.DOMDocument.4.0");
// Ö§³ÖIEä¯ÀÀÆ÷
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
xslDoc = new ActiveXObject('Microsoft.XMLDOM');
xmlDoc.async = false;
xslDoc.async = false;
xmlDoc.load("guestbook/guestbook.xml");
xslDoc.load("guestbook/guestbook.xsl");
guestbookPanel.innerHTML = xmlDoc.documentElement.transformNode(xslDoc);
}
else
{
alert("Browser unknown!");
}
}
javascript dom ´¦ÀíXSLÏÔʾÊý¾ÝµÄµÚ¶þÖÖ·½Ê½¡£
Ö÷Òª´úÂëÈçÏ£º
var xmlDoc;
var xslDoc;
// ÅжÏä¯ÀÀÆ÷µÄÀàÐÍ
if(document.implementation && document.implementation.createDocument)
{
// Ö§³ÖMozillaä¯ÀÀÆ÷
try
{
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load("guestbook/guestbook.xml");
xslDoc = document.implementation.createDocument("", "", null);
xslDoc.async = false;
xslDoc.load("guestbook/guestbook.xsl");
// ¶¨ÒåXSLTProcessor¶ÔÏó
var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xslDoc);
// transformToDocument·½Ê½
var result = xsltProcessor.transformToDocument(xmlDoc);
var xmls = new XMLSerializer();
document.getElementById("guestbookPanel").innerHTML = xmls.serializeToString(result);
}
catch(e)
{
alert("Unable to do xml/xsl processing");
}
}
else if(typeof window.ActiveXObject != 'undefined')
{
try
{
// Ö§³ÖIEä¯ÀÀÆ÷
xmlDoc = new ActiveXObject('Msxml2.DOMDocument');
xslDoc = new ActiveXObject('Msxml2.DOMDocument');
xmlDoc.async = false;
xslDoc.async = false;
xmlDoc.load("guestbook/guestbook.xml");
xslDoc.load("guestbook/guestbook.xsl");
guestbookPanel.innerHTML = xmlDoc.documentElement.transformNode(xslDoc);
}
catch(e)
{
alert("Unable to do xml/xsl processing");
}
}
else
{
alert("Browser unknown!");
}
¡¡