Skip to Content
avatar image
Former Member

How can I Sort a Segment base on the value of one of the Elements

Hi All,

I need to sort a segment base on a line number (one of the elements of the segment). The best way to explain my question is via the example below

For example:

Source

<Order>
	<Article>
		<LineNumber>3</ LineNumber>
                <ArticleCode>333123</ ArticleCode>
		<Description> Some sort of description</Description>
		…
	</Article>
	<Article>
		<LineNumber >1</LineNumber>
		<ArticleCode >111123</ArticleCode>
		<Description> another of description</Description>
		…
	</Article>
	<Article>
		<LineNumber >2</LineNumber>
		<ArticleCode >222123</ArticleCode>
		<Description> Again a description</Description>
		…
	</Article>

</Order>

Result should be:

Target

<Order>
	<Line>
		<LineNumber >1</LineNumber>
		<Article>
			<ArticleCode>111123</ArticleCode>
			<Description> another of description</Description>
		</Article>
		…
	</Line>
	<Line>
		<LineNumber >2</ LineNumber>
		<Article>
			<ArticleCode >222123</ArticleCode>
			<Description> Again a description</Description>
		</Article>
		…
	</Line>
        <Line>
		<LineNumber>3</ LineNumber >
                <Article>
                        <ArticleCode>333123</ArticleCode>
			<Description> Some sort of description</Description>
		</Article>
		…
	</Line>
</Order>

Thanks

Jacques

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Apr 18, 2008 at 10:29 AM

    Hi Maritz,

    I got this one i think 😊

    do this,

    For target LineNum node

    LineNum ->removeContexts ->sort(numerical, ascending) ->Split By value(Each Value -->Target LineNum

    For all the other nodes

    LineNum--->removeContexts

    -->

    >Sort Bykey ->SplitByValue(Each Value)-->ArticleCode

    ArticleCode--->removeContexts

    Please tell me if you have any doubts

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Varun,

      Thank you for your reply it is helpful and you solution will work, but I have one concern.

      I have to map roundabout 20 fields, with complex if statements etc. by adding the extra functions will cause the mappings to be more complex.

      Is there a way to avoid/limit the use of these functions?

      Thanks

      Jacques