<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="XmlToHtml" %>
Untitled Page
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Xml;
public partial class XmlToHtml : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string xslFile = Server.MapPath("Data.xslt");
string xmlFile = Server.MapPath("Data.xml");
string htmlFile = Server.MapPath("Data.htm");
XslTransform transf = new XslTransform();
transf.Load(xslFile);
transf.Transform(xmlFile, htmlFile);
XPathDocument xdoc = new XPathDocument(new XmlTextReader(xmlFile));
XPathNavigator xnav = xdoc.CreateNavigator();
XmlReader reader = transf.Transform(xnav, null);
reader.MoveToContent();
Response.Write(reader.ReadOuterXml());
reader.Close();
}
}
File: Data.xml
title 1
directory 2
1
star 1
star 2
title 2
directory 2
2
star 3
star 4
File: Data.xsl