Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 4th, 2003, 11:28 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help Sorting

hi i have a problem where i want to sort the total of the sum as in the points allocated to each user from highest to lowest and then once i have done that is it possible sorting them by alphabetical order ...

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="e2template.xsl" />

<xsl:key name="nickname" match="Rank" use="Position/NickName"/>
<xsl:key name="weeks" match="Rank" use="Position/WeekID"/>
<xsl:key name="users" match="Rank" use="Position/UserID"/>

<xsl:template match="Page">

    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td height="53"></td></tr>
    <xsl:if test="//Page/SectionName = 'Members'">
    <tr><td background="/images/Header_stretch.gif"><img alt="" width="378" height="17"><xsl:attribute name="src">images/<xsl:value-of select="//Page/SectionName" />_Header.gif</xsl:attribute></img></td></tr>
    </xsl:if>
    <tr><td height="20"></td></tr>
    </table>

    <table border="1" cellpadding="2" cellspacing="0" width="250">
    <tr>
        <td>Username</td>
        <td>Points</td>

    </tr>
    <xsl:for-each select="//Common/Ranks/Rank/Position/NickName[generate-id(ancestor::Rank) = generate-id(key('nickname', .)[1])]">
    <xsl:variable name="current-week-id" select="."/>
    <tr>
        <td><xsl:value-of select="."/></td>
        <td>
        <xsl:for-each select="//Common/Ranks/Rank/Position/UserID[generate-id(ancestor::Rank) = generate-id(key('users', .)[1])]">

            <xsl:if test="//Common/Ranks/Rank/Position[NickName = $current-week-id and UserID = current()]">
                <xsl:value-of select="sum(//Common/Ranks/Rank/Position/Points[preceding-sibling::NickName = $current-week-id and preceding-sibling::UserID = current()])"/> points
            </xsl:if>

        </xsl:for-each>
        </td>
    </tr>
    </xsl:for-each>
    </table>

</xsl:template>

</xsl:stylesheet>

So i want my end result to be

user 1 5 points
user 2 3 points
user 3 3 points

etc ...

If anyone can help me out it would be much appreciated ..


Reply With Quote
  #2 (permalink)  
Old August 7th, 2003, 01:35 PM
Authorized User
Points: 251, Level: 5
Points: 251, Level: 5 Points: 251, Level: 5 Points: 251, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Canada.
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to rushman
Default

Maybe you should post an example of your XML document... It'll be easier to understand.

Help yourself so we can help you ;o)

Dijkstra's law on Programming and Inertia:

If you don't know what your program is supposed to do, don't try to write it.
Reply With Quote
  #3 (permalink)  
Old August 8th, 2003, 03:13 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Without seeing source document it's difficult but it looks like you need "Muenchian Grouping", serach for this on Google, there are examples at:
http://www.jenitennison.com/


--

Joe
Reply With Quote
  #4 (permalink)  
Old August 10th, 2003, 07:50 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default


This is the XML

<Common>
    <Rank>
        <Position>
            <WeekID>1</WeekID>
            <UserID>16</UserID>
            <NickName>Eel</NickName>
            <Points>0</Points>
        </Position>
        <Position>
            <WeekID>2</WeekID>
            <UserID>16</UserID>
            <NickName>Eel</NickName>
            <Points>3</Points>
        </Position>
        <Position>
            <WeekID>2</WeekID>
            <UserID>17</UserID>
            <NickName>Pepper</NickName>
            <Points>1</Points>
        </Position>
        <Position>
            <WeekID>2</WeekID>
            <UserID>18</UserID>
            <NickName>Rachelle</NickName>
            <Points>3</Points>
        </Position>
        <Position>
            <WeekID>2</WeekID>
            <UserID>17</UserID>
            <NickName>Pepper</NickName>
            <Points>1</Points>
        </Position>
        <Position>
            <WeekID>1</WeekID>
            <UserID>18</UserID>
            <NickName>Rachelle</NickName>
            <Points>2</Points>
        </Position>
    </Rank>
</Common>

all i want to do is for each new week
show who is in the lead by adding up the points for each user

user 1 has 5 points
user 3 has 3 points
user 2 has 1 point

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:import href="e2template.xsl" />

<xsl:key name="nickname" match="Rank" use="Position/NickName"/>
<xsl:key name="weeks" match="Rank" use="Position/WeekID"/>
<xsl:key name="users" match="Rank" use="Position/UserID"/>

<xsl:template match="Page">

    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr><td height="53"></td></tr>
    <xsl:if test="//Page/SectionName = 'Members'">
    <tr><td background="/images/Header_stretch.gif"><img alt="" width="378" height="17"><xsl:attribute name="src">images/<xsl:value-of select="//Page/SectionName" />_Header.gif</xsl:attribute></img></td></tr>
    </xsl:if>
    <tr><td height="20"></td></tr>
    </table>

    <table border="1" cellpadding="2" cellspacing="0" width="250">
    <tr>
        <td>Username</td>
        <td>Points</td>

    </tr>
    <xsl:for-each select="//Common/Ranks/Rank/Position/NickName[generate-id(ancestor::Rank) = generate-id(key('nickname', .)[1])]">
    <xsl:variable name="current-week-id" select="."/>
    <tr>
        <td><xsl:value-of select="."/></td>
        <td>
        <xsl:for-each select="//Common/Ranks/Rank/Position/UserID[generate-id(ancestor::Rank) = generate-id(key('users', .)[1])]">

            <xsl:if test="//Common/Ranks/Rank/Position[NickName = $current-week-id and UserID = current()]">
                <xsl:value-of select="sum(//Common/Ranks/Rank/Position/Points[preceding-sibling::NickName = $current-week-id and preceding-sibling::UserID = current()])"/> points
            </xsl:if>

        </xsl:for-each>
        </td>
    </tr>
    </xsl:for-each>
    </table>

</xsl:template>

</xsl:stylesheet>

thanks for you help.


Reply With Quote
  #5 (permalink)  
Old August 11th, 2003, 06:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

this stylesheet will give you the output you specified. You can add back in all the html to make your page pretty...
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:key name="users" match="Position" use="UserID"/>
  <xsl:template match="/">
    <html>
      <body>

        <xsl:apply-templates select="Common/Rank/Position[generate-id()=generate-id(key('users', UserID)[1])]">
          <xsl:sort select="sum(key('users', UserID)/Points)" data-type="number" order="descending"/>
          <xsl:sort select="key('users', UserID)" data-type="text" order="ascending"/>
        </xsl:apply-templates>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="Position">

    User <xsl:value-of select="UserID"/> has <xsl:value-of select="sum(key('users', UserID)/Points)"/> points<br/>
  </xsl:template>
</xsl:stylesheet>
hth
Phil
Reply With Quote
  #6 (permalink)  
Old August 11th, 2003, 07:51 PM
Authorized User
 
Join Date: Jul 2003
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help

:D

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting member XSLT 25 July 13th, 2007 08:44 AM
SORTING pallone XSLT 3 October 29th, 2006 08:45 AM
Sorting sunny76 Excel VBA 2 September 19th, 2005 09:31 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Sorting? pbernardo XSLT 2 October 27th, 2003 11:34 AM



All times are GMT -4. The time now is 04:38 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.