This documentation is for WSO2 Enterprise Integrator version 6.5.0 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.

All docs This doc
||
Skip to end of metadata
Go to start of metadata

Objective

This sample explains the usage of split-to-elements() function.

Introducing split-to-elements() Function

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 accepts four input parameters as follows.

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

For example,

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

if $input is as follows,

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

the output will be 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"

Deploying the Sample

WSO2 BPS provides a sample, which can be deployed and executed to understand the function. Follow the instructions below to deploy and trigger the process.

1. Log in into BPS server management console and select "Processes -> Add" under the "Main" menu.

2. Upload the <EI_HOME>/samples/business-process/bpel/Split.zip directory. 

3. In the "Deployed Processes" window, click the "Process ID" to access its "Process Information" window.

4. Under the "WSDL Details" widget, trigger the process using the "TryIt" link to create an instance of it.

Example Usage

Refer to Split.zip and the example usage of the function as given below: 

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

This method accept three parameters as follows.

  • $tmpVar - input source varaible
  • ',' - delimiter string
  • 'chunk' - the target XML element

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>
  • No labels