webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  select distinct in XQuery?

    Posted Fri March 18, 2005 09:07 AM

    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


    #Tamino
    #API-Management
    #webMethods


  • 2.  RE: select distinct in XQuery?

    Posted Fri March 18, 2005 01:40 PM

    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


    #webMethods
    #Tamino
    #API-Management


  • 3.  RE: select distinct in XQuery?

    Posted Mon March 21, 2005 08:30 AM

    Thanks for the answer but it does’t work.
    I have a document like

    Databases 10
    #Tamino
    #webMethods
    #API-Management


  • 4.  RE: select distinct in XQuery?

    Posted Mon March 21, 2005 06:56 PM

    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


    #Tamino
    #webMethods
    #API-Management