Transform XML in workflows with Azure Logic Apps
Applies to: Azure Logic Apps (Consumption + Standard)
In enterprise integration business-to-business (B2B) scenarios, you might have to convert XML between formats. Your logic app workflow can transform XML by using the Transform XML action and a predefined map.
For example, suppose you regularly receive B2B orders or invoices from a customer that uses the YearMonthDay date format (YYYYMMDD). However, your organization uses the MonthDayYear date format (MMDDYYYY). You can create and use a map that transforms the YearMonthDay format to the MonthDayYear format before storing the order or invoice details in your customer activity database.
Prerequisites
An Azure account and subscription. If you don't have a subscription yet, sign up for a Azure account.
A logic app workflow that already starts with a trigger so that you can add the Transform XML action where necessary in your workflow.
An integration account resource where you define and store artifacts, such as trading partners, agreements, certificates, and so on, for use in your enterprise integration and B2B workflows. This resource has to meet the following requirements:
Is associated with the same Azure subscription as your logic app resource.
Exists in the same location or Azure region as your logic app resource where you plan to use the Transform XML action.
If you're working on a Consumption logic app resource and workflow, your integration account requires the following items:
The map to use for transforming XML content.
If you're working on a Standard logic app resource and workflow, you can link your integration account to your logic app resource, upload maps directly to your logic app resource, or both, based on the following scenarios:
If you already have an integration account with the artifacts that you need or want to use, you can link your integration account to multiple Standard logic app resources where you want to use the artifacts. That way, you don't have to upload maps to each individual logic app. For more information, review Link your logic app resource to your integration account.
If you don't have an integration account or only plan to use your artifacts across multiple workflows within the same logic app resource, you can directly add maps to your logic app resource using either the Azure portal or Visual Studio Code.
Note
The Liquid built-in connector lets you select a map that you previously uploaded to your logic app resource or to a linked integration account, but not both.
So, if you don't have or need an integration account, you can use the upload option. Otherwise, you can use the linking option. Either way, you can use these artifacts across all child workflows within the same logic app resource.
You still need an integration account to store other artifacts, such as partners, agreements, and certificates, along with using the AS2, X12, and EDIFACT operations.
Add Transform XML action
In the Azure portal, open your Standard logic app and workflow in the designer.
If you have a blank workflow that doesn't have a trigger, follow these general steps to add any trigger you want. Otherwise, continue to the next step.
This example uses the Request trigger.
Under the step in your workflow where you want to add the Transform XML action, follow these general steps to add the action named Transform XML.
In the Content box, specify the XML content that you want to transform using any XML data that you receive in the HTTP request.
To select outputs from previous operations in the workflow, in the Transform XML action, click inside the Content box, and select the dynamic content list option (lightning icon).
From the dynamic content list, select the token for the content that you want to transform.
This example selects the Body token from the trigger.
Note
Make sure that you select XML content. If the content isn't XML or is base64-encoded, you must specify an expression that processes the content. For example, you can use expression functions, such as
base64ToBinary()
to decode content orxml()
to process the content as XML.
From the Map Source list, select the location where you uploaded your map, either your LogicApp resource or your IntegrationAccount.
From the Map list, select your map.
When you're done, save your workflow.
You're now finished setting up your Transform XML action. In a real world app, you might want to store the transformed data in a line-of-business (LOB) app such as SalesForce. To send the transformed output to Salesforce, add a Salesforce action.
To test your transformation action, trigger and run your workflow. For example, for the Request trigger, send a request to the trigger's endpoint URL.
The Transform XML action runs after your workflow is triggered and when XML content is available for transformation.
Advanced capabilities
Reference assemblies or call custom code from maps
The Transform XML action supports referencing external assemblies from maps, which enable directly calling custom .NET code from XSLT maps. For more information, see Add XSLT maps for workflows in Azure Logic Apps.
Reference extension objects
In Standard workflows, the Transform XML action supports specifying an XML extension object to use with your map.
In the Transform XML action, open the Advanced parameters list, and select XML Extension Object, which adds the parameter to the action.
In the XML Extension Object box, specify your extension object, for example:
Byte order mark
By default, the response from the transformation starts with a byte order mark (BOM). You can access this functionality only when you work in the code view editor. To disable this functionality, set the transformOptions
property to disableByteOrderMark
:
"Transform_XML": {
"inputs": {
"content": "@{triggerBody()}",
"integrationAccount": {
"map": {
"name": "TestMap"
}
},
"transformOptions": "disableByteOrderMark"
},
"runAfter": {},
"type": "Xslt"
}