0
我正在努力解决XQuery问题。我有一个XML产品列表,其中包含来自2个不同产品目录系统的产品(由于合并和收购)。一些产品是重复的(每个系统中有1个)。重复的产品名称相同,但价格不同。我需要在列表中获得不同的已排序产品,只显示价格最低的产品
我想返回显示最便宜的产品价格的不同产品的列表。例如,考虑这个输入XML
<?xml version="1.0" encoding="UTF-8"?>
<ns1:ProductList xmlns:ns1="http://www.mycorp.com/bus/prod/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:Product>
<ns1:Id>2</ns1:Id>
<ns1:Name>Ace Ski Boot</ns1:Name>
<ns1:Description>An intermediate ski boot</ns1:Description>
<ns1:Price>109.99</ns1:Price>
<ns1:Warehouse>CZE_PRAGUE</ns1:Warehouse>
<ns1:Icon_url/>
<ns1:Latitude>50.07554</ns1:Latitude>
<ns1:Longitude>14.4378</ns1:Longitude>
</ns1:Product>
<ns1:Product>
<ns1:Id>SUM10012</ns1:Id>
<ns1:Name>Ace Ski Boot</ns1:Name>
<ns1:Description>Intermediate ski boot</ns1:Description>
<ns1:Price>200.0</ns1:Price>
<ns1:Warehouse>Seattle</ns1:Warehouse>
<ns1:Icon_url/>
<ns1:Latitude>47.60621</ns1:Latitude>
<ns1:Longitude>-122.33207</ns1:Longitude>
</ns1:Product>
<ns1:Product>
<ns1:Id>4</ns1:Id>
<ns1:Name>Ace Ski Pole</ns1:Name>
<ns1:Description>A ski pole for skiers with an intermediate skill level</ns1:Description>
<ns1:Price>29.99</ns1:Price>
<ns1:Warehouse>FRA_PARIS</ns1:Warehouse>
<ns1:Icon_url/>
<ns1:Latitude>48.856613</ns1:Latitude>
<ns1:Longitude>2.352222</ns1:Longitude>
</ns1:Product>
<ns1:Product>
<ns1:Id>SUM10022</ns1:Id>
<ns1:Name>Ace Ski Pole</ns1:Name>
<ns1:Description>Intermediate ski pole</ns1:Description>
<ns1:Price>21.950000762939453</ns1:Price>
<ns1:Warehouse>Seattle</ns1:Warehouse>
<ns1:Icon_url/>
<ns1:Latitude>47.60621</ns1:Latitude>
<ns1:Longitude>-122.33207</ns1:Longitude>
</ns1:Product>
它显示了2个重复的产品。我期待返回下面的XML:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:ProductList xmlns:ns1="http://www.mycorp.com/bus/prod/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:Product>
<ns1:Id>2</ns1:Id>
<ns1:Name>Ace Ski Boot</ns1:Name>
<ns1:Description>An intermediate ski boot</ns1:Description>
<ns1:Price>109.99</ns1:Price>
<ns1:Warehouse>CZE_PRAGUE</ns1:Warehouse>
<ns1:Icon_url/>
<ns1:Latitude>50.07554</ns1:Latitude>
<ns1:Longitude>14.4378</ns1:Longitude>
</ns1:Product>
<ns1:Product>
<ns1:Id>SUM10022</ns1:Id>
<ns1:Name>Ace Ski Pole</ns1:Name>
<ns1:Description>Intermediate ski pole</ns1:Description>
<ns1:Price>21.950000762939453</ns1:Price>
<ns1:Warehouse>Seattle</ns1:Warehouse>
<ns1:Icon_url/>
<ns1:Latitude>47.60621</ns1:Latitude>
<ns1:Longitude>-122.33207</ns1:Longitude>
</ns1:Product>
我见过的XQuery返回不同的值,而不是你需要选择一个孩子(NS1:价格)的最低值元素。任何人都可以将我指向正确的方向吗?提前谢谢了!
不幸的是,我目前只能访问XQuery 1.0。 – 2014-10-08 16:43:47
我刚刚为您更新了一个XQuery 1.0示例 – adamretter 2014-10-08 21:24:18
杰出!那就是诀窍。非常感谢你提供了一个美丽的解决方案。 – 2014-10-09 17:52:00