Re: Can I use 'about:blank' as target document?

"Michael Vincent van Rantwijk, MultiZilla" <[email protected]> Thu, 05 Apr 2007 13:46:46 +0200
Newsgroups gmane.comp.mozilla.devel.layout.xslt
Message-ID <[email protected]>
Jonas Sicking wrote:
> Michael Vincent van Rantwijk, MultiZilla wrote:
>> Can I use 'about:blank' as 'targetDocument' in the following example:
>>
>> var newFragment = processor.transformToFragment(xmldoc, targetDocument);
>>
>> I ask this because I don't see anything in the DOM when I the snippet 
>> below to insert it into the DOM:
>>
>> targetDocument = xmldoc;
>> _documentElement = targetDocument.documentElement;
>> // Remove everything up to the document's <head> element
>>   while (_documentElement.hasChildNodes()) {
>>     _documentElement.removeChild(_documentElement.firstChild);
>>   }
>>   // Import <head> and <body> elements from the document fragment
>>   for (var i = 0; i < newFragment.firstChild.childNodes.length; i++) {
>>     var newNode = 
>> targetDocument.importNode(newFragment.firstChild.childNodes[i], true);
>>       _documentElement.appendChild(newNode);
>>     }
>>
>> Note: everything I expect (all elements/children) are part of the 
>> 'newFragment' so that can't be the problem.
> 
> First of all, you should use the document that you want to insert the 
> nodes in as 'targetDocument'. 

But of course, and is what I do.

> That way you don't need to call 
> .importNode on each of the nodes in the resulting fragment. That is the 
> whole point of being able to specify a target document.

Sure, but that won't work for people like me, who need to modify the DOM 
after the transformation.

> To answer your question though, there are some tricky security stuff wrt 
> about:blank documents, do you see any errors in the error console?

No error, and my pref are set to show everything.

> Since it sounds like you are getting the result you are expecting from 
> the XSLT transform, you're just then having problems displaying those 
> nodes, this is likely not an XSLT related problem.

It is, sort of.  It is a limitation for when the target document is 
'about:blank', but I can use it now (after I removed the first text 
(rss/rdf) element/node from the source document). Good enough for testing.

> It would be good if you could provide a minimal testcase to see what 
> you're trying to do.

Sorry no testcase here; but I am trying to add a new content handler to 
intercept loads of "application/blob-xml" and load/translate the blob 
document with XSLT into XHTML which should be opened in a new or unused 
(about:blank) tab.

I'm still stuck with some DOM/network issues, but I think that I better 
ask these questions in the respected newsgroup.

Thanks,
Michael