XPath - Part 4: Filtering with Parameter Values

Objective

To filter data based on a single criteria which is set at the time of the document generation in a document which filters out a list of products shipped by a specific shipper.

Background Information

You have learned how to select data in XPath, and you probably know how to sort it from the second tutorial in the set. If you previously looked at XPath - Part 3: Filtering with Static Values , then you also know how to set up a basic filter using a static value. If you didn’t, everything you need to learn will be in this tutorial. Here, we take the case where you have some document (for example, our list of products and shipping costs) and some value you want to filter (which shipper delivered the product), but say you want to change the filter each time you generate the document? This can be done with a parameter filter. AutoTag will then prompt you for the new filter value before you generate your document!

Pre-requisites

Inserting a Tag, ForEach Tag, XPath - Part 1: Basic Selection, XPath - Part 2: Sorting with Orderby

Starting Template

This tutorial is a continuation of the XPath - Part 2: Sorting with OrderBy tutorial. If you haven’t completed that tutorial yet, you should go back and do it first. Start here with the resulting template from the end of Part 2. You may also start from the template from Part 3, in which case you only need to do step 5.

Procedure

1. Add a parameter called ShipperID of type Integer with default value 1

Variables in AutoTag allow you to substitute placeholders for values in your data selection, conditional tags, and many other places. Here, they let us substitute a placeholder in a data filter which we fill in with a value when we generate the document. In order to add a parameter, click the Parameters button in the AutoTag Manager ribbon, click Add, then type a name. We used ShipperID. Select its type as Integer, and set a default value—we used 1. Finally, click Save to save the parameter.

Show Me How!

2. Open the XPath Wizard

As in the earlier sections of the XPath tutorials, select the ForEach tag and click Wizard in the AutoTag ribbon to open the XPath Wizard.

Show Me How!

3. Add a group, add a condition

This step is the same as in Part 3 as mentioned in the Background Information section. You will click to add a group, then click to add a condition.

Show Me How!

4. Set the node to ShipVia

Again, this is the same as what you did in Part 3. Click to select a node, and choose the ShipVia node. This is the left side of your filter. This is the value you will be looking at in your filter.

Show Me How!

5. Set the value to $(ShipperID) parameter

This is where this tutorial varies from Part 3. Instead of choosing a static value as we did there, we’re going to use the parameter we just created as a placeholder for the static value we used earlier. So click to set the value and then in the drop down menu, choose the ShipperID parameter.

Show Me How!

6. Set the parameter and generate document

This is the same step we always do to view the results after finish a tutorial, however this time there is an added action to be completed here! When you click output and select a format, you’ll notice a Parameters window opens prompting you to enter a value for the parameter you created. Enter the value and you are done. Check out the results to see what we have made.

Show Me How!

Quiz Yourself!

True/False: A parameter filter means a condition where a dynamically specified node name meets a specific value.
False. Parameter filter means a specific node value meets a dynamically specified value.
True. I just didn’t learn that in this tutorial.
False. A parameter filter just means that a parameter instead of a node is compared with some static value.
True. A parameter filter lets me select the column when I generate a document.
You can achieve the same effect with if and else tags and a parameter
True. But if you attempt that, you’ll find that it is immensely easier to simply use the wizard.
False. If and Else tags only compare nodes against other nodes
False. If and Else tags only compare nodes against static values.
True. If and Else tags are extremely versatile, but they are meant only for programmers and technical people to use.
What types of comparisons can you make with a filter?
You can make any logical comparison to numbers such as not equal, equal, less than, greater than, or even a combination of those. They also let you make comparisons in strings and text such as starts with, ends with, contains, etc.
You can only compare if values are equal to each other
You can only compare if values are less than, greater than, or equal to each other
Almost anything, they just don’t work on strings and text.

Congratulations!

You have completed this tutorial. We recommend taking a look at the XPath - Part 5: Complex Filters tutorial next!

close
continue