Tuesday, January 20, 2015

Creating XML structure in a recursive using xquery in OSB

Following code snippet generates the desired XML structure in a recursive way.

let $range := 50 div 10
return
let $i in (1 to xs:integer($range))
return
<root>
<boo>
{$input/MyElement/text()}
</boo>
</root>

This snippet generates the XML in the structure <root><boo>sample text</boo></root> for 5 times.

Above snippet can be used in the xquery expression builder of assign ,replace actions on the OSB proxy service or can be used in the xquery transformation.

In this snippet we can make the "50 div 10" dynamic using the xquery variables. 

Ex : $dividend div $divisor

And $input in the element <boo></boo> can be a variable which holds the XML structure from which we can extract the text.