Using Xsl to transform data from Database : Xml transformation « XML « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Xsl;

public class XslTransformDataSet
{
    private static string connectionString = "Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI";

    public static void Main() 
    {
        string SQL = "SELECT TOP 5 * FROM Customers";

        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand com = new SqlCommand(SQL, con);
        SqlDataAdapter adapter = new SqlDataAdapter(com);
        DataSet ds = new DataSet("CustomerDataSet");

        con.Open();
        adapter.FillSchema(ds, SchemaType.Mapped, "Customers");
        adapter.Fill(ds, "Customers");
        con.Close();

        XmlDataDocument dataDoc = new XmlDataDocument(ds);

        XslTransform xsl = new XslTransform();
        xsl.Load("transform.xsl");
             
        xsl.Transform(dataDoc, null, Console.Out);
     }
}








30.26.Xml transformation
30.26.1.XML transformation with XPathDocument
30.26.2.Transform Extension
30.26.3.Transform XML document to a html document
30.26.4.Save XML transformation result to XmlWriter
30.26.5.Read xsl in an XmlTextReader
30.26.6.Use MemoryStream to hold the XmlTransform result
30.26.7.Using Xsl to transform data from Database
30.26.8.XSLT Transformation