Strange error message for XPath 2.0

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Ormek
Posts: 10
Joined: Mon Sep 05, 2005 12:50 pm

Strange error message for XPath 2.0

Post 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
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
Post Reply