Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Sat, 17 May 2008 13:01:45 -0700 (PDT),    group: microsoft.public.xsl        back       


Function to limit nodes? (using xslt to format xml from rss feed)   
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
date: Sat, 17 May 2008 13:01:45 -0700 (PDT)   author:   unknown

Re: Function to limit nodes? (using xslt to format xml from rss feed)   
wrote in message 
news:1970fd18-006d-499a-8597-4c94fb558d82@j22g2000hsf.googlegroups.com...
> 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() < 5">

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


-- 

Joe Fawcett (MVP - XML)
http://joe.fawcett.name
date: Sun, 18 May 2008 11:39:56 +0100   author:   Joe Fawcett am

Re: Function to limit nodes? (using xslt to format xml from rss fe   
In addition to what Joe said in his post, you can limit the number of nodes 
returned by pubDate (e.g. pass the date value as a parameter).


ML

---
Matija Lah, SQL Server MVP
http://milambda.blogspot.com/
date: Mon, 19 May 2008 00:11:00 -0700   author:   ML

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us