xsl-list
[Top] [All Lists]

[xsl] Find First Descendants That Match Predicate?

2018-12-24 14:57:38
Using XPath 3:

I have an XML structure where there are elements with titles (e.g., foo/title, 
bar/title) that may have an arbitrary of untitled wrappers around them, e.g.:

<root>
  <chapter><title>C1</chapter>
  <wrapper>
    <wrapper>
        <section><title>S1</section>            
       </section>
    </wrapper>
    <section><title>S2</title>
      <section><title>S3</title>
      </section>
    </section>
  </wrapper>

Given a starting node, e.g., the root node (but could be any node in the 
hierarchy) I need to find the first titled "child" nodes, so given the chapter 
node  I need to find S1 and S2 but not S3.

I need to do this in a single XPath expression (I'm using the expression to get 
a list of nodes that are then being used elsewhere).

I can't figure out how to construct an expression so that it only returns the 
descendants of the starting node that match the predicate (e.g. *[title]) and 
that are the first such in a breadth-first evaluation.

I feel like there's an obvious solution that I'm just not seeing.

Thanks,

Eliot

--
Eliot Kimber
http://contrext.com
 
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>