[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

Subject: Re: Trying to identify the 3 highest sales results
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 07 Jan 2008 15:57:05 -0500
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 &gt; 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,

I'm using Xslt(v1.0) to convert an Xml(v1.0) file to Xhtml for browser display
and trying to add a visual for the top 3 sales result.


 i.e. trying to build
 <td class="first">9</td>
 <td class="second">6</td>
 <td class="third">3</td>
 The CSS class translates to <img src="boldGold.gif" alt="first" />
 I'm Ok with building the Xhtml and adding CSS classes

 When the row template is being processed.
 How Do you Identify if it's the 1st, 2nd or 3rd highest sales figure?
 Typically there are 200-300 salesmen results per calculation and the Xml
 by design,is pre sorted by salesman name.

Xslt shard
 <xsl:template match="row">
      <tr>
      ...
      <td>
        <xsl:value-of select="sales"/>
      </td>
      </tr>
</xsl:template>


Xml shard <table calculated="08W021T07:16"> <row> <agent>Fred Smith</agent> ... <sales>6</sales> </row> <row> <agent>George Jones</agent> ... <sales>9</sales> </row> <row> <agent>George Jones Jr</agent> ... <sales>1</sales> </row> <row> <agent>Karina Houseman</agent> ... <sales>3</sales> </row> </table>


======================================================================
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
======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.