Oracle SOA Suite Online Training

Interested in learning Oracle SOA Suite 12c?
Learn from the author of this blog!
A complete and comprehensive course on the #1 platform on SOA - Oracle SOA Suite

Click here to find the complete course details
Click here to check the first session on Oracle SOA Suite 12c

================================================================================================

Appending repeating elements using Assign

Criteria element in the following schema repeats - and is Optional aswell




You might want to add some <Criteria> elements to your XML.
You can do this either in Assign activity or XSLT.

Using Assign Activity

First, append the <Criteria> element those number of times that you want the array to be.
Remember that the Criteria element before appending has to exist. Otherwise, only the parent <Criteria> tag gets appended and the children (KeyName, KeyValue) doesn't get appended, and you will get the following error in the assign activity

<selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
   <part name="summary">
      <summary>XPath query string returns zero node.
The assign activity of the to node query is returning zero node.
Either the to node data or the xpath query in the to node was invalid.
According to BPEL4WS spec 1.1 section 14.3, verify the to node value at line number 830 in the BPEL source.</summary>
   </part>
</selectionFailure>

If you feel the <Criteria> element might be null, first you stuff the first element, and then append.
Something like this

Next, APPEND the <Criteria[1]> (which you had just created) from the variable to the same variable those number of times that you want the array to be.

Note : If you don't specify the '[]' / Array nomenclature, the assignment happens even if the element is null. But if you specify the '[]' / Array nomenclature, you have to have the element. Otherwise, you will get the error mentioned above.

 Using XSLT

Using XSLT is straight forward.
You can loop over the source elements and assign the values.
If the source elements from which you want to copy the values are not in a loop, and if you know exactly how many array elements you want to add, go to the source editor of the xslt and manually add the elements, something like this

<criteria>
    <KeyName>SomeHardKey1</KeyName>
    <KeyValue><xslt:value-of select="..."/></KeyValue>
</criteria><criteria>
    <KeyName>SomeHardKey2</KeyName>
    <KeyValue><xslt:value-of select="..."/></KeyValue>
</criteria>
...

Hope it helps!
Thanks.

No comments:

Post a Comment