tags:

views:

38

answers:

2

Hi,

I am trying to use XSL to convert a news feed into a fragment of html for insertion into a web page.

The news feed is several hundred items long and so I only want to include the latest 10 headlines... The xsl is below, I was thinking I could have a counter and break out of the loop after the desired number of iterations. However after a bit of reading it seems xsl is not designed to be used this way.

What is the "best" way to get the desired result in xsl?

Many thanks for any suggestions.

edit: Doesn't seem to let me post xml snippets. But the pattern I am following was lifted from here: http://www.rgagnon.com/javadetails/java-0407.html

+2  A: 
<xsl:for-each select="howto/topic[position() &lt;= 10]">
Martijn
@Martijn: Also in pattern like `match="howto/topic[11 > position()]"`
Alejandro
A: 

I recommend you to solve it using XPath query and no using XSLT. XPath has a two functions, one is count( nodeset ) and another is position(). With combination of these functions you can get interesting results. For example:

//news[position()<11]

returns first 10 items

or

//news[position()>count(//news)-10]

returns last 10 items

Gaim