0
votes

I need to return cno and the zip

x in customers/customer

z in customers/customer/city

return {data($x/@cno)}

{$z/zipcode}

It returns every cno, I need zip code that matches cno

<customers>
<customer cno="2222">
        <city>
        <zip>67226</zip>
        <phone>316-636-5555</phone>
       </city>
    </customer>

    <customer cno="1000">
        <city>
        <zip>67226-1555</zip>
        <phone>000-000-0000</phone>
      </city>
    </customer>    

</customers>
1

1 Answers

0
votes

The following query returns the result you describe:

xquery version "3.1";

for $customer in /customers/customer
return
    $customer/@cno || ": " || $customer/city/zip

The result:

2222: 67226
1000: 67226-1555

Complete sample code can be found at http://xqueryfiddle.liberty-development.net/jyyiVhv.