Azure Function to Apply XSLT Transformations

Azure Function to Apply XSLT Transformations

Another Azure Function? Can we accomplish the same with default capabilities inside Logic Apps or Azure API Management? These may be, once again, the questions that you are asking yourself at the moment. Because if we are using Azure Integration Services, we can easily use: 

  • If we are using Logic App Consumption we can use the Transform XML action in conjugation with an Integration Account.
  • If we are using Logic App Standard it already provides out-of-the-box support for applying XML transformations (using Transform XML action) without the Integration Account need.
  • Or, if you are using API Management, we can make use of the xsl-transform policy to apply an XSL transformation to XML in the request or response body.

Our main objective in creating this function was to use it inside Logic Apps Consumption to avoid needing an Integration Account. But that we will address later on in another blog post.

What does this Azure Function do?

The ApplyXSLTTransformation allows you to dynamically convert an XML payload into another XML, JSON, or any other format using XLST. To use this function, you must set up an Azure Storage Account and a container to store the XSLT files.

To trigger this function, you need to:

  • In the Body, send an XML payload
  • You should specify the following mandatory headers:
    • Content-Type as text/xml, or application/xml.
    • XsltFileName with the name of the xslt file present in the storage account.
  • Optionally, you can set the following header:
    • Output-Content-Type: this will specify the outcome (response) content-type. The default value is text/xml.

Once again, our main objective in creating this function was to use it inside Logic Apps Consumption to avoid needing an Integration Account. But that we will address later on in another blog post. However, it can be used in other scenarios.

Where can I download it?

You can download the complete Azure Functions source code here:

Hope you find this helpful! So, if you liked the content or found it useful and want to help me write more, you can buy (or help me buy) my son a Star Wars Lego! 

Thanks to my team member Luís Rigueira for helping me realize and implement this idea.

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc.

He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.
View all posts by Sandro Pereira

What’s new in BizTalk Server 2020: XSLT 3.0 Support

What’s new in BizTalk Server 2020: XSLT 3.0 Support

Last weekend I delivered a session about BizTalk Server 2020 in action on Global Integration Bootcamp 2020 Madrid, where I spoke about the new features available in the most recent version of the product.

Today I will start this series of blog posts about what’s new in BizTalk Server 2020 by beginning to speak about one of the most expected and log time requested features: XSLT 3.0 Support.

XSLT 3.0 represents a significant upgrade of the XSLT 1.0 (and even XSLT 2.0) standards to become a general-purpose transformation language for the most common data storage and messaging formats.

There are a lot of advantages to using XSLT 3.0 compare with the XSLT 1.0 or, in fact, XSLT 2.0, and the goal here is not to address every single of them, but we can highlight the following one:

  • Extended Function Set, Sequences, Arrays, and Maps: The initial function set for XSLT1.0 was the same as XPath 1.0 functions and was very limited. Minimal math support, no regular expression support, minimal string manipulation capabilities, no support for set (sequence) operations, no support for dates.
    • Grouping:
      • xsl:for-each-group: a set of items can be selected and arranged into groups based on specific criteria (for example, common values); then each group can be processed in turn
        • special XPath functions within for-each-group: current-grouping-key(), currentgroup()
      • Variants of <xsl:for-each-group>:
        • group-adjacent: adjacent items are allocated to the same group if they have common values for the grouping key
        • group-starting-with: whenever an item matches the pattern, a new group is started with this item
        • group-by: whenever an item matches the pattern, a new group is started after this item
    • Sorting:
      • xsl:sort: can be used inside of <xsl:for-each>, <xsl:for-each-group>, <xsl:applytemplates> and <xsl:perform-sort>. It defines the order in which the data is processed by the instruction.
      • Several subsequent sort keys can be defined

BizTalk’s default XSL transform engine implementation is based on .Net Framework XSLT Transformations. This support is limited to XSLT 1.0.

Starting with BizTalk Server 2020, users can choose Saxon:registered: 9 (Saxon 9 HE) as the XSLT transform engine. But most importantly, it will be possible to plug-in your own custom XSLT transform engine.

  • YYou can implement a custom XSLT transform engine by defining XSLT transform implementation derived from abstract class Microsoft.XLANGs.BaseTypes.ITransform2 in assembly Microsoft.XLANGs.BaseTypes.dll.
  • See more details at: Custom XSLT transform implementation.

This makes it possible for BizTalk server maps to support newer versions of XSLT. Using Saxon 9 HE, we can readily use XSLT3.0.

Use XSLT Transform Engine property to specify the XSLT transform engine you wish to use:

This was one of the most expected features, but be careful, this can be a poisoned gift because Saxon 9 HE doesn’t support embedded scripting. As a result, functoids shipped as part of BizTalk may not function well. And for many cases, this can be a showstopper.

The advantages of using XSLT 3.0 with Saxon 9 HE:

  • Development: The XSLT file can be developed separately and hosted in a BizTalk map. It will simplify specific scenarios, especially scenarios that grouping and sorting are required. As we mentioned above, XSLT 3.0 provides an extended set of functions, which was very limited within XSLT 1.0.

Disadvantages when using XSLT 3.0 with Saxon 9 HD:

  • Level of effort: Not quite as intuitive, Functoids are easier to read visually on the map grid and therefore Requires “geeky” coding skills.
  • Overview: You lose the visual map representation. You can conjugate Saxon 9 HE with the BizTalk Mapper, but it is harder to do it.
  • BizTalk Mapper Editor limitations: except for a few built-in Functoids like Scripting Functoid (not all script types will work properly) or advance Functoids, BizTalk Functoids will not work while using the Saxon 9 HE XSLT Transformation Engine.
  • BizTalk Development Tool Integration: it is a brand new feature, and it seems that doesn’t have, at least for now, the same level of integration capabilities with the BizTalk Server development tools that we are usual to have and use if we compared with the default transformation engine

The post What’s new in BizTalk Server 2020: XSLT 3.0 Support appeared first on SANDRO PEREIRA BIZTALK BLOG.

Sorting, Grouping, and Debatching in Pure Messaging

Debatching can be done several different ways in BizTalk 2004. With a few message box hops, debatching can be done with a few maps and an envelope schema in pure messaging. This sample shows a map for Sorting, a map for Grouping, and the Envelope for debatching.

This sample will work in BizTalk 2004 and BizTalk 2006.

Get more information from the original blog post on this topic: https://www.biztalkgurus.com/biztalk_server/biztalk_blogs/b/biztalk/archive/2006/04/03/how-to-use-biztalk-messaging-for-grouping_2c00_-sorting_2c00_-and-debatching.aspx

Creating Nodes Inside A Map

This mapping sample shows how to create repeating nodes from flat data inside the mapper.  This sample also shows the use of some custom XSLT code inside the BizTalk mapper.

This sample works with BizTalk 2004 and BizTalk 2006.

Get more information from the original blog post on this topic: https://www.biztalkgurus.com/biztalk_server/biztalk_blogs/b/biztalk/archive/2004/10/28/how-to-create-nodes-from-flat-data-in-biztalk-maps.aspx