I usually hardwire the xpath in the xqueries like so:
let $xml :=
<books>
<book price="1">
<name>abc</abc>
</book>
</books>
return $xml/book/name
I am trying to figure out if there is a way to path xpath as a string variable and use it in the xquery something like so:
declare variable $xpath as xs:string external;
let $xml :=
<books>
<book price="1">
<name>abc</abc>
</book>
</books>
return $xml/$xpath
Say th开发者_开发问答e value passed to $xpath is book/name.
Thanks.
short answer: no. However, if your processor has an "eval()" method you can construct your query as a string and evaluate it. You might be able to create the query in some external process and embed a dynamic path that way. If you have a small number of cases, you could pass in a variable indicating which one of them to use. But there is no facility in the xquery language for evaluating dynamic paths.
精彩评论