XML : Mapping using Custom XSLT for multiple occurrence of the source

I have a Source XML as follows---

  <Characteristics>      <Cname>.....</Cname>      <Cvalue>....</Cvalue>  </Characteristics>    

Now the above element 'Characteristics' may have multiple occurrences.

Then we have the target XML as follows

  <Parent>    <elem_a/>    <elem_b/>    <elem_c/>    <elem_d/>       .       .       .  </Parent>    

Now the requirement is, for every occurrence of 'Characteristics', we first check, the value of the sub-element 'Cname'; it is given that, the value of the element 'Cname' will always be 'elem_a' or 'elem_b' or 'elem_c' so on... and they can appear in any order as follows---

  <Characteristics>      <Cname>elem_d</Cname>      <Cvalue>123</Cvalue>  </Characteristics>  <Characteristics>      <Cname>elem_a</Cname>      <Cvalue>073</Cvalue>  </Characteristics>         .         .         .    

So, when the value of the element 'Cname' is 'elem_a', then we will send the value of the element 'Cvalue' to the target element 'elem_a'

I tried to go forward as follows, but then I'm stuck.

  <xsl:for-each select="Characteristics/node()[contains(local-name(),&apos;Cname&apos;)]">  <xsl:if test="contains(./text(),'elem_a')>  <Parent xmlns=" ">      <elem_a xmlns=" ">          <xsl:value-of select="Characteristics/Cvalue/text()"/>      </elem_a>  </Parent>  </xsl:if>  </xsl:for-each>    

After writing above piece of code, I realize that I cannot dynamically check and map the values at a time.

SO, it will be helpful, if anyone say the approach how can I dynamically check and send the values correctly at a time

No comments:

Post a Comment