Fwd: Re : [xquery-talk] about a query which have a contains
function
Michael Kay
mike at saxonica.com
Wed Oct 27 11:15:48 PDT 2010
You are using contains() to test whether a sequence S contains a value
V. If you read the spec, you'll see that that isn't what contains() does
- it tests whether a single string has a particular substring within it.
If you want to test whether the collection of books contains one whose
title is "Java Web Services", you can simply use the "=" operator thus:
{$x/books/title = $y} (no need for the /text()). But there's something
else wrong with your query - it returns the whole document if there is a
match, and nothing if there isn't. If you want to return the <book>
element having the relevant title, you can write the query as
doc('books.xml')/books/book[title='Java Web Services']
or if you're in love with FLWOR expressions,
for $x in doc('books.xml')/books/book
where $x/title = 'Java Web Services'
return $x
Michael Kay
Saxonica
On 27/10/2010 08:28, Michael Kay wrote:
>
> Forwarding an off-list reply to the list. (Mohamed, please don't go
> off-list).
>
> MK
>
> -------- Original Message --------
> Subject: Re : [xquery-talk] about a query which have a contains function
> Date: Wed, 27 Oct 2010 00:51:47 +0100 (BST)
> From: Mohamed kharrat <med_khr at yahoo.fr>
> To: Michael Kay <mike at saxonica.com>
>
>
>
> well,
> i have this query
>
> let $y:="Java Web Services"
>
> for $x in doc("query/books.xml")
>
> where contains($x/books/book/title/text(),$y)
>
> return $x
>
> it does't return a value, but it return [err:XPTY0004]A sequence with
> more than one item does not match the type text()? according to the
> Sequence Type Matching rules.
> if i write return $x/books/book/authors/author the same thing, it
> does't work
> it work only if i write return 1 , in this case when the query find
> "Java Web Services" it return 1
>
> thank you
>
> ------------------------------------------------------------------------
> *De :* Michael Kay <mike at saxonica.com>
> *À :* talk at x-query.com
> *Envoyé le :* Mar 26 octobre 2010, 23h 29min 26s
> *Objet :* Re: [xquery-talk] about contains function
>
> On 26/10/2010 21:30, Mohamed kharrat wrote:
>> Dear sir,
>> i need to use contains function with NUX JAVA API
>> second question
>> i need to query a collection.
>>
>> how to do that.
>>
>> thank you
>>
>>
>> _______________________________________________
>> talk at x-query.com
>> http://x-query.com/mailman/listinfo/talk
> It would be useful to know how far you have got, and where you got stuck.
>
> Are you able to run queries at all - or is it this specific query you
> are having difficulty with?
>
> Is your problem with the query, or with the Java API?
>
> What did you try, and how did it fail?
>
> We need to know the answers to these questions so we can try to
> explain what to do in terms you are likely to understand.
>
> When people have problems with the contains function it is often
> because they tried to guess what it did instead of reading the
> specification; the behaviour of a function can sometimes be guessed
> from its name, but not always.
>
> Michael Kay
> Saxonica
>
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20101027/3c6f454c/attachment.htm
More information about the talk
mailing list