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:

  • The message metadata in the MessageHeader element

  • Customer's input XML itself (the Orders element)

  • The list of all available attachments (the Files element)

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:

  • With simple mapping, output.xsd is generated according to batch / folder /document fields defined in the batch class assigned to the destination where the mapping occurs. Therefore, if anything changes in the batch class definition in Kofax Capture, a different schema file is generated.

    Such a schema consists of four optional parts:

    • The sequence of all BatchFields (if any batch fields defined)

    • The sequence of all DocumentTables (if any document tables defined)

    • The sequence of all (non-table) DocumentFields (if any index fields defined)

    • The sequence of all ExpectedTotals (if any total index fields defined)

  • With generic mapping, output.xsd is always the same as it is not related to any specific batch class.

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:

  1. Input.Xml structure is generated for each received message.

  2. The XSL transformation is executed and its output is an internal representation of Output.Xml.

  3. 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:

  1. Consider your input.xml data (along with the schema file).
  2. Consider the output data definition in output.xsd.
  3. Create a XSL transformation that converts the input.xml like data to output.xml.
  4. 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>