<p>I'd like to do the following and can't find an elegant way:</p>

<ol>
<li>Read an XML template into a <code>System.Xml.XmlDocument</code>  </li>
<li>Populate it with data from my UI  </li>
<li>Transform it with an <code>XSLT</code> I've written  </li>
<li>Apply a <code>CSS</code> Stylesheet  </li>
<li>Render it to a <code>WebBrowser</code> control </li>
</ol>

<p>I'm currently reading it from a file on disk, populating it, then saving it back out to disk after populating it. I reference the <code>XSLT</code> in the template, and the <code>CSS</code> in the <code>XSLT</code> and then use the <code>WebBrowser.Navigate([filename])</code> method to display the XML file.</p>

<p>Obviously, when I come to deploy this app, it'll break horribly as the file won't exist on disk, and I won't be able to reference the <code>XSLT</code> and <code>CSS</code> files in the <code>XML</code> file as they'll be resources. I'm planning to include the template as a resource, but can't find a neat way to proceed from there.</p>

<p>Any help much appreciated</p>

[{'answer_id': 37940, 'author': 'Vaibhav', 'author_id': 380, 'author_profile': 'https://Stackoverflow.com/users/380', 'pm_score': 1, 'selected': False, 'text': "<p>Quick question. Why do you need an Xml template? If you already know the schema before hand, then simply generate the complete Xml in your code. There shouldn't be a need for loading a template file.</p>\n"}, {'answer_id': 38024, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 0, 'selected': False, 'text': '<p>Check out <a href="http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx" rel="nofollow noreferrer">Linq to XML</a> - it\'s really good way to write and read Xml based data. Easier than the System.Xml.XmlDocument mechanisms.</p>\n\n<p>Given that you are supplying the XSLT and the CSS, why not build the page in XHTML and inline the CSS? Alternatively just add the XSLT and CSS files as content in your installer.</p>\n\n<p>Compiled help actually does something like what you\'re describing - you can copy a link from a CHM file and visit it with a normal browser. I suppose you could embed your display resources in a help file, depending on how they\'re used.</p>\n'}, {'answer_id': 38130, 'author': 'Jon Artus', 'author_id': 4019, 'author_profile': 'https://Stackoverflow.com/users/4019', 'pm_score': 1, 'selected': False, 'text': "<p>Thanks for the link Keith, I'll have a look at that out of interest, as LINQ is on my list of things to learn. Unfortunately, I need to target .Net 2.0 for this app, so I think (please correct me if I'm wrong!) that LINQ is out of the question. </p>\n\n<p>I've now included the CSS in the header of the XSLT, and I've found a way to use a System.Xml.Xsl.XslCompiledTransform object to transform the XML in memory. I'm currently using the WebBrowser.DocumentText property to pass the formatted XML into the WebBrowser componenet and this seems to work.</p>\n\n<p>I can't help thinking that this isn't the best way of doing things, so any comments on better ways would be appreciated. In particular, if I were using LINQ, would I need a schema to bind to, and also, should I have a schema full-stop? I'm not great with XML, but I like Vaibhav's idea of generating straight from a schema rather than using a template. I'm just not sure where to start, so any pointers appreciated!</p>\n"}, {'answer_id': 165236, 'author': 'rasx', 'author_id': 22944, 'author_profile': 'https://Stackoverflow.com/users/22944', 'pm_score': 0, 'selected': False, 'text': '<p>Because you are using the WebBrowser control and <em>not</em> WPF you <em>must</em> depend on the disk for loading the CSS file you mention in Step 4. The only way around this is to use a tool like <a href="http://rpi.net.au/~ajohnson/resourcehacker" rel="nofollow noreferrer">Resource Hacker</a> to load "unmanaged" resources and use the <strong>res://</strong> protocol (<a href="http://msdn.microsoft.com/en-us/library/aa767740(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa767740(VS.85).aspx</a>) for some real Microsoft 1990s nostalgia.</p>\n\n<p>You will still need to get your data into HTML elements. The code sample that follows might help to answer something:</p>\n\n<pre><code>void WireUpBrowserEvents()\n{\n\n    HtmlElement table = this._browser.Document.GetElementById( "UnitFormsTable" );\n    if ( table != null )\n    {\n        HtmlElementCollection thead = table.GetElementsByTagName( "thead" );\n        if ( ( thead != null ) &amp;&amp; ( thead.Count == 1 ) )\n        {\n            HtmlElementCollection links = thead[0].GetElementsByTagName( "a" );\n            if ( ( links != null ) &amp;&amp; ( links.Count &gt; 0 ) )\n            {\n                foreach ( HtmlElement a in links )\n                {\n                    a.Click += new HtmlElementEventHandler( XslSort_Click );\n                }\n            }\n        }\n    }\n}\n\nvoid XslSort_Click( object sender, HtmlElementEventArgs e )\n{\n    e.ReturnValue = false;\n\n    if ( this._xslSortWorker.IsBusy ) return;\n\n    if ( sender is HtmlElement )\n    {\n        HtmlElement a = sender as HtmlElement;\n        this._browser.Hide();\n        this._browserMessage.Visible = true;\n        this._browserMessage.Refresh();\n        this._xslSortWorker.RunWorkerAsync( a.Id );\n    }\n}\n</code></pre>\n\n<p>You may already be aware that HtmlElement and HtmlElementCollection are in the System.Windows.Forms namespace. These remarks may not be helpful but I tried:)</p>\n'}]
['https://Stackoverflow.com/questions/37932', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4019/']