// XPath expressions
if (queryUsesVars(contextElement)) continue;
String xpath = contextElement.getAttributeValue("select");
XPathContext namespaces = getXPathContext(contextElement);
Node context = source.query(xpath).get(0);
// process counts
Elements tests = contextElement.getChildElements("test");
for (int k = 0; k < tests.size(); k++) {
Element test = tests.get(k);
String select = test.getAttributeValue("select");
Attribute countAttribute = test.getAttribute("count");
int count = -1;
if (countAttribute != null) {
count = Integer.parseInt(countAttribute.getValue());
}
boolean exceptional = false;
String exception = test.getAttributeValue("exception");
if ("true".equals(exception)) {
exceptional = true;
}
if (exceptional) {
try {
context.query(select, namespaces);
fail("Evaluated " + select);
}
catch (XPathException success) {
assertNotNull(success.getMessage());
}
}
else {
try {
Nodes results = context.query(select, namespaces);
if (count != -1) {
assertEquals(select, count, results.size());
}
Elements valueOfs = test.getChildElements("valueOf");
for (int v = 0; v < valueOfs.size(); v++) {