0
votes

With my XML

<products>
    <product id="12" type="modell">
        <attribute type="image">nose.jpg</attribute>
        <product id="13" type="kid">
            <attribute type="image">face.jpg</attribute>
        </product>
    </product>
    <product id="22" type="modell">
        ...
    </product>
</products>

and xquery I except to get every attribute with type image under my product with id 12.

What I tried so far:

 data(for $image in //product[@id = '12']/*/attribute[@type='IMAGE']
 return $image)

Which will not work (without * I'm getting only the nose.jpg), but I m searching for a way to return face.jpg and nose.jpg.

Any hints?

1

1 Answers

1
votes

Use the descendant-or-self::attribute axis step, abbreviated //attribute instead, which matches in the whole subtree (while /*/attribute only "skips" one level):

data(for $image in //product[@id = '12']//attribute[@type='IMAGE']
return $image)

(I was required to change IMAGE to lower case to match your input, though)