Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

XSLT ordering error. What is wrong? How do i fix it?

XSLT ordering error. What is wrong? How do i fix it?

XSLT ordering error. What is wrong? How do i fix it?

Hello all!

I'm trying to do a XSLT document that will get data from two different XML documents.

I have orderd the donations in the document fine, but when i try to take all the persons who have donated a specific amount to the specific category, I only get one person per category, but I want all, What am I doing wrong? Can someone help me fix it and explain to me how I did wrong and how it was fixed please?



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="donerAmount" match="donation" use="@amount"/>
<xsl:key use="@amount" name="howManyDonated" match="donation"/>

<xsl:key use="@pid" name="personsID" match="persons/person"/>
<xsl:variable name="personas" select="document('persons.xml')"/>
<xsl:template match="/">
<title>Lighthouse charitabe Trust!</title>
<link href="listings.css" rel="stylesheet" type="text/css"/>
<img src="logo.jpg" alt="Lighthouse loggo"/>
<td>Total doners: <xsl:value-of select="count(donations/donation)"/>

<td>Total donation amount: <xsl:value-of select="sum(donations/donation/@amount)"/>$</td>

<div id="city_list">
<b>Donations </b> |
<xsl:apply-templates select="donations/donation[not(@amount=preceding::donation/@amount)]" mode="donationList">
<xsl:sort select="@amount" data-type="number"/>
<xsl:for-each select="//donation[generate-id()=generate-id(key('howManyDonated', @amount)[1])]">
<xsl:sort select="@amount" order="descending" data-type="number"/>
<h1 id="{generate-id()}">
<xsl:value-of select="@amount"/>

<xsl:variable name="peID" select="@pin"/>
<xsl:for-each select="$personas">
<th>Name: </th>
<th>last name: </th>
<th>Street: </th>
<th>city: </th>
<th>state: </th>
<th>zip: </th>
<xsl:value-of select="key('personsID', $peID)/firstName"/>
<xsl:value-of select="key('personsID', $peID)/lastName"/>
<xsl:value-of select="key('personsID', $peID)/street"/>
<xsl:value-of select="key('personsID', $peID)/city"/>
<xsl:value-of select="key('personsID', $peID)/state"/>
<xsl:value-of select="key('personsID', $peID)/zip"/>
<!--<xsl:variable name="peid" select="@person"/>
<xsl:for-each select="$persons">
<xsl:value-of select="key('firmID', $fID)/name"/>
<xsl:value-of select="key('personsID', $peid)/street"/>
<xsl:apply-templates select="donations">
<xsl:sort select="donation"/>
<xsl:template match="donation" mode="donationList">
<a href="#{generate-id()}">
<xsl:value-of select="@amount"/>
(<xsl:value-of select="count(key('howManyDonated', @amount))"/>) |
<xsl:template match="donation">
<xsl:value-of select="."/>

Here is the money document:


<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="money.xsl" ?>
<donation pin="p1" amount="10000" />
<donation pin="p2" amount="50" />
<donation pin="p3" amount="100" />
<donation pin="p4" amount="10000" />
<donation pin="p5" amount="100" />
<donation pin="p6" amount="100" />
<donation pin="p7" amount="1000" />
<donation pin="p8" amount="100" />
<donation pin="p9" amount="10000" />
<donation pin="p10" amount="500" />
<donation pin="p11" amount="500" />
<donation pin="p12" amount="50" />
<donation pin="p13" amount="100" />
<donation pin="p14" amount="50" />
<donation pin="p15" amount="100" />
<donation pin="p16" amount="10000" />
<donation pin="p17" amount="1000" />
<donation pin="p18" amount="25000" />
<donation pin="p19" amount="50" />
<donation pin="p20" amount="5000" />
<donation pin="p21" amount="500" />
<donation pin="p22" amount="100" />
<donation pin="p23" amount="100" />
<donation pin="p24" amount="25000" />
<donation pin="p25" amount="500" />
<donation pin="p26" amount="5000" />
<donation pin="p27" amount="1000" />
<donation pin="p28" amount="1000" />
<donation pin="p29" amount="50" />
<donation pin="p30" amount="50" />
<donation pin="p31" amount="100" />
<donation pin="p32" amount="1000" />
<donation pin="p33" amount="50" />
<donation pin="p34" amount="500" />
<donation pin="p35" amount="50" />
<donation pin="p36" amount="500" />
<donation pin="p37" amount="500" />
<donation pin="p38" amount="100" />
<donation pin="p39" amount="500" />
<donation pin="p40" amount="50" />
<donation pin="p41" amount="500" />
<donation pin="p42" amount="1000" />
<donation pin="p43" amount="15000" />
<donation pin="p44" amount="1000" />
<donation pin="p45" amount="100" />
<donation pin="p46" amount="5000" />
<donation pin="p47" amount="500" />
<donation pin="p48" amount="100" />
<donation pin="p49" amount="100" />
<donation pin="p50" amount="50" />
<donation pin="p51" amount="50" />
<donation pin="p52" amount="50" />
<donation pin="p53" amount="15000" />
<donation pin="p54" amount="5000" />
<donation pin="p55" amount="50000" />
<donation pin="p56" amount="500" />
<donation pin="p57" amount="50" />
<donation pin="p58" amount="1000" />
<donation pin="p59" amount="1000" />
<donation pin="p60" amount="50" />

Here is a short sample of the persons document, it's very long so if you want me to post the whole document, just tell me.


<?xml version="1.0" encoding="UTF-8" ?>

<person pid="p1">
<street>5133 Oak Street</street>
<phone>(532) 555-8981</phone>
<person pid="p2">
<street>31 Alice Avenue</street>
<phone>(532) 555-7212</phone>
<person pid="p3">
<street>451 Unwin Court</street>
<phone>(534) 555-9082</phone>
<person pid="p4">
<street>87 Hilltop Drive</street>
<phone>(534) 555-7493</phone>
<person pid="p5">
<street>891 Lindon Lane</street>
<phone>(532) 555-4313</phone>
<person pid="p6">
<street>55 Hawking Street</street>
<phone>(532) 555-9939</phone>
I would realy appreciate help and guidence on why every category only shows one person instead of all. Thank you!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close