INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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.

Jobs

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?

(OP)
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?

XSLT:

CODE

<?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="/">
<html>
<head>
<title>Lighthouse charitabe Trust!</title>
<link href="listings.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<p>
<img src="logo.jpg" alt="Lighthouse loggo"/>
</p>
<td>Total doners: <xsl:value-of select="count(donations/donation)"/>
</td>
<br/>

<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:apply-templates>
</div>
<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"/>
</h1>

<xsl:variable name="peID" select="@pin"/>
<xsl:for-each select="$personas">
<table>
<tr>
<th>Name: </th>
<th>last name: </th>
<th>Street: </th>
<th>city: </th>
<th>state: </th>
<th>zip: </th>
<br/>
</tr>
<tr>
<td>
<xsl:value-of select="key('personsID', $peID)/firstName"/>
</td>
<td>
<xsl:value-of select="key('personsID', $peID)/lastName"/>
</td>
<td>
<xsl:value-of select="key('personsID', $peID)/street"/>
</td>
<td>
<xsl:value-of select="key('personsID', $peID)/city"/>
</td>
<td>
<xsl:value-of select="key('personsID', $peID)/state"/>
</td>
<td>
<xsl:value-of select="key('personsID', $peID)/zip"/>
</td>
</tr>
</table>
</xsl:for-each>
<!--<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:for-each>-->
</xsl:for-each>
<xsl:apply-templates select="donations">
<xsl:sort select="donation"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="donation" mode="donationList">
<a href="#{generate-id()}">
<xsl:value-of select="@amount"/>
</a>
(<xsl:value-of select="count(key('howManyDonated', @amount))"/>) |
</xsl:template>
<xsl:template match="donation">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>

Here is the money document:

CODE

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="money.xsl" ?>
<donations>
<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" />
</donations>

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.

CODE

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

<persons>
<person pid="p1">
<firstName>David</firstName>
<lastName>Olson</lastName>
<street>5133 Oak Street</street>
<city>Delphi</city>
<state>KY</state>
<zip>89011</zip>
<phone>(532) 555-8981</phone>
</person>
<person pid="p2">
<firstName>Cindy</firstName>
<lastName>Wu</lastName>
<street>31 Alice Avenue</street>
<city>Delphi</city>
<state>KY</state>
<zip>89011</zip>
<phone>(532) 555-7212</phone>
</person>
<person pid="p3">
<firstName>Lee</firstName>
<lastName>Thomas</lastName>
<street>451 Unwin Court</street>
<city>Jasper</city>
<state>KY</state>
<zip>89381</zip>
<phone>(534) 555-9082</phone>
</person>
<person pid="p4">
<firstName>Jane</firstName>
<lastName>Whitney</lastName>
<street>87 Hilltop Drive</street>
<city>Jasper</city>
<state>KY</state>
<zip>89381</zip>
<phone>(534) 555-7493</phone>
</person>
<person pid="p5">
<firstName>Andrew</firstName>
<lastName>Sanchez</lastName>
<street>891 Lindon Lane</street>
<city>Delphi</city>
<state>KY</state>
<zip>89011</zip>
<phone>(532) 555-4313</phone>
</person>
<person pid="p6">
<firstName>Gary</firstName>
<lastName>Windt</lastName>
<street>55 Hawking Street</street>
<city>Delphi</city>
<state>KY</state>
<zip>89011</zip>
<phone>(532) 555-9939</phone>
</person>
</persons>
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!

Resources

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