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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...