2

I want to Transform xml using xslt and create new File instead of the set value xmlcontrol in Visual Studio. Below is My code. I need to create a new XML Transformed File Called tr.xml file in My root directory.

  System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            doc.Load(Server.MapPath("hotels.xml"));
            System.Xml.Xsl.XslTransform trans = new
               System.Xml.Xsl.XslTransform();
            trans.Load(Server.MapPath("hotel.xsl"));
            Xml1.Document = doc;
            Xml1.Transform = trans;

Can Any one please help on this??/

1

1 Answer 1

4

If you want to transform an input file to an output file with XSLT 1.0 in .NET 2.0 and later then you should use XslCompiledTransform and it is as easy as

XslCompiledTransform proc = new XslCompiledTransform();
proc.Load(Server.MapPath("hotels.xsl"));

proc.Transform(Server.MapPath("hotels.xml"), Server.MapPath("tr.xml"));

See http://msdn.microsoft.com/en-us/library/0610k0w4.aspx for a detailed documentation of XslCompiledTransform and its possible inputs and outputs.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.