RE: [xsl] need to limit a For:each loop

Subject: RE: [xsl] need to limit a For:each loop
From: "Angel Gavin" <agavin@xxxxxx>
Date: Thu, 5 May 2005 17:41:27 +0200
Hi,

If you want to show only, say, the first 5 items then you can modify the
for-each element as follows:

<xsl:for-each select="//*[local-name()='item'][position() &lt; 6]">

(obviosuly &lt; stands for "lower than"). In case you want to show from item
6 up to item 10 then:

<xsl:for-each select="//*[local-name()='item'][position() &gt; 5 and
position() &lt; 11]">

I hope you get the point. Now the problem is how to manage this, but it
depends on how are you performing the transformation (XSLT engine, etc etc
etc). For instance, you can pass to the stylesheet a couple of parameters,
namely the min and max values, as follows:

  <?xml version="1.0" ?>
- <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
  <xsl:param name="minItem"/>
  <xsl:param name="maxItem"/>
- <xsl:template match="*">
- <table border="0" width="100%" bgcolor="#666666" align="center">
....


and then

<xsl:for-each select="//*[local-name()='item'][position() &gt; $minItem and
position() &lt; $maxItem]">

The only thing you need to know is how to pass these parameters to your XSLT
engine. This will allow you to generate "dynamically" the table to be shown
(probably depending on some user choice like a "next" link or similar).

I am not an expert on ASP stuff, and probably there are many other (more
efficient and smarter) ways to do this. I hope this helps anyway (partially
at least!) I've tested it "off-line" (transformation at client-side) and it
works.

Regards,
Angel



-----Original Message-----
From: sales@xxxxxxxxxxxxxxxxxxxxxx [mailto:sales@xxxxxxxxxxxxxxxxxxxxxx]
Sent: 05 May 2005 16:33
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] need to limit a For:each loop


Hi,

I'm totally new to XSL (didn't know it existed till yesterday!)
i downloaded a RSS newsfeed script for my website and started to modify
the design of it to suit my needs
the current output can be seen here
http://www.discountfirepagers.com/rss2/default.asp
as you can see there are many articles ...
I wish to limit the articles to just 5 items. however i can't figure how
to modify the XSL to do that for me
i know i have to break the for:each somehow or change it to a specified
loop but can't find any info on how to do this
can someone help please
Here is the XSL http://www.discountfirepagers.com/rss2/news.xsl
here is the XML
http://news.search.yahoo.com/news/rss?p=fire%20department


XSL

  <?xml version="1.0" ?>
- <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
- <xsl:template match="*">
- <table border="0" width="100%" bgcolor="#666666" align="center">
- <tr>
- <td valign="top" bgcolor="white" class="headlines">
- <ul>
- <xsl:for-each select="//*[local-name()='item']">
- <li>
- <a>
- <xsl:attribute name="href">
  <xsl:value-of select="*[local-name()='link']" />
  </xsl:attribute>
- <xsl:attribute name="target">
  <xsl:text>top</xsl:text>
  </xsl:attribute>
- <font face="Verdana, Arial, Helvetica" color="#333333" size="0">
  <xsl:value-of select="*[local-name()='title']" />
  </font>
  </a>
  </li>
  </xsl:for-each>
  </ul>
  </td>
  </tr>
  </table>
  </xsl:template>
- <xsl:template match="/">
  <xsl:apply-templates />
  </xsl:template>
  </xsl:stylesheet>


______________________
Este mensaje, y en su caso, cualquier fichero anexo al mismo,
 puede contener informacion clasificada por su emisor como confidencial
 en el marco de su Sistema de Gestion de Seguridad de la 
Informacion siendo para uso exclusivo del destinatario, quedando 
prohibida su divulgacion copia o distribucion a terceros sin la 
autorizacion expresa del remitente. Si Vd. ha recibido este mensaje 
 erroneamente, se ruega lo notifique al remitente y proceda a su borrado. 
Gracias por su colaboracion.
______________________
This message including any attachments may contain confidential 
information, according to our Information Security Management System,
 and intended solely for a specific individual to whom they are addressed.
 Any unauthorised copy, disclosure or distribution of this message
 is strictly forbidden. If you have received this transmission in error,
 please notify the sender immediately and delete it.
______________________

Current Thread