Thursday, August 22, 2013

Modify XML using XSL outbound transform AX 2012



Once I got a client requirement to make changes into the outbound XML generation of electronic VendPayment. Since their bank was not able to accept the current format of the XML generated from AX.
The XML includes Envelope and Header tags with output XML which sometimes needs to be truncated so that the third party applications can read the output XML.
To resolve this I started fresh by configuring the VendPayment using AIF outbound port setup using following Link.
The only change in the above configuration I did is I included the XSL file generated from the resources to outbound pipeline, no changes here,
I created a second XSL and added it into the outbound transformation(see below)

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:wt="schemas.microsoft.com/.../Message" xmlns:xsl="www.w3.org/.../Transform">
            <xsl:output version="1.0" omit-xml-declaration="no" indent="yes" encoding="UTF-8" method="xml"/>
           
<!--Copy all nodes from source-->
-<xsl:template match="@*|node()">-<xsl:copy>
                                    <xsl:apply-templates select="@* | node()"/>
                        </xsl:copy>
            </xsl:template>
           
            <!--Remove header, message parts, body and envelope tags-->
            <xsl:template match="wt:Envelope/wt:Header"/>-<xsl:template match="wt:Envelope/wt:Body/wt:MessageParts">
                        <xsl:apply-templates/>
            </xsl:template>-<xsl:template match="wt:Envelope/wt:Body">
                        <xsl:apply-templates/>
            </xsl:template>-<xsl:template match="wt:Envelope">
                        <xsl:apply-templates/>
            </xsl:template>
</xsl:stylesheet>

This gave me XML document without Envelope, Message part, Body and Header

Reference: http://community.dynamics.com/ax/f/33/t/102465.aspx#.Uhb2Uz_66qk