I need to pass a value at run time get all the childen elements.
For example this is my XML:
<person>
<details1>
<name>jack</name>
<age>26</age>
</details1>
<details2>
<name>john</name>
<age>48</age>
</details2>
</person>
And my query:
let $y as xs:string := "details1"
let $x := fn:doc(cts:uri-match('*person.xml'))
return $x/$y
So here I am expecting the result as
<details1>
<name>jack</name>
<age>26</age>
</details1>
but it returns the same name as that of $y i.e. "details1"
or if I query this way
let $y as xs:string := "details1"
let $x := fn:doc(cts:uri-match('*person.xml'))
return $x//$y
the result would be "details1" for 12 times
I am new to XQuery please help me in solving the issue
It seems like you attempt to use a string
$y
as a node step. However, in XPath/XQuery a path step is different from a string, so you can't simple add a string as path step. Instead, you could look for all descendent elements with the requirement that they do have the same name, i.e.: