All X elements below Y, but before another, descendent, Y

Posted by JPM on Stack Overflow See other posts from Stack Overflow or by JPM
Published on 2012-10-15T01:55:02Z Indexed on 2012/10/15 3:37 UTC
Read the original article Hit count: 143

Filed under:
|
<div n="a">
  . . . 
    . . .
      <spec>red</spec>
      <spec>green</spec>
      . . .
         <div n="b">
            . . .
              <spec>blue</spec>
            . . .
         </div>
         <div n="c">
           <spec>yellow</spec>
         </div>
      . . .
    . . .
  . . .
</div>

When the current element is <div n="a">, I need an XPATH expression that returns the red and green elements, but not the blue and yellow ones, as .//spec does.

When the current element is <div n="b">, the same expression needs to return the blue element; when <div n="c">, the yellow element.

Something like .//spec[but no further than another div if there is one]

© Stack Overflow or respective owner

Related posts about xslt

Related posts about xpath