Business Integration Solutions documentation

About: XMLTOXMLTRANSLATOR activity

In Business Integration Solutions, use the XMLTOXMLTRANSLATOR activity to apply a custom XML style sheet on an XML document.

How to set up the XMLTOXMLTRANSLATOR Activity

Usage

Use this activity to apply a custom XML style sheet on an XML document.

Concept

This is an advanced mapping activity that enables complex XML transformations not supported by the Mapper activity.

After transformation, the resulting XML should match the structure of an external document. Developers with more knowledge of XSLT transformations can link directly to an internal document, making the Mapper obsolete. This approach processes faster but may be harder to achieve.

The output of the XML to XML Translator is ready for processing by the remaining pipeline elements. You can use the XML to XML Translator both for exporting and importing data.

XML input (XSLT) ➡️ [XML to XML Translator] ➡️ XML output

Available templates

This element includes the following templates:

  • Remove namespaces: Removes the namespaces from a document. See Examples.
  • ReportParameters: Reformats a document with nodes matching report options and filters to nodes with attributes that the report parameter format accepts.

Examples

1. Removing namespaces: BIS provides an out-of-the-box XMLTOXMLTRANSLATOR for clearing namespaces within an XML document.

Sample XML:

<salesorder> 
    <hdr:HDR xmlns:hdr="urn:example.microsoft.com:SalesOrder">
        <hdr:resellernumber>27090917</hdr:resellernumber> 
        <hdr:ordernummer>2014-04-04</hdr:ordernummer> 
	</hdr:HDR>
	<ln:DET xmlns:ln="urn:example.microsoft.com:SalesOrderLine">        	
		<ln:item> 
            <ln:GTIN>1500</ln:GTIN> 
            <ln:quantity>20</ln:quantity> 
        </ln:item>
	</ln:DET>
	<ln:DET xmlns:ln="urn:example.microsoft.com:SalesOrderLine">        	
		<ln:item> 
            <ln:GTIN>1600</ln:GTIN> 
            <ln:quantity>25</ln:quantity> 
        </ln:item>
	</ln:DET>
</salesorder>

Sample XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="yes"/>
	<!-- Stylesheet to remove all namespaces from a document -->
	<!-- NOTE: this will lead to attribute name clash, if an element contains two attributes with same local name but different namespace prefix -->
	<!-- Nodes that cannot have a namespace are copied as such -->
	<!-- template to copy elements -->
	<xsl:template match="*">
		<xsl:element name="{local-name()}">
			<xsl:apply-templates select="@* | node()"/>
		</xsl:element>
	</xsl:template>
	<!-- template to copy attributes -->
	<xsl:template match="@*">
		<xsl:attribute name="{local-name()}">
			<xsl:value-of select="."/>
		</xsl:attribute>
	</xsl:template>
	<!-- template to copy the rest of the nodes -->
	<xsl:template match="comment() | text() | processing-instruction()">
		<xsl:copy/>
	</xsl:template>
</xsl:stylesheet>

Result XML after transformation:

<salesorder> 
    <HDR>
        <resellernumber>27090917</resellernumber> 
        <ordernummer>2014-04-04</ordernummer> 
    </HDR>
    <DET>        	
        <item> 
            <GTIN>1500</GTIN> 
            <quantity>20</quantity> 
        </item>
    </DET>
    <DET>        	
        <item> 
            <GTIN>1600</GTIN> 
            <quantity>25</quantity> 
        </item>
	  </DET>
</salesorder>

2. Prepare a complex XML to a mappable external document: This example addresses cases where direct mapping cannot be used between an external XML document and an internal XML document.

Sample XML: In the following example, nodes ShipTo, BillTo, and InvoiceTo have a contactID attribute linked to complex contact nodes within the OrderMessage. The XSLT moves all corresponding nodes from the right contact to the corresponding ShipTo, BillTo, or InvoiceTo based on their attribute.

<?xml version="1.0"?>
<OrderMessage>
	<orderContent>
		<participatingParty>participantParty</participatingParty>
		<sendersIdForReceiver>1000010</sendersIdForReceiver>
		<orderId>1006</orderId>
		<lineCount>2</lineCount>
		<poNumber>1007</poNumber>
		<orderDate>2022102</orderDate>
		<shipTo contactID="46897889" />
		<billTo contactID="46897889" />
		<invoiceTo contactID="01905899" />
		<shippingCode>UPSN</shippingCode>
		<salesDivision>8119</salesDivision>
		<custOrderNumber>1005</custOrderNumber>
		<buyingContract>60002152</buyingContract>

        <lineItem>
            <lineItemId>1900-S</lineItemId>
            <orderLineNumber>1</orderLineNumber>
            <merchantLineNumber>1</merchantLineNumber>
            <qtyOrdered>10</qtyOrdered>
            <unitOfMeasure>PCS</unitOfMeasure>
            <description>PARIS Guest Chair, black</description>
            <unitCost>172.0000</unitCost>
            <shippingCode>UPSN</shippingCode>
            <expectedShipDate>2022102</expectedShipDate>
        </lineItem>
        <lineItem>
            <lineItemId>1924-W</lineItemId>
            <orderLineNumber>1</orderLineNumber>
            <merchantLineNumber>1</merchantLineNumber>
            <qtyOrdered>6</qtyOrdered>
            <unitOfMeasure>PCS</unitOfMeasure>
            <description>CHAMONIX Base Storage Unit</description>
            <unitCost>172.0000</unitCost>
            <shippingCode>UPSN</shippingCode>
            <expectedShipDate>2022102</expectedShipDate>
        </lineItem>

        <contact contactID="01905899">
            <name1>Elkhorn Airport</name1>
            <partnerContactId>8119</partnerContactId>
        </contact>
        <contact contactID="46897889">
            <name1>Englunds Kontorsmöbler AB</name1>
            <partnerContactId>8119</partnerContactId>
            <address1>Kungsgatan 18</address1>
            <address2>9 Wakara Way</address2>
            <city>Norrkobing</city>
            <state>SE</state>
            <postalCode>SE-600 03</postalCode>
            <dayPhone>555-555-5555</dayPhone>
        </contact>
    </orderContent>
</OrderMessage>

Sample XSLT:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<!-- template to copy elements -->
    <xsl:template match="node() | @*">
		<xsl:copy>
			<xsl:apply-templates select="node() | @*"/>
		</xsl:copy>
	</xsl:template>

    <!-- template to copy ship to nodes -->
	<xsl:template match="shipTo">
		<xsl:copy>
			<xsl:copy-of select="following-sibling::contact[@contactID=current()/@contactID]/*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

    <!-- template to copy bill to nodes -->
	<xsl:template match="billTo">
		<xsl:copy>
			<xsl:copy-of select="following-sibling::contact[@contactID=current()/@contactID]/*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

    <!-- template to copy invoice to nodes -->
	<xsl:template match="invoiceTo">
		<xsl:copy>
			<xsl:copy-of select="following-sibling::contact[@contactID=current()/@contactID]/*"/>
			<xsl:apply-templates/>
		</xsl:copy>
	</xsl:template>

    <!-- template to remove the person place nodes -->
	<xsl:template match="contact"/>
</xsl:stylesheet>

Result XML: ShipTo, BillTo, and InvoiceTo now contain the corresponding nodes from their respective contact elements, and the contact nodes are removed. This lets you map these new nodes to an internal document based on a sales order.

<OrderMessage>
	<orderContent>
		<participatingParty>participantParty</participatingParty>
		<sendersIdForReceiver>1000010</sendersIdForReceiver>
		<orderId>1006</orderId>
		<lineCount>2</lineCount>
		<poNumber>1007</poNumber>
		<orderDate>2022102</orderDate>
		<shipTo>
			<name1>Englunds Kontorsmöbler AB</name1>
			<partnerContactId>8119</partnerContactId>
			<address1>Kungsgatan 18</address1>
			<address2>9 Wakara Way</address2>
			<city>Norrkobing</city>
			<state>SE</state>
			<postalCode>SE-600 03</postalCode>
			<dayPhone>555-555-5555</dayPhone>
		</shipTo>
		<billTo>
			<name1>Englunds Kontorsmöbler AB</name1>
			<partnerContactId>8119</partnerContactId>
			<address1>Kungsgatan 18</address1>
			<address2>9 Wakara Way</address2>
			<city>Norrkobing</city>
			<state>SE</state>
			<postalCode>SE-600 03</postalCode>
			<dayPhone>555-555-5555</dayPhone>
		</billTo>
		<invoiceTo>
			<name1>Elkhorn Airport</name1>
			<partnerContactId>8119</partnerContactId>
		</invoiceTo>
		<shippingCode>UPSN</shippingCode>
		<salesDivision>8119</salesDivision>
		<custOrderNumber>1005</custOrderNumber>
		<buyingContract>60002152</buyingContract>

		<lineItem>
			<lineItemId>1900-S</lineItemId>
			<orderLineNumber>1</orderLineNumber>
			<merchantLineNumber>1</merchantLineNumber>
			<qtyOrdered>10</qtyOrdered>
			<unitOfMeasure>PCS</unitOfMeasure>
			<description>PARIS Guest Chair, black</description>
			<unitCost>172.0000</unitCost>
			<shippingCode>UPSN</shippingCode>
			<expectedShipDate>2022102</expectedShipDate>
		</lineItem>
		<lineItem>
			<lineItemId>1924-W</lineItemId>
			<orderLineNumber>1</orderLineNumber>
			<merchantLineNumber>1</merchantLineNumber>
			<qtyOrdered>6</qtyOrdered>
			<unitOfMeasure>PCS</unitOfMeasure>
			<description>CHAMONIX Base Storage Unit</description>
			<unitCost>172.0000</unitCost>
			<shippingCode>UPSN</shippingCode>
			<expectedShipDate>2022102</expectedShipDate>
		</lineItem>
	</orderContent>
</OrderMessage>