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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:24:53+00:00 2026-05-28T19:24:53+00:00

Given this XML: <foos> <foo> <name>Apple</name> <rank>1</rank> <key>asdfasdfasdf</key> </foo> <foo> <name>Orange</name> <rank>3</rank> <key>qwerqwtwetqw</key> </foo>

  • 0

Given this XML:

<foos>
    <foo>
        <name>Apple</name>
        <rank>1</rank>
        <key>asdfasdfasdf</key>
    </foo>
    <foo>
        <name>Orange</name>
        <rank>3</rank>
        <key>qwerqwtwetqw</key>
    </foo>
    <foo>
        <name>Apple</name>
        <rank>2</rank>
        <key>zxcvzxvcxzb</key>
    </foo>
    ...
</foos>

I’m trying to find the key of the foo with a particular name, let’s say “Apple”, that has the highest rank. I’m using the following xpath expression (a workaround for the lack of a max function):

/foos/foo[name='Apple' and rank >= /foos/foo[name='Apple']/rank]/key/text()

However I’m sometimes getting multiple results back, even though every name-rank combination is unique. Where am I going wrong here?

This is being used in Java – if that turns out to be relevant I can post the entire code.

  • 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-28T19:24:54+00:00Added an answer on May 28, 2026 at 7:24 pm

    Try this:

    /foos/foo[name='Apple'][not(preceding-sibling::foo[name='Apple']/rank>./rank) and not(following-sibling::foo[name='Apple']/rank>./rank)]/key/text()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given this xml: <root> <list> <!-- foo's comment --> <item name=foo /> <item name=bar
Given this XML data: <root> <item>apple</item> <item>orange</item> <item>banana</item> </root> I can use this XSLT
Given this XML, what XPath returns all elements whose prop attribute contains Foo (the
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Given this example XML file: <doc> <tag> Hello ! </tag> <tag> My name is
Given an xml structure like this <gesmes:Envelope> <gesmes:subject>Reference rates</gesmes:subject> <gesmes:Sender> <gesmes:name>European Central Bank</gesmes:name> </gesmes:Sender>
Given this sample XML data, is it possible to access a Key directly? eg:
Given this xml schema (fragment): <xs:element name=GetIEnumerableResponse> <xs:complexType> <xs:sequence> <xs:element minOccurs=0 name=GetIEnumerableResult nillable=true xmlns:q4=http://schemas.microsoft.com/2003/10/Serialization/Arrays
Given this xml document: <projects><project><name>sample project</name><location>http://somewhere.com/</location></project></projects> And this linq to xml statement for retrieving

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.