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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:31:12+00:00 2026-06-07T12:31:12+00:00

Sorry for the title, I didnt know what’s the best title for this question

  • 0

Sorry for the title, I didnt know what’s the best title for this question

I’m having difficulties with XQUERY. The result is not what I expected

here’s the xml

<Equipes>
        <Equipe>
            <equipeId>1</equipeId>
            <equipeNom>Equipe A</equipeNom>
            <JoueurEquipe>  
                <dateDebut>2011-01-01</dateDebut>
                <dateFin>2013-01-01</dateFin>
                <numero>1</numero>
                <joueurId>1</joueurId>
            </JoueurEquipe>
            <JoueurEquipe>
                <dateDebut>2010-01-01</dateDebut>
                <dateFin>2012-01-01</dateFin>
                <numero>2</numero>
                <joueurId>2</joueurId>
            </JoueurEquipe>
        </Equipe>
        <Equipe>
            <equipeId>2</equipeId>
            <equipeNom>Equipe B</equipeNom>
            <JoueurEquipe>  
                <dateDebut>2009-01-01</dateDebut>
                <dateFin>2012-01-01</dateFin>
                <numero>1</numero>
                <joueurId>3</joueurId>
            </JoueurEquipe>
            <JoueurEquipe>
                <dateDebut>2010-01-01</dateDebut>
                <dateFin>2014-01-01</dateFin>
                <numero>2</numero>
                <joueurId>4</joueurId>
            </JoueurEquipe>
        </Equipe>
    </Equipes>

and here’s the query

for $b in doc("ligue.xml")/ligue/Equipes
    return 
    <Equipes>
    {
        $b/Equipe/equipeId, 
        $b/Equipe/equipeNom
    }
    </Equipes>

the result is

<equipes>
       <equipeId>1</equipeId>
       <equipeId>2</equipeId>
       <equipeNom>Equipe A</equipeNom>
       <equipeNom>Equipe B</equipeNom>
</equipes>

what I need is

<equipes>
           <equipeId>1</equipeId>
           <equipeNom>Equipe A</equipeNom>
           <equipeId>2</equipeId>
           <equipeNom>Equipe B</equipeNom>
 </equipes>

I don’t know what i’m missing

Thank you

  • 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-07T12:31:15+00:00Added an answer on June 7, 2026 at 12:31 pm

    Iterate over the things you actually want your output to iterate over:

    <Equipes>{
    for $b in doc("ligue.xml")/ligue/Equipes/Equipe[equipeId][equipeNom]
        return ($b/equipeId, $b/equipeNom)
    }</Equipes>
    

    Now, let’s explore why your prior query behaved as it did. This:

    for $b in doc("ligue.xml")/ligue/Equipes
        return 
        <Equipes>
        {
            $b/Equipe/equipeId, 
            $b/Equipe/equipeNom
        }
        </Equipes>
    

    …finds the Equipes element, of which there’s only one (making the for loop useless). It then searches for $b/Equipe/equipeId and $b/Equipe/equipeNom, both of which evaluate to lists containing multiple elements, and concatenates those two lists to get the output.

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

Sidebar

Related Questions

Sorry about the vague title, but i didnt know how to ask the question
Sorry the title is not very clear. This is a follow up to my
Sorry for the title, I couldn't argue something better. Here is my question: Is
I am sorry I didn't know how to title my question any better, you
Sorry for the vague title, I didn't know how else to phrase this. Suppose
Sorry for the question title, i didn t know how to explain the question
Sorry for the poor title, I don't really know what to call this. I
Sorry for the vague title, I didnt know how to explain it better. I
Sorry for the generic title of the question, but I didn't know how else
I really didnt know what to put to the title so sorry about that.

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.