[xquery-talk] xpath1 text node contains attribute, equivalent in xpath2
CMisztur at macleanfogg.com
Fri Dec 27 08:02:07 PST 2013
The period '.' in contains() means that you are passing the current sequence item (aka context) into the contains() function.
Imagine that query  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  as query .
Your other query  returned multiple items or a sequence of strings. You did not specify a predicate / selection criteria so you got an 'array' of strings.
 fn:doc("xmldatabasefile.xml")/bookstore/book/title[fn:contains(.,'Learning XML')]
 for $book-title in doc('xmldatabasefile.xml')/bookstore/book/title
Where contains($book-title/text(), 'Learning XML')
From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf Of e-letter
Sent: Friday, December 27, 2013 6:04 AM
To: liam at w3.org
Cc: talk at x-query.com
Subject: Re: [xquery-talk] xpath1 text node contains attribute, equivalent in xpath2
On 27/12/2013, Liam R E Quin <liam at w3.org> 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
<author>Erik T. Ray</author>
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:
if 'return' is changed to 'return $x/element()', the result is as 'return $x', but interestingly a removal of new line white space.
talk at x-query.com
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
More information about the talk