开发者

How do you select child-or-self (children + self)

开发者 https://www.devze.com 2023-01-28 15:36 出处:网络
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. c开发者_StackOverflowhild-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. c开发者_StackOverflowhild-or-self)?

Is that possible with XPATH?


In XPath 1.0 or later use:

SomeExpression | SomeExpresion/node()

In XPath 2.0 or later use:

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

An incorrect answer would be:

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.

Also incorrect is:

./SomeExpression | ./*/SomeExpression

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

0

精彩评论

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