title: Using variable in XQuery expressions
body: <p>using Xquery, how can I embed variable in an xquery expression on the following xml document. I have the following xml document </p>
  
  <pre><code>&lt;CD&gt;
          &lt;TITLE&gt;Picture book&lt;/TITLE&gt;
          &lt;ARTIST&gt;Simply Red&lt;/ARTIST&gt;
          &lt;COUNTRY&gt;EU&lt;/COUNTRY&gt;
          &lt;COMPANY&gt;Elektra&lt;/COMPANY&gt;
          &lt;PRICE&gt;7.20&lt;/PRICE&gt;
          &lt;YEAR&gt;1985&lt;/YEAR&gt;
      &lt;/CD&gt;
      &lt;CD&gt;
          &lt;TITLE&gt;Red&lt;/TITLE&gt;
          &lt;ARTIST&gt;The Communards&lt;/ARTIST&gt;
          &lt;COUNTRY&gt;UK&lt;/COUNTRY&gt;
          &lt;COMPANY&gt;London&lt;/COMPANY&gt;
          &lt;PRICE&gt;7.80&lt;/PRICE&gt;
          &lt;YEAR&gt;1987&lt;/YEAR&gt;
      &lt;/CD&gt;
      &lt;CD&gt;
          &lt;TITLE&gt;Unchain my heart&lt;/TITLE&gt;
          &lt;ARTIST&gt;Joe Cocker&lt;/ARTIST&gt;
          &lt;COUNTRY&gt;USA&lt;/COUNTRY&gt;
          &lt;COMPANY&gt;EMI&lt;/COMPANY&gt;
          &lt;PRICE&gt;8.20&lt;/PRICE&gt;
          &lt;YEAR&gt;1986&lt;/YEAR&gt;
      &lt;/CD&gt;
  </code></pre>
  
  <p>I need to issue a query to return all the CDs with YEAR > 1986. I want like to have the components of the "where" clause as variables, I mean storing <code>YEAR &gt; 1986</code> in to three variables and use the variables in the query,
  here what I have so far</p>
  
  <pre><code>String queryString =
                  "declare variable $field :=" +"YEAR"+";"+
                  "declare variable $operator :=" +"&gt;"+";"+
                  "declare variable $value :=" +"1986"+";"+
                  "declare variable $docName as xs:string external;" + sep +
                  "for $cat in doc($docName)/*/"+ "CD" +
                   "where $cat/$field $operator $value" +
                  "order by $cat/$field" +
                  "return $cat";
  
                XQExpression expression = conn.createExpression();
                expression.bindString(new QName("docName"), filename,
                conn.createAtomicType(XQItemType.XQBASETYPE_STRING));
                results = expression.executeQuery(queryString);
                return results.getSequenceAsString(new Properties()); 
  </code></pre>
  
  <p>My query expression isn't perfect, I think I am having trouble in using the variables, any one can help me in solving this please?
  Thanks</p>