[xquery-talk] Find All Nodes Between Root Node and Descendant Nodes of Some Type

Eliot Kimber ekimber at contrext.com
Sun Jul 19 07:33:16 PDT 2015

Given this starting document:

Let $doc := 
<a id="a1">
  <a id="a2">
    <a id="a3">

I want to find all the <b> elements descending from <a id="a1"> but not
within nested <a> elements:


This gives me the correct answer:

let $a1 := $doc/a
let $bsInA1 := $a1//b[not(./ancestor::a = ($a1//a))]

My question: With Xpath 3.1, is there a better way to express this query?
I looked at the new outermost() and innermost() operators but I didn't see
a way to apply them to this problem.



Eliot Kimber, Owner
Contrext, LLC

More information about the talk mailing list