EnexoOnoma
EnexoOnoma

Reputation: 8836

How to get only the 10 first entry tags using XSLT?

In a feedburner RSS I use

<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>

to get all the content of a feed with structure like below :

<feed>
<entry><published></published><title></title><content></content>....</entry>
</feed>

My question is, if it is possible to get only the 10 first <entry></entry> instead of all the 25 ? How to do it ?

Note : The entry tag has this form <entry gd:etag="W/&quot;AkcHRH8yfSp7ImA9WhdUFkg.&quot;"> I do not know if this matters

Upvotes: 0

Views: 136

Answers (2)

Eric
Eric

Reputation: 97631

Your template was recursive. You then changed the behaviour of the outer template, breaking the recursion.

The simplest way to do what you want would be:

<xsl:template match="/feed/entry[position() &lt; 10]">
    <xsl:copy-of select="." />
</xsl:template>

Upvotes: 0

seriyPS
seriyPS

Reputation: 7112

smth like

/feed/entry[position()<10]

I mean, you need add this template:

<xsl:template match="entry[position() &gt; 10]"/>

That drop all the entries after 10's, or something equal. The main suggestion is to take a look at position() function.

Upvotes: 2

Related Questions