exporting DOM Transform output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sharon

    #1

    exporting DOM Transform output

    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 buttonExportCli ck()
    {
    var xslt = new ActiveXObject(' Msxml2.XSLTempl ate.3.0');
    var s = new ActiveXObject(' msxml2.FreeThre adedDOMDocument .3.0');
    s.async=false;
    s.load("/lib/xtable/convert.xsl");
    var xslProc;
    xslt.stylesheet = s;
    var xmlDoc = document.XMLDoc ument;
    if (xmlDoc==null)
    {xmlDoc=navigat or.XMLDocument} ;
    xslProc = xslt.createProc essor();
    xslProc.input = xmlDoc;
    xslProc.transfo rm();
    var output = xslProc.output;
    alert(output);
    }
  • Martin Honnen

    #2
    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 FileSystemObjec t 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/

    Comment

    • Sharon Steringa

      #3
      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!

      Comment

      • Martin Honnen

        #4
        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/

        Comment

        • Sharon Steringa

          #5
          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!

          Comment

          • Martin Honnen

            #6
            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/

            Comment

            • Sharon Steringa

              #7
              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 buttonExcelClic k()
              {
              var xslt = new ActiveXObject(' Msxml2.XSLTempl ate.3.0');
              var s = new ActiveXObject ('Msxml2.FreeTh readedDOMDocume nt.3.0');
              s.async=false;
              s.load("/lib/xtable/convert.xsl");
              var xslProc;
              xslt.stylesheet = s;
              var xmlDoc = document.XMLDoc ument;
              if (xmlDoc==null)
              {xmlDoc=navigat or.XMLDocument} ;
              alert(xmlDoc);
              xslProc = xslt.createProc essor();
              xslProc.input = xmlDoc;
              xslProc.transfo rm();
              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!

              Comment

              Working...