Advanced XML rule example: Select a specific node when more than one node matches after using a standard rule
When you use a standard rule for a field, for example, there may still be multiple nodes that match the XPath leaving you with multiple candidates to pick from. You can create an advanced rule to specify the right one.
For this example, the standard rule for a Svefaktura invoice has generated this XPath for the Identifier field for the supplier: /Invoice/SellerParty/Party/Partyidentification/ID, and consequently, the mapping dialog indicates that there are three instances of this path in the invoice after you click Extract to check the results.
- Select the Identifier field under the Supplier 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.
- 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, expand the Invoice node.
- Navigate to and select the sub-node that represents the Identifier field for the supplier (that is, for this example, /Invoice/SellerParty/Party/Partyidentification/ID).
- Click Select.
- Select No condition: Matches both true and false under Conditions to work with in the middle of the screen.
- Select Use value from the XML node.
- In the box below, select the node for the value that is to be used (for Svefaktura invoices, it would be cac:ID). You may need to expand the node that is displayed if the node you need to select is a sub-node.
- Click Add.
- Select Use XSL to the left on the bottom of the window.
-
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:SellerParty/cac:Party/cac:PartyIdentification/cac:ID"> <xsl:value-of select="."/> </xsl:for-each> </xsl:template>
-
Move the contents of the
select attribute of the
<xsl:for-each> element (row
highlighted above in the second row of the code) to the
select attribute of the
<xsl:value-of> element in the
next row so that it looks like the following. Add [2] after
PartyIdentification to indicate that
you want to use the second instance in the file. Also, remove the
<xsl:for-each> element before
and after the original highlighted text so that the code looks like this:
<xsl:template match="/"> <xsl:value-of select="/x:Invoice/cac:SellerParty/cac:Party/cac:PartyIdentification[2]/cac:ID"/> </xsl:template>
- 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 definitionto 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.
Other examples of advanced XML rules:
Correct a misspelled field name in connection with master data
Format an extracted XML value with XSL
Modify an extracted XML field value with XSL
Remove hyphens (-) from an extracted value
Select node X based on node Y (or on attribute a)
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