---
schema_version: "1"
id: 02fa65dec42f892a5a39bd26a51829cf1c6fc743c8ce88de6116d450c6ad6c2f
title: Transform Message Component XML Reference
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/latest/transform-dataweave-xml-reference.md
canonical_url: https://docs.mulesoft.com/mule-runtime/latest/transform-dataweave-xml-reference
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 62741ebafcf6c79bef1ffcc1d5923310b85b75cc3d41613e70b6783524505b1c
description: MuleSoft Documentation Site
release: "4.13"
latest: true
---
---
product: Mule Runtime
version: 4.13
is-latest-version: true
keywords: studio, anypoint, esb, transform, transformer, format, aggregate, rename, split, filter convert, xml, json, csv, pojo, java object, metadata, dataweave, data weave, datamapper, dwl, dfl, dw, output structure, input structure, map, mapping
---

# Transform Message Component XML Reference

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

Instead of using the Studio UI to include DataWeave language in your Mule projects, you can also
create and configure a 'Transform Message' component entirely through XML, either from the XML tab
in Studio or from an external editor.

Note that if you use the UI to create and configure the element, the corresponding XML configuration
is created automatically in the XML editor.

## Namespace and Schema Location

At the very start of your Mule Project, you must include the following dependencies:

```xml
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
      ...
      xsi:schemaLocation="
      ...
      http://www.mulesoft.org/schema/mule/ee/core
      http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
</mule>
```

Note that Studio automatically adds these dependencies when you drag and drop the Transform
component to your canvas.

## <ee:transform/>

The `<ee:transform>` element is the top-level XML tag for the Transform component.

<table><colgroup><col> <col></colgroup><thead><tr><th><code>&lt;ee:transform&gt;</code> Attributes</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p><code>doc:name</code></p></div></div></td><td><div><div><p>Defines the name of the element as it appears in the Studio canvas.</p></div></div></td></tr><tr><td><div><div><p><code>mode</code></p></div></div></td><td><div><div><p>Refers to <a href="https://docs.mulesoft.com/dataweave/latest/dataweave-memory-management#deferred-execution">Deferred Execution</a>. Accepted values: <code>immediate</code> or <code>deferred</code>. See <a href="https://docs.mulesoft.com/dataweave/latest/dataweave-memory-management">DataWeave Memory Management</a>.</p></div></div></td></tr></tbody></table>

## Adding DataWeave Scripts to the Transform Component

You can either type your DataWeave code into your XML using `CDATA` within a
[Transformations](#transformations) element, or you can reference an external `.dwl` file.

This example that writes a DataWeave script inline within a `<dw:set-payload>` transformation
element:

```xml
<ee:transform doc:id="747f74d4-cb66-4f8e-8222-24784e6863ae"
  doc:name="Transform" doc:timestamp="1510861248434">
    <ee:message>
        <ee:set-payload>
          <![CDATA[%dw 2.0
            output application/json
            ---
            {
              // YOUR DW SCRIPT
            }
          ]]>
       </ee:set-payload>
    </ee:message>
</ee:transform>
```

Here is same example, calling an external `.dwl` file:

```xml
<ee:transform doc:id="747f74d4-cb66-4f8e-8222-24784e6863ae"
  doc:name="Transform" doc:timestamp="1510861248434" doc:mode="immediate">
    <ee:message>
      <ee:set-payload resource="transform.dwl" />
    </ee:message>
</ee:transform>
```

The default location for these files is in the `src/main/resources` folder in your project.

> [!NOTE] Starting in Mule 4.5, the runtime validates that referenced `.dwl` files are accessible.
> If the `mule-artifact.json` file of your app declares an `exportedResources` array, or if the
> script comes from a dependency or shared library, export the `.dwl` file there so that the runtime
> can load it. Otherwise, the app fails to deploy with an error such as
> `Error loading referenced file for parameter 'resource'`. For more information, see
> [How to Export Resource Files](https://docs.mulesoft.com/mule-runtime/latest/how-to-export-resources#how-to-export-resource-files).

## Transformations

A single Transform component element (`<ee:transform/>`) can specify content for all parts of the
Mule Event:

- `<ee:message/>` can contain `<ee:set-payload/>` and `<ee:set-attributes/>`.

- `<ee:variables/>` can contain one or more `<ee:set-variable/>` elements.

Example

```xml
<ee:transform doc:id="747f74d4-cb66-4f8e-8222-24784e6863ae"
  doc:name="Transform" doc:timestamp="1510861248434">
    <ee:message>
        <ee:set-payload resource="transform.dwl" />
        <ee:set-attributes resource="myattributes.dwl" />
    </ee:message>
    <ee:variables>
        <ee:set-variable variableName="myVar" resource="myvar.dwl"/>
    </ee:variables>
</ee:transform>
```

The child elements contain some of the same attributes.

<table><colgroup><col> <col></colgroup><thead><tr><th>Attributes</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p><code>resource</code></p></div></div></td><td><div><div><p>Points to a <code>.dwl</code> file containing a DataWeave transformation script. These values are solved statically. For example, using <code>&lt;ee:set-payload resource="myscript-${env}.dwl"/&gt;</code> generates this error in the Transform Message UI: <code>Unexpected end of input, expected header or content</code>.</p></div></div></td></tr><tr><td><div><div><p><code>variableName</code></p></div></div></td><td><div><div><p>For output variables only, defines the name of the variable.</p></div></div></td></tr></tbody></table>

## Full XML Sample

Here is an example that creates transformations for the payload, an attribute, and a variable.

```xml
<ee:transform doc:id="747f74d4-cb66-4f8e-8222-24784e6863ae"
  doc:name="Transform" doc:timestamp="1510861248434">
    <ee:message>
        <ee:set-payload><![CDATA[%dw 2.0

output application/json
---
(payload map (value0, index0) -> {
id: value0.id,
username: value0.username,
address: {
street: value0.address.street
},
website: value0.website
})]]></ee:set-payload>
        <ee:set-attributes><![CDATA[%dw 2.0

output application/json
---
{
reasonPhrase: attributes.reasonPhrase
}]]></ee:set-attributes>
    </ee:message>
    <ee:variables>
        <ee:set-variable variableName="myVar"><![CDATA[%dw 2.0

output application/json
---
{
a: payload[0].phone
}]]></ee:set-variable>
    </ee:variables>
</ee:transform>
```

## See Also

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