使用Xquery返回属性值

时间:2019-05-11 18:28:11

标签: xml xquery

我需要返回cno和zip

  

x个客户/客户

     

z在客户/客户/城市

     

返回{data($ x / @ cno)}

     

{$ z /邮政编码}

     

它返回每个cno,我需要匹配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 个答案:

答案 0 :(得分:0)

以下查询返回您描述的结果:

xquery version "3.1";

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

结果:

2222: 67226
1000: 67226-1555

完整的示例代码可在http://xqueryfiddle.liberty-development.net/jyyiVhv上找到。