Cover Image for XQuery Sequence functions
91 views

XQuery Sequence functions

In XQuery, sequence functions allow you to work with sequences of items, including strings, numbers, nodes, and more. These functions help you manipulate and analyze sequences efficiently. Here are some commonly used sequence functions in XQuery:

  1. fn:count($sequence):
  • Returns the number of items in the input sequence.
  1. fn:empty($sequence):
  • Checks if the input sequence is empty and returns a boolean value.
  1. fn:first($sequence):
  • Returns the first item in the input sequence.
  1. fn:last($sequence):
  • Returns the last item in the input sequence.
  1. fn:subsequence($sequence, $start, $length):
  • Extracts a subsequence from the input sequence, starting at the specified position (1-based) and of the specified length (optional).
  1. fn:distinct-values($sequence):
  • Returns a sequence containing only the distinct values from the input sequence.
  1. fn:insert-before($sequence, $position, $items):
  • Inserts new items into the input sequence before the specified position.
  1. fn:remove($sequence, $position):
  • Removes an item from the input sequence at the specified position.
  1. fn:reverse($sequence):
  • Reverses the order of items in the input sequence.
  1. fn:sort($sequence[, $collation]):
    • Sorts the items in the input sequence in ascending order. An optional collation parameter can be used to specify the collation sequence for sorting.
  2. fn:max($sequence):
    • Finds the maximum value in the input sequence.
  3. fn:min($sequence):
    • Finds the minimum value in the input sequence.
  4. fn:avg($sequence):
    • Calculates the average of numeric values in the input sequence.
  5. fn:sum($sequence):
    • Calculates the sum of numeric values in the input sequence.
  6. fn:filter($sequence, $predicate):
    • Filters the items in the input sequence based on the given predicate function.
  7. fn:fold-left($sequence, $zero, $function):
    • Applies a binary function to the items of the input sequence in a left-to-right order, accumulating a single result.
  8. fn:fold-right($sequence, $zero, $function):
    • Applies a binary function to the items of the input sequence in a right-to-left order, accumulating a single result.

These are some of the essential sequence functions in XQuery that help you manage and manipulate sequences effectively. By leveraging these functions, you can perform various operations on sequences of items efficiently, such as filtering, sorting, aggregating, and more.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS