XPath flatten text excluding certain nodes
<p>Using scrapy's XPath selector I'm trying to flatten the textual content of a div-element which either contains plain text or formatted HTML content. Here are two examples:</p>

<pre><code>&lt;div&gt;
    &lt;div itemprop="content"&gt;
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
        &lt;br&gt;
        Donec fringilla est eu euismod varius.
    &lt;/div&gt;

    &lt;div itemprop="content"&gt;
        &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p&gt;
        &lt;p&gt;Donec fringilla est eu euismod varius.&lt;/p&gt;
        &lt;p class="quote"&gt;
            &lt;span&gt;Quote&lt;/span&gt;
            &lt;a href="#"&gt;Exclude me&lt;/a&gt;
            &lt;ul&gt;
                &lt;li&gt;Exclude me&lt;/li&gt;
                &lt;li&gt;Exclude me&lt;/li&gt;
            &lt;/ul&gt;
        &lt;/p&gt;
        &lt;blockquote&gt;Cras facilisis suscipit euismod.&lt;/blockquote&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Now the goal is to omit the <code>&lt;p class="quote"&gt;Quote&lt;/p&gt;</code> in the flattened text as it only serves as visual cue for the <code>blockquote</code> following it. Due to the nature of the first example, i.e. text as immediate children of the selected <code>div</code>, the solution I've come up with looks as follows:</p>

<pre><code>//div[@itemprop="content"]/descendant-or-self::*[not(self::script)]/text()[normalize-space()]
</code></pre>

<p>This accomplishes three things:</p>

<ol>
<li>Exclude <code>&lt;script&gt;</code> nodes as I don't want to include their text in my result.</li>
<li>Exclude any nodes which don't contain any text.</li>
<li>Include immediate textual children of my top-level <code>div</code> (via <code>descendant-or-self</code>).</li>
</ol>

<p>Unfortunately it seems to me the latter is causing the <code>&lt;p class="quote"&gt;Quote&lt;/p&gt;</code> to be included despite of additional excluding filters, such as:</p>

<pre><code>//div[@itemprop="content"]/descendant-or-self::*[not(self::script) and not(@class="quote")]/text()[normalize-space()]

//div[@itemprop="content"]/descendant-or-self::*[not(self::script)]/text()[normalize-space() and not(ancestor::*[@class="quote"])]
</code></pre>

<p>Iterating over the <code>&lt;div itemprop="content"&gt;</code> nodes the expected output is a list as such:</p>

<pre><code>['Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fringilla est eu euismod varius.',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fringilla est eu euismod varius. Cras facilisis suscipit euismod.']
</code></pre>

<p>Is there a way to solve this issue with a single XPath selector?</p>