I have the following Java Method that uses XQuery:
public String getLocationByName(String name) {
final String nameToQueryFor = name;
return engine.new Query<String>(MY_COLLECTION) {
@Override
protected String query(Collection collection) throws Exception {
XQueryService service = queryService();
ResourceSet resourceSet = service.query(
format("//Products/Product[name='%s']" +
"/attribute"
, StringEscapeUtils.escapeXml(nameToQueryFor)
));
List<String> results = newArrayList();
for (String resource : new IterableStringResources(resourceSet)) {
results.add(resource);
}
return results.get(0);
}
}.execute();
}
As can be seen I currently am only querying using one parameter, i.e. name.
I am a beginner with XQuery, How can I alter this Xquery to take an additional parameter: price
My method would now become:
public String getLocationByNameAndPrice(String name)
//Products/Product[name=$name]instead of string formatting and concatenation.