---
schema_version: "1"
id: c929703cdccf27d01129e1f163be3ae3e7ab80ce6f51c4b98c7ff352d0fbf775
title: Pass XML Attributes
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.3/dataweave-cookbook-pass-xml-attributes.md
canonical_url: https://docs.mulesoft.com/dataweave/2.3/dataweave-cookbook-pass-xml-attributes
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f3ea93eec9f21098554a8fb08085d07e49aaaed9b4c79a946012b5d250b779bc
description: MuleSoft Documentation Site
release: "2.3"
latest: false
---
---
product: DataWeave
version: 2.3
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.3/dataweave-cookbook-output-self-closing-xml-tags)

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

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

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

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

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

## See Also

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

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