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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:37:22+00:00 2026-05-15T17:37:22+00:00

I’m looking for a way to concatenate two arbitrary, valid XPath expressions to build

  • 0

I’m looking for a way to concatenate two arbitrary, valid XPath expressions to build a new XPath expression.

Effectively I’d like to apply the second XPath expression on the result of the first XPath expression.

For example, take this XML:

<foo>
  <bar>
    <baz />
  </bar>
<foo>

The XPath expression /foo would obviously return the root element, while /bar would return nothing. But /bar applied to the result of /foo should return the <bar>element.

Now the naive implementation would be to just use String concatenation to build /foo/bar and evaluate that to get <bar>. This works in this specific case.

Now my question is: is it always that simple? Are there any types of XPath expressions where this won’t result in a valid expression or would lead to unexpected results?

It isn’t much of a problem if some obscure XPath expressions can’t be validated that way, but I’d like the common ones to work.

If there are problems: Is there any kind of concatenation that works in more situations?

  • 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-15T17:37:23+00:00Added an answer on May 15, 2026 at 5:37 pm

    In XPath 1.0 the / operator requires that its operand to the left is of type that selects a nodeset and its operand to the right is a relative XPath expression — also is of type selecting a nodeset.

    Therefore, any expr1 that evaluates to a simple value (number, string, boolean) cannot be used to the left of /. This is exactly true for the right-hand-side argument of /.

    Examples of invalid XPath 1.0 expressions:

    string(/foo)/bar
    
    count(//foo)/bar
    
    (/foo/baz = 3)/bar
    
    /foo/count(bar)
    

    In XPath 2.0 it is still required that in expr1/expr2 expr1 must evaluate to a node-set. However, expr2 can be a function call. Thus the following are valid and have meaningful results:

    /foo/bar/string-length(.) (: a sequence of integers that are the string lengths of every /foo/bar node 🙂

    /foo/bar/name(.) (: a sequence of strings that are the names of every /foo/bar node 🙂

    foo/bar/count(node()) (: a sequence of integers that are the number of children nodes of every /foo/bar node 🙂

    There are other connectors that may be used to combine two expressions to produce a third one:

    In both XPath 1.0 and XPath 2.0:

    The union operator:

    expr1 | expr2
    

    The comparison operators:

    expr1 = expr2
    expr1 >= expr2
    expr1 < expr2
    expr1 <= expr2
    expr1 != expr2
    

    The boolean operators and the not() function:

    not(expr1)
    
    expr1 and expr2
    
    expr1 or expr2
    

    In XPath 2.0:

    the operators except, intersect union

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

Sidebar

Related Questions

I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.