user6338533
user6338533

Reputation:

How XPath axes preceding:: and following:: work?

I have always believed that the preceding axis contains all nodes that are before the context node in document order, excluding any ancestors of the context node, and also excluding attribute nodes and namespace nodes.

Recently I came across two published books on XML. On chapters about XPath and preceding and following axes, those authors didn't mention the nodes that I believed should be excluded from the definition of those two axes. They simply defined them as ALL nodes before and after contexts nodes, respectively.

I get confused, naturally. I don't (dare) normally doubt published books, especially things that I found on two separate books.

I undrrstand XML is an evolving technology. Has there been a change in the official or recommended definition that I missed?

Thanks for any help clarifying it.

Upvotes: 0

Views: 837

Answers (1)

Michael Kay
Michael Kay

Reputation: 163322

This isn't a matter of what you believe, it's a matter of what the specs say. The latest (3.1) version of XPath defines these axes at

https://www.w3.org/TR/xpath-31/#axes

as follows:

the following axis contains all nodes that are descendants of the root of the tree in which the context node is found, are not descendants of the context node, and occur after the context node in document order

the preceding axis contains all nodes that are descendants of the root of the tree in which the context node is found, are not ancestors of the context node, and occur before the context node in document order

The definition has not changed over time.

Sadly, it's not unusual for books to simplify. On the other hand, you may have missed something in the books you were reading, you haven't cited them specifically, so I can't tell.

Upvotes: 2

Related Questions