---
schema_version: "1"
id: 230360b5381a2282d40b4ad2a30368e067a5c384e6d992c7dba9d899ca07cc2a
title: Transform (<ee:transform/>)
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-code-builder/acb-component-transform.md
canonical_url: https://docs.mulesoft.com/anypoint-code-builder/acb-component-transform
source_site: docs.mulesoft.com
content_type: documentation
content_hash: ea7af3ac3039140d9e6cd914315a8d1f6d36cde9c8d74fed310ab85b8f5a580d
description: MuleSoft Documentation Site
latest: true
---
---
product: Anypoint Code Builder
version: master
---

# Transform (<ee:transform/>)

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Write a DataWeave script within this component to set or transform the Mule message payload,
attributes, or variables to the required output format and data structure.

DataWeave is the programming language for all expressions and data transformations in your
integrations and implementations. The language offers function libraries and mechanisms for creating
customizations, including your own functions, libraries, and data types. To learn the basics of
DataWeave and experiment with DataWeave scripts, see
[DataWeave Tutorial and Playground](https://dataweave.mulesoft.com/), and find DataWeave functions
and guidance with the language in the [DataWeave documentation](https://docs.mulesoft.com/dataweave/2.4/).

## Component XML

This component supports the following XML structure:

```xml
<ee:transform doc:name="Transform" doc:id="xnpgke" >
    <ee:message >
        <ee:set-payload ><![CDATA[%dw 2.0
output application/java (1)
---
//DataWeave script (2)
]]></ee:set-payload>
        </ee:message>
    </ee:transform>
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>The <code>output</code> directive of a DataWeave script that configures the <code>application/java</code> format<div><p>See <a href="https://docs.mulesoft.com/dataweave/2.4/dataweave-formats">Supported Data Formats</a>.</p></div></td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Location for the body of the DataWeave script</td></tr></tbody></table>

Write a [DataWeave script](https://docs.mulesoft.com/dataweave/2.4/dataweave-language-introduction) within a Transform
component (`<ee:transform/>`) to create or transform content for any parts of the
[Mule event](https://docs.mulesoft.com/mule-runtime/latest/about-mule-event):

`<ee:message/>` and `<ee:variables/>` are child elements of Transform (`<ee:transform/>`):

- `<ee:message/>` accepts child elements for creating or transforming a Mule message payload and
  attributes:

  <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Element Name</th><th>Element XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>Set payload</strong></p></td><td><p><code>&lt;ee:set-payload/&gt;</code></p></td><td><div><div><p>Sets or transforms the <a href="https://docs.mulesoft.com/mule-runtime/latest/about-mule-message#message-payload">Mule message payload</a>. This child element of <code>&lt;ee:message/&gt;</code> accepts a DataWeave script. One <code>&lt;ee:set-payload/&gt;</code> element is allowed.</p></div></div></td></tr><tr><td><p><strong>Set attribute</strong></p></td><td><p><code>&lt;ee:set-attributes/&gt;</code></p></td><td><div><div><p>Sets or transforms one or more Mule message attributes. This child element of <code>&lt;ee:message/&gt;</code> accepts a DataWeave script. One <code>&lt;ee:set-attributes/&gt;</code> element is allowed.</p></div></div></td></tr></tbody></table>

- `<ee:variables/>` accepts child elements for creating or transforming a Mule variables:

  <table><colgroup><col> <col> <col></colgroup><thead><tr><th>Element Name</th><th>Element XML</th><th>Description</th></tr></thead><tbody><tr><td><p><strong>Set Variables</strong></p></td><td><p><code>&lt;ee:set-variable/&gt;</code></p></td><td><div><div><p>Sets or transforms a <a href="https://docs.mulesoft.com/mule-runtime/latest/about-mule-variables">Mule variable</a>. This child element of <code>&lt;ee:variables/&gt;</code> accepts a DataWeave script. One or more <code>&lt;ee:set-variable/&gt;</code> elements are allowed.</p></div></div></td></tr></tbody></table>

## Examples

The following examples show how to configure an inline transformation and call DataWeave scripts to
apply a transformation.

### Example: Inline DataWeave Transformation

The following example sets the payload using an inline DataWeave script.

```xml
<ee:transform
  doc:id="747f74"
  doc:name="Transform" >
    <ee:message>
        <ee:set-payload>
          <![CDATA[%dw 2.0
            output application/xml
            ---
            example: {
                message @(id: "DSF-829"): "Hello World!",
                date: |2017-03-21|,
                items:
                {
                    item1: 728,
                    item2: "14422"
                }
            }
          ]]>
       </ee:set-payload>
    </ee:message>
</ee:transform>
```

The DataWeave script within `<ee:set-payload/>` returns this XML output as the message’s payload:

```xml
<example>
  <message id="DSF-829">Hello World!</message>
  <date>2017-03-21</date>
  <items>
    <item1>728</item1>
    <item2>14422</item2>
  </items>
</example>
```

### Example: Calling an External DataWeave Script

The following example calls an external DataWeave script within a
[DWL file](https://docs.mulesoft.com/dataweave/2.4/dataweave-language-introduction#dwl_file) to set the payload.

```xml
<ee:transform doc:id="747f74d"
  doc:name="Transform" doc:mode="immediate">
    <ee:message>
      <ee:set-payload resource="myscript.dwl" />
    </ee:message>
</ee:transform>
```

Add your DWL file to the `src/main/resources` directory of your Mule project folder. For example,
you can create a file named `myscript.dwl` in that folder, and provide the same DataWeave script
shown in [Example: Inline DataWeave Transformation](#example1):

```dataweave
%dw 2.0
output application/xml
---
example: {
    message @(id: "DSF-829"): "Hello World!",
    date: |2017-03-21|,
    items:
    {
        item1: 728,
        item2: "14422"
    }
}
```

If you trigger a flow that contains the [Transform example](#example-dwl), the script returns the
same payload returned by [Example: Inline DataWeave Transformation](#example1).

### Example: Payload, Attribute, and Variable Transformation

The following example triggers a flow that requests user data and configures `<ee:transform/>` to
transform the user data payload, select an attribute that provides the status code of the HTTP
request, and set the value of Mule variables. The loggers in the example help track the values
within the Mule event in the flow.

```xml
<http:listener-config name="HTTP_Listener_config" >
  <http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" >
  <http:request-connection port="443" />
</http:request-config>

<flow name="myFlow" >
  <http:listener path="/mytrigger" config-ref="HTTP_Listener_config"
    doc:name="Listener" doc:id="kiohjs" /> (1)
  <http:request method="GET" doc:name="Request"
     config-ref="HTTP_Request_configuration"
     url="https://jsonplaceholder.typicode.com/users"/> (2)
  <set-variable variableName="myVar" value="myVar Value"
    doc:name="Set variable" doc:id="tgwhvc" /> (3)
  <logger level="INFO" message="#[payload[0]]" doc:name="Logger Payload"
    doc:id="9dbeda-430b1f" category="LOGGER-PAYLOAD-1"/> (4)
  <logger level="INFO" message="#[attributes]" doc:name="Logger Attributes"
    doc:id="9dbeda-430b1g" category="LOGGER-ATTRIBUTES-1"/> (5)
  <logger level="INFO" message="#[vars]" doc:name="Logger Variables"
    doc:id="9dbeda-430b1h" category="LOGGER-VARIABLES-1"/> (6)
  <ee:transform doc:name="Transform" doc:id="qtxpfa" > (7)
      <ee:message>
          <ee:set-payload>
            <![CDATA[%dw 2.0
                output application/json
                ---
                payload.id
            ]]>
          </ee:set-payload>
          <ee:set-attributes>
            <![CDATA[%dw 2.0
            output application/json
            ---
            {
                'status-code' : attributes.statusCode
            }]]>
          </ee:set-attributes>
      </ee:message>
      <ee:variables>
          <ee:set-variable variableName="myVar2">
              <![CDATA[%dw 2.0
                  output application/json
                  ---
                  vars.myVar
              ]]>
          </ee:set-variable>
          <ee:set-variable variableName="myVar3">
              <![CDATA[%dw 2.0
              output application/json
              ---
              {
                  'myNewVar' : 'myvariable3'
              }]]>
          </ee:set-variable>
      </ee:variables>
  </ee:transform>
  <logger level="INFO" message="#[payload]" doc:name="Logger Payload 2"
          doc:id="9dbeda-430b1c" category="LOGGER-PAYLOAD-2"/> (8)
  <logger level="INFO" message="#[attributes]" doc:name="Logger Attributes 2"
          doc:id="9dbeda-430b1d" category="LOGGER-ATTRIBUTES-2"/> (9)
  <logger level="INFO" message="#[vars.myVar2]" doc:name="Logger Variables 2"
          doc:id="9dbeda-430b1e" category="LOGGER-VARIABLES-2"/> (10)
  <logger level="INFO" message="#[vars.myVar3.myNewVar]"
          doc:name="Logger Variables 3"
          doc:id="9dbeda-430b1g" category="LOGGER-VARIABLES-3"/> (11)
</flow>
```

<table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td><code>&lt;http:listener/&gt;</code> configures an HTTP Listener operation that triggers the flow from requests to localhost port <code>8081</code> at the endpoint <code>/mytrigger</code>.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td><code>&lt;http:request/&gt;</code> configures and HTTP Request operation for a JSON data sample.</td></tr><tr><td><i data-value="3"></i><b>3</b></td><td><code>&lt;set-variable/&gt;</code> sets Mule variable <code>myVar</code> to the string value <code>"myVar Value"</code>.</td></tr><tr><td><i data-value="4"></i><b>4</b></td><td><code>LOGGER-PAYLOAD-1</code> prints the value of <code>payload[0]</code>, which is the first index of an array of user objects found at <a href="https://jsonplaceholder.typicode.com/users" target="_blank" rel="noopener">https://jsonplaceholder.typicode.com/users</a>.</td></tr><tr><td><i data-value="5"></i><b>5</b></td><td><code>LOGGER-ATTRIBUTES-1</code> is set to the predefined Mule variable <code>attributes</code> to print the HTTP metadata returned from the HTTP request, including the status code, reason phrase, and headers.<div><p>For more information about <code>attributes</code> and other Mule variables, see <a href="https://docs.mulesoft.com/dataweave/2.4/dataweave-variables-context">Predefined Variables</a>.</p></div></td></tr><tr><td><i data-value="6"></i><b>6</b></td><td><code>LOGGER-VARIABLES-1</code> is set to <code>vars</code> to print an object that describes the Mule variable in the Mule event:<div><div><pre>{myVar=TypedValue[value: 'my VarValue',
  dataType: 'SimpleDataType{type=java.lang.String,
  mimeType='*/*; charset=UTF-8'}']}</pre></div></div></td></tr><tr><td><i data-value="7"></i><b>7</b></td><td><code>&lt;ee:transform/&gt;</code> provides DataWeave scripts that select and transform payload, attribute, and variable data in the Mule event.<div><ul><li><p><code>&lt;ee:set-payload/&gt;</code> selects the <code>id</code> value from the user objects in the payload array.</p></li><li><p><code>&lt;ee:set-attributes/&gt;</code> uses <code>attributes.statusCode</code> to select the status code value from the HTTP request metadata.</p><div><p>All the metadata is selectable. For example, you can select the reason phrase with <code>attributes.reasonPhrase</code> and the headers with <code>attributes.headers</code>. For more information, see <a href="https://docs.mulesoft.com/dataweave/2.4/dataweave-selectors">DataWeave Selectors</a>.</p></div></li><li><p><code>&lt;ee:variables/&gt;</code> creates new Mule variables. The first <code>&lt;ee:set-variable/&gt;</code> sets <code>myVar2</code> to the value of the <code>myVar</code> variable (<code>vars.myVar</code>). The second creates a variable named <code>myVar3</code> to the string <code>'myvariable3'</code>.</p></li></ul></div></td></tr><tr><td><i data-value="8"></i><b>8</b></td><td><code>LOGGER-PAYLOAD-2</code> prints the transformed value of <code>payload</code>, which is now an array of user <code>id</code> values (<code>[1,2,3,4,5,6,7,8,9,10]</code>).</td></tr><tr><td><i data-value="9"></i><b>9</b></td><td><code>LOGGER-ATTRIBUTES-2</code> prints the transformed value of <code>attributes</code>, which is now the JSON object <code>{ "status-code": 200 }</code>.</td></tr><tr><td><i data-value="10"></i><b>10</b></td><td><code>LOGGER-VARIABLES-2</code> prints the value of Mule variable <code>vars.myVar2</code>, which is the string <code>"myVar Value"</code>.</td></tr><tr><td><i data-value="11"></i><b>11</b></td><td><code>LOGGER-VARIABLES-3</code> prints the value of Mule variable <code>vars.myVar3.myNewVar</code>, which is the string <code>"myvariable3"</code>.</td></tr></tbody></table>

In the logs, the output looks something like this (edited for readability):

INFO 2023-10-24 16:59:43,279 ... \[processor: myFlow/processors/2; event:
6699ea20-72c9-11ee-b3b5-147ddaaf4f97\] LOGGER-PAYLOAD-1: { "id": 1, "name": "Leanne Graham",
"username": "Bret", "email": "Sincere@april.biz", "address": { "street": "Kulas Light", "suite":
"Apt. 556", "city": "Gwenborough", "zipcode": "92998-3874", "geo": { "lat": "-37.3159", "lng":
"81.1496" } }, "phone": "1-770-736-8031 x56442", "website": "hildegard.org", "company": { "name":
"Romaguera-Crona", "catchPhrase": "Multi-layered client-server neural-net", "bs": "harness real-time
e-markets" } } INFO 2023-10-24 16:59:43,333 ... \[processor: myFlow/processors/3; event:
6699ea20-72c9-11ee-b3b5-147ddaaf4f97\] LOGGER-ATTRIBUTES-1:
org.mule.extension.http.api.HttpResponseAttributes { Status Code=200 Reason Phrase=OK Headers=\[
date=Wed, 25 Oct 2023 20:00:48 GMT content-type=application/json; charset=utf-8
transfer-encoding=chunked connection=keep-alive x-powered-by=Express x-ratelimit-limit=1000
x-ratelimit-remaining=999 x-ratelimit-reset=1698156189 vary=Origin, Accept-Encoding
access-control-allow-credentials=true cache-control=max-age=43200 pragma=no-cache expires=-1
x-content-type-options=nosniff etag=W/"160d-1eMSsxeJRfnVLRBmYJSbCiJZ1qQ" via=1.1 vegur
cf-cache-status=HIT age=21484
report-to={"endpoints":\[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=abcdefg1234..."}\],"group":"cf-nel","max\_age":604800}
nel={"success\_fraction":0,"report\_to":"cf-nel","max\_age":604800} server=cloudflare
cf-ray=81bd0c408c729685-SJC alt-svc=h3=":443"; ma=86400 \] } INFO 2023-10-24 16:59:43,347 ...
\[processor: myFlow/processors/4; event: 6699ea20-72c9-11ee-b3b5-147ddaaf4f97\] LOGGER-VARIABLES-1:
{myVar=TypedValue\[value: 'myVar Value', dataType: 'SimpleDataType{type=java.lang.String,
mimeType='\*/\*; charset=UTF-8'}'\]} INFO 2023-10-24 16:59:43,512 ... \[processor:
myFlow/processors/6; event: 6699ea20-72c9-11ee-b3b5-147ddaaf4f97\] LOGGER-PAYLOAD-2: \[ 1, 2, 3, 4,
5, 6, 7, 8, 9, 10 \] INFO 2023-10-24 16:59:43,519 \[processor: myFlow/processors/7; event:
6699ea20-72c9-11ee-b3b5-147ddaaf4f97\] LOGGER-ATTRIBUTES-2: { "status-code": 200 } INFO 2023-10-24
16:59:43,528 ... \[processor: myFlow/processors/8; event: 6699ea20-72c9-11ee-b3b5-147ddaaf4f97\]
LOGGER-VARIABLES-2: "myVar Value" INFO 2023-10-24 16:59:43,576 ... \[processor: myFlow/processors/9;
event: 6699ea20-72c9-11ee-b3b5-147ddaaf4f97\] LOGGER-VARIABLES-3: "myvariable3"

## See Also

- [Set Payload (<set-payload/>)](https://docs.mulesoft.com/anypoint-code-builder/acb-component-set-payload)

- [Set Variable (<set-variable/>)](https://docs.mulesoft.com/anypoint-code-builder/acb-component-set-variable)

- [DataWeave Language](https://docs.mulesoft.com/dataweave/latest/dataweave-language-guide)

- [DataWeave Selectors](https://docs.mulesoft.com/dataweave/2.4/dataweave-selectors)
