[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] Trying to identify the 3 highest sales results
Subject: Re: [xsl] Trying to identify the 3 highest sales results
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 07 Jan 2008 15:57:05 -0500
|
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,
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
======================================================================
|