Subject: Re: [xsl] Find First Descendants That Match Predicate? From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Tue, 25 Dec 2018 18:42:22 -0000 |
Hi, How about .//*[title] except .//*[title]//*[title] ? (or the same along descendant:: ) Cheers, Happy Solstice, etc. Wendell On Mon, Dec 24, 2018 at 5:34 PM Eliot Kimber ekimber@xxxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > Thanks--setting the $here variable was the trick I was failing to see. > > Cheers, > > E. > > -- > Eliot Kimber > http://contrext.com > > > o;?On 12/24/18, 3:31 PM, "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > given > > <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> > > > (I moved /chapter to the end?) > > and > > <xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > > > <xsl:template match="chapter"> > > <xsl:message select=" > let $here:=. return > .//section[empty(ancestor::*[title] except > $here/ancestor-or-self::*[title])]/title > "/> > > </xsl:template> > > </xsl:stylesheet> > > > the xpath in the message produces > > <title>S1</title><title>S2</title> > > David > > On Mon, 24 Dec 2018 at 21:13, Graydon graydon@xxxxxxxxx > <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > > > > On Mon, Dec 24, 2018 at 08:57:40PM -0000, Eliot Kimber ekimber@xxxxxxxxxxxx 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 > > > > > > -- Wendell Piez | wendell -dot- piez -at- nist -dot- gov | http://www.wendellpiez.com pellucidliterature.org | github.com/wendellpiez | gitlab.coko.foundation/wendell - pausepress.org
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Find First Descendants Th, Eliot Kimber ekimber | Thread | Re: [xsl] Find First Descendants Th, Eliot Kimber ekimber |
Re: [xsl] Find First Descendants Th, Eliot Kimber ekimber | Date | Re: [xsl] Find First Descendants Th, Eliot Kimber ekimber |
Month |