Create XSL transformations manually
Northwest Products can decide to model their data exactly in the same way as explained in the first simple mapping example, but they do not want to use the third party tool MapForce and asked their XSLT expert to create the XSLT file for them manually.
Proceed exactly in the same way as in the first example, and once your destination with simple XML mapping has been created, click Show files for Visual Designer. The following files are created.
File Name |
Purpose |
---|---|
Input.Xml |
This is the sample input XML for the XSL transformation and consists of:
A similar file is internally generated during operation of Kofax Import Connector for each received customer XML document (see screen shot below) |
Input.Xsd |
This is the schema describing the input.xml structure. Both input XML and its schema files are always the same for both XML mapping variants – the simple and generic as well. |
Output.Xml |
This file defines the XML root element for the XML output of the XSL transformation. |
Output.xsd |
This is the schema describing the structure of output.xml. There is a substantial difference between output.xsd generated for simple and generic mappings:
|
The Input.Xml could look similar to the following.
<?xml version="1.0" encoding="utf-8"?>
<Input xsi:noNamespaceSchemaLocation="Input.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MessageHeader>
<KfxMessageCorrelation>1</KfxMessageCorrelation>
<KfxMessageDeliveryPriority>0</KfxMessageDeliveryPriority>
<KfxMessageDeliverySuspectedDupli>false</KfxMessageDeliverySuspectedDupli>
<KfxMessageDeliveryType>TO</KfxMessageDeliveryType>
<KfxMessageID>message_id_sample</KfxMessageID>
<KfxMessagePages>1</KfxMessagePages>
<KfxMessageReceptionTimeCreated>2001-12-17T09:30:47Z</KfxMessageReceptionTimeCreated>
<KfxMessageSubject>message subject sample</KfxMessageSubject>
<KfxOriginatorName>originator name sample</KfxOriginatorName>
<KfxOriginatorNumber>originator@localhost</KfxOriginatorNumber>
<KfxOriginatorService>EMAIL</KfxOriginatorService>
<KfxRecipientName>Orders sample</KfxRecipientName>
<KfxRecipientNumber>orders@localhost</KfxRecipientNumber>
<KfxRecipientService>EMAIL</KfxRecipientService>
</MessageHeader>
<RootXml>
<Orders xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Order PONumber="42367">
<ShipTo>
<FirstName>Martin</FirstName> <LastName>Janeway</LastName>
</ShipTo>
<Articles>
<Article>
<Quantity>1</Quantity> <ItemNr>638</ItemNr>
<Description>LANG STERLING PIE SERVER</Description>
<UnitPrice>32.95</UnitPrice> <Amount>32.95</Amount>
</Article>
</Articles>
<Subtotal>32.95</Subtotal>
<SalesTax>2.55</SalesTax>
<Shipping>5.00</Shipping>
<Total>40.50</Total>
</Order>
</Orders>
</RootXml>
<Files>
<File ImportFileName="filename.ext" />
</Files>
</Input>
The XSL transformation in Kofax Import Connector involves the following actions:
-
Input.Xml structure is generated for each received message.
-
The XSL transformation is executed and its output is an internal representation of Output.Xml.
-
Output.Xml is parsed and corresponding batch fields are created/filled with the input data.
If you want to create XSL transformations manually, proceed as follows:
- Consider your input.xml data (along with the schema file).
- Consider the output data definition in output.xsd.
- Create a XSL transformation that converts the input.xml like data to output.xml.
- Save the created XSLT file as "XMLMapping.xslt" to the destination's visual designer folder. You can click Show files for Visual Designer in the Destination configuration to open the folder.
If you do not want to create the file manually, use the sample file from the Samples\DemoMapping\SimpleMappingManual\SampleSimpleMappingManual folder.
An XSL transformation that fulfills the same task as in the simple XML mapping example may look like the following.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Batch><xsl:apply-templates/></Batch>
</xsl:template>
<xsl:template match="MessageHeader"/>
<!--Ignore MessageHeader-->
<xsl:template match="Files"/>
<!--Ignore Files-->
<xsl:template match="RootXml/Orders/Order">
<BatchFields>
<PONumber><xsl:value-of select="@PONumber"/></PONumber>
</BatchFields>
<DocumentTables>
<xsl:apply-templates select="ShipTo|Articles"/>
</DocumentTables>
<DocumentFields>
<Subtotal><xsl:value-of select="Subtotal"/></Subtotal>
<SalesTax><xsl:value-of select="SalesTax"/></SalesTax>
<Shipping><xsl:value-of select="Shipping"/></Shipping>
<Total><xsl:value-of select="Total"/></Total>
</DocumentFields>
</xsl:template>
<xsl:template match="ShipTo">
<ShipTo>
<Row>
<FirstName><xsl:value-of select="FirstName"/></FirstName>
<LastName><xsl:value-of select="LastName"/></LastName>
</Row>
</ShipTo>
</xsl:template>
<xsl:template match="Articles">
<Articles>
<xsl:for-each select="Article">
<Row>
<Quantity><xsl:value-of select="Quantity"/></Quantity>
<ItemNr><xsl:value-of select="ItemNr"/></ItemNr>
<Amount><xsl:value-of select="Amount"/></Amount>
<Description><xsl:value-of select="Description"/></Description>
<UnitPrice><xsl:value-of select="UnitPrice"/></UnitPrice>
</Row>
</xsl:for-each>
</Articles>
</xsl:template>
</xsl:stylesheet>