XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 27th, 2012, 06:47 AM
pikusinski pikusinski is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2012
Posts: 1 pikusinski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 31 m 16 sec
Reputation Power: 0
XSL ordering error, what's the problem? How can 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?

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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > XSL ordering error, what's the problem? How can I fix it?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap