XSLT is a technology which uses XPath and transforms one XML document representation to another XML or formats such as HTML for webpages, plain text, or XSL formatting objects. JavaScript can be used to do the manipulation of document which helps in doing browser specific testing and use different style sheets based on needs.

In IE, the transformNode() method is used to transform the documents. It accepts one argument that is, the style sheet document for the nodes and returns the string containing transformation.

For other browsers a new XSLTProcessor() object is created. The importStylesheet() method may be used to assign the XSLT to it. It can be transformed to complete DOM document using transformToDocument() method or document fragment object by calling transformToFragment() method.

Example of XSLT processing methods 

In the example below a HTML file will pull out the data from msgList.xml file, while styles will be defined within the file named msgList.xsl.

In the example, the XMLHttpRequest object is created and open() and send() methods are used to send request to server for XML and XSL data. For IE browsers transformNode() method is used and for other browsers use XSLTProcessor object and importStylesheet() method is used to import style sheet. The transformed XML is displayed in the browser.


›› go to examples ››