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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:31:59+00:00 2026-06-12T10:31:59+00:00

i have below 2 xml file(fruit.xml and toy.xml).I wanted to use xquery to retrieve

  • 0

i have below 2 xml file(fruit.xml and toy.xml).I wanted to use xquery to retrieve the fruit and toy that is produce by the country Japan.

the expected result should be like below toys need to be list out first before the fruit.

 <JapanProduct>
    <Prod type="Toy">Digimon<Prod>
    <Prod type="Toy">Doll<Prod>
    <Prod type="Fruit">Peach<Prod>
</JapanProduct>

below is the xquery code that i wrote and is currently stuck here.how can i produce the expected result as above?

for $f in doc("Fruit.xml")//Produce
for $t in doc("Toy.xml")//Produce

where $f[Country="Japan"] and $t[Country="Japan"]
return element JapanProduct {attribute Prod{if ($f[country=Japan"])then }

Fruit.XML
<fruitsOrigin>
  <Produce>      
     <Country>Australia</Country>
     <Prod>Kiwi</Prod>
     <Size>M</Size>
  </Produce>
  <Produce>
     <Country>China</Country>
     <Prod>Pear</Prod>
     <Size>M</Size>    
  </Produce>
  <Produce>
     <Country>Japan</Country>
     <Prod>Peach</Prod>
     <Size>L</Size> 
  </Produce>   
</fruitsOrigin>

Toy.XML
<ToyMaker>
   <Produce>
     <Country>Australia</Country>
     <Prod>Lego</Prod>
     <cost>$15</cost>
   </Produce>
   <Produce>
     <Country>Japan</Country>
     <Prod>Doll</Prod>
     <cost>$20</cost>      
   </Produce>
   <Produce>
     <Country>Japan</Country>
     <Prod>Digimon</Prod>
     <cost>$17</cost>
   </Produce>
</ToyMaker>
  • 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-12T10:32:00+00:00Added an answer on June 12, 2026 at 10:32 am

    Below works..

    <JapanProduct>
    {
    for $t in doc("Toy.xml")//Produce
      where $t[Country='Japan'] 
      order by $t
      return 
        <Prod type="Toy">{$t/Prod/string()}</Prod>
    
    }
    {
    for $f in doc("Fruit.xml")//Produce
      where $f[Country='Japan'] 
      order by $f
      return 
        <Prod type="Fruit">{$f/Prod/string()}</Prod>
    
    }
    </JapanProduct>
    

    You can give a try here http://basex.org/products/live-demo/

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

Sidebar

Related Questions

I have an xml file like below which I will use to set background
I have the below xml file and I need to use an xpath to
How do I change my XML file below to have CAS return to the
I have an xml file likes below. <?xml version=1.0 encoding=utf-8 ?> <Book> <Title>Title</Title> <Content>Content</Content>
I have a xml file as below: <?xml version=1.0 encoding=UTF-8 standalone=no?> <RULES> <RULE DESCRIPTION=
i have an xml file sitemap.xml as shown below ..i need to add one
I have an XML file which has many section like the one below: <Operations>
I have a flat structured XML file as below: <rs> <r id=r1 lev=0/> <r
I have a sample xml file which looks like the one below: <Root> <SubOne>
I have a long xml file the content of the file are below: <?xml

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.