WSO2 BPS - Sample Guide - split-to-elements()

Sample Guide - split-to-elements()

Table of Content


Objective

This function is a XPath extension supported by the Apache ODE engine ( http://ode.apache.org/xpath-extensions.html) which can be used to generate arrays from a string.

The method accept four input parameters as follows.

split-to-elements(stringToSplit, separator, targetElement, targetNamespace)

eg -

split-to-elements($input,'123','chunk','http://ode/bpel/unit-test.wsdl')

if $input is -

<unit:split><TestPart>hello123bill123smith</TestPart></unit:split>

output will be some thing as follows -

<TestPartxmlns:unit="http://ode/bpel/unit-test.wsdl"><chunkxmlns="http://ode/bpel/unit-test.wsdl">hello</chunk><chunkxmlns="http://ode/bpel/unit-test.wsdl">bill</chunk><chunkxmlns="http://ode/bpel/unit-test.wsdl">smith</chunk></TestPart>

Note - split-to-elements() method should be used under the namespace of "http://www.apache.org/ode/type/extension"


Prerequisites


Overall Idea

<copy><from>ode:split-to-elements($tmpVar, ',', 'chunk')</from><tovariable="myVar"part="TestPart"/></copy>

This method accept three parameters as follows.

Suppose initial value of tmpVar is

<unit:split><TestPart>1,2,3,4</TestPart></unit:split>

After executing split-to-elements() the value of myVar is

<TestPartxmlns:unit="http://ode/bpel/unit-test.wsdl"><chunk>1</chunk><chunk>2</chunk><chunk>3</chunk><chunk>4</chunk></TestPart>