xsl for-each group-by

Posted by user348810 on Stack Overflow See other posts from Stack Overflow or by user348810
Published on 2010-05-24T10:53:19Z Indexed on 2010/05/24 11:11 UTC
Read the original article Hit count: 151

Filed under:

My input xml is in this format:

<Root>

<Name>N1</Name>
<YEAR>2010</YEAR>
<MYVALE>
  <F1>V1</F1>
  <V1>100</V1>
<MYVALUE>
<MYVALE>
  <F1>V2</F1>
   <V1>100</V1>
<MYVALUE>
<MYVALE>
  <F1>V3</F1>
  <V1>100</V1>
<MYVALUE>

<Name>N1</Name>
<YEAR>2011</YEAR>
 <MYVALE>
  <F1>V1</F1>
   <V1>100</V1>
<MYVALUE>
 <MYVALE>
  <F1>V4</F1>
   <V1>400</V1>
<MYVALUE>

</Root>

i want to group-by Name with the following child element <myvalue>. If the myvalue TAG has the same F1 TAG value then I need to group by these values.

My expected output is this:

<Root>

<Name>N1</Name>
<MYVALE>
    <F1>V1</F1>
    <V1>200</V1>
</MYVALUE>
<MYVALE>
    <F1>V2</F1>
    <V2>100</V2>
</MYVALUE>
<MYVALE>
    <F1>V3</F1>
    <V2>100</V2>
</MYVALUE>
<MYVALE>
    <F1>V4</F1>
    <V2>400</V2>
<MYVALUE>
</Root>

© Stack Overflow or respective owner

Related posts about xslt