---
schema_version: "1"
id: d374c18d0b81a2c691a5ebf6bef4894f41d1b45ac329a0e03868b16d5f58f56a
title: TransformXML()
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/ampscript/references/content/mc-ampscript-reference-content-transform-xml.md
canonical_url: https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-transform-xml.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 3c62929100ed84aa0b1065ae36e11443153dd464f5d8ff583fc9b07f24f17a7a
products:
  - AMPscript for Marketing Cloud
  - Marketing Cloud
---
# TransformXML()

Apply an XSL transformation to XML data.

**note:** The `TransformXML()` function was designed for use with Classic Content. In some situations, using this function with Content Builder throws an exception. See [Usage with Content Builder](#with-content-builder).

## Availability

<table>
  <tr>
    <td>Marketing Cloud Engagement</td>
    <td>✅ Yes</td>
  </tr>
  <tr>
    <td>Marketing Cloud Next</td>
    <td>❌ No</td>
  </tr>
</table>

## Syntax

```
TransformXML(xmlDocument, xslDocument)
```

The `TransformXML()` function has these parameters:

- `xmlDocument` (string): Required. The XML data to transform.
- `xslDocument` (string): Required. The XSL document to use to transform the XML data.

For both parameters, you can use another function, such as [GetPortfolioItem()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-get-portfolio-item.md), to retrieve the XML or XSL content.

## Usage

To use this function, pass it a source XML document and the XSL document that you want to use to transform the XML data.

### With Classic Content

This example uses the `GetPortfolioItem()` function to retrieve the XML and XSL files. Next, it applies the XSL file to the XML file as part of the transformation process. The result is passed to the [TreatAsContent()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-treat-as-content.md) function so that the AMPscript content in the transformed XML is evaluated.

```
%%= TreatAsContent(TransformXML(GetPortfolioItem('formGenXML'),GetPortfolioItem('formGenXSL'))) =%%
```

### With Content Builder

This function throws an exception when you use it with Content Builder. To continue using this function with Content Builder, convert the XML and XSL documents to Base64 encoding, and store the encoded content as content blocks. Then, use the [Base64Decode()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/utilities/mc-ampscript-reference-utilities-base64-decode.md) function to decode the content blocks and pass them to this function.

This example shows how to transform XML by using content blocks encoded in Base64.

```
%%[

set @xsl = Base64Decode(ContentBlockById("YOUR_XSL_ID"), "UTF-8")
set @xml = Base64Decode(ContentBlockById("YOUR_XML_ID"), "UTF-8")

]%%

%%= TreatAsContent(TransformXML(@xml,@xsl)) =%%
```

Because the process of converting XML and XSL documents to Base64 encoding makes them difficult to maintain and debug, we recommend that you avoid using this method when possible. Instead, use the [BuildRowsetFromXml()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-build-rowset-from-xml.md) function to handle XML content.

## See Also

- [TreatAsContent()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-treat-as-content.md)
- [BuildRowsetFromXml()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-build-rowset-from-xml.md)
- [Base64Decode()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/utilities/mc-ampscript-reference-utilities-base64-decode.md)
- [GetPortfolioItem()](https://developer.salesforce.com/docs/marketing/marketing-cloud-ampscript/references/mc-ampscript-content/mc-ampscript-reference-content-get-portfolio-item.md)
