Hi Horn,

first af all i know my question is more about general xquery than sedna
> itself, so if that's again the rules of this list please let me know and
> then in the future i'll stick to strictly sedna related dicussion here.
> Now the question :) I have an xml document like this:
>


First of all, yes, this a Sedna-specific discussion list. There is a very
good one to get help from XQuery experts:
http://www.x-query.com/mailman/listinfo/talk . Please, use that list next
time. Anyway, here is the answer :).



> - all products which are for "Home" category - so where the
> product/categories/category/@uid is a descendant or self of the category
> where /shopData/categories/category/@uid=10?
>


To get all subcategories of the 'Home' (top-level) category (including
'Home' itself):

doc("shop")/shopData/categories/category[name eq
'Home']/descendant-or-self::category/@uid


To get all products from the given top-level category (including
subcategories):

let $uids := doc("shop")/shopData/categories/category[name eq
'Home']/descendant-or-self::category/@uid
return doc("shop")/shopData/products/product[categories/category[@id =
$uids]]




> - get all the products of a category with uid=X, if we don't know how
> deep the /shopData/categories/ node is, and where in that hierarchy the
> category with uid=X is? So i guess first i need to find the descendants
> of this category (which has uid X), and then compare that againts the
> /shopData/products/product/categories/ nodes' category childrens' uid
> attributes.
>


Just the same but descendant XPath axis in this case:

let $uids := doc("shop")/shopData/categories/descendant::category[@uid eq
'X']/descendant-or-self::category/@uid
return doc("shop")/shopData/products/product[categories/category[@id =
$uids]]




> If this is not possible in a single flwor query, could somebody tell me
> a nice "xquery-ish" way to solve similar problems? Am i right that for
> such questions fn:descendant() and fn:ancestor and fn:ancestor-or-self
> is the way to go?
>

There are no such functions in XQuery 1.0. All these functions are expressed
via XPath / -> descendant, .. -> ancestor, etc.

In a production application you should consider using value indices (see
http://modis.ispras.ru/sedna/progguide/ProgGuidesu8.html#x14-540002.5.3,
http://modis.ispras.ru/sedna/progguide/ProgGuidesu5.html#x9-310002.2.2) to
significantly increase performance of queries like "get category with @uid
eq X" or "get products within category Y". For example, the last query can
be rewritten like:

for $uid in index-scan('category-by-uid', 'X', 'EQ')
/descendant-or-self::category/@uid
return index-scan('product-by-category', $uid, 'EQ')



Ivan Shcheklein,
Sedna Team
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Sedna-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sedna-discussion

Reply via email to