dynamic xpath evaluation
Added by Anonymous about 20 years ago
Legacy ID: #2864147 Legacy Poster: Kesav Kumar (kesav)
Hi I am new to XQuery, I am trying to write a function which is similar in functionality of jsp taglibraries. Is there any way in XQuery to execute dynamic XPath expressions? example declare function fleetcycle:ListBox($elements as element()*, $selectedOption, $valueProperty, $textProperty) as element() { <select> { for $item in $elements let $attrib := concat("$item/", $valueProperty) let $msg := trace($attrib, "value") return element option { attribute value { data($attrib) }, (: here is the question how can I evaluate xpath which I appended in attrib :) if ($item/@ataCodeId eq $selectedOption ) then attribute checked {"true"} else () , text { $item/description } } } </select> }; In the above example I am trying to preapre a variable with concat which finally gets a value $item/@ataCodeId and I want to evaluate the XPath which is stored in variable $attrib. Is there any way to achieve this. Thanks
Replies (3)
Please register to reply
RE: dynamic xpath evaluation - Added by Anonymous about 20 years ago
Legacy ID: #2864335 Legacy Poster: Michael Kay (mhkay)
There's no standard way of doing this in XQuery, but Saxon has an extension function saxon:evaluate() that does the job. Check in the documentation under "extensions". Michael Kay
RE: dynamic xpath evaluation - Added by Anonymous about 20 years ago
Legacy ID: #2865555 Legacy Poster: Kesav Kumar (kesav)
Thanks for your reply. When I tried saxon:evaluate I get the following error Static error in XPath expression supplied to saxon:evaluate: XPath syntax error at char 5 What is the context available for evaluate function? Will it have context of vairables that are created using let expression? In my previous code snipped I had a FOR expression which iterates over the element list and a LET expression creates XPath necessary for lookup. This XPath uses the variable created during FOR expression. When I call evaluate will all the variables be available? Is there any code example I can get howto use evaluate? Thanks
RE: dynamic xpath evaluation - Added by Anonymous about 20 years ago
Legacy ID: #2865591 Legacy Poster: Michael Kay (mhkay)
The variables defined in the query aren't in scope for the dynamic expression. Instead you can pass in parameters p1..p9: let $x := 2 return saxon:evaluate('$p1 + $p1', $x) Michael Kay
Please register to reply