Forum Stats

  • 3,872,224 Users
  • 2,266,407 Discussions
  • 7,911,107 Comments

Discussions

XQuery

KaushikBose
KaushikBose Member Posts: 7
edited Apr 29, 2016 5:36AM in XQuery

XQuery

Input: (1,2,3,4,5,6,7,14,15,16,17,24,25,26,27,28)

Output: (1,7,14,17,24,28)

I tried to remove consecutive numbers from the input sequence using the XQuery functions but failed doing so

 xquery version "1.0" encoding "utf-8";

 declare namespace ns1="http://www.somenamespace.org/types";
 declare variable $request as xs:integer* external;

 declare function local:func($reqSequence as xs:integer*) as xs:integer* {
 let $nonRepeatSeq := for $count in (1 to count($reqSequence)) return
 if ($reqSequence[$count+1] - $reqSequence) then remove($reqSequence,$count+1) else ()
 return $nonRepeatSeq 
};

local:func<span style="color: #242729; font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif; font-size: 15px;">((1,2,3,4,5,6,7,14,15,16,17,24,25,26,27,28))</span>

Please suggest how to do so in XQuery functional language.

Tagged:

Answers

  • odie_63
    odie_63 Member Posts: 8,493 Silver Trophy
    edited Apr 29, 2016 5:36AM

    Something like this :

    let $input := (1,2,3,4,5,6,7,14,15,16,17,24,25,26,27,28)
    return
      for $i at $p in $input
      return if ( $input[$p - 1] != $i - 1
               or $input[$p + 1] != $i + 1
               or $p = 1
               or $p = count($input) ) then $i else ()
    
This discussion has been closed.