RE: [xsl] Top n values

Subject: RE: [xsl] Top n values
From: Jarno.Elovirta@xxxxxxxxx
Date: Fri, 18 Oct 2002 12:17:08 +0300
Hi Vasu,

Yes, he could do it like that, but why? Why resort to extensions and build a RTF, when he could just sort by item and filter by position - why make things the hard way?

Cheers,

Jarno

> -----Original Message-----
> From: ext Vasu Chakkera [mailto:vasucv@xxxxxxxxxxx]
> Sent: 18. October 2002 12:04
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Top n values
> 
> 
> Following is an example of how you can work with node-set()..
> 
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; xmlns:xalan = 
> "http://xml.apache.org/xalan"; exclude-result-prefixes="xalan">
> <xsl:template match="/">
> <xsl:variable name="sorted-items">
> <xsl:for-each select="/root/item">
> <xsl:sort select="." order="descending" data-type="number"/>
> <xsl:copy-of select="."/>
> </xsl:for-each>
> </xsl:variable>
> <xsl:variable name="n-value" select="'3'"/>
> <xsl:for-each 
> select="xalan:nodeset($sorted-items)/item[position()&lt;= 
> $n-value]">
> <xsl:value-of select="."/><br/>
> </xsl:for-each>
> </xsl:template>
> </xsl:stylesheet>
> 
> This works with XALAN..
> 
> 
> 
> 
> 
> 
> >From: Dan Diebolt <dandiebolt@xxxxxxxxx>
> >Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >Subject: [xsl] Top n values
> >Date: Thu, 17 Oct 2002 12:30:04 -0700 (PDT)
> >
> >I need to process the top n values in a list where n
> >is dynamic. So if n=3 and I had the following XML:
> >
> ><root>
> >  <item>1</item>
> >  <item>5</item>
> >  <item>3</item>
> >  <item>2</item>
> >  <item>6</item>
> >  <item>4</item>
> ></root>
> >
> >I need to process <item>'s with values 6,5,4. If I had
> >captured n in a variable/parameter, what is the most
> >efficient way to do this? What I want to avoid is walking
> >the <item> nodset multiple times as there are a lot of
> ><item>s (thousands). Thanks.
> >
> >  XSL-List info and archive:  
> http://www.mulberrytech.com/xsl/xsl-list
> 
> 
> _________________________________________________________________
> Get a speedy connection with MSN Broadband.  Join now! 
> http://resourcecenter.msn.com/access/plans/freeactivation.asp
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread