title: Effective way to get all nodes (text and attribute) containing a specific text
body: <p>My goal was to retrieve all nodes that contain a specific text. </p>
  
  <p>1- I can retrieve nodes that contain some text with the folowing request:</p>
  
  <pre><code>[node for node in root.xpath('//*[contains(.,"Carte de chaleur")]') ]
  
  
  Out[62]: 
  [&lt;Element workbook at 0x1818bc76e88&gt;,
   &lt;Element worksheets at 0x1819b886dc8&gt;,
   &lt;Element worksheet at 0x1819c156488&gt;,
   &lt;Element layout-options at 0x1819c1564c8&gt;,
   &lt;Element title at 0x1818e9509c8&gt;,
   &lt;Element formatted-text at 0x1819c156c48&gt;,
   &lt;Element run at 0x1818e955048&gt;,
   &lt;Element worksheet at 0x1819c156a88&gt;,
   &lt;Element layout-options at 0x1819c156fc8&gt;,
   &lt;Element title at 0x1818e9508c8&gt;,
   &lt;Element formatted-text at 0x1819c1565c8&gt;,
   &lt;Element run at 0x1818e955088&gt;]
  </code></pre>
  
  <p>but when i checked, i only get 2 elements that contain the specific text.:</p>
  
  <pre><code>[node for node in root.xpath('//*[contains(.,"Carte de chaleur")]') if node.text.__contains__("Carte de chaleur")]
  Out[66]: [&lt;Element run at 0x1818e955048&gt;, &lt;Element run at 0x1818e955088&gt;]
  </code></pre>
  
  <p>In fact when i look for the path of one of theses run nodes i can find that all the 'workbook',worksheets' etc...  are in fact their parent nodes.</p>
  
  <pre><code>run_node
  Out[71]: &lt;Element run at 0x1818e955048&gt;
  tree.getpath(run_node)
  Out[72]: '/workbook/worksheets/worksheet[3]/layout-options/title/formatted-text/run[1]'
  </code></pre>
  
  <p>So why this xpath query return me all the parent nodes of the nodes i am looking for (just the 2 run nodes in fact) ?</p>
  
  <p>2- If i want nodes whose attribute contain a specific text i run this query:</p>
  
  <pre><code>root.xpath('//@*[contains(.,"bold")]/..')
  Out[86]: 
  [&lt;Element format at 0x18199f56948&gt;,
   &lt;Element format at 0x18199f56148&gt;]
  </code></pre>
  
  <p>(It 's logic since i want the node that contain a specific attribute nodes, so i am looking for the parent of this attribute node)</p>
  
  <p>Very strangely, this request do not produce the same result:</p>
  
  <pre><code>root.xpath('//*[contains(@*,"bold")]') 
  </code></pre>
  
  <p>Even if for me this last one mean: "take any descendant element of the root whose any attribute contain the text "bold" (the same that the preceding one for me)</p>
  
  <p>3- Can i retrieve the nodes whose attribute contain different value, using variable ?</p>
  
  <p>For one variable i could do:</p>
  
  <pre><code>root('//*[@name=$var]', var="[Petal_length]") 
  </code></pre>
  
  <p>But is there a way to do something like:</p>
  
  <pre><code>root('//*[@name=$var1]//title[@format=$var2]', var1="[Petal_length]",var2="bold") 
  </code></pre>
  
  <p>EDIT: Here is the original text <a href="https://ctxt.io/2/AACATwNVFA" rel="nofollow noreferrer">https://ctxt.io/2/AACATwNVFA</a> .
  Ps: if someone knows a way to share some text for more than 1 day it would help me.</p>