How to bind an XQuery external variable in Zorba from PHP?
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开发者_如何学编程?
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?
精彩评论