|
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Xsl;
namespace SampleProj
{
class DataTableToHTMLUsingXSLT
{
public void Table()
{
DataTable _logTable = new DataTable("LogTable");
_logTable.Columns.Add("Column1");
_logTable.Columns.Add("Column2");
_logTable.Rows.Add();
_logTable.Rows.Add();
_logTable.Rows[0][0] = "Col1";
_logTable.Rows[0][1] = "Col2";
_logTable.Rows[1][0] = "Col3";
_logTable.Rows[1][1] = "Col4";
XDocument htmlResult = new XDocument();
using (TextWriter stringWriter = new StringWriter())
{
_logTable.WriteXml(stringWriter);
XDocument originalXML = XDocument.Parse(stringWriter.ToString());
using (XmlWriter xmlWriter = htmlResult.CreateWriter())
{
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SampleProj.Default.xslt"))
{
using (XmlReader reader = XmlReader.Create(stream))
{
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(reader);
xslt.Transform(originalXML.CreateReader(), xmlWriter);
}
}
}
}
// Now do whatever with this html
string html = htmlResult.Document.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.