Tob*_*bia 6 xslt xpath xslt-1.0
在XPath 1.0中,如何选择当前(上下文)节点A的所有后代节点C,它们不包含在类型B的中间节点中?
例如,查找<a>当前元素中包含的不在a内的所有链接<p>.但是如果当前元素本身在一个内部<p>,则无关紧要.
<p> <—— this is irrelevant, because it's outside the current element
...
<div> <—— current element (context node)
...
<a></a> <—— the xpath should select this node
...
<p>
...
<a></a> <—— but not this, because it's inside a p, which is inside context
...
<p>
...
</div>
...
</p>
Run Code Online (Sandbox Code Playgroud)
将...在本例中可能是介入的节点的几个深度.
我在写XSLT 1.0,因此额外的功能generate-id(),current()以及如可用.
这是一个可能的XPath:
.//a[not(ancestor::p/ancestor::* = current())]
Run Code Online (Sandbox Code Playgroud)
此XPath检查当前后代a元素是否没有祖先p,祖先是当前上下文节点.换句话说,它检查a元素是否具有p介于a当前上下文节点之间的祖先.