Connecting Tech Pros Worldwide Forums | Help | Site Map

exporting DOM Transform output

Sharon
Guest
 
Posts: n/a
#1: Jul 23 '05
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);
}

Martin Honnen
Guest
 
Posts: n/a
#2: Jul 23 '05

re: exporting DOM Transform output




Sharon wrote:

[color=blue]
> 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![/color]

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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sharon Steringa
Guest
 
Posts: n/a
#3: Jul 23 '05

re: exporting DOM Transform output


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



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Martin Honnen
Guest
 
Posts: n/a
#4: Jul 23 '05

re: exporting DOM Transform output




Sharon Steringa wrote:

[color=blue]
> 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?[/color]

It is rather easy, to start save your file as whatever.hta instead of
whatever.html.
Then you can check the documentation on MSDN:
http://msdn.microsoft.com/library/de...node_entry.asp

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sharon Steringa
Guest
 
Posts: n/a
#5: Jul 23 '05

re: exporting DOM Transform output


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Martin Honnen
Guest
 
Posts: n/a
#6: Jul 23 '05

re: exporting DOM Transform output




Sharon Steringa wrote:
[color=blue]
> 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...[/color]

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.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Sharon Steringa
Guest
 
Posts: n/a
#7: Jul 23 '05

re: exporting DOM Transform output


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



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Closed Thread