XPath - select parent nodes based on multiple child selection
xpath
Solution
You can chain the conditions one after another:
//bookshelf[cathegory/@name][.//translator/text()]
It selects a bookshelf for which there is a cathegory child with a name attribute, and which hash a non-empty translator descendant.
Problem
Let we have XML looks like that ``` <bookshelf> <cathegory name = "Programming" /> <book name = "Tille 1" > <author>....</author> </book> <book name = "Tille 2" > <author>....</author> <translator></translator> </book> <book name = "Tille 3" > <author>....</author> <translator>John D.</translator> <!-- non-empty nodes are acceptred! --> </book> </bookshelf> ``` How can we select bookshelves which have cathegory node with name attribute and at least one book with non-empty translator node? Basic XPath tutorials do not provide so complicated examples.