cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping output not in sequence

Former Member
0 Kudos

All,

We have a system where we send in an xml message. The request XML has a list of two fields "index" and "sourcevalue". The message returned has the list of two fields "index" and "targetvalue".

The problem is the returned message, where the output is not ordered. while the input message might send in ascending sequence of index

<inputmessage>

<mesg1><index>1</index><sourecvalue>svalue1</sourecvalue></mesg1>

<mesg1><index>2</index><sourecvalue>svalue2</sourecvalue></mesg1>

<mesg1><index>3</index><sourecvalue>svalue3</sourecvalue></mesg1>

<mesg1><index>4</index><sourecvalue>svalue4</sourecvalue></mesg1>

</inputmessage>

<outputmessage>

<mesg2><index>1</index><targetvalue>tvalue1</targetvalue></mesg2>

<mesg2><index>4</index><targetvalue>tvalue4</targetvalue></mesg2>

<mesg2><index>2</index><targetvalue>tvalue2</targetvalue></mesg2>

<mesg2><index>3</index><targetvalue>tvalue3</targetvalue></mesg2>

</outputmessage>

we need to send the message out with the right target values properly mapped based on the index and sent out.

how can we do this in mapping?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You'll first need to create a global variable and a global String array in the mappings, I'll call it

int number; and

String[] order;

Then you need to map index over like this,

Index --> removeContexts --> UDFSplitAndReorder --> newIndex

Make UDFSplitAndReorder a Queue function, Index will enter it as a String array.

For later purposes store this string array as the global variable order mentioned above.

Now in the UDFSplitAndReorder, just use a sorting algorythm of your choice, when you are done sorting the String array from lowest index to greatest, use a for loop and the result.addValue("value from string array") function to add all indexs into the result list. This will wrk for the indexes

Now for the actual items, its a little more complicated,

you need to map item over like this,

Item --> removeContexts --> UDFSplitAndReorderItems --> newItem

In the UDFSplitAndReorderItems function, you will need to do the same things as the last time, but instead you will need to sort the items out by referencing the global array list order.

An example of this sorting would be that if you had Index number 1 in position three of the array, then you would need to sort Item number 3 to position 1.

Hope this helps you, I'll take points if you can get it to work, I actually had a similar situation and it took me days the first time I did it.

Message was edited by:

Paul Reimius Schroeder

Answers (3)

Answers (3)

Former Member
0 Kudos

I have to agree with SriHari Bandi on this one, when I read your question deeper, it doesn't really make sense. But I think I answered for what you meant to ask.

Former Member
0 Kudos

Hello,

Output is not properly ordered that should not be the case when your input is sorted so will the ouput be.

Or else if you still say the output is not ordered you can sort the output to get the order right.

or else test with the below XSL if this is helpful.

<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output indent="yes" encoding="utf-8" media-type="XML"/>

<xsl:template match="/">

<xsl:element name="mseg1">

<xsl:element name="inputmessage">

<xsl:for-each select="inputmessage/mesg1">

<xsl:sort select="index" order="ascending"/>

<xsl:element name="index">

<xsl:value-of select="index"/>

</xsl:element>

<xsl:element name="targetvalue">

<xsl:value-of select="sourecvalue"/>

</xsl:element>

</xsl:for-each>

</xsl:element>

</xsl:element>

</xsl:template>

</xsl:stylesheet>

Regards,

Former Member
0 Kudos

I'll help you on this one, it's a very complicated mapping solution, so sit tight.