This is the output. However, client wants the Test id=1 to be unique in the output rather than repeating it twice(the complete Test id= tree). So if there are 2 Test id=1 then in the output the output XML needs to be something like below:
Joined: 27 Mar 2003 Posts: 1564 Location: Hartford, CT.
Quote:
Do we have any DISTINCT type keywords in E-SQL.
No.
The best solution may be to prevent the duplicate entries from appearing in the Output tree in the first place:
Code:
DECLARE inIndex INTEGER 1;
DECLARE outIndex INTEGER 1;
DECLARE inRef REFERENCE TO InputRoot.XML.ParentTag;
DECLARE inCount INTEGER CARDINALITY(inRef.Test[]);
CREATE FIELD OutputRoot.XML.ParentTag;
DECLARE outRef REFERENCE TO OutputRoot.XML.ParentTag;
WHILE inIndex <= inCount DO
IF EXISTS(SELECT * FROM outRef.Test[] AS T WHERE T.(XML.Attribute)id = inRef.Test[inIndex].(XML.Attribute)id) THEN
ELSE
SET outRef.Test[outIndex] = inRef.Test[inIndex];
SET outIndex = outIndex + 1;
END IF;
SET inIndex = inIndex + 1;
END WHILE;
But, if that's un-avoidable, this should suffice:
Code:
DECLARE outRef REFERENCE TO OutputRoot.XML.ParentTag;
DECLARE testRef REFERENCE TO outRef.Test;
WHILE LASTMOVE(testRef) = TRUE DO
IF (SELECT COUNT(*) FROM outRef.Test[] AS T WHERE T.(XML.Attribute)id = testRef.(XML.Attribute)id) > 1 THEN
DECLARE test2Ref REFERENCE TO testRef;
MOVE testRef NEXTSIBLING;
DETACH test2Ref;
ELSE
MOVE testRef NEXTSIBLING;
END IF;
END WHILE;
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