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

The Archive Base Latest Questions

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

I have 3 XML files as below and I would want to join all

  • 0

I have 3 XML files as below and I would want to join all this 3 documents together so that i can perform an aggregation function to find out how many sales have been made for a particular classification name. However seems like the code i wrote has a problem. Please, guide me on how can I perform aggregation function on the three documents.

ClassDescription.XML
<classification name="Electronic">
   <Description>electronic devices that requires electric</Description>
</classification>
<classification name="SoftToy">
   <Description>Fluffy toys that kids like</Description>
</classification>


ToyClassification.XML
<toy toyID="11">
  <name>Doll</name>
  <classification>SoftToy</classification>
</toy>
<toy toyID="22">
  <name>Xbox</name>
  <classification>Electronic</classification>
</toy>
<toy toyID="33">
  <name>PS3</name>
  <classification>Electronic</classification>
</toy>


 ToySale.XML
 <toySale companyID="1" toyID="11" >
   <amount>15</amount>
 </toySale>
 <toySale companyID="3" toyID="11" >
   <amount>12</amount>
 </toySale>
 <toySale companyID="1" toyID="22" >
   <amount>3</amount>
 </toySale>
 <toySale companyID="2" toyID="33" >
   <amount>7</amount>
 </toySale>



<ClassList>
  <classification name="SoftToy">
    <totalSale>4</totalSale>
  </classification>
  <classification name="Electronic">
    <totalSale>3</totalSale>
  </classification>
</ClassList>

Below was the code that i have but seems like its not working.May i know what is the correct xquery for this to work?

for $class in (ClassDescription.XML)//classification/@name
for $toyClass in (ToyClassification.XML)//toy/@toyID
for $sale in (ToySale.XML)//toySale/@toyID
let $sum := (ToySale.XML)//toySale[@toyID = $toyClass]
where $sale=$toyClass and $class=$toyClass/../name
order by sum($sum/amount)
return <ClassList>{$class}</ClassList>
  • 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-12T11:36:32+00:00Added an answer on June 12, 2026 at 11:36 am

    This query:

    for $total-sale in
        let $vClasses := doc('file:///c:/temp/delete/classDescription.xml'),
            $vDetails := doc('file:///c:/temp/delete/toyClassification.xml'),
            $vSales   := doc('file:///c:/temp/delete/toySale.xml')
         return
           for $c in $vClasses/*/*
            return
               let $d := $vDetails/*/*[classification eq $c/@name],
                   $s := $vSales/*/*[@toyID = $d/@toyID]
                 return
                    <classification name="{$c/@name}">
                             <totalSale>{sum($s/amount)}</totalSale>
                    </classification>
      order by $total-sale/totalSale descending
      return $total-sale
    

    when the three XML documents reside in the respective files:

    c:/temp/delete/classDescription.xml:

    <t>
        <classification name="Electronic">
            <Description>electronic devices that requires electric</Description>
        </classification>
        <classification name="SoftToy">
            <Description>Fluffy toys that kids like</Description>
        </classification>
    </t>
    

    c:/temp/delete/toyClassification.xml:

    <t>
        <toy toyID="11">
            <name>Doll</name>
            <classification>SoftToy</classification>
        </toy>
        <toy toyID="22">
            <name>Xbox</name>
            <classification>Electronic</classification>
        </toy>
        <toy toyID="33">
            <name>PS3</name>
            <classification>Electronic</classification>
        </toy>
    </t>
    

    c:/temp/delete/toySale.xml:

    <t>
        <toySale companyID="1" toyID="11" >
            <amount>15</amount>
        </toySale>
        <toySale companyID="3" toyID="11" >
            <amount>12</amount>
        </toySale>
        <toySale companyID="1" toyID="22" >
            <amount>3</amount>
        </toySale>
        <toySale companyID="2" toyID="33" >
            <amount>7</amount>
        </toySale>
    </t>
    

    produces the wanted, correct result:

    <classification name="SoftToy">
       <totalSale>27</totalSale>
    </classification>
    <classification name="Electronic">
       <totalSale>10</totalSale>
    </classification>
    

    Do note, that the CompanyID data isn’t used at all in the two other tables.

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

Sidebar

Related Questions

I have a number of xml files that should follow this format: <root> <question>What
I want to write a stored procedure that queries XML files after I have
I have two XML files. The structure of both XML files is as below:
I have an XML file that I want to sort by an attribute. The
I have xml file as below: <Name ns1:translate=yes>Overview</Name> <TextValue>Start</TextValue> <Title ns1:translate=yes>This is a book</Title>
I have a class that processes a 2 xml files and produces a text
I have some *.hbm.xml files that are placed in the same folder at the
I have an XML configuration file that contains a list of documents with field
I have a xml file that looks like this <a> <bb> <c date=20110706 time=1:20
Ok so I have these xml files that have date ranges on them. Heres

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.