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 7060325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:20:21+00:00 2026-05-28T04:20:21+00:00

I have several lists which may or may not be empty. I want to

  • 0

I have several lists which may or may not be empty. I want to find those elements which occur in all lists, but only for those lists that are not empty.
I have something like this:

let $results := 
    $list1 intersect  
    $list2 intersect 
    $list3 intersect 
    $list4

But if any of the lists is empty this expression returns an empty list. Is there any way I can exclude a list from my intersection if it is empty?

SOLUTION:
This is the solution I ended up using, based on the answer provided by Ranon.

let $union := $list1 | $list2 | $list3 | $list4
let $results :=
    (if ($list1) then $list1 else $union)  intersect
    (if ($list2) then $list2 else $union)  intersect
    (if ($list3) then $list3 else $union)  intersect
    (if ($list4) then $list4 else $union)

I would like to thank all who have contributed. Coming from an object-oriented and procedural background, and with XQuery being a functional language it doesn’t come as naturally to me (yet).

  • 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-05-28T04:20:22+00:00Added an answer on May 28, 2026 at 4:20 am

    You could check all lists if they’re empty. If so, assign the union of all lists to them.

    For my example I used the functx-implementation of intersect and union to be able to intersect sequences, too. Maybe one should write some function to avoid redundant code, but for showing the idea this code is fine:

    import module namespace functx = "http://www.functx.com"  at ".../functx-1.0-nodoc-2007-01.xq";
    
    let $list1 := (1,2,3)
    let $list2 := (1,3)
    let $list3 := ()
    let $union := functx:value-union($list1, functx:value-union($list2, $list3))
    let $list1a := if (count($list1) != 0) then $list1 else $union
    let $list2a := if (count($list2) != 0) then $list2 else $union
    let $list3a := if (count($list3) != 0) then $list3 else $union
    return functx:value-intersect($list1a, functx:value-intersect($list2a, $list3a))
    

    $union could also be written as ($list1, $list2, $list3), but that will lead to double elements which result in slower intersection-operations for large element counts.

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

Sidebar

Related Questions

I have several different lists I want to call. They all have the same
It may seem to be asked several times, but I could not find answers
I have several lists in Matlab that I want to write to the same
I have several unordered lists that I want to display like this: <ul> <li><img></li>
I have a page which lists several messages, and each of these messages has
I have several similar methods, say eg. CalculatePoint(...) and CalculateListOfPoints(...). Occasionally, they may not
I currently have a list view which has several rows of data and I
I have a list, each item of which has several things in it, including
I have several lists in a sitecollection that are currently using ListTemplateID 101 (DocumentLibary).
I have several hundred files in a non-flat directory structure. My Makefile lists each

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.