title: Comparing two decimal values in xquery
body: <p>I am trying to find which price value is the smallest in xquery. I have two price values being passed in XML and I can't seem to get past syntax errors when trying to compare the values. </p>
  
  <p>Example XML:</p>
  
  <pre><code>&lt;purchase&gt;
    ....
    &lt;articlePrice&gt;$20.00&lt;/articlePrice&gt;
    &lt;issuePrice&gt;$154.00&lt;/issuePrice&gt;
    ....
  &lt;/purchase&gt;
  </code></pre>
  
  <p>I have the below to strip out the '$'</p>
  
  <pre><code>let $price := fn:substring-after($price, '$')
  let $priceIssue := fn:substring-after($priceIssue, '$')
  </code></pre>
  
  <p>I've tried to use the built in fn:min() but gives "XDMP-UNEXPECTED: (err:XPST0003) Unexpected token syntax error, unexpected QName_".</p>
  
  <pre><code>fn:min(((xs:decimal($price)), (xs:decimal($priceIssue))))
  </code></pre>
  
  <p>Ive tried using both 'gt' and '>' in an if statement but still get syntax error above.</p>
  
  <p>The only way that I could get around the errors is casting them as strings but the comparison is wrong. Given the data above, as strings the logic returns '154.00' as smaller than '20.00' because the '1' is smaller than the '2'. </p>
  
  <p>My exact code:</p>
  
  <pre><code>let $price := if (xs:string($ecommerce/articlePrice)) then fn:substring-after(xs:string($ecommerce/articlePrice), '$') else ""
  
  let $priceIssue := if (xs:string($ecommerce/issuePrice)) then fn:substring-after(xs:string($ecommerce/issuePrice), '$') else ""
  
  let $priceDisplay := fn:min(xs:decimal($price), xs:decimal($priceIssue))
  </code></pre>
  
  <p>results as XDMP-ARGTYPE: (err:XPTY0004) fn:min(20.0, 154.0) -- arg2 is not of type xs:string   </p>