[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 := 
<root>	
<a id="a1">
  <b>b1</b>
  <b>b2</b>
  <c>
    <b>b6</b>
  </c>
  <a id="a2">
    <b>b3</b>
    <b>b4</b>
    <a id="a3">
      <b>b5</b>
    </a>
  </a>
 </a>
 </root>

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

<b>b1</b>
    <b>b2</b>
    <b>b6</b>


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.

Thanks,

Eliot

----
Eliot Kimber, Owner
Contrext, LLC
http://contrext.com





More information about the talk mailing list