The period '.' in contains() means that you are passing the current sequence 
item (aka context) into the contains() function.
Imagine that query [1] is actually doing a for-each loop on each <title/> and 
the predicate in square brackets is applying a 'where' statement on each 
iteration.  You can also rewrite query [1] as query [3].

Your other query [2] returned multiple items or a sequence of strings.  You did 
not specify a predicate / selection criteria so you got an 'array' of strings.

[1] fn:doc("xmldatabasefile.xml")/bookstore/book/title[fn:contains(.,'Learning 
XML')]
[2] fn:doc("xmldatabasefile.xml")/bookstore/book/title/text()
[3] for $book-title in doc('xmldatabasefile.xml')/bookstore/book/title
        Where contains($book-title/text(), 'Learning XML')
        Return $book-title/text()


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of 
e-letter
Sent: Friday, December 27, 2013 6:04 AM
To: [email protected]
Cc: [email protected]
Subject: Re: [xquery-talk] xpath1 text node contains attribute, equivalent in 
xpath2

On 27/12/2013, Liam R E Quin <[email protected]> wrote:
> On Fri, 2013-12-27 at 09:20 +0000, e-letter wrote:
>> Xpath1 specification ยง 4.2 string functions
>> (http://www.w3.org/TR/xpath/#section-String-Functions) describes a
>> "contains" function, but this was not found in xpath2;
>
> Better to use the XPath 2 Functions and Operators spec, which does
> indeed list fn:contains().
>

{
                let $x := 
fn:doc("xmldatabasefile.xml")/bookstore/book/title[fn:contains(.,'Learning
XML')]/parent::*
                return $x
        }

returns:

...<p>
         <book category="WEB">

            <title lang="en">
                                Learning XML

            </title>

            <author>Erik T. Ray</author>

            <year>2003</year>

            <price>39.95</price>

         </book>
      </p>...

Why is the full stop applied before the comma, because this is not specified as 
an option in the specification about 'fn:contains'?

>> Is it possible to remove the xml elements from the output file?
>
> Change return $x to return $x/text() maybe
>

Not quite, returns:

...<p>





      </p>...


if 'return' is changed to 'return $x/element()', the result is as 'return $x', 
but interestingly a removal of new line white space.

_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

________________________________

The contents of this message may be privileged and confidential. Therefore, if 
this message has been received in error, please delete it without reading it. 
Your receipt of this message is not intended to waive any applicable privilege. 
Please do not disseminate this message without the permission of the author.

Please consider the environment before printing this e-mail


_______________________________________________
[email protected]
http://x-query.com/mailman/listinfo/talk

Reply via email to