Advanced XML rule example: Modify an extracted XML field value using XSL

For this example, the Kofax ReadSoft Invoices DeliveryDate field is captured correctly in a Svefaktura invoice but in the format "2011-06-01 T00:00". An advanced rule can be created so that the value displayed is limited to "2011-06-01":

  1. Select the DeliveryDate field under the Fields category on the Fields tab of the XML Mapper (on the right side of the window).
    • Click the button to the right of the value:

      if no rule has been defined, or

      if there is already an existing rule for the field.

  2. In the XML node selection section of the Advanced rules toward the top of the Field mapping rules tab that is displayed on the left of the window, expand the Invoice node.
  3. Navigate to and select the sub-node that represents the DeliveryDate field (which is Invoice/cac:Delivery/cbc:ActualDeliveryDate in the Svefaktura XML invoice standard), and click Select.
  4. Select No condition: Matches both true and false under Conditions to work with in the middle of the screen.
  5. Select Use value from XML node.
  6. Select the node for the value to be used in the box below (for Svefaktura invoices, it would be cbc:ActualDeliveryDate).

You may need to expand the node that is displayed if the node you need to select is a sub-node.

  1. Click Add.
  2. Select Use XSL to the left on the bottom of the window.
  3. Click the Import from advanced rules button to add the XSL code that represents the rule selected above to the code box below. This would be the code for Svefaktura invoices:
    <xsl:template match="/">
       <xsl:for-each select="/x:Invoice/cac:Delivery/cbc:ActualDeliveryDateTime">
          <xsl:value-of select="."/>   </xsl:for-each>
    </xsl:template>
  4. Add substring-before(.,'T') to the third row so that it looks like this:

    <xsl:value-of select="substring-before(.,'T')"/>   </xsl:for-each>

Click Extract and review the image to check the results. If you need to modify the rule, you need to click it in the Rules applied to map this field box, click Del to delete it, make the changes needed to fix the rule, and click Add again to add the modified rule. If you need to modify a condition, the process is the same (and if a rule is based on it, the rule is also deleted if you delete the condition).

Consider if the change(s) should apply to all invoices or only those for the current XML invoice definition. Click Save XML definition to save the change for the current XML invoice definition only (that is, the current supplier). Click Save XML profile if you want the rule to apply to all XML invoices that match the XML invoice profile regardless of the XML invoice definition.

About sub-string functions

  • Substring-before(source, str) returns the portion of source that comes before the first occurrence of str.

If str is not found, then the result is an empty string.

In this example, the source is "2011-06-01 T00:00" so the result of adding  substring-before(.,'T') is 2011-06-01 since that is what comes before the first occurrence of 'T'.

  • Substring-after(source, str) would return the portion of source that comes after the first occurrence of str.

If str is not found, then the result is an empty string.

Note

Whenever you use XSL to get a desired value, be sure to test the output when the data contains special characters (such as &).

To display special characters normally (an ampersand character, &, would be displayed as &, for example), add <xsl:output method="text" /> to the XSL snippet in this way.  



If this code is not added, the ampersand would be displayed as &amp;.

Other examples of advanced XML rules:

Correct a misspelled field name in connection with master data

Format an extracted XML value with XSL

Remove hyphens (-) from an extracted value

Select node X based on node Y (or on attribute a)

Select a specific node when more than one node matches after using a standard rule

Select node X if it exists and node Y if it does not

Specify a constant value for a field

Summarize data from line items as a note in summary invoices

Translate an XML value to one that Kofax ReadSoft Invoices understands