Business Integration Solutions Documentation

About: XMLTOXMLTRANSLATOR Activity

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

How to setup the XMLTOXMLTRANSLATOR Activity

Usage

Use this activity if you want to apply a custom XML Style sheet on an XML document.

Concept

This is an advanced mapping activity which enables complex XML Transformations that aren't supported by the Mapper acitvity

After transformation, the resulting XML should be matching the structure of an External Document. For developers with more knowledge of XSLT transformations, they could opt to link directly to an internal document, making the mapper obsolete. The latter will process faster, but might be harder to achieve.

The output of the XML to XML Translator is ready to be processed by the remaining Pipeline Elements. The XML to XML Translator can be used both for exporting and importing data.

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

Available Templates

This element comes with the following templates:

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

Examples

  1. Removing Namespaces: TI offers an out of the box XMLTOXMLTRANSLATOR for clearing namespaces within an xml

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 containstwo 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>
  1. Prepare a complex xml to a map-able external document: this examples takes into account cases where a direct mapping cannot be used between an external xml document and an internal xml document

Sample XML: In the below example, nodes "ShipTo", "BillTo" and "InvoiceTo" have an attribute "contactID" that is linked to other complex nodes "contact" withint the "OrderMessage". To transform this into an external document, viable to use within a mapper, we are going to apply an XSLT that will move all the 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: Notice "ShipTo", "BillTo" and "InvoiceTo" now have the corresponding nodes from their respective "contact", and the "contact" nodes are removed. This will allow you to further 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>