xsl-list
[Top] [All Lists]

Re: [xsl] Understanding XPath contains function

2006-07-30 06:23:17
On 7/30/06, Ferdinand Soethe <xsl-list(_at_)soethe(_dot_)net> wrote:
I'm confused by the difference in results when running the following
xpath expressions against the same document:

/common/Oberbereich[6][.//@Kursart='Bildungsurlaub']

will give me Oberbereich[6] as a result as expected (because it has
child elements that have a Kursart-Attribute of that value.

While
/common/Oberbereich[6][contains(.//@Kursart,'Bildungsurlaub')]
will not give me any results where it should at least give me the same
or more results that the previous expression, should it not?


In the second case the first argument to the function
 contains()
is a node-set.

In XPath 1.0 when a function expects a single argument and a node-set
of two or more nodes is passed, (only) the first node is taken as the
argument.

In your concrete case the first node passed is
   (.//@Kursart)[1]

and it happens so, that it doesn't contain the string
 'Bildungsurlaub'

Therefore, the reference to the contains() function returns false()
and the XPath expression
  /common/Oberbereich[6][contains(.//@Kursart,'Bildungsurlaub')]

does not select any node.

Hope this helped.

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>