line-o
line-o

Reputation: 1895

Remove specific item in a sequence in XQuery

What is a good way to remove a specific item in a sequence?

I want to remove "b" from the sequence ("a", "b", "c") for example.

("a", "b", "c")
-> do something
-> ("a", "c")

What I know does work is to split the sequence in two and then glue them back together but I would like to know if there are nicer solutions.

Upvotes: 2

Views: 146

Answers (3)

line-o
line-o

Reputation: 1895

I ended up using ('a', 'b', 'c')[. ne 'b']

Upvotes: 0

jdk
jdk

Reputation: 159

$seq[not(. eq 'b')], i.e., return items in the sequence, except for values of b. This approach avoids some of the vagaries of !=.

Upvotes: 1

Norm
Norm

Reputation: 1036

How about $seq[. != 'b'] where $seq contains your sequence, naturally.

Upvotes: 2

Related Questions