Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
XPathDocument myXPathDoc = new XPathDocument(@"C:\aa.xml");
           XslTransform myXslTrans = new XslTransform();
           myXslTrans.Load(XSLTFile1);
           XmlTextWriter myWriter = new XmlTextWriter("result.html", null);
           myXslTrans.Transform(myXPathDoc, null, myWriter);
           XPathDocument myXPathDoc = new XPathDocument(@"C:\aa.xml");
           XslCompiledTransform myXslTrans = new XslCompiledTransform();
           myXslTrans.Load("XSLTFile1.xslt");
           XmlTextWriter myWriter = new XmlTextWriter("result.html", null);
           myXslTrans.Transform(myXPathDoc, null, myWriter);
Posted
Updated 21-Mar-13 7:01am
v3
Comments
joshrduncan2012 21-Mar-13 9:50am    
Are you getting any errors? Are you getting any output? What is your question?
ridoy 21-Mar-13 14:57pm    
So what is the problem with this code?
Kuthuparakkal 22-Mar-13 0:02am    
Added a solution please try.

1 solution

Try this:
C#
public void XslTransform(string xsltFileLocation, string xmlDocumentLocation, string DestinationFilepathName)
{

    //myXslTrans.Load(xsltFileLocation);
    using (MemoryStream ms = new MemoryStream())
    {
        Stream fs = File.OpenRead(xsltFileLocation);

        XPathDocument myXPathDoc = new XPathDocument(xmlDocumentLocation);
        XmlTextReader xtr = new XmlTextReader(fs);

        XslCompiledTransform myXslTrans = new XslCompiledTransform();
        myXslTrans.Load(xtr);

        myXslTrans.Transform(myXPathDoc, null, ms);
        ms.Flush();
        ms.Position = 0;

        FileStream fsNew = new FileStream(DestinationFilepathName, FileMode.Create, FileAccess.Write);
        byte[] bytes = new byte[ms.Length];
        ms.Read(bytes, 0, (int)ms.Length);
        fsNew.Write(bytes, 0, bytes.Length);
        fsNew.Close();
        ms.Close();
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900