Problem

You have a sequence and want to know whether each item in that sequence is also in another sequence.

Solution

Applies to MarkLogic versions 7+

declare function local:seq-contains($s1 as item()*, $s2 as item()*)
{
  every $s in $s1 satisfies $s = $s2
};

local:seq-contains((1, 2), (1, 2, 3, 4)) => true
local:seq-contains((2, 1), (1, 2, 3, 4)) => true (order does not matter)
local:seq-contains(('a', 'b', 'z'), ('a', 'b', 'c', 'd')) => false

Discussion

The line of code within the local:seq-contains function is a Quantified Expression. This will work with scalar values as well as with nodes, making it a flexible way of determining membership.

Learn More

Application Developer's Guide

Read the methodologies, concepts, and use cases related to application development in MarkLogic Server, with additional resources.

MarkLogic Developer Learning Track

Want to build that awesome app? Get off the ground quickly with the developer track, with instructor-led and self-paced courses.

Getting Started Video Tutorials for Developers

This series of short videos tutorials takes developers who are new to MarkLogic from download to data hub, fast.

This website uses cookies.

By continuing to use this website you are giving consent to cookies being used in accordance with the MarkLogic Privacy Statement.