Skip to content
Advertisement

PHP xPath with multiple not conditions

I want to select all the images but exclude the images under id="adminbar" and the images start with or contain src="data:image

<div id="wpadminbar" class="nojq nojs">
<img src="example.com/img">
<img src="example.com/img">
</div>
<img class="d-none d-lg-block" src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%200%200'%3E%3C/svg%3E">
<img src="example/img.jpg">
<img src="example/img.png">

i tried this but it just excludes the images under id="adminbar"

//img[not(ancestor::div[@id="wpadminbar"])]

how to add not again to exclude all the img contain or startwith src="data:image

Advertisement

Answer

You can just add another predicate to the end of the expression, which will filter the results a second time. In the second predicate, use the starts-with function to check if the @src starts with data:image:

//img[not(ancestor::div[@id='wpadminbar'])][not(starts-with(@src, 'data:image'))]
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement