为给定的XML编写XQuery

时间:2014-02-06 19:53:33

标签: xml xquery xquery-3.0

我需要从给定的XML编写XQuery,但我找不到正确的方法。

这是xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Edited by XMLSpy -->
<onlinecomputer>
    <item name="Processor" price="100.00"/>
        <item name="USB driver" price="50.00"/>
        <item name="Webcam" price="20.50"/>
        <item name="Notebook" price="700.00"/>
        <place>
         <name>Prishtin</name>
           <customer>
                <name>Hana</name>
                <street> Nen Tereza</street>
                <order item="Processor" amount="1"/>
                <order item="USB driver" amount="3"/>
                <order item="Webcam" amount="3"/>
                <order item="Notebook" amount="2"/>
           </customer>
            <customer>
                <name>Ron</name>
                <street> blbl</street>
                <order item="Webcam" amount="1"/>
           </customer>
      </place>
        <place>
         <name>Tetove</name>
           <customer>
                <name>Edin</name>
                <street> gggg</street>
                <order item="Processor" amount="4"/>
                <order item="Notebook" amount="1"/>
           </customer>
            <customer>
                <name>Alex</name>
                <street> bbbb</street>
                <order item="Processor" amount="2"/>
           </customer>
      </place>
</onlinecomputer>

XQuery应该编写一个表达式,该表达式将给出一组对(地点和项目),以便此项目已在给定位置发货。

结果应该是:

<answer place="nameOfPlace" item="nameOfItem" />

1 个答案:

答案 0 :(得分:0)

for $p in onlinecomputer/place
for $i in distinct-values(customer/order/@item)
return <answer place="{ $p/name }" item="{ $i }"/>