• « Interesting article on Business Intelligence that speaks to the use of XQuery for performing real-time queries of BI data
    • |
    • Main
    • |
    • Michael Kay compares XSLT and XQuery »
            • December 02, 2004

              XSLT and ASP.NET tutorial

            • 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"/>
              
            • Posted by m.david : December 2, 2004 08:23 PM GMT

            Trackback Pings

            TrackBack URL for this entry:
            http://www.xsltblog.com/xslt-blog-mt/mt-tb.cgi/87

            Comments

            Post a comment




            Remember Me?

            (you may use HTML tags for style)

          • © 2005 :: <XSLT:Blog/> (xsltblog.com) is a product of M. David Peterson and FunctionalX Consulting. See Licensing Info Below.
          • Except where otherwise noted, this sites content and source code is licensed under the Attribution License from Creative Commons.