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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:18:06+00:00 2026-05-18T07:18:06+00:00

I have a question on xquery grouping. From what I understand, the usual case

  • 0

I have a question on xquery grouping. From what I understand, the usual case would be to use distinct-values on the docs in the for loop, however as I have a condition to fulfill before grouping the values, and I am not quite sure how this can be done.

This is part of my xmldb:

<element tag="0001,0000" name="Pos1>198</element>
<element tag="0001,0001" name="Pos2">123</name>
<element tag="0002,0001" name="Pos3">433</element>
<element tag="000b,0000" name="Pos3">16</element>
<element tag="0005,0000" name="Pos4>532</element>
<element tag="0005,0001" name="Pos5">342</name>
<element tag="0008,0001" name="Pos6">17</element>

The condition to fulfill is that the x-coordinates (number or hexdec) have to be in odd values (e.g. from the above xml, i would only need results from tag=”0001,…”, tag=”000b,…”, tag=”0005,…”), and then count how many items in each group.

This is how the results should look like:

<group>
<element xcoord="0001">2</element>
<element xcoord="000b">1</element>
<element xcoord="0005">2</element>
</group>

My xquery code so far looks like this, where I could generate results that have odd x-coordinates, but I have no idea how to proceed on from here for the grouping.

import module namespace functx="http://www.functx.com" at "http://www.xqueryfunctions.com/xq/functx-1.0-nodoc-2007-01.xq"; 

for $x in collection('/db/mapdb/')//element
let $coord := number(functx:substring-before-last($x/@tag, ","))
where $coord mod 2 != 0
return $x

Kindly advise me. Thank you very much.

  • 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-05-18T07:18:07+00:00Added an answer on May 18, 2026 at 7:18 am

    This XQuery:

    for $x in 
      distinct-values(/*/*/substring-before(@tag,',')
                        [contains('13579bdf', 
                                   substring(., string-length(.))
                                  )
                         ]
                      )
     return
       <element xcoord="{$x}">
        {count(/*/*[$x eq substring-before(@tag,',')])}
       </element>
    

    produces the wanted, correct result:

    <element xcoord="0001">2</element>
    <element xcoord="000b">1</element>
    <element xcoord="0005">2</element>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have question from programming pearls problem is following show how to use Lomuto's
I have question regarding the use of function parameters. In the past I have
I have question concerning a function I created. I would like to show the
i have question about why should we use return in get,if dont use what
I have question how to stop the timer. I don't really understand how it
I have question about sending emails from MVC3 application. I already read for exmple
I have a question about formatting the output of the sum() function in XQuery/XSLT/XPath.
I have question about python and sqlite3. I want to drop a table from
I have question please refer the following code to understand the question. (I removed
I have question about removing element from QList. myclass.h: class node2D : public QObject

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.