I am using an RSS xml file to show news titles on my site. SOmetines the news feeds have 5 stories sometimes there are 10 stories. I only want to show the top 3. How can I do that? Here is my code for the XSLT and the XML link to the RSS: RSS link: http://rss.com.com/2547-12-0-5.xml
XSLT file:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<div class="ChannelTitle">
</div>
<div class="ArticleEntry">
<div class="ArticleTitle">
</div>
<div class="ArticleHeader">
</div>
<div class="ArticleDescription">
More on this story.
</div>
</div>
The .aspx page:
private void Page_Load(object sender, System.EventArgs e)
{
XmlDocument _xmlDocument;
XmlDocument _xmlOutput;
XslTransform _xslTransform;
_xmlDocument = new XmlDocument();
_xmlOutput = new XmlDocument();
_xslTransform = new XslTransform();
_xmlDocument.Load("http://rss.com.com/2547-12-0-5.xml");
_xslTransform.Load(Server.MapPath("RssArticles.xslt"));
StringWriter sw = new StringWriter();
_xslTransform.Transform(_xmlDocument, null, sw, new XmlUrlResolver());
Response.Write(sw.ToString());
}
You can change the apply-templates you have to select only top XXX elements like this: remember to encode the '<' sign to be < or it will be invalid XML.
joee
Participant
1728 Points
377 Posts
Parsing out Nodes
Sep 03, 2003 03:38 PM|LINK
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <div class="ChannelTitle"> </div> <div class="ArticleEntry"> <div class="ArticleTitle"> </div> <div class="ArticleHeader"> </div> <div class="ArticleDescription"> More on this story. </div> </div>The .aspx page:private void Page_Load(object sender, System.EventArgs e) { XmlDocument _xmlDocument; XmlDocument _xmlOutput; XslTransform _xslTransform; _xmlDocument = new XmlDocument(); _xmlOutput = new XmlDocument(); _xslTransform = new XslTransform(); _xmlDocument.Load("http://rss.com.com/2547-12-0-5.xml"); _xslTransform.Load(Server.MapPath("RssArticles.xslt")); StringWriter sw = new StringWriter(); _xslTransform.Transform(_xmlDocument, null, sw, new XmlUrlResolver()); Response.Write(sw.ToString()); }CarlosAg
Participant
1355 Points
271 Posts
Microsoft
Re: Parsing out Nodes
Sep 03, 2003 09:51 PM|LINK
joee
Participant
1728 Points
377 Posts
Re: Parsing out Nodes
Sep 03, 2003 10:00 PM|LINK