Give back parents per children

Questions about XML that are not covered by the other forums should go here.
mariomueller
Posts: 25

Give back parents per children

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: 25

Re: Give back parents per children

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

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 1 guest