I’ve been messing around with using XSL to display RSS on MSDN, as a simpler alternative to a custom ASP.NET control, and while it works perfectly in the core case (display all the items in a feed in a format), there are two additional requirements that were very easy to handle in a .NET class, but trickier (for me) in XSL.

  • Display the top n items
  • Out of the full list, display n randomly picked items

For the first, it was pretty easy… <xsl:if test="position < 6"> could be used to only output the top 5 items, for example… For the second though, I was stumped for a bit… then I came up with an idea. I would write a script function that would pick n items out of the total count, put those choices into an array, then use another function that tests the current position against that list of choices… sound good? Well, I’m still working on implementing this one… I have it working, but I’m not 100% sure of my solution.

If you are interested, you can see the code running here, and pull down the xsl from here, and the backing rss file from here. Code for the pageCode for the control it references