combine (concat) two XPATH (path(.) and the text())
Added by Mario Mueller over 6 years ago
Hi all,
I got two XPATH wich I which to concat You can use the XML on https://www.w3schools.com/xml/books.xml
First XPATH gives back the Path of the nodes
/bookstore/book/author/path(.)
Result:
/Q{}bookstore[1]/Q{}book[1]/Q{}author[1]
/Q{}bookstore[1]/Q{}book[2]/Q{}author[1]
/Q{}bookstore[1]/Q{}book[3]/Q{}author[1]
/Q{}bookstore[1]/Q{}book[3]/Q{}author[2]
/Q{}bookstore[1]/Q{}book[3]/Q{}author[3]
/Q{}bookstore[1]/Q{}book[3]/Q{}author[4]
/Q{}bookstore[1]/Q{}book[3]/Q{}author[5]
/Q{}bookstore[1]/Q{}book[4]/Q{}author[1]
Second XPATH gives back values
combine (concat) two XPATH (path(.) and the text())
Report this post
Quote
Tue Jun 05, 2018 7:56 am
Hi all,
I got two XPATH wich I which to concat
You can use the XML on https://www.w3schools.com/xml/books.xml
First XPATH gives back the Path of the nodes
Code: Select all
/bookstore/book/author/path(.)
Second XPATH gives back values
Code: Select all
/bookstore/book/author/text()
Result:
Giada De Laurentiis
J K. Rowling
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyanathan Nagarajan
Erik T. Ray
Is it possible to concat the results of both XPATH?
Many Thanks Regards Mario
bookstore.xml (908 Bytes) bookstore.xml |
Replies (3)
Please register to reply
RE: combine (concat) two XPATH (path(.) and the text()) - Added by Mario Mueller over 6 years ago
Sorry, there was something wrong while formatting my tread.
The second XPATH looks :
/bookstore/book/author/text()
And the result is
Giada De Laurentiis
J K. Rowling
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyanathan Nagarajan
Erik T. Ray
Regards Mario
RE: combine (concat) two XPATH (path(.) and the text()) - Added by Michael Kay over 6 years ago
I don't think this question is Saxon-specific, so it might be more appropriate on StackOverflow.
It's not entirely clear to me what you want as your final result. If it's a single sequence containing alternating paths and values, you could use
/bookstore/books/author!(path(.), string(.))
Note that it's generally better to use string() rather than text() to get the content of an element.
RE: combine (concat) two XPATH (path(.) and the text()) - Added by Mario Mueller over 6 years ago
Hi Michael,
I tested your suggestion. Unftunatelly it does not work.
But this one works:
/bookstore/book/author/(path() || text())
Thanks Regards Mario
Please register to reply