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

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

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

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

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

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

## See Also

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

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