Here is a piece of XML document:
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
I’m asked to find out the authors whose lastname begin with a capital “C” using XPath. It’s simple in this question because there is only one qualified and I can just use the function substring-after() after a whitespace and then check whether it begins with “C”. But there is also a possibility that this guy has a very long name, thus middlename can appear, such as Kurt Van Persie Cagle. How can I strip out exactly the substring after the last whitespace?
Please explain and use the functions in XPath.
You can use “mess” XPath, e.g. you have limit of 4 word in
author:Input:
Above XPath will select 2 authors:
Kurt CagleandKurt Van Persie Cagle. You can extend this XPath to match authors having 5 words and so on… 🙂