XPath - Part 2: Sorting with Orderby


To sort data and gain more experience in the XPath Wizard.

Background Information

Assuming you’ve completed the previous tutorial and have a list of orders showing the shipper, and shipping costs, you are probably wondering what you can do with this list next. Let’s go ahead and sort the shipments by cost so we can get a better idea of the range of shipping costs.


Inserting a Tag, ForEach Tag, XPath - Part 1: Basic Selection

Starting Template

This tutorial is a continuation of the XPath - Part 1: Basic Selection tutorial. We will start off with the template as it is at the end of that tutorial, so if you haven’t already, you should check that tutorial out (it won’t take very long)!


1. Open the XPath Wizard

This is exactly the same as in the previous tutorial. Select the ForEach tag [forEach Order: and click the Wizard button in the AutoTag ribbon.

Show Me How!

2. Add an OrderBy for Freight

Now, we decided to sort by the shipping cost, so that we can get a good view of the range of results. To do this, simply click to add an order by, which will cause a window to show up, similar to the window you saw in the previous tutorial. Select a child node. We chose Order/Freight. You’ll notice when you are done that the add an order by link is still there. You may add a second order by criteria for cases where multiple rows have the same value in a column. A good example is in a directory, where you would like to first sort people by last name, and then by first name.

Show Me How!

3. Generate and view results

Finally, generate a document and see what you have created. If you don’t know how to do this, check out the tutorials in the AutoTag Basics category.

Show Me How!

Quiz Yourself!

Can you sort XPath data in a table in AutoTag?
Yes. All I have to do is add an orderby for the column I wish to sort by in the XPath Wizard!
Yes. Just hit the magic “sort” button in the Home ribbon of Microsoft Word every time I generate my document.
No. The only way I can have sorted data is if it’s already sorted in the datasource.
Yes, but I have to program is myself which sounds like a daunting and time-consuming task, so no.
True/False: You can only sort by one column. In cases where several rows have the same data in that column, those rows appear together in a random order.
False. I can sort by as many columns as I want by adding more orderbys in the XPath Wizard.
True. This is an unfortunate limitation that I wish could be amended.
False. After generating the report, I can sort it the rest of the way using Microsoft Word’s magic “Sort” button
Kind of true. I can sort by only two columns, but no more than that.


You have completed this tutorial. We recommend taking a look at the XPath - Part 3: Filtering with Static Values tutorial next!