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

  • Home
  • SEARCH
  • 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 8948485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:00:18+00:00 2026-06-15T13:00:18+00:00

Beginner’s question here: Given the following XML excerpt: <root> <element> <child1>a</child1><child2>b</child2><child3>c</child3> </element> </root> When

  • 0

Beginner’s question here:

Given the following XML excerpt:

<root>
  <element>
    <child1>a</child1><child2>b</child2><child3>c</child3>
  </element>
</root>

When I’m at the child3 context, I can use preceding-sibling::* to get the child2 node. All right.

In the following XML excerpt:

<root>
  <element child1="a" child2="b" child3="c">
  </element>
</root>

When I’m at the child3 context, is it right that there is no axis in XPath 1.0 to get the child2 attribute node? I think I’d need something like preceding-sibling-attribute:: that is not available.

As a side question, is this possible with XPath 2?

  • 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-15T13:00:20+00:00Added an answer on June 15, 2026 at 1:00 pm

    It’s true that there is no single axis to get from one attribute to another, but of course you can get there by chaining axes.

    Attributes are not considered siblings, because they are not considered ‘children’ of the parent element, in the data model XPath uses. That’s one reason why preceding-sibling:: won’t work. It also means that attribute names such as child1, child2 etc. are misleading in that attributes are not “children”.

    The other reason preceding-sibling:: won’t work is that the order of attributes of a given element is undefined (implementation-dependent). Attributes must be listed in some order in a given serialization (e.g. in a file), but that file could be parsed and output again with the attributes in a different order, and it would still be considered the same document from an XML info model point of view. Therefore, there is no such thing as the “previous” or “preceding” attribute in XML.

    To get the value of the child2 attribute from the context of the child3 attribute, you can use one of these depending on how you know which attribute you want…

    ../@child2
    

    “The attribute named child2 of the parent element”

    ../@*[name() != name(current())]
    

    “The other attributes of the parent element (not this one)”

    You could even try

    ../@*[2]
    

    but the results would not be predictable in general, since the order of attributes is undefined.

    If the attribute names include an index component (1, 2, 3) as in your example, you could replace the number in name(current()) with a smaller number.

    To answer your side question, it depends on how your requirement is defined. If the requirement is “select the previous attribute”, then no, that concept is not defined in XPath 2 either.

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

Sidebar

Related Questions

Beginner here trying to get a pipeline working in bash. If somebody can see
Beginner question here! look at picture, I want the butten-edittext-button to fill the width
Beginner question here. I'm going to make a Jquery function that is used to
Beginner here: In this answer to my question of how to insert data into
Beginner here, I have a simple question. In Android what would be the best
Beginner question here: I'm trying to understand the some basic memory management. if I'm
Python beginner here. I've looked around and found similar questions but can't quite cobble
Beginner Question. Below is an example given on the Cradle CouchDB documentation: https://github.com/cloudhead/cradle What
A beginner's Cygwin question here - I'd like to install a newer version of
Beginner question. How do I substitute: $_SESSION['personID'] for {personID} in the following: public static

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.