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 7814249

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:08:27+00:00 2026-06-02T05:08:27+00:00

I work with XQuery to do statistics. I have one document like this :

  • 0

I work with XQuery to do statistics. I have one document like this :

<tr>
  <td>Element 1</td>
  <td>100</td>
</tr>
<tr>
  <td>Element 2</td>
  <td>80</td>
</tr>
<tr>
  <td>Element 3</td>
  <td>40</td>
</tr>
<tr>
  <td>Element 4</td>
  <td>12</td>
</tr>
<tr>
  <td>Element 5</td>
  <td>8</td>
</tr>

And want to retrieve only a part of this document : I want to have only 80% of the sum of the number of element (The Pareto distribution in fact).

In this case, I have a total of 240 elements. I want in my output the first elements so that the total of the elements is 192 (240*80/100).

In this example, the ideal output would have only the first three elements, like this :

<tr>
  <td>Element 1</td>
  <td>100</td>
</tr>
<tr>
  <td>Element 2</td>
  <td>80</td>
</tr>
<tr>
  <td>Element 3</td>
  <td>40</td>
</tr>

I hope I’m clear :s. I am looking for long time, without success, I don’t find how to do…

Thank so much

  • 0 0 Answers
  • 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-02T05:08:29+00:00Added an answer on June 2, 2026 at 5:08 am

    Use:

       for $total in sum(/*/*/td[2]),
            $pareto in $total*80 div 100,
            $i in 1 to count(/*/*)
          return
            if(sum(/*/*[position() le $i]/td[2]) ge $pareto
             and
               sum(/*/*[position() lt $i]/td[2]) lt $pareto
               )
               then /*/*[position() le $i]
               else ()
    

    When this XPath expression (yes this is an XQuery expression that is also an XPath 2.0 expression) is evaluated against the provided XML (wrapped into a single tope element to be made a well-formed XML document):

    <table>
        <tr>
            <td>Element 1</td>
            <td>100</td>
        </tr>
        <tr>
            <td>Element 2</td>
            <td>80</td>
        </tr>
        <tr>
            <td>Element 3</td>
            <td>40</td>
        </tr>
        <tr>
            <td>Element 4</td>
            <td>12</td>
        </tr>
        <tr>
            <td>Element 5</td>
            <td>8</td>
        </tr>
    </table>
    

    the wanted, correct result is produced:

    <tr>
        <td>Element 1</td>
        <td>100</td>
      </tr>
    <tr>
        <td>Element 2</td>
        <td>80</td>
      </tr>
    <tr>
        <td>Element 3</td>
        <td>40</td>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Work on C# linq.I have a list to list .From this list I want
Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit
Work on this small test application to learn threading/locking. I have the following code,
I work on code something like this ... HEADERS ... int *var; void child()
At work I have two XP PCs. On one, I can click with the
Work on C# .I want to inherit generic class for this purpose i write
I'm trying to learn xQuery coming from a php background, I have this expression
Work on ASP.NET Visual Studio 2008 C#. I have a page. From this page
At work, I have a large table (some 3 million rows, like 40-50 columns).
I'm having difficulty getting XQuery to work. I downloaded Saxon-HE 9.2. It seems to

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.