[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Trying to identify the 3 highest sales results
Arthur,
If you are sorting your rows, then the simplest way may be to do as Ian suggested and use position(). That would perform plenty fast. It would not, however, be able to resolve ties. Depending on your exact requirements, however, this could work for you: <xsl:variable name="competitors" select="//row"/> <xsl:template match="row"> <xsl:variable name="higher-count" select="count($competitors[sales > current()/sales])"/> <!-- higher count is the count of all competitors with sales better than this one --> <!-- the 'place' variables are bound to Boolean values --> <xsl:variable name="first-place" select="$higher-count = 0"/> <xsl:variable name="second-place" select="$higher-count = 1"/> <xsl:variable name="third-place" select="$higher-count = 2"/> <!-- change the tagging here to fit --> <agent> <xsl:attribute name="place"> <xsl:choose> <xsl:when test="$first-place">First</xsl:when> <xsl:when test="$second-place">Second</xsl:when> <xsl:when test="$third-place">Third</xsl:when> <xsl:otherwise>Rest</xsl:otherwise> </xsl:choose> </xsl:attribute> <xsl:value-of select="agent"/> </agent> </xsl:template> Note that this resolves ties in classic form: if there is a two-way tie for first, there is no second place, only third, while if there is a tie for second or a three-way tie for first, there is no third. But all ties for third are listed. If you wish to define who takes the places differently, you may have to resort to the two-pass approach. I hope this helps, Wendell At 02:21 AM 1/7/2008, you wrote: Hello xsl-list, ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|