Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2009, 10:44 AM
Authorized User
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default Create a new window and fill it with XHTML

the following code opens a new tab in browser and fill it with "print preview" version of current tab.
Code:
function printPreview() {
   // loadSyncXML is my cool method
   if (!xsl_p) xsl_p = loadSyncXML('print.xsl.php');
   var xsltProcessor = new XSLTProcessor();
   xsltProcessor.importStylesheet(xsl_p);
   var win = window.open();
   // 'xml' already loaded
   win.document = xsltProcessor.transformToDocument(xml);
}
But, the new tab is not filled with anything.
Firefox console display no problem.
Where is the problem?
What I can do?

Last edited by chameleon; August 31st, 2009 at 10:47 AM..
 
Old August 31st, 2009, 11:11 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't think you can assign to the document property.
Why can't you simply let the browser do its XSLT transformation and put an xml-stylesheet processing instruction into your XML document e.g.
Code:
<?xml-stylesheet type="text/xsl" href="print.xsl.php"?>
then do a window.open("file.xml")?
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 31st, 2009, 11:17 AM
Authorized User
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Martin Honnen View Post
I don't think you can assign to the document property.
Why can't you simply let the browser do its XSLT transformation and put an xml-stylesheet processing instruction into your XML document e.g.
Code:
<?xml-stylesheet type="text/xsl" href="print.xsl.php"?>
then do a window.open("file.xml")?
Because I don't want a standalone page and because I change XSLT nodes with javascript.
 
Old August 31st, 2009, 12:07 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I don't think you can assign a complete document object to a window to have it rendered.
What you can try is serializing the transformation result and document.writing it to the new window:
Code:
var win = window.open('', 'windowName');
win.document.open();
win.document.write(new XMLSerializer().serializeToString(xsltProcessor.transformToDocument(xml)));
win.document.close();
That however is a pretty awful approach as the transformation result is first serialized as XML and then document.written and that way parsed as text/html.

What you should use is transformToFragment, passing in the document of an already existing window or frame as the second argument, and then you can appendChild the fragment returned by transformToFragment to a node (e.g. the body element) in the existing document.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 31st, 2009, 02:19 PM
Authorized User
 
Join Date: Aug 2009
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Martin Honnen View Post
I don't think you can assign a complete document object to a window to have it rendered.
What you can try is serializing the transformation result and document.writing it to the new window:
Code:
var win = window.open('', 'windowName');
win.document.open();
win.document.write(new XMLSerializer().serializeToString(xsltProcessor.transformToDocument(xml)));
win.document.close();
That however is a pretty awful approach as the transformation result is first serialized as XML and then document.written and that way parsed as text/html.

What you should use is transformToFragment, passing in the document of an already existing window or frame as the second argument, and then you can appendChild the fragment returned by transformToFragment to a node (e.g. the body element) in the existing document.
your solution works.
I prefer an xhtml solution instead of html, but first of all I prefer my page to work.
Thanks!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Communication between a parent window and a modal dialog window swizz182g Javascript 0 August 27th, 2009 04:41 PM
How to create 2 Frames in a Single window+Java kotaiah Java Basics 0 August 13th, 2007 10:07 AM
Centering Popup window & Blur Parent window jkusmanto Javascript How-To 0 May 25th, 2007 03:19 AM
Close Parent window on opening child window pkdev Javascript How-To 8 April 11th, 2004 12:06 PM
How to create a custom window shape lotfi VS.NET 2002/2003 1 November 17th, 2003 08:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.