Ksice
Ksice

Reputation: 3327

C#: XML transformation

I have an XML-file with known structure, but I can't change anything on it. The task is to show data from this XML in browser (C# WebBrowser control) perhaps as html using some style sheet.

The question is how I could apply transform on existing XML without inserting anything like

 <?xml-stylesheet type="text/xsl" href="my-style.xsl"?>

I'm thinking of copy an XML somewhere, then add this xml-stylesheet and then show it in browser. But maybe I can dynamically apply style-sheet somehow?

Maybe it's possible to hold an XML in memory, apply style-sheet, and load in-memory xml to WebBrowser control?

I'm just wondering what is the best way for doing this...

Upvotes: 3

Views: 1509

Answers (2)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243449

See the XSLT transformation used by the XPath Visualizer to produce HTML-formatted XML document.

Alternatively you can also have a look at IE's defaultss.xsl stylesheet, but be aware that it uses a non-standard dialect of XSLT -- strictly speaking not XSLT at all.

Upvotes: 0

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56162

Sure, you can! Look at XslCompiledTransform class. So you can transform your XML in memory, then load transformed document.

Upvotes: 7

Related Questions