Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>I need to query a series of ul's in the document for a node containing a specific value, then find that node's parent's direct previous sibling...</p> </blockquote> <p>That would be (here <code>$v</code> is the value you look for):</p> <pre><code>$p = "/html/body//ul[li[contains(text(), '$v')]]/preceding-sibling::li[1]"; </code></pre> <ul> <li>Make sure that you check that <code>$v</code> does not contain single quotes, since this would break the XPath expression.</li> <li>When you want to look for whole words only, use:<br> <code>[contains(concat(' ', text(), ' '), concat(' ', '$v', ' '))]</code>.</li> <li>When you want to look case-insentitively, use (I abbreviated the full alphabet with <code>…</code>):<br> <code>[contains(translate(text(), 'ABC…XYZ', 'abc…xyz'), '{strtolower($v)}')]</code>.</li> <li>Note that predicates can be nested.</li> <li>Note that the use of <code>text()</code> ensures only direct child text nodes are taken into account. When you use <code>.</code> instead, the whole "subtree" of the <code>&lt;li&gt;</code> is converted to string and you might get more results than you actually want.</li> <li>Note that I restricted the <code>//</code> operator (a shortcut for the <code>descendant</code> axis) to a certain part of the tree - if you can restrict it further, by all means do so.<br> Letting your XPath start with <code>//</code> makes it much slower than it needs to be since <em>all</em> nodes of the entire document are checked, even those that can not under any circumstances produce a match.</li> <li>As others have already noted, the HTML is invalid.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload