Subject:return different result based on conditions Author:Steve Anderson Date:15 Nov 2009 11:54 PM
I am having a hard time returning a value based on certain conditions.
SORRY FOR THE LAME EXAMPLE...
I have a group of departments which contain certain items.
Dept A: PS3, PSP, XBox, WII
Dept B: PS3, XBox
Dept C: WII
Dept D: PSP, WII
Each of these items have a price. I want to return the total for each department.
So, lets say
PS3 = $300
PSP = $150
Xbox = $350
WII = $250
So the total for Dept D should be $400
How can i do this using XQuery. I just found out that variables don't change in XQuery, so there goes that idea (can't use a counter of any sort). I am stuck and need your help.
Subject:return different result based on conditions Author:(Deleted User) Date:16 Nov 2009 09:07 AM
Hi Steve,
in XQuery (and XSLT) you work on set of nodes, so you can compute the sum once you have written down the XPath query that highlights the prices of the items of department D. If you post the XML fragment, we could tell you such a query.
total = 0
for all departments
string array of <items> using tokenize with delimiter ", "
for all items found in the department
if item = "PS3"
then total = total + 300
else if item = "PSP"
then total = total + 150
and
so
on...
So, I found out the hard way that you can't change a variable in XQuery. So, this sudo code will not work.