PDA

View Full Version : determing the number of records by position()


AdAve
06-23-2006, 09:41 PM
Hi Again,
Does anyone have any code that will take the value of the position
<xsl:value-of select="position()" />
and allow for an if statement that would use that value?
I know I can limit the number of records by using something like
<xsl:for-each select="//*[local-name()='item'][position() &lt; 10]">
However there are times where there is nothing in the feed (like the link below)
http://news.google.com/news?hl=en&ned=us&q=pppppppp&ie=UTF-8&output=rss
and I'd like to adjust the output accordingly

ealbrecht
06-23-2006, 11:32 PM
Not sure that I understand you correctly, but I think you're wanting something like this perhaps???

<xsl:variable name="pos" select="position()" />

<xsl:if test="$pos = 15">true clause here</xsl:if>

AdAve
06-26-2006, 08:16 PM
Thanks, that's very close to what I am looking for, but what I want to be able to do is display a different message when there are no results. Is there an else clause that can be used or can you check for a null?

ealbrecht
06-26-2006, 10:27 PM
Try one of these two solutions, perhaps they are closer to what you are seeking:

* XSL choose/when/otherwise
http://www.w3schools.com/xsl/xsl_choose.asp

* XSL for-each if w/ variable test
http://www.mhonarc.org/archive/html/xsl-list/2004-02/msg00768.html