Skip to content

XQuery reverse Function

How to use the XQuery reverse function to reverse sequences while preserving the original data, with syntax and practical examples.

XQuery reverse Function

The reverse function is used to reverse the given sequence. This function returns the modified sequence but the original sequence is not altered.

Syntax

reverse($seq as item()*)

Input Parameters

  • $seq is the provided sequence. A sequence can contain 0 or more items.

Example

XQuery Expressionxquery
let $items := (1,2,3,4,5,6)
let $new-items := reverse($items)
return
   <result>
      <items>
      {
         for $item in $new-items
         return <item>{$item}</item>
      }
      </items>
   </result>
Outputxml
<result>
   <items>
      <item>6</item>
      <item>5</item>
      <item>4</item>
      <item>3</item>
      <item>2</item>
      <item>1</item>
   </items>
</result>
Navigation