1 Reply Latest reply: May 5, 2013 10:09 PM by 991448 RSS

    XSLT in BPEL : Get only elements that are not repeating in an XML

    kiransaravi
      Hope you are doing fine I have a scenario where the XML doc contains some nodes that are repeating. I want to get rid of all such nodes. Please note that this is not "Removing Duplicates". I want to completely remove all entries of those nodes that are occuring more than once.

      Ex My XML

      <ReadUserOBSResponse>
      <UserOBS>
      <OBSObjectId>1510</OBSObjectId>
      <UserObjectId>443</UserObjectId>
      </UserOBS>
      <UserOBS>
      <OBSObjectId>540</OBSObjectId>
      <UserObjectId>514</UserObjectId>
      </UserOBS>
      <UserOBS>
      <OBSObjectId>1521</OBSObjectId>
      <UserObjectId>514</UserObjectId>
      </UserOBS>
      <UserOBS>
      <OBSObjectId>547</OBSObjectId>
      <UserObjectId>544</UserObjectId>
      </UserOBS>
      </ReadUserOBSResponse>

      Desired Output : I want to remove both entries with UserObjectId 514

      <ReadUserOBSResponse>
      <UserOBS>
      <OBSObjectId>1510</OBSObjectId>
      <UserObjectId>443</UserObjectId>
      </UserOBS>
      <UserOBS>
      <OBSObjectId>547</OBSObjectId>
      <UserObjectId>544</UserObjectId>
      </UserOBS>
      </ReadUserOBSResponse>

      I've done some things, but its not working. My Idea was to count the nodes with UserObjectId as the current value, put this in an xsl:if and then print the nodes. But I'm not sure how to write this snippet. Would you please help me in this regard. Thanks in Advance
        • 1. Re: XSLT in BPEL : Get only elements that are not repeating in an XML
          991448
          you can try the following in BPEL,
          Assign this response to a new variable lets say originalResponse,
          Run a for each loop in BPEL for the count of this UserObjectId in this response, count($ReadUserOBSResponse/UserOBS)
          assign the value of $ReadUserOBSResponse/UserOBS[$forEachCounter]/UserObjectId to a variable say y
          count the number of$ReadUserOBSResponse/UserOBS/UserObjectId with value =y, count($ReadUserOBSResponse/UserOBS[./UserObjectId=$y]) to variable z
          if (count>1) then delete the node from originalReponse using the remove construct in BPEL.
          <bpel:assign>
          <bpelx:remove>
          <bpelx:target variable="originalResponse" part="response "? query="$ReadUserOBSResponse/UserOBS[./UserObjectId=$y]" />
          </bpelx:append>
          </bpel:assign>

          Edited by: 988445 on May 5, 2013 8:08 PM