有没有人可以建议一种XPath表达式格式,它返回一个字符串值,其中包含元素的某些合格子节点的串连值,但忽略其他节点:
<div>
This text node should be returned.
<em>And the value of this element.</em>
And this.
<p>But this paragraph element should be ignored.</p>
</div>
返回值应为单字符串:
This text node should be returned. And the value of this element. And this.
这在单个XPath表达式中是可能的吗?
谢谢。
发布于 2009-09-10 08:13:32
这样的外观是有效的:
使用as context /div/
text() | em/text()
或者不使用上下文:
/div/text() | /div/em/text()
如果您想要连接前两个字符串,请使用以下命令:
concat(/div/text(), /div/em/text())
发布于 2009-09-10 08:14:48
/div//text()
双斜杠强制提取文本,而不考虑中间节点
发布于 2013-06-18 08:57:48
如果您想要除p之外的所有子项,您可以尝试执行以下操作...
string-join(//*[name() != 'p']/text(), "")
它返回..。
This text node should be returned.
And the value of this element.
And this.
https://stackoverflow.com/questions/1403971
复制相似问题