Hi,
While processing a XML-file with xquery I need to find the nearest ancestor that has a child-element with a certain ID-value( $refID).
I found this solution [1] but I was wondering if also a solution is possible that makes use of the ancestor being a reverse-axis[ 2].
That way I could replace the [ last()]-predicate with a [1]-predicate, which I find more transparant. Also my gut-feeling tells me that would be a more efficient solution then the current one.
[ 1] ( $element/ancestor::*/child::*[ @ID = $refID] ) [ last()]
[ 2] https://www.w3.org/TR/xquery-30/#id-predicate
TIA for your replies,
Take care,
Rob Stapper
Hi Rob,
I found this solution [1] but I was wondering if also a solution is possible that makes use of the ancestor being a reverse-axis[ 2].
[ 1] ( $element/ancestor::*/child::*[ @ID = $refID] ) [ last()]
You probably need two id tests:
$element/ancestor::*[*/@ID = $refID][1]/*[@ID = $refID]
I guess it depends mostly on the input if the first or second alternative will be faster.
Hope this helps, Christian
Hi Christian,
I've been thinking about that solution too.
Thanx for your reply, Rob
-----Oorspronkelijk bericht----- Van: Christian Grün [mailto:christian.gruen@gmail.com] Verzonden: woensdag 25 mei 2016 16:40 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] searching for the nearest ancestor
Hi Rob,
I found this solution [1] but I was wondering if also a solution is possible that makes use of the ancestor being a reverse-axis[ 2].
[ 1] ( $element/ancestor::*/child::*[ @ID = $refID] ) [ last()]
You probably need two id tests:
$element/ancestor::*[*/@ID = $refID][1]/*[@ID = $refID]
I guess it depends mostly on the input if the first or second alternative will be faster.
Hope this helps, Christian
PS. I opted for your version because it's consistent with the map:contains, map:get functions.
-----Oorspronkelijk bericht----- Van: Christian Grün [mailto:christian.gruen@gmail.com] Verzonden: woensdag 25 mei 2016 16:40 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] searching for the nearest ancestor
Hi Rob,
I found this solution [1] but I was wondering if also a solution is possible that makes use of the ancestor being a reverse-axis[ 2].
[ 1] ( $element/ancestor::*/child::*[ @ID = $refID] ) [ last()]
You probably need two id tests:
$element/ancestor::*[*/@ID = $refID][1]/*[@ID = $refID]
I guess it depends mostly on the input if the first or second alternative will be faster.
Hope this helps, Christian
basex-talk@mailman.uni-konstanz.de