If the Sequence = [a a b c c c a d d e e e f g h h]
then the Output = [1 2 1 1 2 3 1 1 2 1 2 3 1 1 1 2]
Have tried to use recursion but no luck...Please Help..Thanks in Anticipation
Note: Using XQuery implementation 1.0
One of my failed implementation looks like:
declare function local:test($sequence,$count){
for $counter in (1 to count($sequence))
let $maxIndex := count($sequence)
return
if (matches(subsequence($sequence,1,$maxIndex)[$counter],subsequence($sequence,1,$maxIndex)[$counter + +1])) then let $count := $count + 1 return $count[last()]
else let $count := 1 return $count[last()]
};
It seems that as $counter is a sequence hence it returns a sequence in matches condition and hence this implementation fail