Greg,
This is not hard to do in simple cases, as in (assuming the entry
elements are children of the context node):
<xsl:for-each select="entry">
<xsl:sort select="date" order="descending"/>
<xsl:if test="position() <= 10">
<xsl:apply-templates select="." mode="display"/>
</xsl:if>
</xsl:for-each>
What you're doing here is first, sorting, then filtering out the
number you need. If there are only seven entries, no problem, since
their positions are all <= 10.
In more complex cases (say, where grouping is involved) you may find
this is most easily done in a pipeline.
This is actually a nice example illustrating why position() does
*not* have reference to the position of a node in a document
(something recently remarked on in another thread). Here, the node
list being processed has been sorted, and position() refers to the
position of a node in the sorted order.
Cheers,
Wendell
At 07:24 PM 12/20/2006, you wrote:
Hi all, I have a situation where I need to filter the results of one
XML doc into an Atom feed; I'm of course using xslt. The underlying
XML represents entries and/or comments in a blog for example, and
they want to be able to request the feed and filter using criteria
like "show only the last 10 entries". The problem is that last ten
is ambiguous. There may be only 7 entries for example. Using dates
won't work because I can't know apriori what date would qualify the
last n entries. I've got to think some of you have done this kind of
filtering before and probably even more robustly. Any suggestions?
I'm thinking maybe sorting by date and then using some node operator
to pick off the N I need, I'm sort of new to XSLT so I'm not sure of
the idioms for this kind of operation. Thanks in advance. -Gregory
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Suppose you were an idiot, and suppose you
were a member of congress; but I repeat
myself." - Mark Twain
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__________________________________________________ Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
======================================================================
Wendell Piez
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--