简体   繁体   English

使用Xquery返回属性值

[英]Returning attribute value using Xquery

I need to return cno and the zip 我需要返回cno和zip

x in customers/customer x在客户/客户中

z in customers/customer/city z在客户/客户/城市

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

{$z/zipcode} {$ z /邮政编码}

It returns every cno, I need zip code that matches cno 它返回每个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>

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 . 完整的示例代码可以在http://xqueryfiddle.liberty-development.net/jyyiVhv中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM