Topic
1 reply Latest Post - ‏2013-05-15T16:19:45Z by thorstenhirsch
RPotteti
RPotteti
10 Posts
ACCEPTED ANSWER

Pinned topic Restrict Functional Map Occurances

‏2013-05-10T22:08:03Z |

Hi -

Can anyone help with the below WTX problem?

My input message looks like -

<Header>
    <Lines>
        <Line>
            <LineRef>1</LineRef>
            <LineNo>1</LineNo>
        </Line>
        <Line>
            <LineRef>1</LineRef>
            <LineNo>2</LineNo>
        </Line>
        <Line>
            <LineRef>1</LineRef>
            <LineNo>3</LineNo>
        </Line>
        <Line>
            <LineRef>2</LineRef>
            <LineNo>1</LineNo>
        </Line>
        <Line>
            <LineRef>2</LineRef>
            <LineNo>2</LineNo>
        </Line>
        <Line>
            <LineRef>3</LineRef>
            <LineNo>1</LineNo>
        </Line>
    </Lines>
</Header>

And outut should look like this-
<Header>
    <Lines>
        <Line>
            <LineRef>1</LineRef>
            <Quantity>6</Quantity> (Count of occurances of LineRef 1)
            <LineNoNote>1, 2,3</LineNoNote> (Line No's of LineRef 1)
        </Line>
        <Line>
            <LineRef>2</LineRef>
            <Quantity>3</Quantity> (Count of occurances of LineRef 2)
            <LineNoNote>1, 2</LineNoNote> (Line No's of LineRef 2)
        </Line>
        <Line>
            <LineRef>1</LineRef>
            <Quantity>1</Quantity> (Count of occurances of LineRef 3)
            <LineNoNote>1</LineNoNote> (Line No's of LineRef 3)
        </Line>
    </Lines>
</Header>

I am thinking to use a functional map to implement this. I can get count of unique LineRef using Unique and count functions. I want to use this number to restrict the no of times Lines in output.

But I an not sure how to implement this. Please help if you have a solution for this.

Thanks. Raj.

  • thorstenhirsch
    thorstenhirsch
    83 Posts
    ACCEPTED ANSWER

    Re: Restrict Functional Map Occurances

    ‏2013-05-15T16:19:45Z  in response to RPotteti

    You might want to use an additional group for grouping lines with the same LineRef in the input. Let's call this group "LineRefGroup". You place it between the Lines element and the Line element. And you add a component rule like this one:

    LineRef:Line:$ = LineRef:Line:$[LAST]
    

    That way your resulting objects have the following count:

    Header: 1

    1: Lines: 1

    1: LineRefGroup: 3

    1: Lines: 3 (SUM(LineNo): 6)

    2: Lines: 2 (SUM(LineNo): 3)

    3: Lines: 1 (SUM(LineNo): 1)

    That way you can use a functional map on LineRefGroup, which already has the 3 Line items that you want in your output.