Display an RSS Feed Using XSLT

Introduction

 
There are many ways to display data. When we have the data then we need some control that can display it, but choosing the right control will give better performance. Let's discuss displaying an RSS feed using XSLT
 
Basics of XSLT 
 
The extended style sheet language transformation is a language that has statements like in other languages which helps the developers to display in a convenient format. XSLT is used to convert the XML data into graphical format. This can use the CSS, HTML and Javascript.
 
Display RSS Feed content
 
The RSS feeder gives the data in the XML format that needs to be converted in the graphical output. Which is lightweight and it can be designed table or table-less (CSS) layout.
 
Most of the RSS feed output gives the standard format and can be frequently updated and it will returns thetop update to their followers. The data has to be read from the link and the XML data will be converted to XSLT.
  1. <xsl:for-each select="rss/channel/item">  
  2.      <tr style="color:#0080FF;">  
  3.           <td style="text-align:left;font-weight:bold;">  
  4.                <xsl:value-of select="title"></xsl:value-of>  
  5.           </td>  
  6.           <td style="text-align:right;font-weight:bold;">  
  7.                <i>  
  8.                     <xsl:value-of select="author"></xsl:value-of>  
  9.                </i>,  
  10.                <xsl:value-of select="pubDate" />  
  11.           </td>  
  12.      </tr>  
  13.      <tr>  
  14.           <td colspan="2" style="text-align:left;padding-top:10px;">  
  15.                <xsl:value-of select="description" />  
  16.           </td>  
  17.      </tr>  
  18.      <tr>  
  19.           <td colspan="2" style="text-align:right;">  
  20.                <a href="{link}" rel="bookmark">  
  21.                     More...  
  22.                </a>  
  23.           </td>  
  24.      </tr>  
  25.      <tr>  
  26.           <td colspan="2" style="height:20px;">  
  27.                <hr>  
  28.                </hr>  
  29.           </td>  
  30.      </tr>  
  31. </xsl:for-each> 
XSLT has the for loop statement which can be used like in other languages.
  1. <rss version="2.0">  
  2.   <channel>  
  3.     <title>C-Sharpcorner Latest Articles</title>  
  4.     <link>http://www.c-sharpcorner.com/</link>  
  5.     <description>Watch articles from C# Corner</description>  
  6.     <copyright>© 1999 - 2011  Mindcracker LLC. All Rights Reserved</copyright>  
  7.     <item>  
  8.       <title>Joins Using LINQ in C#</title>  
  9.       <description>Today, in this article we will see how to perform join operation using LINQ queries. I have created two tables in database named 'Candidate'. The first table name is Employee. the second table name is Student.  I have used LINQ to SQL to communicate with database. </description>  
  10.       <link>http://www.c-sharpcorner.com/UploadFile/54db21/joins-using-linq-in-C-Sharp/</link>  
  11.       <pubDate>12/13/2011 3:08:33 AM</pubDate>  
  12.       <author>Vijay  Prativadi</author>  
  13.     </item>  
  14.     <item>  
  15.       <title>Simple Arithmetic Operation using WCF Service Hosted on WebApp</title>  
  16.       <description>Today, in this article we will try to perform simple arithmetic operation importing some created service into our web application. Once the application is fully developed we can request values from our web form which retrieve the output by performing an expected operation to the values specified by the service. </description>  
  17.       <link>http://www.c-sharpcorner.com/UploadFile/54db21/simple-arithmetic-operation-using-wcf-service-hosted-on-weba/</link>  
  18.       <pubDate>12/13/2011 2:41:30 AM</pubDate>  
  19.       <author>Vijay  Prativadi</author>  
  20.     </item>  
  21.     <item>  
  22.       <title>Print in C#</title>  
  23.       <description>Here is a good list of resource related to printing in C# using GDI+.</description>  
  24.       <link>http://www.c-sharpcorner.com/UploadFile/mahesh/print-in-C-Sharp/</link>  
  25.       <pubDate>12/12/2011 3:19:54 PM</pubDate>  
  26.       <author>Mahesh Chand</author>  
  27.     </item>  
  28. </channel>  
  29. </rss> 
It will keep on iterating the XML data and traverse through all the specified nodes. The value-of statement is used to read the text in the specified node. The format of display can be designed through HTML.
 
Sample Screen
 
Clipboard01.jpg

Conclusion

 
The xml data can be directly used to display graphical data. It can be designed like Grid, List, etc., It does not have the bubbled event or any other event. It will render quickly and improve performance.