Jump to content
Sign in to follow this  
nagabhb@gmail.com

Group based on element value

Recommended Posts

Hi , Need xslt help for the below conversion.

Currently we are iterating based on the accNo , however would like to check if we get a better solution using Muenchian Method.


Input:


<Details>

<GroupA>

<rec1A>

<accNo>123</accNo>

<accName>abc</accName>

</rec1A>

<rec2A>

<accNo>234</accNo>

<accName>xyz</accName>

</rec2A>

</GroupA>

<GroupB>

<rec1B>

<accNo>123</accNo>

<accValue>100</accValue>

</rec1B>

<rec2B>

<accNo>234</accNo>

<accValue>200</accValue>

</rec2B>

</GroupB>

<GroupC>

<rec1C>

<accNo>123</accNo>

<accAddress>address1</accAddress>

</rec1C>

<rec2C>

<accNo>234</accNo>

<accAddress>address2</accAddress>

</rec2C>

</GroupC>

</Details>


Output:


<Details>

<Group1>

<rec1A>

<accNo>123</accNo>

<accName>abc</accName>

</rec1A>

<rec1B>

<accNo>123</accNo>

<accValue>100</accValue>

</rec1B>

<rec1C>

<accNo>123</accNo>

<accAddress>address1</accAddress>

</rec1C>

</Group1>

<Group2>

<rec2A>

<accNo>234</accNo>

<accName>xyz</accName>

</rec2A>

<rec2B>

<accNo>234</accNo>

<accValue>200</accValue>

</rec2B>

<rec2C>

<accNo>234</accNo>

<accAddress>address2</accAddress>

</rec2C>

</Group2>

</Details>


Thanks.

Share this post


Link to post
Share on other sites

I'm not sure if it can be done, but the solution would probably have been easier if you had the grouping data in attributes. In XML, the element name should be used to indicate the type of data and not actually contain data in itself.

<rec number="1" letter="B">
  <accNo>123</accNo>
  <accName>abc</accName>
</rec>
<rec number="1" letter="B">
  <accNo>123</accNo>
  <accValue>100</accValue>
</rec>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×