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??/

4

1 回答 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.

于 2013-07-09T08:56:07.813 回答