Skip to content

Instantly share code, notes, and snippets.

@dmcassel
Created September 16, 2015 20:24
Show Gist options
  • Save dmcassel/ad90d751b227a20d861e to your computer and use it in GitHub Desktop.
Save dmcassel/ad90d751b227a20d861e to your computer and use it in GitHub Desktop.
/*
* Evaluate standard XPath against JSON (or XML or both). JSON properties operate similar to unnamespaced
* XML elements.
*/
var total = 0, count = 0;
// XPath is a subset of XQuery. Evaluate it.
var resultIter =
xdmp.xqueryEval('/node()[some $name in friends/name satisfies starts-with(upper-case($name), "N") or eyeColor = "blue"]');
for (var result of resultIter) {
total += result.age;
count++;
};
"Average age of people who have blue eyes or are friends with others whose names start with \"N\": " + (total/count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment