Exactly when does the reverse direction of an axis apply?

偶尔善良 提交于 2019-12-04 17:07:57

The best answer I found was in an old email by Evan Lenz.

It's worth reading in full, as an explanation of how XPath works in this regard, and how the XPath 1.0 spec shows us the answer. But the executive summary is in this rule:

Step    ::=    AxisSpecifier NodeTest Predicate*
                  | AbbreviatedStep

The Step production defines the syntax of a location step, and it's only within a location step that the reverse direction of an axis applies. Any syntax that comes between the axis and a positional predicate, other than the nodetest and predicates, will break the chain and the direction will revert to forward.

This explains why, if you put parentheses around a preceding::foo and append a positional predicate outside the parentheses, the positional predicate ignores the direction of the preceding:: axis.

It also explains why my first attempt in my code today worked, despite my expectations: you can put as many predicates after a NodeTest as you want, and the direction of the axis will still apply to all of them.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!