XQuery statement to get all nodes containing a substring

Viewed 23

I've got the following XML file. I need to extract all item containing a specific substring in the title. For this, I need to write an XQuery statement.

<channel>
<item>
<title>Trans Researchers Want Google Scholar to Stop Deadnaming Them</title>
<link>https://www.wired.com/story/trans-researchers-want-google-scholar-to-stop-deadnaming-them/</link>
<description>The academic search engine’s policy on name changes is out of step with other search tools and publishers.</description>
<category>Business</category>
<thumbnail>https://media.wired.com/photos/630fe159567860ab6c66c667/master/pass/business-deadnames-google.jpg</thumbnail>
</item>
<item>
<title>Babylon Disrupted the UK’s Health System. Then It Left</title>
<link>https://www.wired.com/story/babylon-disrupted-uk-health-system-then-left/</link>
<description>The AI-powered online doctor app is ditching its controversial NHS contracts as it focuses on the US market.</description>
<category>Business</category>
<thumbnail>https://media.wired.com/photos/63042ca2f06d7dee6f53bbc6/master/pass/Babylon-Leaves-NHS-Business-1253255825.jpg</thumbnail>
</item>
</channel>

In my JavaScript program, I need to get all the items containing a specific substring in the title. For example, suppose the substring is "rupted", then I must get all items having that substring in the title. In the case above, the items would be:

<item>
<title>Babylon Disrupted the UK’s Health System. Then It Left</title>
<link>https://www.wired.com/story/babylon-disrupted-uk-health-system-then-left/</link>
<description>The AI-powered online doctor app is ditching its controversial NHS contracts as it focuses on the US market.</description>
<category>Business</category>
<thumbnail>https://media.wired.com/photos/63042ca2f06d7dee6f53bbc6/master/pass/Babylon-Leaves-NHS-Business-1253255825.jpg</thumbnail>
</item>

For this purpose, I need to write an XQuery statement.

1 Answers

Find all item elements that have a title that contains() the word "rupted":

//item[contains(title, "rupted")]
Related