Discussion:
saving xslt transform output to file???
(too old to reply)
Thomas Blome
2003-09-25 18:29:52 UTC
Permalink
Hi,
I' m converting some xml-data into a html-file using xslt.
I do this using javascript in another html-page by creating Msxml2-objects.
My problem now is that I can't seem to figure out how to save my
xsl-processor output to the filesystem.
I can load the xml- and xsl- files from disk, but I also want to save my
html-output.

Example:
function Test(){
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("sample.xsl");
xslt.stylesheet = xslDoc;

xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("books.xml");

xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
alert(xslProc.output); // --> I want to save this as a html-file!
}
I don't want to use the Scripting.FileSystemObject, because I don't want
those annoying ActiveXObject-warnings to pop up.
Can anybody help?

Thanks in advance
Thomas
Joe Fawcett
2003-09-26 10:09:51 UTC
Permalink
Post by Thomas Blome
Hi,
I' m converting some xml-data into a html-file using xslt.
I do this using javascript in another html-page by creating
Msxml2-objects.
Post by Thomas Blome
My problem now is that I can't seem to figure out how to save my
xsl-processor output to the filesystem.
I can load the xml- and xsl- files from disk, but I also want to save my
html-output.
function Test(){
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("sample.xsl");
xslt.stylesheet = xslDoc;
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("books.xml");
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
alert(xslProc.output); // --> I want to save this as a html-file!
}
I don't want to use the Scripting.FileSystemObject, because I don't want
those annoying ActiveXObject-warnings to pop up.
Can anybody help?
Thanks in advance
Thomas
You can't save to a file on the client without the ActiveX warning unless
you have low security settings for the relevant zone.
The most generic output class would probably be ADODB.Stream which can be
saved to file. It doesn't mind wheteher your output is xml, text or binary
unlike the DomDocument or FileSystemObect might.

--

Joe
Thomas Blome
2003-09-27 07:44:52 UTC
Permalink
Thanks for the hint, Joe.
If I understand the documentation right, the objXSLProcessor.output property
can also be an ADODB.Stream object.
Than that would be in code:
...
var AdoStreamOut = new ActiveXObject("ADODB.Stream");
AdoStreamOut = xslProc.output;
AdoStreamOut.SaveToFile("C:\\Test.svg", 1);

This does not work though, maybe because I have to open the Stream object
explicitly before using the 'SaveToFile' method? The problem is how do I
open it, the source is neither a URL or a record. I tried all the
possibilities that I could think of - where am I going wrong?
Thanks

Thomas
Post by Thomas Blome
Post by Thomas Blome
Hi,
I' m converting some xml-data into a html-file using xslt.
I do this using javascript in another html-page by creating
Msxml2-objects.
Post by Thomas Blome
My problem now is that I can't seem to figure out how to save my
xsl-processor output to the filesystem.
I can load the xml- and xsl- files from disk, but I also want to save my
html-output.
function Test(){
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("sample.xsl");
xslt.stylesheet = xslDoc;
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("books.xml");
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
alert(xslProc.output); // --> I want to save this as a html-file!
}
I don't want to use the Scripting.FileSystemObject, because I don't want
those annoying ActiveXObject-warnings to pop up.
Can anybody help?
Thanks in advance
Thomas
You can't save to a file on the client without the ActiveX warning unless
you have low security settings for the relevant zone.
The most generic output class would probably be ADODB.Stream which can be
saved to file. It doesn't mind wheteher your output is xml, text or binary
unlike the DomDocument or FileSystemObect might.
--
Joe
Joe Fawcett
2003-09-27 10:19:33 UTC
Permalink
Post by Thomas Blome
Thanks for the hint, Joe.
If I understand the documentation right, the objXSLProcessor.output property
can also be an ADODB.Stream object.
...
var AdoStreamOut = new ActiveXObject("ADODB.Stream");
AdoStreamOut = xslProc.output;
AdoStreamOut.SaveToFile("C:\\Test.svg", 1);
You need to set the steram the other way around:
var AdoStreamOut = new ActiveXObject("ADODB.Stream");
AdoStreamOut .open()
xslProc.output = AdoStreamOut;
xslProc.transform();
AdoStreamOut.saveToFile("myFile.txt");
AdoStreamOut.close();
--
Joe
David Carnes
2003-09-26 18:07:26 UTC
Permalink
Thomas:
Take a look at the transformNodeToObject method. Basically, you take an XML
document, tell it which stylesheet to use, and where to place the resulting
transformation, which is another XML document. Then you could do .Save(), I
suppose.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xml_mth_sz_2jp0.asp?frame=true

I've even sent the result back to the original:
(in javascript)
xmlEditData.transformNodeToObject(xslSort, xmlTemp);
xmlEditData.loadXML(xmlTemp.xml);

HTH!
Dave
Thomas Blome
2003-09-27 09:38:35 UTC
Permalink
David, using the transformNodeToObject method works fine, but when I'm
trying to save the object to the local file system I receive a 'permission
denied' error.
Basically all I'm trying to do is to take a xml-input file, use a
xsl-transform file and save the resulting output file to the file system.
When you use the commandline, this is the easiest thing to do, you just
supply the parameters. It should also be possible to do this using script in
a html-page...
Any ideas???

Thomas
Post by David Carnes
Take a look at the transformNodeToObject method. Basically, you take an XML
document, tell it which stylesheet to use, and where to place the resulting
transformation, which is another XML document. Then you could do .Save(), I
suppose.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/
xml_mth_sz_2jp0.asp?frame=true
Post by David Carnes
(in javascript)
xmlEditData.transformNodeToObject(xslSort, xmlTemp);
xmlEditData.loadXML(xmlTemp.xml);
HTH!
Dave
Joe Fawcett
2003-09-27 10:19:32 UTC
Permalink
Post by Thomas Blome
David, using the transformNodeToObject method works fine, but when I'm
trying to save the object to the local file system I receive a 'permission
denied' error.
Basically all I'm trying to do is to take a xml-input file, use a
xsl-transform file and save the resulting output file to the file system.
When you use the commandline, this is the easiest thing to do, you just
supply the parameters. It should also be possible to do this using script in
a html-page...
Any ideas???
Thomas
As I said you can't save to the client under standard security settings.
What security zone will the page run under (right hand side of IE status
bar)?
--
Joe
Philo Del Middleston
2003-09-26 19:45:40 UTC
Permalink
If these are one-time transformations, why not use msxsl or saxon from the
command line?
Post by Thomas Blome
Hi,
I' m converting some xml-data into a html-file using xslt.
I do this using javascript in another html-page by creating
Msxml2-objects.
Post by Thomas Blome
My problem now is that I can't seem to figure out how to save my
xsl-processor output to the filesystem.
I can load the xml- and xsl- files from disk, but I also want to save my
html-output.
function Test(){
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("sample.xsl");
xslt.stylesheet = xslDoc;
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("books.xml");
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
alert(xslProc.output); // --> I want to save this as a html-file!
}
I don't want to use the Scripting.FileSystemObject, because I don't want
those annoying ActiveXObject-warnings to pop up.
Can anybody help?
Thanks in advance
Thomas
Thomas Blome
2003-09-27 07:52:38 UTC
Permalink
Hi Philo,
these are not one-time transformations. To clarify what I'm trying to do:
I have a html-frameset with a navigation frame and a content frame. The user
selects settings from the navigation frame and I send those settings as
parameters to an xslt file that transforms an xml file into html which is
then displayed in the content frame. So far so easy.
I am also displaying an svg-graphic within the resulting html file. The
svg-graphic is also generated by a xslt file which uses the parameters from
the navigation frame on transforming the underlying xml file.
This is mainly why I want to save xslt-transform output to disk and why I
can't just use msxml on the command line.
Post by Philo Del Middleston
If these are one-time transformations, why not use msxsl or saxon from the
command line?
Post by Thomas Blome
Hi,
I' m converting some xml-data into a html-file using xslt.
I do this using javascript in another html-page by creating
Msxml2-objects.
Post by Thomas Blome
My problem now is that I can't seem to figure out how to save my
xsl-processor output to the filesystem.
I can load the xml- and xsl- files from disk, but I also want to save my
html-output.
function Test(){
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("sample.xsl");
xslt.stylesheet = xslDoc;
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("books.xml");
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
alert(xslProc.output); // --> I want to save this as a html-file!
}
I don't want to use the Scripting.FileSystemObject, because I don't want
those annoying ActiveXObject-warnings to pop up.
Can anybody help?
Thanks in advance
Thomas
Oleg Tkachenko
2003-09-29 08:34:18 UTC
Permalink
Post by Thomas Blome
I have a html-frameset with a navigation frame and a content frame. The user
selects settings from the navigation frame and I send those settings as
parameters to an xslt file that transforms an xml file into html which is
then displayed in the content frame. So far so easy.
I am also displaying an svg-graphic within the resulting html file. The
svg-graphic is also generated by a xslt file which uses the parameters from
the navigation frame on transforming the underlying xml file.
This is mainly why I want to save xslt-transform output to disk and why I
can't just use msxml on the command line.
Actually you can embed SVG into HTML effectively avoiding saving file to the
client disk.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
Philo Del Middleston
2003-09-29 15:45:59 UTC
Permalink
You can't stream the stuff straight back to the browser? Can you use a
document() call in the HTML transform to do the SVG transform and embed it
in the output? Could you do two transforms with two DOMS and then stuff the
SVG nodes into the HTML DOM, then stream the HTML output to the client and
avoid writing anything to disk?

HTA's will only work on the client machine, and Norton Antivirus will
complain every time your user attempts to open them. Is this a web
application, or a standalone, disk based deployment?
Post by Thomas Blome
Hi Philo,
I have a html-frameset with a navigation frame and a content frame. The user
selects settings from the navigation frame and I send those settings as
parameters to an xslt file that transforms an xml file into html which is
then displayed in the content frame. So far so easy.
I am also displaying an svg-graphic within the resulting html file. The
svg-graphic is also generated by a xslt file which uses the parameters from
the navigation frame on transforming the underlying xml file.
This is mainly why I want to save xslt-transform output to disk and why I
can't just use msxml on the command line.
Post by Philo Del Middleston
If these are one-time transformations, why not use msxsl or saxon from the
command line?
Post by Thomas Blome
Hi,
I' m converting some xml-data into a html-file using xslt.
I do this using javascript in another html-page by creating
Msxml2-objects.
Post by Thomas Blome
My problem now is that I can't seem to figure out how to save my
xsl-processor output to the filesystem.
I can load the xml- and xsl- files from disk, but I also want to save my
html-output.
function Test(){
var xslt = new ActiveXObject("Msxml2.XSLTemplate.4.0");
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.4.0");
var xslDoc = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var xslProc;
xslDoc.async = false;
xslDoc.resolveExternals = false;
xslDoc.load("sample.xsl");
xslt.stylesheet = xslDoc;
xmlDoc.async = false;
xmlDoc.resolveExternals = false;
xmlDoc.load("books.xml");
xslProc = xslt.createProcessor();
xslProc.input = xmlDoc;
xslProc.transform();
alert(xslProc.output); // --> I want to save this as a html-file!
}
I don't want to use the Scripting.FileSystemObject, because I don't want
those annoying ActiveXObject-warnings to pop up.
Can anybody help?
Thanks in advance
Thomas
Thomas Blome
2003-09-29 23:24:44 UTC
Permalink
I didn't realize, I could embed my .svg files directly into the HTML stream.
So no more need to save anything to disk :-)

Thanks
Philo Del Middleston
2003-10-01 22:36:50 UTC
Permalink
Post by Thomas Blome
I didn't realize, I could embed my .svg files directly into the HTML stream.
So no more need to save anything to disk :-)
Thanks
Well, it may be harder than it looks... but the spec says:
Philo Del Middleston
2003-10-01 22:38:21 UTC
Permalink
Post by Thomas Blome
I didn't realize, I could embed my .svg files directly into the HTML stream.
So no more need to save anything to disk :-)
Thanks
Well, it may be harder than it looks, but the spec says:

Embedding inline

In this case, SVG content is embedded inline directly within the parent Web
page. An example is an XHTML Web page with an SVG document fragment
textually included within the XHTML.

http://www.w3.org/TR/SVG/concepts.html

Dimitre Novatchev
2003-09-27 09:57:58 UTC
Permalink
Post by Thomas Blome
Hi,
I' m converting some xml-data into a html-file using xslt.
I do this using javascript in another html-page by creating
Msxml2-objects.
Post by Thomas Blome
My problem now is that I can't seem to figure out how to save my
xsl-processor output to the filesystem.
I can load the xml- and xsl- files from disk, but I also want to save my
html-output.
The answer is simple: This is not allowed!!!

It should not be possible for the script of an html page to save to a file
on a client computer. Otherwise people would not have to write virusses.

In case you're using this html page locally (from a local file but not from
a server), you may want to read about the so called html application (hta)
and develop and deploy this as html application.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
Thomas Blome
2003-09-27 13:44:55 UTC
Permalink
Thanks for all the input.
I guess my best bet is to look into hta's.

Cheers
Thomas
Loading...