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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:34:29+00:00 2026-06-10T07:34:29+00:00

How do I formulate an XPath expression for obtaining the attribute value for the

  • 0

How do I formulate an XPath expression for obtaining the attribute value for the first input node following the a node (value A) for the following HTML:

<a href="http://www.link.com">link</a>
<input value="value A" />
<input value="value B" />

I tried:

//input[(preceding-sibling::a[1])]/@value

But this gets the value attribute for both input nodes when I only want the attribute for the node for which the a node is the nearest preceding sibling.

  • 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-10T07:34:31+00:00Added an answer on June 10, 2026 at 7:34 am

    You’re using the [1] predicate on the wrong node. You want the first input that has a preciding-sibling::a, not all inputs that follow the first a element at a given level.

    This should yield the right result:
    //a/following-sibling::input[1]/@value

    It means: for every element a found at any level in the document, select the first input element that follows it, while being its sibling. Then read its value attribute.

    For this input:

    <xml>
      <p>
        <input value="value A" />
        <a href="http://www.link.com">link</a>
        <input value="value B" />
        <input value="value C" />
      </p>
      <p> 
        <a href="http://www.link.com">link</a>
        <input value="value D" />
        <input value="value E" />
        <a href="http://www.link.com">link</a>
        <input value="value F" />
      </p>
    </xml>
    

    It returns:

    • value B
    • value D
    • value F

    EDIT

    This works provided that there are no elements between a and the first input that follows it.

    For instance, with input like this:

        <a href="http://www.link.com">link</a>
        <strong>OMG NOEZ!</strong>
        <input value="value A" />
    

    value A still gets selected

    If it’s OK, keep the above expression. If it’s not, modify it like this to filter other elements:

    //a/following-sibling::*[1][self::input]/@value

    This selects the first following sibling of a, no matter what the tag is and only after it’s selected does it check the actual tag. This way the input that’s further at the same level is not chosen.

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

Sidebar

Related Questions

Ok guys, I am using the following library: http://www.codeproject.com/KB/recipes/AdvancedMatrixLibrary.aspx And I wish to calculate
I'm trying to formulate a regular expression which will recognise the search term truncated
I am trying to formulate a regex expression in JavaScript to get the cents
How can I formulate the following idea? I have p (parameter). I want to
I'm struggling few days with quite complex xpath and I'm not able to formulate
How do I formulate the following in LINQ with LAMBDA expressions. Given (for simplicity
I am trying to formulate a regex expression (running in Python) that gets passed
I was wondering if you could help me formulate a regular expression to match
First of all I'm sorry about the title, I didn't know how to formulate
Hi I have some input like so: $string = 0°25'30S, 91°7'W I want formulate

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.