[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Fwd: Re : about a query which have a contains function

Michael Kay mike at saxonica.com
Wed Oct 27 11:15:48 PDT 2010


 Fwd: Re :  about a query which have a contains
	function
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 :  about a query which have a contains function
> Date: 	Wed, 27 Oct 2010 00:51:47 +0100 (BST)
> From: 	Mohamed kharrat <http://x-query.com/mailman/listinfo/talk>
> To: 	Michael Kay <http://x-query.com/mailman/listinfo/talk>
>
>
>
> 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 <http://x-query.com/mailman/listinfo/talk>
> *À :* http://x-query.com/mailman/listinfo/talk
> *Envoyé le :* Mar 26 octobre 2010, 23h 29min 26s
> *Objet :* Re:  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
>>
>>
>> _______________________________________________
>> http://x-query.com/mailman/listinfo/talk
>> 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
>
>
>
> _______________________________________________
> http://x-query.com/mailman/listinfo/talk
> 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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.