XML
  Home arrow XML arrow Page 3 - XSL Transformations using ASP.NET
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XSL Transformations using ASP.NET
By: Harish Kamath
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 23
    2004-11-30

    Table of Contents:
  • XSL Transformations using ASP.NET
  • Start it up
  • Dynamic transformation
  • Jumping higher
  • Code dissection
  • Publish or you will perish
  • To err is human

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    XSL Transformations using ASP.NET - Dynamic transformation


    (Page 3 of 7 )

    The first example is about as simple as it gets when it comes to using ASP.NET for XSL Transformations. Next, I will attempt to make things dynamic - take a look at the next two examples that re-use the ASP.NET "Xml" server control; each introducing its own new, little twist.

    <%@ Page Language="C#" %>
    <SCRIPT runat="server">

    void Page_Load() {

    output.DocumentSource = "articles.xml";
    output.TransformSource = "articles.xsl";
    }

    </SCRIPT>
    <HTML>
    <HEAD>
        <TITLE>ASPFree.com</TITLE>
        <BASEFONT face="Arial" size="2">
    </HEAD>
    <BODY>
        <asp:Xml id="output" runat="server" />
    </BODY>
    </HTML>

    If you have been using ASP.NET server controls for some time, you will already know that it is possible to ssign values to the attributes of a server control by invoking them as properties of the same .NET object at run time.

    Confused? Let me review quickly.

    Behind the scenes in the .NET environment, I can safely state that "everything is an object." Consider the ASP.NET "Xml" server control used in all my examples so far. Under the hood, this control is an instance of the "System.Web.UI.WebControls.Xml" class, equipped with its own set of properties and methods. This means that you can specify values for the attributes of the server control by simply assigning those values to the corresponding properties of the underlying class.

    This is exactly what I have done in the second example - I have assigned values to the "DocumentSource" and "TransformSource" properties of the local instance of the "System.Web.UI.WebControls.Xml" class at run time. This modification allows me to drop the definitions of the "DocumentSource" and "TransformSource" attributes from within the <asp:Xml> element and thereby make the process of XSL Transformation more dynamic.

    The next example demonstrates another manner in which this <asp:Xml> element can be used:

    <%@ Page Language="C#" %>
    <HTML>
    <HEAD>
        <TITLE>ASPFree.com</TITLE>
        <BASEFONT face="Arial" size="2">
    </HEAD>
    <BODY>
    <asp:Xml id="output" runat="server" TransformSource="articles.xsl" >
    <article id="110">
                <title>Implementing XSL Transformations with ASP.NET</title>
                <author>Harish R. Kamath</author>
                <category>ASP.NET</category>
                <abstract>Leverage on the built-in functionality available in ASP.NET to transform your XML documents using XSL Transformations!</abstract>
    </article>
    </asp:Xml>
    </BODY>
    </HTML>

    While the output (for the third example) remains the same as that for the first two, the noteworthy difference is the manner in which the XML content has been provided to the "Xml" server control. Instead of the customary use of the "DocumentSource" attribute (or property), you will notice that I have chosen to enclose the XML text within the <asp:Xml> element.

    This ability to enclose the raw XML between start and end elements of the <asp:Xml> element allows me to change the source of XML data with great ease. This technique is useful if I do not have the XML data in a flat file, but I have to generate it dynamically - say, from a database, or by combining multiple XML documents into a single file at run time. In case of the former, I can easily connect to a database, build the entire XML structure in memory and spit it out between the <asp:Xml> elements. Then, the .NET compiler takes over - it loads the associated XSLT style sheet, applies it to the raw XML data between the <asp:Xml> tags, thereby generating the desired HTML output. 

    And there’s more - you can learn about the ASP.NET "Xml" server control at the following URL: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIWebControlsXmlClassTopic.asp

    More XML Articles
    More By Harish Kamath


       · pls post the tested sample files also.thnks pankajsrivastava@vsnl.net
     

    XML ARTICLES

    - More on Triggers and Styles and Control Temp...
    - Looking at Triggers with Styles and Control ...
    - A Closer Look at Styles and Control Templates
    - Styles and Control Templates
    - Properties and More in XAML
    - Elements and Attributes in XAML
    - XAML in a Nutshell
    - Importing XML Files into Access 2007
    - Using MSXML3.0 with VB 6.0
    - MSXML, concluded
    - MSXML, continued
    - MSXML Tutorial
    - Generating XML Schema Dynamically Using VB.N...
    - XSL Transformations using ASP.NET
    - Applying XSLT to XML Using ASP.NET





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT