开发者

Find parent node position using XSLT

I want to find the parent node position from the child node in XSLT开发者_如何学编程.


I want to find the parent node position from the child node in XSLT.

This is done entirely using XPath.

The answer depends on what is the definition of "parent node position:

count(../preceding-sibling::*) + 1

is the ordinal number of the parent among all upper-level elements

count(../preceding-sibling::node()) + 1

is the ordinal number of the parent among all upper-level nodes (including text-nodes, comments and PIs.

The above expression is the only correct one if the current node is an immediate child of the root / (such as top element, top-level comment or top-level processing instruction).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜