Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9115477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:26:31+00:00 2026-06-17T04:26:31+00:00

I have two lists of elements which I use to query a third type

  • 0

I have two lists of elements which I use to query a third type of elements (in eXist DB). But since I only want those results that are found by both queries (i.e. satisfy two sets of initial parameters) I do an intersection of those two sub-results:

let $aList1 := for $elementB in $elementListB return //ElementA[ft:query(@referenceB, $elementB/@id)]
let $aList2 := for $elementC in $elementListC return //ElementA[ft:query(@referenceC, $elementC/@id)]
let $results := $aList1 intersect $aList2

The thing is, there is a function i need to call on each element in the starting lists to get some additional info. Normally I would do something like this:

let $aList1 := for $elementB in $elementListB
    let $additionalInfo := additionalInfoFunction($elementB)
    return
        <wrapper>
        <additionalInfo>{$additionalInfo}</additionalInfo>
        {
             //ElementA[ft:query(@referenceB, $elementB/@id)]
        }
        </wrapper>

However, if I do this I will not be able to perform intersection of $aList1 and $aList2 since intersection works with references not values.

I thought of calling the additionalInfoFunction after the intersection like this:

return for $result in $results
let $elementB := $elementListB[@id = $result/@referenceB]
let $additionalInfo := additionalInfoFunction($elementB)
return
    <wrapper>
    <additionalInfo>{$additionalInfo}</additionalInfo>
    {
         BLA BLA
    }
    </wrapper>

But the problem here is that while $elementListB and $elementListC only contain a few elements, $results can contain hundreds which is a problem since additionalInfoFunction is relatively expensive.

Is there some clever workaround here which I just can’t see?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T04:26:33+00:00Added an answer on June 17, 2026 at 4:26 am

    XQuery is a functional language with immutable variables and thus without side-effects.

    However, if I do this I will not be able to perform intersection of
    $aList1 and $aList2 since intersection works with references not
    values.

    Whether a function or operator like intersects will return references or not is only relevant for the implementation (references could be faster), but as all values are immutable, this can never be a problem to you.


    The actual problem is related, but not similar; intersects does not do a deep-equal but only looks at some internal “node id” (or reference if you want). Creating two elements – though containing the same contents – will creating different nodes, so intersect will return no results.

    You will have to build your own intersects, which isn’t too difficult:

    let $a := (<a><a1/><a2/></a>, <b><b1/><b2/></b>),
        $b := (<a><a1/><a2/></a>, <c><c1/><c2/></c>)
    
    return $a[
      some $e in $b
      satisfies deep-equal(., $e)
    ]
    

    This will return all elements from $a for which there is some element in $b which deep-equals the one from $a.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists. They are sortable but not connected (elements of list one
I have two lists which are guaranteed to be the same length. I want
We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that
I have two lists: [a, b, c] [d, e, f] I want: [a, d,
I have the following two lists, which are pairs of strings. One is what
Let's say I have a list somewhere called majorPowers which contain these two lists:
I have two select lists which are being styled using the jQuery UI Selectmenu
In my code, I have two lists, of different lenghts, which I'll call main
I have two activities which I want to combine with a FragmentPagerAdapter. I followed
I have custom Question objects which I render into html form elements. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.