你如何选择child-or-self (children + self) [英] How do you select child-or-self (children + self)

查看:27
本文介绍了你如何选择child-or-self (children + self)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XSL 1.0 中,descendant-or-self 将选择所有后代和当前节点.如果您只想选择直接子节点和当前节点(即 child-or-self)怎么办?

In XSL 1.0, descendant-or-self will select ALL descendants and the current node. What if you want to select only the immediate children and the current node (i.e. child-or-self)?

XPATH 可以吗?

推荐答案

在 XPath 1.0 或更高版本中使用:

SomeExpression | SomeExpresion/node()

在 XPath 2.0 或更高版本中使用:

SomeExpression/(self::node()|node())

不正确的答案是:

SomeExpression | SomeExpresion/*

因为这仅选择作为元素的 SomeExpression 的子元素,而 SomeExpression 也可能有其他子元素——如文本节点、注释节点、处理指令节点.

because this selects only those children of SomeExpression that are elements, while SomeExpression may have other children too -- as text-nodes, comment nodes, processing-instruction nodes.

同样不正确的是:

./SomeExpression | ./*/SomeExpression

这不会选择 ./SomeExpression 的直接子代,也不会选择 ./*/SomeExpression 的直接子代.

This doesn't select the immediate children of ./SomeExpression and it doesn't select the immidiate children of ./*/SomeExpression.

这篇关于你如何选择child-or-self (children + self)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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