- From: Jule Kleine <listmail@web.de>
- Date: Tue, 16 Aug 2005 22:56:10 +0200
- To: www-ql@w3.org
HI,
I got these two hints which was exactly what I needed.
Thanks so much.
Jule
--------------------
> [...]
> I would like to check, if the name of the second element of a parent element is "youngestSon". Is it possible to query this with xpath/xquery (I use xquery with xpath-expressions, in fact I already know the name of the element but want to get sure with an exist-statement, that the element's position is 2) ?
>
> <parent>
> <oldestSon>A</oldestSon>
> <youngestSon>B</youngestSon>
> </parent>
Is this useful?
let $a :=
<parent>
<oldestSon>A</oldestSon>
<youngestSon>B</youngestSon>
</parent>
return $a/*[2] intersect $a/youngestSon
Best wishes,
--Torsten
--
| Prof. Dr. Torsten Grust grust@in.tum.de |
| http://www-db.in.tum.de/~grust/ |
| Database Systems - Technische Universität München (Germany) |
----------------------------------
philippe michiels <philippe.michiels@gmail.com> schrieb am 16.08.05 13:49:17:
>
> Hi,
>
> Is this the sort of expression you are looking for?
>
> for $parent in doc("sample.xml")/parent
> where $parent/oldestSon and $parent/*[2]/self::youngestSon
> return <success/>
>
> Note that XPath has implicit existential semantics, you don't need to
> write the exists-calls every time.
> The expression $parent/*[2]/self::youngestSon checks wether the second
> child of parent is a youngestSon and returns it if it exists.
>
> Best
> Ph
>
> On 8/16/05, Jule Kleine <listmail@web.de> wrote:
> >
> >
> > Hi,
> >
> > I would like to check, if the name of the second element of a parent element is "youngestSon". Is it possible to query this with xpath/xquery (I use xquery with xpath-expressions, in fact I already know the name of the element but want to get sure with an exist-statement, that the element's position is 2) ?
> >
> > <parent>
> > <oldestSon>A</oldestSon>
> > <youngestSon>B</youngestSon>
> > </parent>
> >
> > Note, that the child element names are different. What I dont need is the second son in the following example (therefor I could use /parent/son[position()==2] )
> >
> > <parent>
> > <son>A</son>
> > <son>B</son>
> > </parent>
> >
> > ----
> > My XQuery is:
> >
> > xquery version "1.0";
> >
> > for $parent in doc("sample.xml")/parent
> > let $oldestson:= $parent/oldestSon
> > let $youngestson:= $parent/youngestSon
> >
> > where (
> > exists($parent)
> > and exists($oldestson)
> > and exists($youngestson)
> > )
> >
> > return (
> > <success/>
> > )
> >
> > -----
> > The Query checks, if in the sample-document there exists a parent with oldestSon and youngestSon, but doesnt make sure, that oldestSon comes before youngestSon. I could use
> >
> > where $oldestson < $youngestson
> >
> > but have cases where I dont know all elements (and therefor nothing about oldestson), so would like something like
> >
> > where $youngestson "IS SECOND CHILD OF PARENT"
> >
> >
> >
> > Thank you for any help!!!
> >
> > Jule
> >
_________________________________________________________________________
Mit der Gruppen-SMS von WEB.DE FreeMail können Sie eine SMS an alle
Freunde gleichzeitig schicken: http://freemail.web.de/features/?mc=021179
Received on Tuesday, 16 August 2005 20:56:25 UTC