xsl-list
[Top] [All Lists]

Re: [xsl] Find First Descendants That Match Predicate?

2018-12-24 15:24:58
.//title[1] should find the title, then work from there?

On Mon, 24 Dec 2018 at 21:13, Graydon graydon(_at_)marost(_dot_)ca <
xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

On Mon, Dec 24, 2018 at 08:57:40PM -0000, Eliot Kimber
ekimber(_at_)contrext(_dot_)com scripsit:
Using XPath 3:
[snip]
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.

If you meant:

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

then

//descendant::*[self::section][title][not(ancestor::*[self::section][title])]

will give you the first titled element of the type you're looking for.

You'll need to put the actual values for "foo" and "bar" in where there's
a predicate for [self::section]; [self:foo or self::bar]

-- Graydon


-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
--~----------------------------------------------------------------
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>