How to limit rss records? RRS feed

  • Question

  • User1946081430 posted

    I'm using the following code to pull in Reuters headlines. I'd only like to see the top 2 headlines. Is there any way to limit the records imported using the code below?  Seems like it should be easy but I can;t figure it out.

     Private Sub Page_load(ByVal sender As Object, ByVal e As System.EventArgs)
        End Sub

     <asp:XmlDataSource ID="XmlDataSource2" Runat="server"
                 XPath="rss/channel/item" >

    asp:DataList ID="DataList2" runat="server" CellPadding="4" DataSourceID="XmlDataSource2" ForeColor="#333333">
            <b><%#XPath("title")%></b><br />
            <i><%#XPath("pubDate")%></i><br />
            <%#XPath("description")%><br />
            <a href='<%#XPath("link")%>'>Link</a><br />
            <br /> <


    Thursday, February 2, 2006 9:28 PM

All replies

  • User-2016200658 posted
    I would like to know the answer too! anyone can help is appreciated!
    Wednesday, February 8, 2006 8:08 AM
  • User2069888697 posted

    It took me awhile but this seems to do the trick.


    change your aspx code to:

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:Xml ID="Xml1" runat="server" DocumentSource="~/rss.xml" TransformSource="~/rss.xsl"></asp:Xml>



    Create an xml file named rss.xml and add this code:

    <?xml version="1.0" encoding="UTF-8" ?>

    <?xml- stylesheet href="rss.xsl" type="text/xsl"?>


    <feed src="http://www.microsite.reuters.com/rss/topNews"/>


    Create an xsl file named rss.xsl and add this code:

    <?xml version="1.0"?>


    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="feeds">

    <html><head><title>Today's News</title></head>






    <xsl:template match="feed">

    <xsl:apply-templates select="document(@src)"/>


    <xsl:template match="channel">

    <h1><xsl:value-of select="title"/></h1>

    <xsl:apply-templates select="item"/>


    <xsl:template match="item">


    <xsl:if test="position() &lt; 6">

    <xsl:element name="a">

    <xsl:attribute name="href">

    <xsl:apply-templates select="link"/>


    <xsl:value-of select="title"/>


    <br />

    <xsl:value-of select="description"/>

    <br />

    <span class="date">

    <xsl:if test="pubDate">

    <xsl:value-of select="pubDate"/>







    To change qty change the value in

    <xsl:if test="position() &lt; 6">

    in the xsl

    also you can add multiple rss feeds in the xml file


    will show the top 5 of sports

    you can also add  style tag ahead of the body tag in the xsl to change the look.

    Thanks to DNN forums for the solution. it wasn't any one post but several that led me to the solution. (I like puzzles)



    Thursday, February 9, 2006 2:04 PM
  • User2069888697 posted

    if you use the sports feed use:

    <feed src="http://www.microsite.reuters.com/rss/sportsNews/"/>

    sorry for the error.

    Thursday, February 9, 2006 2:17 PM
  • User700454612 posted
    XPath="rss/channel/item[position() < 3]"

    <div class="leftblock">
                    <h5>skionline.ch - Ski News</h5>
                    <asp:XmlDataSource DataFile="http://www.skionline.ch/feed/news_headlines_de.xml" ID="XmlDataSource1"
                        runat="server" XPath="rss/channel/item[position() < 6]" CacheDuration="600" EnableCaching="true">
                    <asp:datalist id="DataList3" runat="server" datasourceid="XmlDataSource1" CellPadding="2">
                            <a href="<%# XPath("link") %>" target="_blank"><%#XPath("title") %></a>

    tom rally
    Friday, February 10, 2006 9:05 AM
  • User-2016200658 posted

    This is too cool! Thanks Tom Rally!

    I was able to limit the number of quote of the day down to 1, it used to be 4


    Friday, February 10, 2006 12:25 PM
  • User2069888697 posted

    Nice job, I spent 2 hrs trying to get the position to work in the xmldatasource, now I see it was because I wasn't useing the square barackets.

    By far a better solution.

    Friday, February 10, 2006 2:32 PM
  • User1946081430 posted
    Thanks a bunch. Without a doubt the nicest, concisest, code I've seen to address this problem.
    Wednesday, February 22, 2006 7:57 PM