Browsing subnodes using XQuery

Could someone tell me how I can browse subnodes within a document using XQuery4 and at the same time retrieve data from its parents and/or sibblings.

E.g

Doc instance 1
--------------


Monday
Wednesday



1
2


3
3




Doc instance 2
--------------


Tuesday
Friday



2
3


4
5




Doc instance 3
--------------


I want to browse all Allocations and display Planning/@active attribute and the operational days using Tamino cursor and Xquery.

I’m able to accomplish this with the following xquery

declare namespace tf="http://namespaces.softwareag.com/tamino/TaminoFunction"

for $alloc in input()/Planning/Checkin/Allocation,
$planning in input()/Planning
where $planning/@row=“1” and tf:getInoId($alloc) = tf:getInoId($chkplan)
return
*** I can now use both $alloc and $planning and they are related since tf:getInoId($alloc) = tf:getInoId($chkplan) ***

The problem with this query is that I need to get the parent via input()/planning and I would like
to get the parent context via the Ancestor (or any other) axes of $alloc, which does not work since $alloc has no ancestors. That is why I use $planning to get the context of subnode Allocation.

Using planning as the starting point is not an option since then you will browse the Planning documents and not the subnodes, and that is not what I want: if I request 18 Allocations via a cursor then I expect 18 Allocations and not 18 Planning documents, since these may contain more than 18 Allocations (and I do have to implement the logic to get to the allocations).

Has anyone some useful suggestions or is this the only way to solve this problem?

Regards,
Rudolf de Grijs

Hi Rudolf,

Would the root() function help here? For example:

for $alloc in input()/Planning/Checkin/Allocation
let $root := root($alloc)
return

{$alloc}
{$root/Planning/AppliesOn/*}
{$root/Planning/@active}


which returns element each containing a single Allocation element (within its children), the children of AppliesOn (the Day elements) and the attribute @active which is returned as an attribute of the element.

Then cursoring would restrict the number of elements returned with each query.

Does this help?

Stuart Fyffe-Collins
Software AG (UK) Ltd.

Thank you Stuart.

My colleague played a bit with a similar query and the same outcome can be accomplished with the following query.

for $planning in input()/Planning,
$alloc in $planning/Checkin/Allocation
return

{$alloc}
{$planning/AppliesOn/*}
{$planning/@active}



Regards,
Rudolf