Body: <h2>Abstract</h2>
  
  <p>In some search operations in calibre one can use an xpath expression to get the values for particular tags, i.e. the following expression:</p>
  
  <pre><code>//h:div[re:test(@class, "figbox", "i")]
  </code></pre>
  
  <p>selects the content of a "div" tag whose "class" attribute is set to "figbox", so in the following html line:</p>
  
  <pre><code>&lt;div class="figbox"&gt;Volterra&lt;/div&gt;
  </code></pre>
  
  <p>the preceding xpath expression returns the value "Volterra". This is useful to compile the ToC of a book and for other tasks.</p>
  
  <h2>Question</h2>
  
  <p>Now, with the following processing-instructions</p>
  
  <pre><code>&lt;?bag value="2" content="Volterra"?&gt;
  &lt;?bag value="3" content="Ferrara"?&gt;
  </code></pre>
  
  <p>which xpath expression can I use to obtain the value "Ferrara" but not "Volterra"?</p>
  
  <h2>Fieldwork</h2>
  
  <p>With the calibre editor I've tried putting in a book the following line</p>
  
  <pre><code>&lt;?bag value="3" content="Ferrara"?&gt;
  </code></pre>
  
  <p>and testing the following expressions to add the word "Ferrara" in the ToC:</p>
  
  <pre><code>//processing-instruction("bag")[@value="3"]/@content
  
  substring-before(substring-after(//processing-instruction('bag'), 'value="3" content="'), '"')
  </code></pre>
  
  <p>but in both cases I get only</p>
  
  <pre><code>"calibre, version 3.30.0
  ERROR: No items found: No items were found that could be added to the Table of Contents.
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-09-01T09:31:37.730Z
Comments.Text: @NemoXXX I posted in [Calibre forum](https://www.mobileread.com/forums/showthread.php?t=310319) but with no better fortune. Sadly I definitely need an help about processing instructions.
Comments.UserDisplayName: Reverendo Asperso
Tags: <epub><calibre><editing><html><table-of-contents>
Title: xpath in the calibre editor
UserDisplayName: Reverendo Asperso
ThreadText: # xpath in the calibre editor
  
  (Asked by: username_0 on 2018-09-01)
  
  Abstract
  In some search operations in calibre one can use an xpath expression to get the values for particular tags, i.e. the following expression:
  //h:div[re:test(@class, "figbox", "i")]
  
  selects the content of a "div" tag whose "class" attribute is set to "figbox", so in the following html line:
  Volterra
  
  the preceding xpath expression returns the value "Volterra". This is useful to compile the ToC of a book and for other tasks.
  Question
  Now, with the following processing-instructions
  
  
  
  which xpath expression can I use to obtain the value "Ferrara" but not "Volterra"?
  Fieldwork
  With the calibre editor I've tried putting in a book the following line
  
  
  and testing the following expressions to add the word "Ferrara" in the ToC:
  //processing-instruction("bag")[@value="3"]/@content
  
  substring-before(substring-after(//processing-instruction('bag'), 'value="3" content="'), '"')
  
  but in both cases I get only
  "calibre, version 3.30.0
  ERROR: No items found: No items were found that could be added to the Table of Contents.
  
  **Tags:** epub, calibre, editing, html, table-of-contents
  
  > **Comments:**
  > **username_0**: @NemoXXX I posted in [Calibre forum](https://www.mobileread.com/forums/showthread.php?t=310319) but with no better fortune. Sadly I definitely need an help about processing instructions.  
  
  ---
  
  ## 0 answers
  
  