xsl-list
[Top] [All Lists]

Re: [xsl] XSLT interacting with Javascript

2009-06-02 13:28:10
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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>