I have problem with my path to XML-elements. In XML document I have:
<team id="6">
<refer>
<team IDREF="7"/>
<team IDREF="8"/>
</refer>
</team>
<team id="7">
<refer>
<team IDREF="6"/>
<team IDREF="8"/>
</refer>
</team>
<team id="8">
<refer>
<team IDREF="6"/>
<team IDREF="7"/>
</refer>
</team>
And I want action -> click refer for team with id=6, and print refers children (two elements -> 7 and 8). I tried this path:
for $z in $path/team[@id = $path/team[@id=$id]/refer/team/@idref]
Where $id is variable id from chosed team (in eg. $id=6), but it doesn't work. I have empty return from this path. Thanks for every help!
EDIT:
I have described it badly. I wanted return whole elements <team id="7">...</team>
id and <team id="8">...</team>
I tried this ($path is doc("input.xml")/root):
for $z in $path/team[@id = $path/team[@id=$id]/refer/team/@idref]
What is badly in this path?
EDIT2: XML document has only this:
<root>
<team id="1">
<ele1/>
<ele2/>
<refer>
<team idref="2"/>
<team idref="3"/>
</refer>
</team>
<team id="2">
<ele1/>
<ele2/>
<refer>
<team idref="3"/>
</refer>
</team>
<team id="3">
<ele1/>
<ele2/>
<refer>
<team idref="1"/>
</refer>
</team>
</root>
And it should return me whole
<team id="1">
<ele1/>
<ele2/>
<refer>
<team idref="2"/>
<team idref="3"/>
</refer>
</team>
with childrens elements when $id=3.
I can't reproduce your problem, for the second sample you posted with the query being
declare variable $id external := 3;
/root/team[@id = /root/team[@id=$id]/refer/team/@idref]
in https://xqueryfiddle.liberty-development.net/gWcDMeu, where I simply declared the variable id
properly and replaced the use of $path
in $path/team[@id = $path/team[@id=$id]/refer/team/@idref]
with /root
to allow the use with in that tool without loading an external resource the selected result is
<team id="1">
<ele1/>
<ele2/>
<refer>
<team idref="2"/>
<team idref="3"/>
</refer>
</team>
So it seems at least one of your posted samples should work with one of the paths you have shown. If you still have problems then you might want to edit and show a single, minimal and complete XML sample together with a minimal and complete XPath or XQuery that allows us to reproduce the problem.