为了模拟在XQuery中更新一个自动增加的值,下面的工作正常,假设<root count="0"/>
在第一次运行此时:
let $count := /root/@count
return (
insert node <node id='{ $count }'/> into /root,
replace value of node $count with $count + 1
)
...很好的收益:
<root count="1">
<node id="0">
</root>
不过,我想定义节点在我的Java代码,然后绑定 ,作为一个org.w3c.dom.Node
或Document
,甚至是String
。 喜欢:
String expr =
" declare variable $n external; "
+ " let $count := /root/@count; "
+ " return ( "
+ " insert node $n into /root, "
+ " replace value of node $count with $count + 1 "
+ " ) ";
XQConnection xqc = ...;
XQPreparedExpression xqp = xqc.prepareExpression(expr);
// org.w3c.dom.Node node is <node id='{ $count }'/>
xqp.bindNode(new QName("n"), node, null);
xqp.executeQuery();
然而,这只是让我的文字 { $count }
中的属性。 结合节点作为xs:string
值具有相同的效果。
当然,这是针对“XQuery的注射液”一个很好的保护作用。 尽管如此则:有没有什么办法,使XQuery的更新过程中的封闭表达我对变量本身?
(任何其他奇思妙想XQuery中使用自动增量值都非常欢迎过,但后来看到使用XQuery更新自动递增? )