Author |
Message
|
maxmq |
Posted: Tue Jan 18, 2011 12:15 pm Post subject: reading different inner xml tag in loop and sum |
|
|
Newbie
Joined: 18 Jan 2011 Posts: 3
|
i want to create a loop from an input which has different xml inner tag which adds the total and sets it to an output totalsales :
InputRoot.XMLNSC.PL.T.TR.LI.SalesfromA.amt.Amount;
InputRoot.XMLNSC.PL.T.TR.LI.BSales.amt.Amount;
InputRoot.XMLNSC.PL.T.TR.LI.SalesC.amt.Amount;
...............
the Sales are different/keep changing..rest all tags are same in the file
i cant even find the cardinality of sales since the tag is different
i am a total newbie....plz help..totally confused  |
|
Back to top |
|
 |
Vitor |
Posted: Tue Jan 18, 2011 12:38 pm Post subject: Re: reading different inner xml tag in loop and sum |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
maxmq wrote: |
the Sales are different/keep changing..rest all tags are same in the file
i cant even find the cardinality of sales since the tag is different |
So what you're actually adding are the values of:
InputRoot.XMLNSC.PL.T.TR.some random tag name.amt.Amount?
In that case what you need is a way of making WMB sum amt.Amount irrespective of what's in front it. Like this for instance.
maxmq wrote: |
i am a total newbie.... |
Get some formal training. Push back on whoever's given you this task & point out how complex WMB is. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Tue Jan 18, 2011 3:25 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Sounds like one of those tasks that would be very simple in XPath. /ducks/
I expect the op really wants to stay with ESQL, though. In which case the SELECT function offers hope of a really nice solution:
http://publib.boulder.ibm.com/infocenter/wmbhelp/v6r1m0/topic/com.ibm.etools.mft.doc/ak05620_.htm
Note especially that you can apply the SUM function to the SELECT.
The only question is whether you can use a wildcard ( * ) in the FROM expression. I think you probably can, but mgk is sure to know either way. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Jan 18, 2011 6:21 pm Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
kimbert wrote: |
Sounds like one of those tasks that would be very simple in XPath. /ducks/ |
I'd use an ESQL Select. If, at least, I'd bothered to confirm that ESQL select supports SUM. /ducks/ |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jan 19, 2011 3:32 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
You're both quackers.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jan 19, 2011 3:33 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
You're both quackers.  |
We also both agree that mgk is sure to know either way... |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jan 19, 2011 3:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mqjeff wrote: |
Vitor wrote: |
You're both quackers.  |
We also both agree that mgk is sure to know either way... |
He always does... _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mgk |
Posted: Wed Jan 19, 2011 5:00 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
I would not go that far, but I do in this case
This code shows how to do this.
Code: |
--set up the data to select from
CREATE LASTCHILD OF Environment DOMAIN 'XMLNSC' NAME 'XMLNSC' ;
SET Environment.XMLNSC.PL.T.TR.LI.SalesfromA.amt.Amount = 42;
SET Environment.XMLNSC.PL.T.TR.LI.BSales.amt.Amount = 43;
SET Environment.XMLNSC.PL.T.TR.LI.SalesC.amt.Amount = 44;
--find out how many sales records there are (cardinality)
SET OutputRoot.XMLNSC.Top.NumberOfSales = CARDINALITY(Environment.XMLNSC.PL.T.TR.LI.*[]);
--get all the records
SET OutputRoot.XMLNSC.Top.All.Data[] = SELECT SALES.amt.Amount FROM Environment.XMLNSC.PL.T.TR.LI.*[] AS SALES ;
--sum the total of all the records
SET OutputRoot.XMLNSC.Top.Totalsales = SELECT SUM( SALES.amt.Amount ) FROM Environment.XMLNSC.PL.T.TR.LI.*[] AS SALES ; |
The above code produces this output message:
Code: |
<Top>
<NumberOfSales>3</NumberOfSales>
<All>
<Data><Amount>42</Amount></Data>
<Data><Amount>43</Amount></Data>
<Data><Amount>44</Amount></Data>
</All>
<Totalsales>129</Totalsales>
</Top> |
I hope this helps, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
|