Skip to content

XQuery remove Function

How to use the XQuery remove function to delete an item from a sequence by position while preserving the original data structure.

XQuery remove Function

The remove function is used to remove an item in a given sequence from any position. This function returns the modified sequence but the original sequence is not altered.

Syntax

remove($seq as item()*, $position as xs:integer)

Input Parameters

  • $seq is the provided sequence. A sequence can contain 0 or more items.
  • $position is the index of item to be removed. Index starts from 1.

Example

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