I try to match ancestor-or-self of any element containing certain text string:
In step 1 matching of elements containing text works: //*[contains(text(),"ABC")].
But I struggle with the syntax of adding an ancestor. I tried //*ancestor-or-self::[contains(text(),"ABC")] and //*[contains(text(),"ABC")]/ancestor-or-self without success.
What is the correct syntax for this?
The code and string I want match can look like:
<p><strong>Vertreten durch:</strong><br>Max Mustermann</p>
So I look for the string Vertreten durch to catch the parent element <p>...</p>
I created an example xml, and named it
test.xml:Using xmlstarlet, you can do:
EDIT: With a minimum example from HTML (I made sure it is also valid XML):