Re: XQuery - XPath: Get position of Element TAG (not element)

You might want to write this as:

xquery version "1.0";

for $parent in doc("sample.xml")/parent
let $oldestson:= $parent/oldestSon
let $youngestson:= $parent/youngestSon

where (
$parent/*[1] instance of element(oldestSon)
and $parent/*[2] instance of element(youngestSon)
)

return (
<success/>
)

                                                -- Andrew

--------------------
Andrew Eisenberg
IBM
4 Technology Park Drive
Westford, MA  01886

andrew.eisenberg@us.ibm.com
Phone: 978-399-5158    Fax: 978-399-7012





Jule Kleine <listmail@web.de> 
Sent by: www-ql-request@w3.org
08/16/2005 07:07 AM

To
www-ql@w3.org
cc

Subject
XQuery - XPath: Get position of Element TAG (not element)








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















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 Friday, 19 August 2005 15:21:07 UTC