0
votes

I am running into a weird problem with accessing nodes in my XML file.

If I do (in my XQuery file) :

return <result>$myfile/option[2]</result>

It works fine, however, if I try :

return <result>$myfile/option[$myfile/data(@index)]</result>

It doesn't work. The value of $myfile/data(@index) is 2.

Any insights would be greatly appreciated.

1
I assume you've left out the curly braces from these code examples. - Michael Kay

1 Answers

0
votes

The value of $myfile/data(@index) is 2

I suspect it is the string "2" rather than the number 2. Try casting it

return <result>$myfile/option[xs:integer($myfile/data(@index))]</result>