Instead of traversing back to the parent, just find the right parent to begin with:
//x
will select all x
elements.
//x[//z]
will select all x
elements which have z
elements as descendants.
//x[//z]/@name
will get the name
attribute of each of those elements.