質問

In xPath if one has sequence1 = sequence2, it returns true if there is at least one element in sequence1 which is also in sequence2. I need something which allows me to test if all elements of sequence1 exist in sequence2 (the set of values of sequence1 is a subset of the set of values in sequence2).

Is this feasible?

役に立ちましたか?

解決

Use the double negation law:

not($seq1[not(. = $seq2)])

Alternatively, and much more efficiently -- for sequence of nodes and node-identity based equality semantics: (O(N) vs O(N^2)):

count($seq1 | $seq2) = count($seq2)

II. XPath 2.0

For a sequence of nodes (node-identity - based equality semantics):

not($seq1 except $seq2)

and an efficient expression for sequence of values:

count(distinct-values(($seq1, $seq2))) eq count(distinct-values($seq2))

他のヒント

This should work in XPath 1.0:

not($sequence1[not(. = $sequence2)])

You could use every to check if every element is in sequence2

every $x in $sequence1 satisfies $x = $sequence2
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top