开发者

Find parent node position using XSLT

开发者 https://www.devze.com 2023-01-27 08:20 出处:网络
I want to find the parent node position from the child node in XSLT开发者_如何学编程. I want to find the parent node

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

精彩评论

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