title: Using functx:index-of-match-first in XQuery to return a substring of a text node
body: <p>I am trying to write an XQuery which would find all text nodes that contain a given key word in an xml file. The text node is long so I would like to return a substring(of a desired length) of the text starting at the matching key word. </p>
  
  <p>Samplefile.xml</p>
  
  <pre><code>&lt;books&gt;
  &lt;book&gt;
    &lt;title&gt;linear systems&lt;/title&gt;
    &lt;content&gt;vector spaces and linear system analysis &lt;/content&gt;
  &lt;/book&gt;
  &lt;book&gt;
    &lt;title&gt;some title&lt;/title&gt;
    &lt;content&gt;some content&lt;/content&gt;
  &lt;/book&gt;
  &lt;/books&gt;
  </code></pre>
  
  <p>samplexquery.xq</p>
  
  <pre><code>declare namespace functx = "http://www.functx.com";
  
  for $match_result in /*/book/*[contains(.,'linear')]/text()
    return substring($match_result, functx:index-of-match-first($match_result,'linear'), 50)
  </code></pre>
  
  <p>I expect to get the result [linear systems, linear system analysis]. The title node of first book contains the word 'linear'. Return 50 characters starting from 'linear....'. Similarly for the content node of first book.</p>
  
  <p>I am using XQuery 1.0 and I included the namespace functx as shown in the example at: <a href="http://www.xqueryfunctions.com/xq/functx_index-of-match-first.html" rel="nofollow">http://www.xqueryfunctions.com/xq/functx_index-of-match-first.html</a></p>
  
  <p>But, this is giving me an error: [XPST0017] Unknown function "functx:index-of-match-first(...)". </p>
  
  <p>Thanks,
  Sony</p>