Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 26th, 2008, 02:14 AM
Registered User
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rank items into quartiles

My source xml:
Code:
<root>
    <emp>
        <level>1</level>
        <salary>20000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>16000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>19000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>17000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>18000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>19000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>16000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>15000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>14000</salary>
    </emp>
    <emp>
        <level>1</level>
        <salary>13000</salary>
    </emp>

</root>
I need to produce a table showing which quartile an employee belongs to:

Level Salary Quartile
1 20000 1
1 19000 1
1 19000 1
1 18000 2
1 17000 2
1 16000 3
1 16000 3
1 15000 3
1 14000 4
1 13000 4

The table has to be ordered by Level ascending, Salary descending and then each item ranked into a quartile. From the example, we take all the employees with Level=1, take the distinct Salary (20,19,18,17,16,15,14 and 13000) and assign a quartile to which the employee falls in. 20 and 19 fall into the first quartile so all the employees with a salary of 20 or 19 (3 items) are given the quartile 1.

this is my xslt so far. I can get as far as the order but have no idea how to give rating for quartiles.... any help would be greatly appreciated. my xslt so far:

Code:
<xsl:key name="levels" match="emp" use="level"/>
<xsl:template name="InsertTable">
        <xsl:for-each select="//emp[generate-id() = generate-id(key('levels', level)[1])]">
            <xsl:sort select="level" data-type="number"/>
            <xsl:for-each select="key('levels', level)">
                <xsl:sort select="salary" data-type="number" order="descending"/>
                <xsl:apply-templates select="."/>
            </xsl:for-each>
        </xsl:for-each>
    </Table>
</xsl:template>

<xsl:template match="emp">


</xsl:template>
 
Old September 26th, 2008, 02:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You've shown some Muenchian grouping code which suggests you are trying to tackle this in XSLT 1.0. Is that a constraint? It makes it much more difficult. Are there any other constraints, e.g. does it have to be a single-pass solution, can you use exsl:node-set()?

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
 
Old September 26th, 2008, 04:37 AM
Registered User
 
Join Date: Sep 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Michael (btw, i cut my xslt teeth on your XSLT Programmers Reference book!)

XSLT 1.0. isn't a constraint... we (as a company) just havent made the leap to 2.0 yet. A solution in 1.0 would be ideal but if its easier in 2.0 i would take the 2.0 solution. Also, it doesn't have to be a single-pass solution - i have used exsl:node-set() in other stylesheets I have worked with.

Thanks again






Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting all listbox items Lucy_H85 C# 2005 2 December 1st, 2009 05:36 AM
Count the same items stasnikov Access VBA 1 January 12th, 2007 12:27 PM
Change in forum rank kherrerab BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 December 18th, 2006 10:39 AM
Datagrid items!!!!! mike_remember ASP.NET 1.0 and 1.1 Professional 1 October 28th, 2006 01:01 AM
displaying 6 items only having 20 items Lakshmi KS VB Components 1 February 17th, 2004 10:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.