How to use the fontoxpath.evaluateUpdatingExpression 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 / xquery-updating / ReplaceExpression.tests.ts View on Github external
it('allows replacing something with something asynchronous', async () => {
		const element = documentNode.appendChild(documentNode.createElement('element'));

		// Duplicate all list items and set the @count attribute to the new count of items, in a very roundabout way
		const result = await evaluateUpdatingExpression(
			`
declare namespace fontoxpath="http://fontoxml.com/fontoxpath";

replace node fontoxpath:sleep(/element, 100) with fontoxpath:sleep(, 1)
`,
			documentNode,
			null,
			{},
			{}
		);

		chai.assert.deepEqual(result.xdmValue, []);
		assertUpdateList(result.pendingUpdateList, [
			{
				replacementXML: [''],
				target: element,
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / RenameExpression.tests.js View on Github external
it('allows rename', async () => {
		const element = documentNode.appendChild(documentNode.createElement('element'));

		const result = await evaluateUpdatingExpression(
			`rename node /element as "elem"`,
			documentNode,
			null,
			{},
			{});

		chai.assert.deepEqual(result.xdmValue, []);
		assertUpdateList(result.pendingUpdateList, [
			{
				type: 'rename',
				target: element,
				newName: { prefix: '', namespaceURI: null, localPart: 'elem' }
			}
		]);
	});
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / DeleteExpression.tests.ts View on Github external
it('merges pul from target expressions', async () => {
		const element = documentNode.appendChild(documentNode.createElement('element'));
		const a = element.appendChild(documentNode.createElement('a'));

		const result = await evaluateUpdatingExpression(
			`delete node (/element, delete node /element/a)`,
			documentNode,
			null,
			{},
			{}
		);

		chai.assert.deepEqual(result.xdmValue, []);
		assertUpdateList(result.pendingUpdateList, [
			{
				type: 'delete',
				target: element
			},
			{
				type: 'delete',
				target: a
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / ReplaceExpression.tests.ts View on Github external
it('disallows replacing attributes with elements', async () => {
		documentNode
			.appendChild(documentNode.createElement('element'))
			.setAttribute('attr', 'value');

		let error;
		try {
			await evaluateUpdatingExpression(
				'replace node /element/@attr with ',
				documentNode,
				null,
				{},
				{}
			);
		} catch (err) {
			error = err;
		}

		chai.assert.throws(() => {
			if (error) {
				throw error;
			} else {
				return null;
			}
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / RenameExpression.tests.ts View on Github external
it('allows rename', async () => {
		const element = documentNode.appendChild(documentNode.createElement('element'));

		const result = await evaluateUpdatingExpression(
			`rename node /element as "elem"`,
			documentNode,
			null,
			{},
			{}
		);

		chai.assert.deepEqual(result.xdmValue, []);
		assertUpdateList(result.pendingUpdateList, [
			{
				type: 'rename',
				target: element,
				newName: { prefix: '', namespaceURI: null, localName: 'elem' }
			}
		]);
	});
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / ReplaceExpression.tests.ts View on Github external
it('disallows replacing multiple nodes at once', async () => {
		let error;
		try {
			await evaluateUpdatingExpression(
				'replace node (/, /) with ',
				documentNode,
				null,
				{},
				{}
			);
		} catch (err) {
			error = err;
		}

		chai.assert.throws(() => {
			if (error) {
				throw error;
			} else {
				return null;
			}
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / TransformExpression.tests.ts View on Github external
it('merges puls from copy clauses', async () => {
		const element = documentNode.appendChild(documentNode.createElement('element'));
		const result = await evaluateUpdatingExpression(
			`
copy $a := (element, replace node element with ),
     $b := (element, rename node element as "renamed")
modify replace value of node $a with "content"
return $a
`,
			documentNode,
			null,
			{},
			{ returnType: evaluateXPath.NODES_TYPE }
		);
		chai.assert.equal(result.xdmValue.length, 1);
		const actualXml = new slimdom.XMLSerializer().serializeToString(result.xdmValue[0]);
		chai.assert.equal(actualXml, '<element>content</element>');
		assertUpdateList(result.pendingUpdateList, [
			{
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / ReplaceExpression.tests.ts View on Github external
it('can replace a node and generate the correct update list', async () =&gt; {
		const ele = documentNode.appendChild(documentNode.createElement('ele'));
		const result = await evaluateUpdatingExpression(
			'replace node ele with ',
			documentNode,
			null,
			{},
			{}
		);

		chai.assert.deepEqual(result.xdmValue, []);
		assertUpdateList(result.pendingUpdateList, [
			{
				replacementXML: [''],
				target: ele,
				type: 'replaceNode'
			}
		]);
	});
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / ReplaceExpression.tests.ts View on Github external
it('disallows replacing the value of a document node', async () =&gt; {
		let error;
		try {
			await evaluateUpdatingExpression(
				'replace value of node . with ',
				documentNode,
				null,
				{},
				{}
			);
		} catch (err) {
			error = err;
		}

		chai.assert.throws(() =&gt; {
			if (error) {
				throw error;
			} else {
				return null;
			}
github FontoXML / fontoxpath / test / specs / parsing / xquery-updating / TransformExpression.tests.ts View on Github external
const getChildNode = (node: slimdom.Node) =&gt;
			node === documentNode ? xml : node === xml ? a : null;
		const myDomFacade: IDomFacade = {
			getAllAttributes: () =&gt; [],
			getAttribute: () =&gt; null,
			getChildNodes: (node: slimdom.Node) =&gt; (getChildNode(node) ? [getChildNode(node)] : []),
			getData: () =&gt; '',
			getFirstChild: getChildNode,
			getLastChild: getChildNode,
			getNextSibling: () =&gt; null,
			getParentNode: (node: slimdom.Node) =&gt;
				node === a ? xml : node === xml ? documentNode : null,
			getPreviousSibling: () =&gt; null
		};

		const result = await evaluateUpdatingExpression(
			`copy $a := xml modify () return $a`,
			documentNode,
			myDomFacade,
			{},
			{}
		);
		const actualXml = new slimdom.XMLSerializer().serializeToString(result.xdmValue[0]);
		const expectedXml = new slimdom.XMLSerializer().serializeToString(sync('<a></a><a>'));
		chai.assert.equal(actualXml, expectedXml);
		assertUpdateList(result.pendingUpdateList, []);
	});
</a>