1 Reply Latest reply: Jan 26, 2012 9:49 PM by 427535 RSS

    Append/Merge in XSLT

    866735
      hi all,

      We have a requirement in our project where we need to convert the following source xml into the target xml.

      source:

      <Request xmlns="http://xmlns.oracle.com/testApp_jws/Extract/Extract">
      <Reg>
      <RefNum>RefNum1</RefNum>
      <Name>Name2</Name>
      <Status>Status3</Status>
      </Reg>
      <Reg>
      <RefNum>RefNum4</RefNum>
      <Name>Name5</Name>
      <Status>Status6</Status>
      </Reg>
      <Reg>
      <RefNum>RefNum1</RefNum>
      <Name>Name2</Name>
      <Status>Status3_New</Status>
      </Reg>
      <Reg>
      <RefNum>RefNum7</RefNum>
      <Name>Name8</Name>
      <Status>Status9</Status>
      </Reg>
      </Request>

      target:

      <client:Response xmlns:client="http://xmlns.oracle.com/testApp_jws/Extract/Extract">
      <client:Reg_Target>
      <client:RefNum>RefNum1</client:RefNum>
      <client:Name>Name2</client:Name>
      <client:Status>
      <client:Status>Status3</client:Status>
      <client:Status>Status3_New</client:Status>
      </client:Status>
      </client:Reg_Target>
      <client:Reg_Target>
      <client:RefNum>RefNum4</client:RefNum>
      <client:Name>Name5</client:Name>
      <client:Status>
      <client:Status>Status6</client:Status>
      </client:Status>
      </client:Reg_Target>
      <client:Reg_Target>
      <client:RefNum>RefNum7</client:RefNum>
      <client:Name>Name8</client:Name>
      <client:Status>
      <client:Status>Status9</client:Status>
      </client:Status>
      </client:Reg_Target>
      </client:Response>


      Basically, we need to look out for IDs and merge the Statuses using XSLT. Please throw some light on this if anybody has worked on it before.

      Thanks,
      KK

      Edited by: 863732 on 15-Jan-2012 19:42
        • 1. Re: Append/Merge in XSLT
          427535
          Are you doing this in OSB? or is this a general XSLT transformation question...

          I assume the latter... here is the pseudocode (it assumes that your Reg.Name is uniquely associated to your ReqNum)

          1. you have to configure your XSLT to only match the <Request> element in a template
          In this template:
          1a. create a variable ie called xmlResponse that will hold your target
          1b. for-each <Reg>
          set currentReg as variable
          if xmlResponse contains //client:Reg_Target/client:RefNum[.=$currentReg/RefNum/text()]
          add <client:Status>$currentReg/Status/text()</client:Status> into $xmlResponse//client:Reg_Target/client:RefNum[.=$currentReg/RefNum/text()]/../client:Status
          else
          add <client:Target><client:RefNum>$currentReg/RefNum/text()<client:RefNum><client:Name>$currentReg/Name/text()</client:Name><client:Status>$currentReg/Status/text()</client:Status><client:Target> as child of $xmlResponse