我想从XSLT中的子节点找到父节点位置。
最佳答案
I want to find the parent node position from the child node in XSLT.
这完全是使用 XPath 完成的。
答案取决于“父节点位置”的定义:
count(../preceding-sibling::*) + 1
是父元素在所有上层元素中的序号
count(../preceding-sibling::node()) + 1
是父节点在所有上层节点(包括文本节点、注释和PI)中的序号。
如果当前节点是根/
的直接子节点(例如顶级元素、顶级注释或顶级处理指令),则以上表达式是唯一正确的表达式。
关于xslt - 使用 XSLT 查找父节点位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4312255/