---
schema_version: "1"
id: 296bdb6b3edd4d1fdc3f1b0795c4cf5effdb0af8542c60c74c9a420674c0d9fe
title: Pass XML Attributes
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.4/dataweave-cookbook-pass-xml-attributes.md
canonical_url: https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-pass-xml-attributes
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 14c04a783e1b289a54995014c3cc36af1b3146aa07d61a7982483e7b7c99a37b
description: MuleSoft Documentation Site
release: "2.4"
latest: false
---
---
product: DataWeave
version: 2.4
keywords: studio, anypoint, 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
---

# Pass XML Attributes

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

DataWeave enables you to pass attributes from within an XML tag input source to the target output
XML. The DataWeave example shows how to pass the XML attributes in the `NameDetail` field of the
input source payload to the `TargetName` field of the XML output.

This example uses: - `.*` multivalue selector that returns an array of `NameDetail` elements. -
`map` function to iterate over the array of NameDetail elements of the input. - The dynamic
attribute expression `@dynamicAttributes` to create the attributes of the new output tag by
selecting the attributes dynamically from the input.

DataWeave Script:

```dataweave
%dw 2.0
output application/xml
---
{
    Result: {
        (payload.Names.*NameDetail  map ( nameDetail , indexOfNameDetail ) -> {
            TargetName @((nameDetail.@)): {
                item: nameDetail.item
            }
        })
    }
}
```

Input XML Payload:

```xml
<?xml version="1.0" encoding="UTF-8"?>
      <Names>
         <NameDetail NameId="11111" NameType="Person" Name="Richarson" GivenNames="John" PreferredLanguage="English" CompanyNumber="" Gender="Male" Title="" >
            <item>doo</item>
         </NameDetail>
         <NameDetail NameId="22222" NameType="Person" Name="Richarson" GivenNames="Susan" PreferredLanguage="Spanish" CompanyNumber="" Gender="Female" Title="" >
            <item>dah</item>
         </NameDetail>
         <NameDetail NameId="33333" NameType="Person" Name="Knox" GivenNames="Frances" PreferredLanguage="English" CompanyNumber="" Gender="Male" Title="" >
            <item>dab</item>
         </NameDetail>
      </Names>
```

Output XML:

```xml
<?xml version='1.0' encoding='UTF-8'?>
<Result>
  <TargetName NameId="11111" NameType="Person" Name="Richarson" GivenNames="John" PreferredLanguage="English" CompanyNumber="" Gender="Male" Title="">
    <item>doo</item>
  </TargetName>
  <TargetName NameId="22222" NameType="Person" Name="Richarson" GivenNames="Susan" PreferredLanguage="Spanish" CompanyNumber="" Gender="Female" Title="">
    <item>dah</item>
  </TargetName>
  <TargetName NameId="33333" NameType="Person" Name="Knox" GivenNames="Frances" PreferredLanguage="English" CompanyNumber="" Gender="Male" Title="">
    <item>dab</item>
  </TargetName>
</Result>
```

## Related Examples

- [Output Self-closing XML tags](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-output-self-closing-xml-tags)

- [Insert an Attribute into an XML Tag](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-insert-attribute)

- [Include XML Namespaces](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-include-xml-namespaces)

- [Exclude Fields from the Output](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-exclude-field)

- [Output a Field When Present](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-output-a-field-when-present)

- [Conditionally Reduce a List through a Function](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-conditional-list-reduction-via-function)

## See Also

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

- [DataWeave Cookbook](https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook)
