JL.
JL.

Reputation: 81262

XSLT and XML Question

I have this kinda interesting requirement.

Typically you use XSLT to transform an XML document. The transformed HTML is viewable in a web browser, this works just great. I am also guessing the browser handles the transformation in memory, because if you view the page source of an xml document with XSLT, you don't see html, only xml.

What I would like to do is the following.

using c#

  1. grab an xml file from the fileSystem.... Load it into some framework object
  2. attach an XSLT stylesheet
  3. output the rendered HTML back to an html file on the file system.

Is this possible.

I don't expect a full answer on the entire solution. Just a push in the right direction would be great :) thanks in advance.

Upvotes: 0

Views: 267

Answers (3)

ariso
ariso

Reputation: 1443

what if the html is a invaild format xml?

it looks like we can not use xslt?

Any feedbacks?

Upvotes: 0

RichieHindle
RichieHindle

Reputation: 281475

You can use System.Xml.Xsl to do XSLT in C#.

There's an article here: XML transformation using Xslt in C# that explains how - here's the core of it:

XPathDocument myXPathDoc = new XPathDocument(<xml file path>);
XslTransform myXslTrans = new XslTransform();
myXslTrans.Load(<xsl file path>);
XmlTextWriter myWriter = new XmlTextWriter("result.html", null);
myXslTrans.Transform(myXPathDoc, null, myWriter);

(Edit: Note to @John: that code illustrates the basic idea. It doesn't pretend to be production quality.)

Upvotes: 5

JL.
JL.

Reputation: 81262

So, I found the answer, and pretty quickly... Its all explained here... http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=63

Upvotes: 0

Related Questions