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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:43:06+00:00 2026-06-17T04:43:06+00:00

Using XQuery in DBXML I want to prioritize some elements depending on multiple nodes

  • 0

Using XQuery in DBXML I want to prioritize some elements depending on multiple nodes set to certain values.

I want to be able to show three of this elements at the top and the rest below.

<properties>
   <property>
       <zip_code>5550</zip_code>
       <agency>ABC</agency>
   </property>
   <property>
       <zip_code>5550</zip_code>
       <agency>DEF</agency>
   </property>
   <property>
       <zip_code>5550</zip_code>
       <agency>DEF</agency>
   </property>
   <property>
       <zip_code>XYZ</zip_code>
       <agency>ABC</agency>
   </property>
</properties>

We are getting this XML in a property search page. Real search results will be having hundreds of records but we are only taking the first 10 records to display on the first page. Here we need to apply a sorting order which will show properties of “ABC” agency followed by zip code “XYZ” always on top. If the total result set does not have these agencies we can show them in the normal sorting order.

  • 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-17T04:43:07+00:00Added an answer on June 17, 2026 at 4:43 am

    XQuery’s flwor-expressions know order by, which can order by arbitrary values which can also be computed. Use an expression which decides if some product is a “top product” or not (resulting in a boolean value).

    Afterwards split up result sequence to highlight only a number of results and limit to a total results.

    let $highlighted := 3
    let $total := 10
    let $sorted := 
      for $p in //property
      (: order by highlighting predicate :)
      order by $p/agency eq "ABC" and $p/zip_code eq "XYZ" descending
      return $p
    return (
      (: first $highlighted elements as defined by predicates above :)
      $sorted[ position() = (1 to $highlighted) ],
      (: the other elements, `/.` forces sorting back to document order :)
      $sorted[ position() = ($highlighted + 1 to $total) ]/.
    )
    

    The boolean expression can get arbitrary complex for being more precise on top products, like limiting to TVs or defining some minimum price.

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

Sidebar

Related Questions

I´m starting using xquery and I want to know how to get the values
I want to parse a xml file using xquery in Ruby, I found this
When getting values out of xml attributes, using the xquery value operator, missing attributes
I have to generate a series of random numbers using XQuery.I found a set
I try to return a set of result from an xml document using xquery
I've just started using Xquery with Xqilla. I want my result to be returned
I'm working on some Xquery code (using SAXON) to execute a simple XQuery file
I want to get attribute value from XML using Xquery. MY XML is <Answers>
Using MSSQL 2008 and XQUERY Consider the following XML stored in a table: <ROOT>
I am using xqj api for implemeting XQuery in java, the following is a

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.