Product: Mapping Manager
Predicates are used to filter or narrow down your xPath results by allowing you to attach additional requirements that must be met in order for the XML to be returned. These predicates allow Mapping Manager to be more selective on its results by checking for conditions prior to being selected.
Examples |
|
Filter by Item Code | First or Last Instance |
Quantity is above a certain threshold | Check for Attribute Presence |
Sample XML
For all examples below - we will be using this sample XML to display results
<LineItems>
<Item>
<LineNumber>1</LineNumber>
<ProductCode>ABC123</ProductCode>
<Description>Widget A</Description>
<Quantity>10</Quantity>
<UnitPrice>250.00</UnitPrice>
<TotalPrice>2500.00</TotalPrice>
</Item>
<Item>
<LineNumber>2</LineNumber>
<ProductCode>XYZ789</ProductCode>
<Description>Gadget B</Description>
<Quantity>5</Quantity>
<UnitPrice>200.00</UnitPrice>
<TotalPrice>1000.00</TotalPrice>
</Item>
<Item>
<LineNumber>3</LineNumber>
<ProductCode>GEF567</ProductCode>
<Description>Gadget C</Description>
<Quantity>0</Quantity>
<UnitPrice>128.00</UnitPrice>
<TotalPrice>0</TotalPrice>
</Item>
</LineItems>
Predicate Structure
Predicates are defined by introducing a condition wrapped within Square Brackets [ ] after the XML Pathing has been defined. These conditions can be attributes, children nodes, or even special selections such as a specific loop number or requirement.
Example - Filter by Positive Quantity
Invoice/Items/Item[Quantity > 0]
With this conditional predicate in place, we ignore all Items that do not have a Quantity greater than 0.
Results
<Item>
<LineNumber>1</LineNumber>
<ProductCode>ABC123</ProductCode>
<Description>Widget A</Description>
<Quantity>10</Quantity>
<UnitPrice>250.00</UnitPrice>
<TotalPrice>2500.00</TotalPrice>
</Item>
<Item>
<LineNumber>2</LineNumber>
<ProductCode>XYZ789</ProductCode>
<Description>Gadget B</Description>
<Quantity>5</Quantity>
<UnitPrice>200.00</UnitPrice>
<TotalPrice>1000.00</TotalPrice>
</Item>
The 3rd item is not returned - since it's Quantity is 0
Combining Predicates
You can combine Predicates by utilizing multiple square brackets [ ] one after the other chaining them together to form an xPath selection utilizing conditionals that apply in succession, filtering the selections based on the last predicate results.
For example - you can utilize the first predicate to select only items that have a Quantity above 0, and then of those items filter down to ones below a Price Threshold.
Example - Filter by Positive Quantity with Price Threshold
Invoice/Items/Item[Quantity > 0][TotalPrice < 1500]
By combining predicates you can create fairly useful filter conditions that allow you to provide specific results based on a number of key data points.
<Item>
<LineNumber>2</LineNumber>
<ProductCode>XYZ789</ProductCode>
<Description>Gadget B</Description>
<Quantity>5</Quantity>
<UnitPrice>200.00</UnitPrice>
<TotalPrice>1000.00</TotalPrice>
</Item>
1st Predicate: The 3rd item is removed - because its Quantity is 0
2nd Predicate: The 1st item is removed - because its TotalPrice is greater than 1500
Combined Results in only the 2nd item being present
rev 10/15/2024