Page 1 of 1

Give back parents per children

Posted: Mon Jul 23, 2018 11:29 am
by mariomueller
Hi ,

I have a XML like

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
</book>

<book category="web">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>Vaidyanathan Nagarajan</author>
</book>

<book category="it" cover="paperback">
<title lang="en">Learning XML</title>
<year>2003</year>
<price>39.95</price>
</book>

</bookstore>

When I evaluate the XPATH

Code: Select all

/bookstore/book/author/parent::book
I get the result:

Code: Select all

XPath Location: /bookstore[1]/book[1]
XPath Location: /bookstore[1]/book[2]
But as the second <book> has three <author>-nodes I am searching for a XPATH expression that gives me back the following:

Code: Select all

XPath Location: /bookstore[1]/book[1]
XPath Location: /bookstore[1]/book[2]
XPath Location: /bookstore[1]/book[2]
XPath Location: /bookstore[1]/book[2]
Is this possible?

Thanks
Regards
Mario

Re: Give back parents per children

Posted: Mon Jul 23, 2018 12:36 pm
by mariomueller
Hi ,
I got a solution

Code: Select all

//author!parent::book/path()
returns:

Code: Select all

/Q{}bookstore[1]/Q{}book[1]
/Q{}bookstore[1]/Q{}book[2]
/Q{}bookstore[1]/Q{}book[2]
/Q{}bookstore[1]/Q{}book[2]
/Q{}bookstore[1]/Q{}book[2]
Thanks
Regards
Mario