Re: cliente-side dynamic XSLT transformation with javascript

Martin Honnen <[email protected]>
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Organization Liberty Development
Message-ID <[email protected]>

..tato.. wrote:


> removing the clause so it runs, it shows the images on the 2nd frame
> but never finishes loading eg. I cannot see the frame´s source and
> inspecting the DOM it looks like it is growing recursivelly 8-/
> 
> code--------------
> xmlDoc = document.implementation.createDocument('', '', null);
> xslDoc = document.implementation.createDocument('', '', null);
> 
> xmlDoc.addEventListener('load', xslLoad, false);
> xmlDoc.load("fcImgList.xml");
> 
> function xslLoad()
> { xslDoc.addEventListener('load', xslTransform, false);
>   xslDoc.load("fcImgList.xsl");
> }
> 
> function xslTransform()
> { proc = new XSLTProcessor();
>   proc.importStylesheet(xslDoc);
>   var xmlObj = proc.transformToDocument(xmlDoc);
>   var xmls = new XMLSerializer();
>   var output = xmls.serializeToString(xmlObj);
>   parent.frmBot.document.write(output);

That has nothing to do with XSLT, if you use document.write to write 
markup to a window or frame you need call
   document.close()
at the end e.g. in this case
   parent.frmBot.document.close();


As for the whole attempt to create a document using XSLTProcessor, then 
serialize it and then use document.write to have the browser parse the 
serialization, that is not the proper way to do it with Mozilla, you can 
transform to a document fragement and simply use the DOM then to 
exchange content as needed e.g.
   var documentFragment = proc.transformToFragment(xmlDoc, 
parent.frmBot.document);
   parent.frmBot.document.documentElement.replaceChild(documentFragment, 
parent.frmBot.document.body);

Depending on what the transformation creates you might want to replace 
something else than the body but the approach to create a fragment and 
insert as needed with the DOM is certainly better than DOM creation, 
serialization, parsing again.



-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.