Hi,
I have a problem.
I need to eliminate double node-sets in my XQuery Result but the dinstinct-values() function only works with atomic-values!
Is there a simple option like the select distinct in SQL?
Thanks
tovo
Hi,
I have a problem.
I need to eliminate double node-sets in my XQuery Result but the dinstinct-values() function only works with atomic-values!
Is there a simple option like the select distinct in SQL?
Thanks
tovo
Hi,
You can eliminate duplicate nodes by applying a path expression. An according query may look like this:
(for $a in input()/bib/book return $a, for $a in input()/bib/book return $a)/.
The path expression applied on the flwr expression removes all duplicate “book” elements and sorts the resulting node sequence in document order.
Best regards,
Thorsten Fiebig
Thanks for the answer but it does’t work.
I have a document like
Hi,
To perform a value-based duplicate elimination you have to apply the distinct-values() function. For your example I would suggest the following query:
for $dt in input()/book/title
for $dp in input()/book/price
let $g := input()/book[title =$dt and price = $dp]
where $g
return
{$dt, $dp}
The two “for” clauses retrieve all distinct book titles and prices. The result is a cross-product over the two distinct value sets. The “let” clause retrieves for each combination of “title” and “price” the according “book” elements. By referencing the variable $g in the “where” clause you perform a none-empty check on the node set determined by the “let” clause. Hence, you create a “BookInformation” element just for the existing combinations of “title” and “price”.
Best regards,
Thorsten Fiebig