Javascript selects XML nodes and xslt deformation-IE

Source: Internet
Author: User

Bkjia.com XML documentLet's take a look at a piece of code:

Reference content is as follows:
Var doc = null;
Var sdoc = null;
Try
{
Doc = new ActiveXObject ("MSXML2.DOMDocument. 6.0 ");
Sdoc = new ActiveXObject ("MSXML2.DOMDocument. 6.0 ");
}
Catch (e)
{
Alert (e. toString ());
}
If (doc)
Document. write ("OK ");
Else
Document. write ("fail ");

Doc. async = false;
Doc. load ("http: // localhost/xml/a. xml ");
Sdoc. async = false;
Var r = sdoc. load ("http: // localhost/xml/a. xsl ");
Try
{
// Var result = doc.transformNode(sdoc.doc umentElement );

Sdoc. setProperty ("SelectionNamespaces", "xmlns: xsl = 'HTTP: // www.w3.org/5o/#/transform '");
Var tmp = sdoc.doc umentElement. selectSingleNode ("xsl: template [@ mode = 'B']");
Alert (tmp. xml );

Var result = doc. transformNode (sdoc );
Alert (result );
// Document. write (result );
}
Catch (e)
{
Alert (e. toString ());
}


To use node selection and XSLT deformation in IE, use newActiveXObject ("MSXML2.DOMDocument. 6.0"); to generate an image (the subsequent version 6.0 varies depending on the specific environment ). In addition, in the loadxml document, if asynchronous LOAD is not used, set async to false. The deformation is still very simple. You can see the code above, when selecting a node, if there is a namespace, call the setProperty "SelectionNamespaces", "xmlns: xsl = 'HTTP: // www.w3.org/5o/xsl/transform'"); method, you can use the xpath with prefix: nodename to search for nodes. Otherwise, the nodes cannot be searched.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.