How Do I Use X-Path Expressions in XML Conditional Patterns?
    • 21 Jun 2024
    • 3 Minutes to read
    • Contributors
    • PDF

    How Do I Use X-Path Expressions in XML Conditional Patterns?

    • PDF

    Article summary

    The Lasernet Form Editor allows for the use of Patterns to identify line items. Patterns can be defined based on the Start pattern criterion. The start pattern criterion can be defined simply by using the XPath for each line item. However, expressions can be used within the Start pattern criterion to further specify which lines to pick up. This article provides a guide on how to build conditionals for Start pattern criteria by showing examples.

    Note

    XPATH is a query language for selecting nodes from an XML document. XPATH was not invented or created by Formpipe, but it is used by Lasernet Form Editor.

    You will require a good knowledge of X-PATH rules because certain operators you may want to use are not allowed in X-Path, for example, Negative number comparisons.

    Examples

    The examples used in the article will be for a project invoice with five lines. This is a basic Start pattern criterion that validates the XPath existence so it can identify all the lines of this project invoice. As shown, this example has five lines, two of which are type Item, two of type Hour, and one of type Expense.

    Validate a Specific Field

    Add square brackets to the end of the XPath, followed by the complete field name, an operator, and your value to check for a specific field within the pattern. This pattern is using the = operator, but you can also use <> to check that the fields do NOT equal the value.

    Example: Only show invoice lines of transaction type Hour.

    The following is another example of validating a specific field. In this case, the field is a number and so we can use operators like > or <.

    Example: Only show invoice lines with a line amount greater than 0.

    Specify which Line Number to Print

    Add square brackets to the end of the XPath, followed by the line number you wish to display.

    Example: Only show the 5th invoice line.

    Combine Different Conditions

    Add multiple conditions by defining each one within square brackets. In this case, you are not using operators but the behavior is similar to using an AND operator. These conditions must all be true for the line to pass the criterion.

    Example: Only show invoice lines of transaction type Item with a quantity greater than 1.

    Add multiple conditions within the same square brackets and combine them using and. All conditions before and after the and must be true to pass the criterion.

    Example: Only show invoice lines of transaction type Item with a quantity greater than 1.

    Add multiple conditions within the same square brackets and combine them using or At least one of the conditions before or after the or must be true to pass the criterion.

    Example: Only show invoice lines that are either transaction type Item or have a quantity greater than 1.

    The following are two examples of a start pattern criterion that combines and and or. Best practice when combining and and or is to use parenthesis to group conditions. Both start pattern criteria are the same, except for the difference in the placement of the parenthesis.

    Example: Only show invoice lines that are transaction type Hour or

    Show invoice lines that have a quantity greater than 1 and a description of MidRangeSpeakers

    We get the hour lines displayed because they meet the condition before the or operator. We also get the item line because, while it is not type Hour, it does have a quantity greater than 1 and a description of MidRangeSpeaker.

    Example: Only show invoice lines that are either transaction type Hour or that have a quantity greater than 1.

    These lines must also have a description of MidRangeSpeakers.

    We get one line that matches this criterion. The line has a quantity greater than 1 and a description of MidRangeSpeakers.

    Attached is an object file and a grab file from the examples presented in this article to use for testing/ practice.

    StartPatternExample
    64.02 KB
    3C3B7MOYDPNU5LQLWEK5CIFV4U
    23.36 KB


    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.