How to use the fontoxpath.evaluateXPathToFirstNode function in fontoxpath

To help you get started, we’ve selected a few fontoxpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FontoXML / fontoxpath / test / specs / parsing / axes / SelfAxis.tests.ts View on Github external
it('parses self::', () => {
		const element = documentNode.createElement('someElement');
		chai.assert.deepEqual(evaluateXPathToFirstNode('self::someElement', element), element);
	});
	it('throws the correct error if context is absent', () => {
github FontoXML / fontoxpath / test / specs / parsing / predicates / predicates.tests.js View on Github external
it('can parse a simple any element + attribute selector', () => {
		const element = documentNode.createElement('someElement');
		element.setAttribute('someAttribute', 'someValue');
		chai.assert.deepEqual(evaluateXPathToFirstNode('self::*[@someAttribute=\'someValue\']', element), element);
		const comment = documentNode.createComment('someComment');
		chai.assert.deepEqual(evaluateXPathToNodes('self::*[@someAttribute=\'someValue\']', comment), []);
	});
github FontoXML / fontoxpath / test / specs / parsing / predicates / predicates.tests.js View on Github external
it('uses correct contexts in predicates', () => {
		jsonMlMapper.parse([
			'someGrandParentElement',
			[
				'someParentElement',
				['someChildelement']
			]
		], documentNode);
		chai.assert.deepEqual(evaluateXPathToFirstNode('parent::someParentElement[parent::someGrandParentElement]', documentNode.documentElement.firstChild.firstChild), documentNode.documentElement.firstChild);
	});
github FontoXML / fontoxpath / test / specs / parsing / evaluateXPath.tests.ts View on Github external
it('Keeps nodes nodes', () =>
			chai.assert.equal(
				evaluateXPathToFirstNode('.', documentNode, domFacade),
				documentNode
			));
github FontoXML / fontoxpath / test / specs / parsing / evaluateXPath.tests.ts View on Github external
it('Throws when the xpath resolves to an attribute', () => {
			jsonMlMapper.parse(
				[
					'someElement',
					{
						someAttribute: 'someValue'
					}
				],
				documentNode
			);
			chai.assert.equal(
				evaluateXPathToFirstNode('//@someAttribute', documentNode, domFacade),
				documentNode.documentElement.attributes[0]
			);
		});
		it('Throws when the xpath resolves to not a node', () => {
github FontoXML / fontoxpath / test / specs / parsing / axes / ChildAxis.tests.js View on Github external
it('sets the context sequence', () => {
		jsonMlMapper.parse([
			'someParentElement',
			['someElement'],
			['someOtherElement']
		], documentNode);
		chai.assert.deepEqual(evaluateXPathToFirstNode('someParentElement/child::*[last()]', documentNode), documentNode.documentElement.lastChild);
	});
	it('throws the correct error if context is absent', () => {
github FontoXML / fontoxpath / test / specs / parsing / functions / functions.node.tests.ts View on Github external
it('returns the root of the given document', () =>
			chai.assert.equal(evaluateXPathToFirstNode('root(.)', documentNode), documentNode));
github FontoXML / fontoxpath / test / specs / parsing / xquery / ElementConstructor.tests.ts View on Github external
it('can create an element', () => {
		chai.assert.equal(
			evaluateXPathToFirstNode(
				'<element>',
				documentNode,
				undefined,
				{},
				{ language: evaluateXPath.XQUERY_3_1_LANGUAGE }
			).nodeType,
			1
		);
	});
	it('Sets the correct name', () =&gt; {</element>
github FontoXML / fontoxpath / test / qt3tests.ts View on Github external
function getAsserterForTest(baseUrl, testCase, language) {
	return createAsserter(baseUrl, evaluateXPathToFirstNode('./result/*', testCase), language);
}
github FontoXML / fontoxpath / test / xqutsTests.js View on Github external
if (isUpdating) {
			const it = await evaluateUpdatingExpression(...args);
			xdmValue = it.xdmValue;
			if (it.pendingUpdateList) {
				executePul(it.pendingUpdateList, args);
			}
			xdmValue.forEach(nodeValue => {
				if (nodeValue.value.normalize) {
					nodeValue.value.normalize();
				}
			});
		}

		switch (outputFile.compare) {
			case 'XML': {
				const actual = xdmValue ? xdmValue[0].value : evaluateXPathToFirstNode(...args);
				const expected = actual.nodeType === actual.DOCUMENT_NODE ?
					parser.parseFromString(expectedString) :
					parser.parseFromString(expectedString).documentElement;

				catchAssertion(() => assertXml(actual, expected));
				break;
			}
			case 'Fragment': {
				const actualNodes = xdmValue ? xdmValue.map(nodeValue => nodeValue.value) : evaluateXPathToNodes(...args);

				catchAssertion(() => assertFragment(actualNodes, expectedString));
				break;
			}
			case 'Text': {
				if (xdmValue) {
					throw new Error('Not yet supported: Updating query with text assertion.');