XML
  Home arrow XML arrow Page 5 - Applying XSLT to XML 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

Applying XSLT to XML Using ASP.NET
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 62
    2004-09-13

    Table of Contents:
  • Applying XSLT to XML Using ASP.NET
  • A Simple Example on XSLT
  • XSLT with ASP.NET
  • Query a Database and Transform through XSLT using ASP.NET
  • How to Transform More than One Row?

  • 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


    Applying XSLT to XML Using ASP.NET - How to Transform More than One Row?


    (Page 5 of 5 )

    Till now we worked with only one record using XSLT. But what if we want more than one record to be transformed using XSLT? This section addresses those needs. We shall further enhance the example in previous section so that it can transform more than one order from ‘orders’ table at a time.

    In the example given in previous section, the SELECT retrieves only one row (as it is filtered by orderID). We need to change it, so that it can retrieve more than one row. Make the modification to the above statement as following:

    Dim docXML As XmlDocument = getXMLContent("select top 10 orderid,freight from orders ")

    The above SELECT statement retrieves only first 10 orders (of course you can give any query you require). Now, we need to make few more changes to Format1.xslt file. Modify the Format1.xslt file so that it looks consistent with the following code:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
      <body>
        <table width="50%" cellspacing="0" cellpadding="0" style="font-family:verdana;font-size:X-Small" border="1">
        <tr bgcolor="#336699"><th align="left"><font color="White">OrderID</font></th><th align="right"><font color="White">Freight</font></th></tr>
        <xsl:for-each select="SQLData/Rows">
        <tr><td align="left"><xsl:value-of select="orderid" /></td><td align="right"><xsl:value-of select="freight" /></td></tr>
        </xsl:for-each>
        </table>
      </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    Let us examine the modified code:

    <xsl:for-each select="SQLData/Rows">
        <tr><td align="left"><xsl:value-of select="orderid" /></td><td align="right"><xsl:value-of select="freight" /></td></tr>
        </xsl:for-each>

    ‘<xsl:for-each>’ element can be used to select every XML element of a specified node set. It is quite similar to ‘for’ loop. As we are filtering to some extent using ‘<xsl:for-each>’ element, ‘<xsl:value-of>’ element should be given with more specific information excluding the filtering.

    Press F5 to execute the web application and you should be able to see a table of 10 orders from database transformed using XSLT.

    Closing Remarks

    I suggest you to learn XPath language to design XSLT very effectively. As this article mainly focuses on basics of XSLT, I could not give any information on XPath. I examined these examples using Microsoft SQL Server 2000 Enterprise Edition and Visual Studio.NET 2003 Enterprise Architect. But all the above samples would definitely work with any database (provided you make modifications to the .NET data provider). And it is not at all necessary to have Visual Studio.NET to work with XSLT. You can also implement the in-line approach of ASP.NET to get the things worked out. By designing XSLT with a bit analysis, you can design templates for entire web site (for look and feel compatibility). These templates could be reused for new web applications without any hurdle. Complicated reports can also be designed using XSLT.

    I leave it to the developers to further research and investigate the above examples in all the aspects, till it meets yours requirements. Any doubts, comments, suggestions, bugs, errors or feedback are welcomed at jag_chat@yahoo.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · this article help intermediates to know about the power of xml using xls.can help...
     

    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