Solution
Use the System.Xml.Xsl.XslTransform class. Load the XSLT stylesheet using the XslTransform.Load method, and generate the output document by using the Transform method and supplying a source document.
xstl:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0" >
<xsl:template match="Order">
<html><body><p>
Order <b><xsl:value-of select="Client/@id"/></b>
for <xsl:value-of select="Client/Name"/></p>
<table border="1">
<td>ID</td><td>Name</td><td>Price</td>
<xsl:apply-templates select="Items/Item"/>
</table></body></html>
</xsl:template>
<xsl:template match="Items/Item">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="Name"/></td>
<td><xsl:value-of select="Price"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
xml:
<?xml version="1.0"?>
<Order id="2004-01-30.195496">
<Client id="ROS-930252034">
<Name>Remarkable Office Supplies</Name>
</Client>
<Items>
<Item id="1001">
<Name>Electronic Protractor</Name>
<Price>42.99</Price>
</Item>
<Item id="1002">
<Name>Invisible Ink</Name>
<Price>200.25</Price>
</Item>
</Items>
</Order>
the progrming:
using System;
using System.Windows.Forms;
using System.Xml.Xsl;
public class TransformXml : System.Windows.Forms.Form {
private AxSHDocVw.AxWebBrowser webBrowser;
// (Designer code omitted.)
private void TransformXml_Load(object sender, System.EventArgs e) {
XslTransform transform = new XslTransform();
// Load the XSL stylesheet.
transform.Load("orders.xslt");
// Transform orders.xml into orders.html using orders.xslt.
transform.Transform("orders.xml", "orders.html", null);
object var = null;
webBrowser.Navigate(
"file:///" + Application.StartupPath + @"\orders.html",
ref var, ref var, ref var, ref var);
}
}
The .NET Framework does not include any controls for rendering HTML content.
However, this functionality is available through COM interoperability
if you use the ActiveX Web browser control provided with Microsoft Internet
Explorer and the Microsoft Windows operating system. This window can
show local or remote HTML files, and supports JavaScript, VBScript,
and all Internet Explorer plug-ins.
![](mk:@MSITStore:C:\Documents%20and%20Settings\xhzhu\Desktop\CSharp%20Programmer's%20Cookbook.chm::/8351final/images/f05kp02.jpg)
:To add the Web browser to a project in Microsoft Visual Studio .NET, right- click the Toolbox and
choose Add/Remove Items. Then select the COM Components tab, and check the Microsoft Web Browser
control (shdocvw.dll). This will add the Microsoft Web Browser control to your Toolbox. When you
drop this control onto a form, the necessary interop assemblies will be generated and added to your
project.