STx 3.9 Documentation

Book

Shell Items

Up

XML Element and Attribute Manipulation

Previous

SETATTRIBUTE

Next

XML Element Data Manipulation

SORT

SET xmlfile SORT [attrID0 dir0 attriIDN dirN] [/Delete]

Sort the selected elements children according to the given attributes and directions and set the element's sort attribute. Previous sort attributes are overwritten. Calling this function without parameters resorts using the existing attributes. Calling the function without parameters and with the /Delete option removes the sort attributes. This function only supports attributes defined in the doctype. Note that if one of the attributes is unique (as defined in the doctype definition), only this attribute will be used to sort.

attrId

The name of an attribute defined in the doctype.

dir

The direction in which the elements should be sorted. The following values are allowed: 'Ascending' or 'Descending' (or any shorter version thereof, e.g. 'Asc' or 'Desc' or 'a' or 'd'). or '0' or '1'

/Delete

If no parameters are passed, the existing sort attributes are deleted.

The internal implementation works in the following way:

Unique Attributes: If one of the attributes passed to the SORT command is unique (as defined in the doctype), only this attribute is used for sorting. The elements are sorted according to the direction and case is respected, if so defined in the doctype. All elements added to this level after sorting are added at the correct sorted position. Changing attributes of sorted elements also rearranges the sort order. If you have a large number of segments in an AFile, sorting according to a unique attribute is highly recommended, since the performance of the dataset validation is very slow for unsorted unique attributes. If you set the parent 'sort' attribute by hand and want the sort to happen automatically, please set the 'unsorted' attribute to '1'. The next time an attribute is changed, or an element is added, all elements will first be sorted.

Non-unique Attributes: If the sort attributes are not unique, multiple attributes can be used. Elements added after sorting are not inserted at the correct position; instead, a further attribute 'unsorted' is set in the parent element. Changing attributes after sorting does not affect the sort order – the parent attribute 'unsorted' is set.

Validation: the validate command checks for sort attributes and sorts the elements before validation. When closing S_TOOLS-STx, the DataSet is validated, and therefore all elements with sort attributes are sorted.

SET $#xmlfile SORT ID Asc

The children of the selected element are sorted by their ID attribute in ascending order. The following command does the same by means of the SETATTRIBUTE command.

SET $#xmlfile SETATTRIBUTE sort 'ID Asc' unsorted '1'

When $#xmlfile's selected element is an AFile, all ASegs in this AFile will be sorted according to their ID. Sorting will happen automatically, either on modification/addition of an element or attribute to one of the ASegs, or on validation.

© 2009 The Austrian Academy of Sciences Acoustics Research Institute