Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Function to limit nodes? (using xslt to format xml from rss feed)

From: "Joe Fawcett" <joefawcett@---------.------>
To: NULL
Date: 5/18/2008 11:40:00 AM



<robinchesterman@g...> wrote in message 
news:1970fd18-006d-499a-8597-4c94fb558d82@j......
> I've just started using xslt, and it seems straightforward enough (for
> now!). I am using a simple xsl template to format and display news
> items from an rss news feed:
>
> <xsl:template match="rss">
>       <xsl:apply-templates select="channel"/>
> </xsl:template>
>
> <xsl:template match="channel">
>       <xsl:apply-templates select="item"/>
> </xsl:template>
>
> <xsl:template match="item">
>      <dt>
>           <a href="/"><xsl:value-of select="title"/></a>
>      </dt>
>      <dd>
>            <ul>
>                <li>
>                    <a><xsl:attribute name="href"><xsl:value-of
> select="link"/></xsl:attribute>
>                           <xsl:value-of select="description"/>
>                    </a>
>                </li>
>             </ul>
>       </dd>
> </xsl:template>
>
>
> However, in another section of the site I'm building, I would like to
> display only the four or so most recent items of the rss feed, rather
> than the whole lot.
>
> Can anyone tell me how to do this using xslt functions? As you will
> see, at the moment my knowledge is limited to applying a blanket
> template to every item.
>
> Any help would be very much appreciated.
>
> Many thanks,
>
> Robin
Use the position() function in the item template:
<xsl:template match="item">
  <xsl:if test="position() &lt; 5">

  </xsl:if>
</xsl:template>


-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name 



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent