I want to use XPath to find every <blockquote>
element that has at least one child <pre>
element, no other kinds of child elements, and optionally text nodes as children:
<body><div><!-- arbitrary nesting -->
<blockquote><pre>YES</pre></blockquote>
<blockquote><p>NO</p></blockquote>
<blockquote><pre>NO</pre><p>NO</p></blockquote>
<blockquote><p>NO</p><pre>NO</pre></blockquote>
<blockquote><pre>YES</pre> <pre>YES</pre></blockquote>
<blockquote>NO</blockquote>
</div></body>
This XPath appears to work, but I suspect that it's overly complicated:
//blockquote[pre][not(*[not(name()="pre")])]
Is there a better (less code, more efficient, more DRY) way to select what I want?
//blockquote[pre][count(pre)=count(*)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With