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

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

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

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

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

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

## See Also

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

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