exporting DOM Transform output

S

Sharon

Hi!
I'm trying to add an export option to my application. I use Javascript
DOM to transform XHTML-tables displayed in the browser window to
CSV-format (client-side) using a simple XSL. All works fine, except
that I can't seem to get any further than alerting the output
*sigh*... Who can give me hints on how to get the output to the client
somehow? Should I save it to the server first and then allow the
client to get it from there, or can I pass it directly back to the
client who pressed the export button and requested it? I tried writing
the output to a document and then do execCommand to let the client
save it but
1) I don't want the output in a new window, I just want the 'save as'
dialog to appear directly. But the execcommand method needs an object
e.g. the document and I don't know how to circumvent this...
2) the 'save as' dialog only allows me to save the output as *txt or
*html and does not have ANSI coding as an option. As a result, when I
save the file as html using the default coding (Unicode) and open it
in Excel all data are displayed in one column. I need ANSI. (When I
open the csv in Notepad and save it with ANSI coding it is displayed
correctly in Excel).
Who can give me a hint on what to do next? I'm desperately waiting for
your replies, TIA!

This is the DOM function:

function buttonExportClick()
{
var xslt = new ActiveXObject('Msxml2.XSLTemplate.3.0');
var s = new ActiveXObject('msxml2.FreeThreadedDOMDocument.3.0');
s.async=false;
s.load("/lib/xtable/convert.xsl");
var xslProc;
xslt.stylesheet = s;
var xmlDoc = document.XMLDocument;
if (xmlDoc==null)
{xmlDoc=navigator.XMLDocument};
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
var output = xslProc.output;
alert(output);
}
 
M

Martin Honnen

Sharon wrote:

I'm trying to add an export option to my application. I use Javascript
DOM to transform XHTML-tables displayed in the browser window to
CSV-format (client-side) using a simple XSL. All works fine, except
that I can't seem to get any further than alerting the output
*sigh*... Who can give me hints on how to get the output to the client
somehow? Should I save it to the server first and then allow the
client to get it from there, or can I pass it directly back to the
client who pressed the export button and requested it? I tried writing
the output to a document and then do execCommand to let the client
save it but
1) I don't want the output in a new window, I just want the 'save as'
dialog to appear directly. But the execcommand method needs an object
e.g. the document and I don't know how to circumvent this...
2) the 'save as' dialog only allows me to save the output as *txt or
*html and does not have ANSI coding as an option. As a result, when I
save the file as html using the default coding (Unicode) and open it
in Excel all data are displayed in one column. I need ANSI. (When I
open the csv in Notepad and save it with ANSI coding it is displayed
correctly in Excel).
Who can give me a hint on what to do next? I'm desperately waiting for
your replies, TIA!

What you have is IE/Win or even IE 6/Win only as you are using MSXML 3.
If you know that you only have such clients then maybe you can write an
HTA( HTML application) where you then have access to object like
ADODB.Stream or the FileSystemObject to save the result directly on the
client.
If not then it seems better to use the server to to the transformation
and save it back to the client.
 
S

Sharon Steringa

Yes, thanks, I have read about that. However the information I found was
not very clear and I don't exactly know how I should go about that.
Could you give me a hint or perhaps even show me an example on how to do
this HTA thing?
TIA, Sharon
 
S

Sharon Steringa

Thanks Martin, but what exactly should be saved as *.hta? I'm not saving
anything as *.html to begin with so I'm not really getting this... :S
Sharon
 
M

Martin Honnen

Sharon said:
Thanks Martin, but what exactly should be saved as *.hta? I'm not saving
anything as *.html to begin with so I'm not really getting this...

Your HTML documents are not saved as for instance page.html (or page.htm)?
These documents need to be saved as page.hta so they are treated as HTML
applications.
 
S

Sharon Steringa

Nope, they aren't. They are dynamically generated out of XML records
(also generated from a db) into neat pages with HTML tables, using XSL.
They are never saved. Now I have added an 'export' button so that users
can export whatever table they have displayed in their browsers at that
moment.
What I'm trying at the moment is to have the 'export' button open a
HTA-page. In the HTA page I have a BODY onload call the aforementioned
function that transforms to CSV:

function buttonExcelClick()
{
var xslt = new ActiveXObject('Msxml2.XSLTemplate.3.0');
var s = new ActiveXObject ('Msxml2.FreeThreadedDOMDocument.3.0');
s.async=false;
s.load("/lib/xtable/convert.xsl");
var xslProc;
xslt.stylesheet = s;
var xmlDoc = document.XMLDocument;
if (xmlDoc==null)
{xmlDoc=navigator.XMLDocument};
alert(xmlDoc);
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
var output = xslProc.output;
alert(output);
}

But of course, the var xmlDoc returns 'undefined', since the HTA
document contains no XMLDocument > I need the XMLDocument from the
browser window that is still open. How do I call/address this browser
window? Hope you can help me!Sharon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top