Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > ASP.NET 1.x and 2.0 Application Design
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 4th, 2005, 07:51 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding XSLT transformed XML content dynamically

I am currently trying to figure out how I can add content to a web page, which has been transformed from an XML document into HTML by an XSLT document. The solution I have thought of looks like this...
Code:
        public static LiteralControl XmlFileTransform(string xmlfile, string xslfile)
        {
            XslTransform xslt;
            XPathDocument xml;
            StringWriter writer = new StringWriter();
            try
            {
                xml = new XPathDocument(new XmlTextReader(xmlfile));

                xslt = new XslTransform();
                xslt.Load(xslfile);
                xslt.Transform(xml, null, writer, null);

                return new LiteralControl(writer.ToString());
            }
            catch(Exception e)
            {
                writer.Write(e.Message);
            }
            return null;
        }
        Is there a better way?

In the above solution I turn the generated HTML into a LiteralControl and then return this. I am not sure if this is the best solution for adding the generated output to the page dynamically. What do you think?

Is it possible to make a transformation of part of a document? Say I have selected only one node and I have made an XSLT document that matches this one node.

Thanks, Jacob.
__________________
Danish audio books for download at http://www.lytenbog.dk (Danske lydbøger til download).
 
Old December 1st, 2005, 02:47 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

you can add an xml control to the page and it has properties to set the DocumentSource (the XML) and the TransformSource (the XSLT). it will automatically merge these two and push it to your page. You dont need to write any code for the transformation

Regards
Ganesh
 
Old December 1st, 2005, 04:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 440
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is cool, I just tried it out. Thanks. For some reasson unknown to myself I didn't know about that one, or rather this way to do it. It saves a lot of work.

Thanks, Jacob.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Switching list content dynamically ... asearle XSLT 1 September 24th, 2006 11:41 AM
Dynamically Changing the content of a table cell asdasd Javascript 4 February 18th, 2005 01:44 PM
Add XSLT transformed XML (html) on an aspx page humour XSLT 2 September 30th, 2004 05:13 AM
How to split pages when content load dynamically bekim Classic ASP Basics 0 August 5th, 2004 02:57 AM
adding content to an already loaded page adeptz Javascript 5 March 19th, 2004 06:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.