StellaMaris
StellaMaris

Reputation: 867

xpath only return search string

I want to search for the strings "formEmail", "form_q\d{1,3}" and "title" in a xml document via xpath 2.0 from saxon and want to return only list of those strings if they were found by the engine. Till know I only return a list of nodes. Is it possible to return a list of the relevant strings?

XPathCompiler xpath = proc.newXPathCompiler();
XPathExecutable exePath=xpath.compile(".//property[matches(@value,'formEmail|form_q\\d{1,3}$|title')]");

Upvotes: 1

Views: 52

Answers (1)

har07
har07

Reputation: 89285

Since the target string is in attribute named value, you could've returned value of matching attributes as string instead of returning the attribute's parent element, by using the following XPath :

.//property/@value[matches(.,'formEmail|form_q\\d{1,3}$|title')]/string()

Upvotes: 1

Related Questions