OutForCode
OutForCode

Reputation: 461

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

Upvotes: 2

Views: 1457

Answers (2)

kjhughes
kjhughes

Reputation: 111686

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.

For example, for this XML,

<a>Label: WORD</a>

this XPath,

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

will return

WORD

as requested.

Upvotes: 3

xyhhx
xyhhx

Reputation: 6674

You can't.

XPath is for traversing the XML-based documents. XML would consider the text content as one entity and XPath won't distinguish among the words it contains.

Upvotes: 0

Related Questions