sony
sony

Reputation: 1587

passing xpath to xquery

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 the value passed to $xpath is book/name.

Thanks.

Upvotes: 1

Views: 247

Answers (1)

Mike Sokolov
Mike Sokolov

Reputation: 7044

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.

Upvotes: 2

Related Questions