[xquery-talk] retrieving node depending on its context

Philippe Michiels philippe.michiels at ua.ac.be
Sun May 8 16:26:50 PDT 2005


A quick solution:

let $x := <p>His name was <name>Christian</name> and he lived in
<place>Kyoto</place>.<name>test</name></p>
return
  for $y in $x/descendant::name
  let $text := $y/parent::node()/child::text()[. >> $y][1]
  where fn:starts-with(fn:trim($text), " and")
  return $y

Note that you have to take into account the leading space of the text node 
after the name-tag.

--Ph

On Sunday 08 May 2005 14:47, Christian Wittern wrote:
> Dear XQuery users,
>
> Having tried to solve the following problem without success for a
> while, I  would be grateful for any pointers or advice:
>
> Given sample data like the following:
>
> <p>His name was <name>Christian</name> and he lived in
> <place>Kyoto</place>.</p>
>
> I would like to retrieve with XQuery the "<name>" node based on the
> content of the following text, e.g. for example only if the <name> is
> followed by a text node that starts with the word "and".
>
> I would like to avoid using following or following-sibling and assume
> I would have to use "<<" and ">>", but I can't think of how to do
> that.
>
> Any help appreciated,
>
> Chris

-- 
Philippe Michiels
Universiteit Antwerpen
ADReM (Advanced Database Research and Modelling)
http://www.adrem.ua.ac.be/~michiels


More information about the talk mailing list