using Xquery, how can I embed variable in an xquery expression on the following xml document. I have the following xml document
<CD>
<TITLE>Picture book</TITLE>
<ARTIST>Simply Red</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>Elektra</COMPANY>
<PRICE>7.20</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Red</TITLE>
<ARTIST>The Communards</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>London</COMPANY>
<PRICE>7.80</PRICE>
<YEAR>1987</YEAR>
</CD>
<CD>
<TITLE>Unchain my heart</TITLE>
<ARTIST>Joe Cocker</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>EMI</COMPANY>
<PRICE>8.20</PRICE>
<YEAR>1986</YEAR>
</CD>
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 YEAR > 1986
in to three variables and use the variables in the query,
here what I have so far
String queryString =
"declare variable $field :=" +"YEAR"+";"+
"declare variable $operator :=" +">"+";"+
"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());
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