简体   繁体   English

如何使用xpath javascript选择特定单词

[英]how to select a specific word using xpath javascript

I can select a element that containing a specific word, 我可以选择一个包含特定单词的元素,

//p[@class="class"][contains(text(),"disease")]

But I wanna select the word alone using xpath., 但我想使用xpath单独选择单词。

You can. 您可以。

If you stretch what you mean by selection to include values returned by XPath functions against actually selected nodes, you can use string functions to extract a word from the string value of a node. 如果扩展选择的含义以包含XPath函数针对实际选择的节点返回的值,则可以使用字符串函数从节点的字符串值中提取单词。

For example, for this XML, 例如,对于此XML,

<a>Label: WORD</a>

this XPath, 这个XPath

substring-after(/a,"Label: ")

will return 将返回

WORD

as requested. 按照要求。

You can't. 你不能

XPath is for traversing the XML-based documents. XPath用于遍历基于XML的文档。 XML would consider the text content as one entity and XPath won't distinguish among the words it contains. XML会将文本内容视为一个实体,XPath不会在其中包含的单词之间进行区分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM