title: Get first n entries from rss or atom feed using YQL and feednormalizer
body: <p>I'm using YQL to retrieve RSS and ATOM feeds as JSON, and normalize them to ATOM style using the feednormalizer table.</p>
  
  <p><a href="https://developer.yahoo.com/yql/console/#h=select+*+from+feednormalizer+where+output%3D&#39;atom_1.0&#39;+AND+url%3D&#39;http%3A%2F%2Ffeeds.delicious.com%2Fv2%2Frss%2Fmsuweb&#39;" rel="nofollow noreferrer"><code>select * from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb'
  </code></a></p>
  
  <p>I need to get only the first X entries. I know that, in theory, <a href="https://stackoverflow.com/questions/26221654/how-to-select-the-first-n-elements-in-xpath">an xpath expression should be able to do that</a>. However, when I try one that I assume ought to work...</p>
  
  <p><a href="https://developer.yahoo.com/yql/console/#h=select+*+from+feednormalizer+where+output%3D&#39;atom_1.0&#39;+AND+url%3D&#39;http%3A%2F%2Ffeeds.delicious.com%2Fv2%2Frss%2Fmsuweb&#39;+and+xpath%3D&#39;%2F%2Fentry%5Bcount(preceding%3A%3Aentry)+%3C+5%5D&#39;" rel="nofollow noreferrer"><code>select * from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb' AND xpath='//entry[count(preceding::entry) &lt; 5]'</code></a></p>
  
  <p>...the results object comes back null. I've also tried <a href="https://developer.yahoo.com/yql/console/#h=select+*+from+feednormalizer+where+output%3D&#39;atom_1.0&#39;+AND+url%3D&#39;http%3A%2F%2Ffeeds.delicious.com%2Fv2%2Frss%2Fmsuweb&#39;+and+xpath%3D&#39;%2F%2Fitem%5Bcount(preceding%3A%3Aitem)+%3C+5%5D&#39;" rel="nofollow noreferrer">using item instead of entry</a> in the xpath query, since that's what an RSS feed will have in the actual XML. That also returns a null results object.</p>
  
  <h2>Other Stuff I've Tried</h2>
  
  <h3>Limits</h3>
  
  <p>I've also tried using <a href="https://developer.yahoo.com/yql/guide/paging.html" rel="nofollow noreferrer">both local and remote limits</a>, which returns the same number of entries as if I hadn't specified a limit.</p>
  
  <p><a href="https://developer.yahoo.com/yql/console/#h=select+*+from+feednormalizer(0%2C5)+where+output%3D&#39;atom_1.0&#39;+AND+url%3D&#39;http%3A%2F%2Ffeeds.delicious.com%2Fv2%2Frss%2Fmsuweb&#39;" rel="nofollow noreferrer"><code>select * from feednormalizer(0,5) where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb'</code></a></p>
  
  <p><a href="https://developer.yahoo.com/yql/console/#h=select+*+from+feednormalizer+where+output%3D&#39;atom_1.0&#39;+AND+url%3D&#39;http%3A%2F%2Ffeeds.delicious.com%2Fv2%2Frss%2Fmsuweb&#39;+limit+6" rel="nofollow noreferrer"><code>select * from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb' limit 6</code></a></p>
  
  <h3>Selecting Columns with CrossProduct</h3>
  
  <p>Notably, I still need all the metadata that comes with the typical <code>select *</code> query. That is, I need the feed's title, link, etc., and I'd prefer they stayed at the root element. So, I know that I can do</p>
  
  <p><code>select title, link, entry from feednormalizer(0,6) where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb'</code></p>
  
  <p>or </p>
  
  <p><code>select title, link, entry from feednormalizer where output='atom_1.0' AND url='http://feeds.delicious.com/v2/rss/msuweb' limit 6</code></p>
  
  <p>But that puts the title and feed link directly onto each entry in the list, even with <a href="https://developer.yahoo.com/yql/guide/optimizing_response.html#optimizing_response-configuring" rel="nofollow noreferrer"><code>crossProduct=optimized</code></a> in the URL string. Call me picky, but I'd rather not do that.</p>