Altova StyleVision 2023 Professional Edition

Example: Sorting on Multiple Sort-Keys

Home Prev Top Next

In the simple example below (available in the (My) Documents folder, C:\Documents and Settings\<username>\My Documents\Altova\StyleVision2023\StyleVisionExamples\Tutorial\Sorting\SortingOnTwoTextKeys.sps), team-members are listed in a table. Each member is listed with first name, last name, and email address in a row of the table. Let us say we wish to sort the list of members alphabetically, first on last name and then on first name. This is how one does it.

 

When the list is unsorted, the output order is the order in which the member elements are listed in the XML document (screenshot below, which is the HTML output).

 

SS_Sort_UnsortedHTML

 

In Design View, right-click the member element (highlighted blue in screenshot below), and from the context menu that appears, select the Sort Output command.

 

SS_Sort_SelectElementDes

 

This pops up the Define Output Sort Order dialog (screenshot below). Notice that the element selected for sorting, member, is named at the Sort Nodes entry. This node is also the context node for XPath expressions to select the sort-key. Click the Add Row button (at left of pane toolbar) to add the first sort instruction. In the row that is added, enter an XPath expression in the Match column to select the node last. Alternatively, click the Build button BtnEdit to build the XPath expression. The Datatype column enables you to select how the sort-key content is to be evaluated: as text or as a number. The Order column lists the order of the sort: ascending or descending. Select Text and Ascending. Click OK to finish.

 

DlgDefineSortOrder1

 

In Design View, the member tag displays an icon indicating that it contains a sort filter tag_sort. The HTML output of the team-member list, sorted on last name, is shown below. Notice that the two Edwards are not alphabetically sorted (Nadia is listed before John, which is the order in the XML document). A second sort-key is required to sort on first name.

SS_Sort_SortedOnLast

In Design View, right-click the member tag and select the Sort Output command from the context menu. The Define Output Sort Order dialog pops up with the last sort instruction listed. To add another sort instruction, append a new row and enter the first element as its sort-key (screenshot below). Click OK to finish.

DlgDefineSortOrder2

In the HTML output, the list is now sorted alphabetically on last name and then first name.

SS_Sort_SortedOnLastFirst

 

© 2017-2023 Altova GmbH