XML Script logo next up prev
Slices
Description

A slice is used to specify certain elements in an array (an array is a group of elements with the same name and the same parent element). A slice consists of one or more ranges, each separated by a comma. If the ranges overlap, the parts that overlap will only be returned once. The elements will be returned in the same order as they occur in the array, regardless of the order in which the ranges are specified.

A range is either a single expression (which is evaluated to a number, n, and returns the nth element), or the '$' character (which always returns the last element in the array), or a pair of two expressions (evaluated to numbers) separated by a '~' character. If the first of the pair is blank, all elements up to and including the value of the second expression are returned. If the second is blank, all elements after and including the value of the first expression are returned. Note that indexing starts from 1, not from zero, and descending ranges are treated as being empty (they don't return elements in reverse order).

Example

Syntax: [expression]

foo[\.bar]

The foo element at the position equal to the value of \.bar

Example

Syntax: [expression~expression]

foo[2~4]

The second to fourth foo elements

Example

Syntax: [~expression]

foo[~3]

The first three foo elements

Example

Syntax: [expression~]

foo[3~]

The 3rd foo element onwards

Example

Syntax: [$]

foo[$]

The last foo element

Example

foo[4~7,$,1~5]

The 1st to 7th and the last foo elements

Next...

XML Script homepage | Documentation home | XML Script docs | Command list | Function list | X-Tract docs

X-Stream, X-Tract and XML Script are trade marks of DecisionSoft Limited
© Copyright 1998-2000 DecisionSoft Limited