Complex 'WHERE' clause

As I’m new to XQuery and Timano I’ve run into a bit of a problem, and I’m not able to find a suitable answer.

Here’s the deal:

We’ve stored several documents within the Tamino Database, looking somewhat like this :





Something


1
link
5


2
link
3





This article has a specific category type, but is referenced by different higher entities. I need to have an overview of ARTICLEs that meet three criteria :

1. First of all a specific Category type
2. A certain Link number and 3. Whithin that same Link a specific Position

The query I’ve been given is the following :

for $a in input()/ARTICLE where $a//INFO/CATEGORY/TYPE=“Something” and $a//INFO/LINK/NR=“2” and $a//INFO/LINK/POSITION=“5” return $a

Obviously this doesn’t work as it gives back all ARTICLES with a node that holds the value “2” and a tag that holds the value “5”. But I need the ARTICLES that have these values within a single node.

I’m kind of desperate, so please help me out here.

Does this help:

for $a in input()/ARTICLE  
for $b in $a/DESCRIPTION/INFO/LINK
where $a/DESCRIPTION/INFO/CATEGORY/TYPE="Something"
and  $b/NR = '2' and $b/POSITION = '5'
return $a

Thanks for the example. It worked like a charm !