"+ ....">
C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

How to send data from c# file(.cs) to xslt file


Posted Date: 02 Jul 2009      Posted By: kumar      Member Level: Gold     Points: 1   Responses: 4



have cretaed an xml fine

string myXml = "<email>"+
"<user_name>Kavita</user_name>"+
"<city_message>has successfully changed the passsword</city_message>" +
"</email>";

now i need to send string myXml as a input to xslt file
how to i send this data to xslt file

so that i can get the html from xslt file .
can any one help out syntax.

thank you

looking forward for ur help





Responses

Author: Sajid P K    03 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

pls chk

The steps to transform an Xml document are

1) Load the Xml document
XPathDocument myXPathDoc = new XPathDocument(<xml file path>) ;


2) Load the Xsl file
XslTransform myXslTrans = new XslTransform() ;
myXslTrans.Load(<xsl file path>);


3) Create a stream for output
XmlTextWriter myWriter = new XmlTextWriter("result.html",null) ;


4) Perform the actual transformation
myXslTrans.Transform(myXPathDoc,null,myWriter) ;

Do not forget to Rate the post...
Regards,
Sajid P K



Author: Robin Thomas    03 Jul 2009Member Level: GoldRating: 3 out of 53 out of 53 out of 5     Points: 3

I think you are confused with the use of XSLT. You are not "sending " data to XSLT. You are using XSLT to transform the XML into a different format.

What "saji" described is the perfect method for doing that. But just a small correction. Instead of XslTransform you can use XslCompiledTransform because XslTransform is deprecated.
Try this
private static string TranformXML(string xmlFile , string xsltFile)
{

StringBuilder resultString = new StringBuilder();

string FilePath = HttpContext.Current.Server.MapPath(XsltFolderPath + System.IO.Path.DirectorySeparatorChar + xsltFile).ToString();

//create an XPathDocument using the reader from the XML string
MemoryStream m = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(xmlFile));

XPathDocument xpathDoc = new XPathDocument(new StreamReader(m));

//Create the new transform object

XslCompiledTransform transform = new XslCompiledTransform();

//String to store the resulting transformed XML (Excel file)

XmlWriter writer = XmlWriter.Create(resultString);

transform.Load(FilePath); //Loading XSLT file.
transform.Transform(xpathDoc, writer); //Transforming the XML file

return resultString.ToString();

}

Robin Thomas
Freelancer
visit for fresher jobs



Author: Sajid P K    03 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

http://www.dotnetspider.com/resources/29895-XML-HTML-transformation-using-Xslt.aspx

Do not forget to Rate the post...
Regards,
Sajid P K



Author: kumar    03 Jul 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 2

hi
Robin Thomas your code works fine for me
thank you



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Comparing two dates in msaccess
Previous : How to display message box in asp.net application?its very urgent
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use