W3C home > Mailing lists > Public > www-ql@w3.org > July to September 2005

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

From: Jule Kleine <listmail@web.de>
Date: Tue, 16 Aug 2005 13:07:41 +0200
Message-Id: <573844782@web.de>
To: www-ql@w3.org


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) ?


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] )


My XQuery is:

xquery version "1.0";

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

where (
and exists($oldestson)
and exists($youngestson)

return (

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!!!


Thank you for any help!
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 11:07:47 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:17:17 UTC