|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
input to ouput xml in ESQL |
« View previous topic :: View next topic » |
Author |
Message
|
chenna.hari |
Posted: Sun Oct 28, 2012 4:27 am Post subject: input to ouput xml in ESQL |
|
|
Centurion
Joined: 21 Mar 2009 Posts: 103
|
Any suggestions how to do in esql the best way.
Input is given below
Quote: |
<input>
<A>
<B>x</B>
<C>1</C>
</A>
<A>
<B>y</B>
<C>5</C>
</A>
<A>
<B>x</B>
<C>2</C>
</A>
</input> |
from the above input, need to convert to below output using esql
Quote: |
<output>
<A>
<B>x</B>
<C>3</C>
</A>
<A>
<B>y</B>
<C>5</C>
</A>
</output> |
|
|
Back to top |
|
 |
Vitor |
Posted: Sun Oct 28, 2012 4:54 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
You could use a ROW variable for each value of B and sum the values of C into it.
Unless you can do something clever with SELECT like:
Code: |
SELECT SUM(I.C) FROM input AS I WHERE DISTINCT(B) |
Which I am almost certain doesn't work as I've written it (early Sunday morning, out of coffee, much pet noise) but you could maybe iterate through each value of B to SELECT all C, then sum them.
Other and more elegant methods are undoubtedly possible. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqsiuser |
Posted: Sun Oct 28, 2012 7:56 am Post subject: Re: input to ouput xml in ESQL |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
At the end of this thread I list the choices that you have. I have basically created my project around this problem. There are a couple of ways to do it.
The most straight forward way I see is to use the MOVE ref WHERE function(s) (on "B") and add/append the data to "C", e.g.:
Code: |
CALL CopyMessageHeaders();
DECLARE rOut REFERENCE TO OutputRoot;
CREATE LASTCHILD OF rOut AS rOut DOMAIN 'XMLNSC';
CREATE LASTCHILD OF rOut AS rOut NAME 'output';
DECLARE rIn REFERENCE TO InputRoot.XMLNSC.input;
MOVE rIn FIRSTCHILD NAME 'A'; -- do/try this MOVE: Since the INPUT-List (of "A"s) could be empty !
DECLARE rOutA REFERENCE TO rOut;
WHILE LASTMOVE( rIn ) DO
IF NOT moveFirstChildWhere( rOutA, 'A', 'B', rIn.B ) THEN -- "MOVE rOutA FIRSTCHILD NAME 'A' WHERE 'B' EQUALS rIn.B"
CREATE LASTCHILD OF rOutA AS rOutA NAME 'A';
END IF;
SET rOutA.B = rIn.B;
SET rOutA.C = COALESCE(rOutA.C, 0) + CAST(rIn.C AS INT);
MOVE rOutA TO rOut;
MOVE rIn NEXTSIBLING REPEAT NAME;
END WHILE;
RETURN TRUE; |
This code should work... anyhow: If there are any mistakes, please let me know. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|