title: XQuery: extract number from string to use in comparison
body: <p>I am very new to XQuery, and frankly find the learning curve incredibly steep.</p>
  
  <p>I have an XML structure that looks something like this:</p>
  
  <pre><code>&lt;root&gt;
      &lt;product&gt;
          &lt;size&gt;500 units&lt;/size&gt;
      &lt;/product&gt;
      &lt;product&gt;
          &lt;size&gt;1000 units&lt;/size&gt;
      &lt;/product&gt;
      &lt;product&gt;
          &lt;size&gt;Unlimited units&lt;/size&gt;
      &lt;/product&gt;
  &lt;/root&gt;
  </code></pre>
  
  <p>I need to write an XQuery statement that returns all nodes where the numerical value in <strong>size</strong> is less than say 1000. So I somehow need to determine this numerical value (ignoring any text) to perform an 'le' operation I assume.</p>
  
  <p>On top of this, there is the possibility that the node will have no digits at all (e.g. 'Unlimited units'), in which case it needs to be treated as having a value of say 1000000.</p>
  
  <p>Is there some way to do this? I've tried various combinations of <strong>fn:replace(blah, '\D', '')</strong> and casting to xs:int, but I can't seem to get it to work.</p>
  
  <p>Any guidance would be greatly appreciated.</p>