Give back parents per children

Questions about XML that are not covered by the other forums should go here.
mariomueller
Posts: 30
Joined: Wed Feb 14, 2018 3:27 pm

Give back parents per children

Post by mariomueller » Mon Jul 23, 2018 11:29 am

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

mariomueller
Posts: 30
Joined: Wed Feb 14, 2018 3:27 pm

Re: Give back parents per children

Post by mariomueller » Mon Jul 23, 2018 12:36 pm

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

Post Reply