[XQZone General] XQuery question
David Sewell
dsewell at virginia.edu
Wed Dec 28 06:55:41 PST 2005
On Wed, 28 Dec 2005, Sandesh Pai wrote:
> Hi!
> I am struggling to query a part of the node
>
> eg:
> I have node
> <root>
> <a>
> It starts with
> <tag1>hello</tag1>
> I need This Content
> <tag2>I need this too</tag2>
> I need Till here
> <tag3>goodbye</tag3>.
> </a>
> </root>
>
> Here I want to get the content which are in between <tag1> and <tag3>
> ( i.e
> I need This Content
> <tag2>I need this too</tag2>
> I need Till here
> )
>
> Is it possible to query for this ? If yes please give an example
This code will work with ML Server:
let $input :=
<root>
<a>
It starts with
<tag1>hello</tag1>
I need This Content
<tag2>I need this too</tag2>
I need Till here
<tag3>goodbye</tag3>.
</a>
</root>
for $n in $input/a/node()
where $n >> $input/a/tag1[1] and $n << $input/a/tag3[1]
return $n
The basic idea is to identify the two nodes that surround the content
you want to return, then use the ">>" and "<<" operators to return the
nodes in between. The above code returns a sequence of nodes that will
not be well-formed XML by itself (you want to wrap it inside something,
probably). (Some XQuery processors will complain unless you do this. If
you run the above code by itslef in Saxon 8, for example, it will give
the error message "Cannot serialize output nodes".)
--
David Sewell, Editorial and Technical Manager
Electronic Imprint, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4318 USA
Courier: 310 Old Ivy Way, Suite 302, Charlottesville VA 22903
Email: dsewell at virginia.edu Tel: +1 434 924 9973
Web: http://www.ei.virginia.edu/
More information about the General
mailing list