473,324 Members | 2,268 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to XslTransform.Transform to new web page from code behind?

I'm working with a typed dataset and want to implement a print button that
prints my formatted data without the company logo and other stuff on the
form. I've created an XSLT file to transform the XML version of the dataset
into HTML and would like to display it in a new browser window leaving the
original window up and/or maybe even just send it out to the default printer
or bring up the print dialog for printing out the web page. I have
successfully saved the html file, but I'm not sure how to send to a new
browser window instead of a file. Please help, code below:

XmlDataDocument xmlDoc = new XmlDataDocument(dsAffidavit);
XslTransform xslTran = new XslTransform();
xslTran.Load(Server.MapPath("Affidavit.xslt"));
XmlTextWriter writer = new
XmlTextWriter(@"C:\tmp\Printout.htm,System.Text.En coding.UTF8);
xslTran.Transform(xmlDoc,null,writer);

John Holmes
jo****@co.skagit.wa.us
Nov 18 '05 #1
3 2774
This works and is great, but I'd like to have it come up in a new browser
window if possible. Everything I've read about the Response object says it's
associated with the current page and I'm not sure how I would open in a new
window. I know how to do this with the javascript window.open method, but
not sure how to do that with c# code behind.

Thanks,

John

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:6o**************@cpmsftngxa06.phx.gbl...
Hi Join,

Thanks for posting in the community!
From your description, you used a xsl style sheet to transform a certain
DataSet into a html stream. You've successfuly outputing the html stream
into a html file on the harddisk. HOwever, now you'd like to directly
output it to the response's content, yes?

As for this question, I think you can make use of the "Response.Output"
member, it is a TextWriter, which enable use to write text into the output
response stream. For example,

-----------------------
XmlDataDocument xmlDoc = new XmlDataDocument(ds);
XslTransform xslTran = new XslTransform();
xslTran.Load(Server.MapPath("simple.xslt"));
//XmlTextWriter writer = new
XmlTextWriter(Response.out,System.Text.Encoding.UT F8);
XPathNavigator nav = xmlDoc.CreateNavigator();

Response.ClearContent();
Response.Clear();

xslTran.Transform(nav,null,Response.Output,null);

Response.End();

------------------------

Also, I've attached a sample page in this message to show this means.
Please refer to it if you feel anything unclear. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #2
John Holmes wrote:
xslTran.Transform(xmlDoc,null,writer);


Transform directly to the Response output stream.

--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com
Nov 18 '05 #3
Hi John,

Thanks for your response. As for opening a new browser window. This is only
possible to do in clientside script. The serverside code is unable to
perform such function. Generally we used the "Page.RegisterStartupScript()"
function to register a clientside script such as "window.open(..)" at
runtime to simulate the effect. As for your siutation, I think you need to
also register a certain clientside script to open a new browser window at
client. You may build a certain page which only used to show the html
transformed from DataSet. You can used some querystring param in this page
to determine whch datatable to use or how to generate the DataSet and then
use the code we discussed in former messages to transform it and display in
the page.

In addition, if you do think it necessary to generate the dataset in the
original page's postback event, then, you need to store the result dataset
in a session member , and then retrieve it again from the session and
display it. Do you think so?
If you have any other ideas or questions ,please feel free to post here.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Holmes | last post by:
I'm working with a typed dataset and want to implement a print button that prints my formatted data without the company logo and other stuff on the form. I've created an XSLT file to transform the...
2
by: Graham Pengelly | last post by:
Hi I am trying to transform on System.Xml.XmlDocument into another using XslTransform without writing the object out to a file. I am guessing it should work something like this... public...
3
by: Steve | last post by:
Is there any way of specifying the startMode when using the xslTransform class? We are updating code which used msxml to the system.xml classes but can find no way to specify the startMode. We...
1
by: Franck | last post by:
Hi, Getting crazy with the XslTransform Class. I'm trying to transform an xml string with an xsl string with the following code : 'Create the XslTransform object and load the stylesheet. Dim...
4
by: Sean Hoffman | last post by:
Framework 1.1 SP1. Page.xml is about 1.5mg. m_oXSLTransform.Transform takes about 2 minutes. When Page.xml is trimmed down to a smaller doc, it takes about 2 seconds. Same code ran in about...
4
by: David S. Alexander | last post by:
I am trying to transform XML to XML using an XSLT in C#, but the root node of my XML is not being matched by the XSLT if it has an xmlns attribute. Am I handling my namespaces incorrectly? My C#...
1
by: rmgalante | last post by:
Hello, I have a VB.Net component that uses the XslTransform object. I am using the FXSL randomizeList function in my XSL template. When I transform the XML in the VB.Net component, my...
12
by: InvalidLastName | last post by:
We have been used XslTransform. .NET 1.1, for transform XML document, Dataset with xsl to HTML. Some of these html contents contain javascript and links. For example: // javascript if (a &gt; b)...
9
by: WT | last post by:
Hello, I have code created with .net 1.0 and migrated to 3.5. Form 2.0 the XslTransform class is obsolete and the vs2008 compiler generates warnings that these classes are absolete suggesting to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.