3
votes

Can the Zorba XQuery processor PHP API bind to variables declared as external within an xquery?

For example this line in an xquery would bind to an external variable named $foo;

declare variable $foo as xs:string external;

But I can't find an example in the Zorba PHP API documentation showing how to do the PHP part of the bind, so that the PHP variable $foo becomes bound to the xquery variable $foo.

Can it be done?

1
Take a look for the set_variable() function in the PHP API. I don't know it specifically for PHP, but the C API has this. - hakre

1 Answers

0
votes

You can do the following:

$query = $this->zorba->compileQuery("declare variable $i external; $i + 1");
$dctx  = $this->zorba->getDynamicContext();

$param = $this->zorba->compileQuery(".");
$itemFactory = $this->zorba->getItemFactory();
$value = $itemFactory->createString("1");

$param->getDynamicContext()->setContextItem($value);

$dctx->setVariable("", "i", $param->iterator());

Does this help?