使用 XSLT 查找父节点位置 [英] Find parent node position using XSLT

查看:29
本文介绍了使用 XSLT 查找父节点位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 XSLT 中从子节点中找到父节点位置.

解决方案

我想找到父节点从子节点的位置XSLT.

这完全是使用 XPath 完成的.

答案取决于父节点位置"的定义是什么:

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

是所有上层元素中父元素的序号

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

是所有上层节点(包括文本节点、评论和PI)中父节点的序数.

如果当前节点是根/的直接子节点(例如顶级元素、顶级注释或顶级处理指令),则上述表达式是唯一正确的.

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).

这篇关于使用 XSLT 查找父节点位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆