Forum Discussion

keaner's avatar
13 years ago

Xquery: More than one match

So I have the following XML response, where I am trying to retrieve the link from each <Id></Id> tags., and then I will try to request each of those links.

--------------------------
<Products xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schema.pnimedia.com/2012/4/PniProduct.xsd">
<Product>
<Id>http://devcms001.photochannel.net:8350/PniProduct/1</Id>
<Name>name1</Name>
<RelatedResources>
<RelatedResource p6:type="Simple" p6:href="http://devcms001.photochannel.net:8350/PniProduct/1/Builder" p6:role="http://schema.pnimedia.com/2012/4/ProductBuilder.xsd" xmlns:p6="http://www.w3.org/1999/xlink"/>
<RelatedResource p6:type="Simple" p6:href="http://devcms001.photochannel.net:8350/PniProduct/1/Price" p6:role="http://schema.pnimedia.com/2012/4/ProductPrice.xsd" xmlns:p6="http://www.w3.org/1999/xlink"/>
<RelatedResource p6:type="Simple" p6:href="http://devcms001.photochannel.net:8350/PniProduct/1" p6:role="http://schema.pnimedia.com/2012/4/PniProduct.xsd" xmlns:p6="http://www.w3.org/1999/xlink"/>
</RelatedResources>
</Product>

<Product>
<Id>http://devcms001.photochannel.net:8350/PniProduct/2</Id>
<Name>name1</Name>
<RelatedResources>
<RelatedResource p6:type="Simple" p6:href="http://devcms001.photochannel.net:8350/PniProduct/2/Builder" p6:role="http://schema.pnimedia.com/2012/4/ProductBuilder.xsd" xmlns:p6="http://www.w3.org/1999/xlink"/>
<RelatedResource p6:type="Simple" p6:href="http://devcms001.photochannel.net:8350/PniProduct/2/Price" p6:role="http://schema.pnimedia.com/2012/4/ProductPrice.xsd" xmlns:p6="http://www.w3.org/1999/xlink"/>
<RelatedResource p6:type="Simple" p6:href="http://devcms001.photochannel.net:8350/PniProduct/2" p6:role="http://schema.pnimedia.com/2012/4/PniProduct.xsd" xmlns:p6="http://www.w3.org/1999/xlink"/>
</RelatedResources>
</Product>

</Products>
------------------------------

i am using the following XQUERY, but each time i get a "More than one match in current response", i tried encapsulating it in html element but then i don't get any results:

declare namespace ns1='http://schema.pnimedia.com/2012/4/Product.xsd';
declare namespace p6='http://www.w3.org/1999/xlink';
for $z in //ns1:Product
return $z/ns1:Id

*Also how do I hit each return link after that, can I do a loop?
  • Aaronliu's avatar
    Aaronliu
    Frequent Contributor
    it is because the node of Product are in parallel. so using for expression that would return more than one match

    for $z in //ns1:Product[1]
    return $z/ns1:Id


    you can have a try. but I have not such resource to verify it.

    thanks,
    Aaron