XML
  Home arrow XML arrow Page 2 - 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 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
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: 4 stars4 stars4 stars4 stars4 stars / 22
    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 - Start it up


    (Page 2 of 7 )

    Consider the following XML document (say articles.xml) that lists the details of an article (on a web site such ASPFree.com):

    <?xml version="1.0"?>
    <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>

    While this looks fine and dandy to an XML-aware client, ordinary mortals (such as you and me) prefer an HTML version that looks more like this:

    XSLT Transformations using ASP NET

    This is possible if I use the following XSLT style sheet (say articles.xsl) to transform the above XML file:

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <H3>Article Title: <xsl:value-of select="article/title" /></H3>
     <H4>Author: <xsl:value-of select="article/author" /></H4>
    <H4>Category: <xsl:value-of select="article/category" /></H4>
    <H5>Abstract:</H5>
    <xsl:value-of select="article/abstract" />
    </xsl:template>
    </xsl:stylesheet>

    I have the XML content and I have the XSLT style sheet. Now, I need the glue to ensure that the two of them interact with each other and return the desired HTML output. This is where ASP.NET steps in - I can leverage on the .NET Framework, which is equipped with a wide array of .NET assemblies specifically defined for this purpose.
     
    Take a peek at the following ASP.NET script (say articles.aspx) that uses the server-side .NET "Xml" control.

    <%@ Page Language="C#" %>
    <HTML>
    <HEAD>
        <TITLE>ASPFree.com</TITLE>
        <BASEFONT face="Arial" size="2">
    </HEAD>
    <BODY>
        <asp:Xml id="output" runat="server" DocumentSource="articles.xml" TransformSource="articles.xslt" />
    </BODY>
    </HTML>

    Load the example in your browser in order to see the desired HTML output (as shown above).

    After a quick review of the code listing, I can safely conclude that the task of transforming an XML document using an XSLT style sheet is pretty simple in ASP.NET. All that I need to do is to create an instance of the .NET "Xml" server control using the <asp:Xml> element. This "Xml" server control is associated with several useful attributes - I have used the following:

    • DocumentSource: allows me to specify the name of the XML file that I wish to transform
    • TransformSource: allows me to specify the name of the XSLT file that is used to transform the XML file specified in the "DocumentSource" property

    Next, I have assigned the names of the XML and XSLT style sheet files to the corresponding attributes (listed above) of the <asp:Xml> element and the end result is the transformation of the XML data into the desired HTML output.

    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 5 hosted by Hostway