Should XPath have virtual axes?

In his recent blog-article: “XPath needs virtual axes. Making XPath more XPathy?Rick Jelliffe sais:

I really like XPath2. I would never recommend anyone start with XPath1, unless you were doing very basic transformations with no text processing or data formatting.

But the niggle I have with XPath2 is that it is less XPath-y than XPath1. It does not significantly improve the central syntactical feature of XPaths: the location steps. (The only improvement that springs to mind is that XPath2 did improve the use of parentheses in location steps.) Instead, XPath2 provided much more conventional features like a for iterator. I think these significantly decrease the comprehensibility of an XPath, are anonymous and therefore require may comments to explain them, and fracture the line. To an extent, once you start to use nested syntaxes and iterators, why both using XPath at all?”

Rick gives this example:

find-rep( find-client(//manager/clients/client-ref)/rep-ref)/name

and proposes to improve the expression above by introducing “virtual axes” so that it could be written as:


So, curious reader, pause for a while, don’t read below, and think: has Rick uncovered a hole in XPath? 

Here is my answer:

What you are asking for can be expressed almost exactly in the same form (actually I prefer the current XPath 2.0 form of expression).

You are asking for:


One can write this in XPath 2.0 as:


The current XPath way of expressing this is cleaner — no need for virtual axes.

This is a feature of XPath 2.0 that is not widely used and known: any function can be used as the current location step. The syntax rules that resolve its use are (at

[27] StepExpr ==> [38] FilterExpr ==> [41] PrimaryExpr

and the fact that a FunctionCall is a PrimaryExpr:

[41]   PrimaryExpr   ::=   Literal | VarRef | ParenthesizedExpr | ContextItemExpr | FunctionCall


Also, consider that the axes in XPath have been useful so far mainly because there are just a few of them. Imagine having to deal with zillions of axes and struggling to remember what they mean. And if everyone can introduce their own axes, then why bother with them at all?

Dear reader, it’s up to you to decide… as I have already done.

This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Should XPath have virtual axes?

  1. Dave Pawson says:

    Neat. I admit it. I’ve never used a function in an xpath.
    Now there’s a good use of your blog (and your knowledge Dimitre), hunt out and explain the dark corners of XSLT 2.0?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s