Page 1 of 1

Strange error message for XPath 2.0

Posted: Fri Dec 16, 2005 2:45 pm
by Ormek
Hi,

I just used the following expression to find all elements whose textual content starts with "LV_EVAL".

Code: Select all

//*[starts-with(text(),"LV_EVAL")]
This works for XPath 1.0. With XPath 2.0 I get the message:
A sequence of more than one item is not allowed as the first argument of starts-with()
I did not look up XPath 2.0 syntax, but just guessed the above expression. Is what I experience correct behaviour?

Regards,
Oliver

Posted: Fri Dec 16, 2005 4:20 pm
by george
Hi Oliver,

The fist argument of starts-with in XPath 2.0 is xs:string
http://www.w3.org/TR/xquery-operators/#func-starts-with

When you say text() in XPath that returns a sequence containing all the text nodes inside the context element (if the context node is an element). If you have multiple nodes in the retuned sequence (this is the case when you use mixed content models for instance) then you will get more nodes thus the error.

You should use something like

Code: Select all


//*[starts-with(text()[1],"x")]
or

Code: Select all


//*[starts-with(string-join(text(), ""),"x")
Best Regards,
George