XSL Transformations using ASP.NET
This is actually a really good tutorial on getting started with XSLTransformations on .NET using ASP.NET. The one thing I would add to this would be to showcase the ability to pass parameters into the transformation when using the asp:Xml server-side control. For whatever reason that piece of information never seems to get propogated via tutorials or even the documentation. So in the extended portion of this post I’ll just post some code I have lying around that showcases how to do this. This article does a great job of explaining the ins and outs of XSLT via ASP.NET so I’ll just let the additional code sample speak for itself.
<%@ Page Trace="false" Language="C#" Debug="false" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Globalization" %>
<script runat="server">
string xmlSource = "index.xml";
string xslSource = "/gdc/home/index.xslt";
string defaultRSS = "content.rss";
DateTime dt = DateTime.Now;
void Page_Load(Object sender, EventArgs e)
{
if (Request.QueryString["xml"] != null) defaultRSS = Request.QueryString["xml"];
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath(xmlSource));
string date = dt.ToString("U", DateTimeFormatInfo.InvariantInfo);
XslTransform trans = new XslTransform();
trans.Load(Server.MapPath(xslSource));
XsltArgumentList xslArg = new XsltArgumentList();
xslArg.AddParam("defaultRSS", "", defaultRSS);
xslArg.AddParam("dateTime", "", date);
mainTransform.Document = doc;
mainTransform.Transform = trans;
mainTransform.TransformArgumentList = xslArg;
}
</script>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<asp:Xml id="mainTransform" runat="server"/>
TrackBack URL for this entry:
http://www.xsltblog.com/xslt-blog-mt/mt-tb.cgi/87