openrosa-xpath-evaluator
Advanced tools
Comparing version 2.0.0-beta.8 to 2.0.0-beta.9
{ | ||
"name": "openrosa-xpath-evaluator", | ||
"version": "2.0.0-beta.8", | ||
"version": "2.0.0-beta.9", | ||
"description": "Wrapper for browsers' XPath evaluator with added support for OpenRosa extensions.", | ||
@@ -5,0 +5,0 @@ "main": "src/XPathJS.js", |
@@ -12,11 +12,14 @@ require('./date-extensions'); | ||
createNSResolver: evaluator.createNSResolver, | ||
evaluate: function (expr, contextPath, namespaceResolver, resultType, result) { | ||
var wrappedXpathEvaluator = function(v, node, rt) { | ||
if(resultType < 7 || v.startsWith('//')) resultType = null; | ||
var wrappedResultType = rt || resultType || XPathResult.ANY_TYPE; | ||
return evaluator.evaluate(v, node || contextPath, namespaceResolver, wrappedResultType || XPathResult.ANY_TYPE, result); | ||
}; | ||
var xevaluator = new ExtendedXPathEvaluator(wrappedXpathEvaluator, extensions); | ||
return xevaluator.evaluate.apply(xevaluator, arguments); | ||
} | ||
evaluate: function (expr, node, nsr, rt, result) { | ||
const xevaluator = new ExtendedXPathEvaluator( | ||
(v, xnode, xnsr, xrt) => { | ||
if(!rt || rt<7 || v.startsWith('//')) rt = null; | ||
xrt = xrt || rt || XPathResult.ANY_TYPE; | ||
const result = evaluator.evaluate(v, xnode || node, xnsr || nsr, xrt, null); | ||
// console.log(`${v} => ${result.resultType}`); | ||
return result; | ||
}, | ||
extensions); | ||
return xevaluator.evaluate(...arguments); | ||
}, | ||
} | ||
@@ -23,0 +26,0 @@ } |
@@ -7,2 +7,3 @@ | ||
const config = require('../src/config'); | ||
const engine = require('../src/engine'); | ||
@@ -24,3 +25,2 @@ let doc, xEval, evaluator, nsr, rt, node, docs = []; | ||
const initDoc = (xml, xnsr) => { | ||
@@ -30,14 +30,6 @@ doc = new DOMParser().parseFromString(xml, 'application/xml'); | ||
nsr = xnsr; | ||
evaluator = new ExtendedXPathEvaluator( | ||
(v, xnode, xnsr, xrt) => { | ||
if(!rt || rt<7 || v.startsWith('//')) rt = null; //TODO ??? | ||
xrt = xrt || rt || XPathResult.ANY_TYPE; | ||
const result = doc.evaluate.call(doc, v, xnode || node || doc, xnsr || nsr, xrt, null); | ||
// console.log(`${v} => ${result.resultType}`); | ||
return result; | ||
}, | ||
openRosaXPathExtensions(config)); | ||
xEval = function(e, xnode, resultType, xnsr) { | ||
node = xnode; | ||
rt = resultType; | ||
evaluator = new engine.XPathEvaluator(); | ||
xEval = function(e, xnode, xrt, xnsr) { | ||
node = xnode || doc; | ||
rt = xrt; | ||
_document(e); | ||
@@ -44,0 +36,0 @@ return evaluator.evaluate(e, node, xnsr || nsr, rt, null); |
@@ -113,1 +113,30 @@ const { initDoc, nsResolver, filterAttributes, assert } = require('../../helpers'); | ||
}); | ||
describe('XPath expression evaluation5', () => { | ||
const doc = initDoc(` | ||
<html xmlns="http://www.w3.org/2002/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:h="http://www.w3.org/1999/xhtml" | ||
xmlns:jr="http://openrosa.org/javarosa" | ||
xmlns:orx="http://openrosa.org/xforms/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
<model> | ||
<instance> | ||
<data id="nested-repeat-v5"> | ||
<region jr:template=""> | ||
<livestock jr:template=""> | ||
<type/> | ||
<type_other/> | ||
</livestock> | ||
</region> | ||
<meta> | ||
<instanceID/> | ||
</meta> | ||
</data> | ||
</instance> | ||
</model></html>`); | ||
it('returns correct result type', () => { | ||
const expr = '/model/instance[1]/*//*[@template] | /model/instance[1]/*//*[@jr:template]'; | ||
const res = doc.xEval(expr, doc, 7, nsResolver); | ||
assert.equal(res.resultType, 7); | ||
assert.equal(res.snapshotLength, 0); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
346763
8376