JS¼¼Êõ

ÈçºÎʹÓà JavaScript XSLT ´¦Àí XML Îļþ£¨Ö§³Ö Firefox£©

×ÖºÅ+ ×÷Õߣº À´Ô´£º    2014-11-17 20:00 ÎÒÒªÆÀÂÛ( )

ÈçºÎʹÓà JavaScript XSLT ´¦Àí XML Îļþ£¨Ö§³Ö Firefox£©,ÔĶÁÈçºÎʹÓà JavaScript XSLT ´¦Àí XML Îļþ£¨Ö§³Ö Firefox£©, ×î½üʹÓÃFirefox½øÐÐÍøÒ³µÄµ÷ÊÔ,·¢ÏÖÓÐЩJavascript XSLT´¦ÀíXMLµÄÓï¾ä½ö½öÖ§³ÖIEä¯ÀÀÆ÷¡£¶øÍøÂçÖеÄһЩ½éÉÜjavascript XSLT ´¦ÀíXML

    ×î½üʹÓÃ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!");
}

¡¡

1.±¾Õ¾×ñÑ­ÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ­´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ­´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄܻᾭÎÒÃDZ༭Ð޸Ļò²¹³ä¡£

Ïà¹ØÎÄÕÂ
  • ÀÏÉú³£Ì¸£¬JavaScript±Õ°üÖеÄthis¶ÔÏó

    ÀÏÉú³£Ì¸£¬JavaScript±Õ°üÖеÄthis¶ÔÏó

    2016-02-26 10:21

  • ѧϰJavaScriptÖ®this,call,apply

    ѧϰJavaScript֮this,call,apply

    2016-01-28 20:45

  • JavaScript¸´Ï°±Ê¼Ç--×Ö·û´®

    JavaScript¸´Ï°±Ê¼Ç--×Ö·û´®

    2016-01-27 17:16

  • WEBÇ°¶Ë½Ì³Ì-JavaScriptÀïµÄÀàºÍ¼Ì³Ð

    WEBÇ°¶Ë½Ì³Ì-JavaScriptÀïµÄÀàºÍ¼Ì³Ð

    2016-01-21 15:28

ÍøÓѵãÆÀ
Ò