[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XSLT interacting with Javascript


Subject: Re: [xsl] XSLT interacting with Javascript
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 02 Jun 2009 19:27:39 +0200

Robert G wrote:

var xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
xsltProcessor.setParameter(null,"type","html");
xsltProcessor.setParameter(null,"type2","java"); var result= xsltProcessor.transformToDocument(xml);
var serial= new XMLSerializer();
var out= serial.serializeToString(result.documentElement);
var output= document.getElementById("example");
output.innerHTML=out;

Well Mozilla nicely allows you to produce HTML DOM nodes with an XSLT transformation that you can appendChild directly into your HTML document, simply by using


  var fragment =  transformToFragment(xml, document);
  // might want/need to remove contents of output first
  output.appendChild(fragment);

so use that instead of creating a result document first, then serializing that (as XML) with XMLSerializer, then parsing that (as HTML) by setting innerHTML.

--

	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/


Current Thread
Keywords