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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:38:14+00:00 2026-06-08T13:38:14+00:00

The more I learn XPath the more I need back refererencing For example, when

  • 0

The more I learn XPath the more I need back refererencing

For example, when I discovered some information in some of intermediate steps, I sometimes need to use the info later. This problem actually has a workaround with a little help of ability of predicate expression also to contain XPathes also. The working solution can look something like this

/foo/item[@attrtocheck = ../../otheritem[@anotherattr]]

But the problem with this approach is that I just evaluate predicate on some criteria and can not have multiple following results based on this. Even if there are many otheritem with the same @anotherattr, I can not collect them. So the better solution would be

/foo/item[@attrtocheck]/../../otheritem[@anotherattr=BACKREFERENCING_ATTRTOCHECK_VALUE] 

but as long as I know it’s not possible.

If there’s no solution in the standard, maybe there’s an extension in some tools/libraties? Actually I implement my own engine and if there’s a non-standard syntax already existing, I would adopt it.

UPDATE: After Michael Kay comment, more about why I miss the feature

Actually I’m imlementing XPath search for AST (Abstract syntax trees). I’m not the first who try to do this (web search for [Xpath AST]). This kind of searches reveals very strong relations between different parts of the tree. For example,when I found some call in some context (for example inside some other method), I would like to know whether this symbol is introduced as a virtual function and if it is then output it to the results. In this case my first search produces some previously unknown symbol (function name) and I would like to use it in the following sub-pathes (searching class declaration and its keywords). So, back referencing would be very helpful.

I think if it’s appliable to AST then there is a possibility to have such relations in other structured data.

  • 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-08T13:38:16+00:00Added an answer on June 8, 2026 at 1:38 pm

    In XQuery you can use let .. return to declare temporary variables. Like this:

     /foo/item[@attrtocheck]/(let $backreference := @attrtocheck return ../../otheritem[@anotherattr=$backreference]) 
    

    And in XPath 2 you can emulate the let expression with a for loop:

     /foo/item[@attrtocheck]/(for $backreference in @attrtocheck return ../../otheritem[@anotherattr=$backreference]) 
    

    Or you can use the for loop as intended and do it without “backreference”:

     for $value in /foo/item[@attrtocheck]/@attrtocheck  return otheritem[@anotherattr=$value]
    

    And in this case since comparisons are existential and you can just use:

    otheritem[@anotherattr = /foo/item/@attrtocheck]
    

    (and btw, I also wrote my own XPath implementation and I have the syntax ((values := /xx/a/@id)[0], /xx/b[@id = $values]) for variable declaration, with := defining the variable, and the ()[0] preventing $values from being in the returned sequence. )

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

Sidebar

Related Questions

I need to learn more about creating setup projects from within Visual Studio to
I am trying to learn more about the DOM and have been writing some
Im looking to learn more about your testing flows with Django. Background information http://docs.djangoproject.com/en/dev/topics/testing/
I'm always trying to learn more about the languages I use (different styles, frameworks,
The more I learn about .NET web developement, the more I come back to
I need to learn more about streaming techniques. I am using biztalk and want
The more i learn about OpenGL, the more problems i find! All i need
I would like to learn more about C++0x. What are some good references and
I was trying to learn more about bits, and I came across this example
I'm trying to learn more information on how apache Qpid works and I do

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.