[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: with XPath 1.0, select all following sibling eleme

Subject: Re: with XPath 1.0, select all following sibling elements of name "foo" up to the first non-"foo" element
From: "Wendell Piez wapiez@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Feb 2021 16:06:01 -0000
Re:  with XPath 1.0
Hi,

With a sequence of variable declarations:

<xsl:variable name="name" select="name()"/>
<xsl:variable name="followers" select="following-sibling::*[name()=$name]"/>
<xsl:variable name="interlopers"
select="following-sibling::*[not(name()=$name)] |
following-sibling::*[not(name()=$name)]/following-sibling::*"/>
<xsl:variable name="invited" select=". |
$followers[not(count(.|$interlopers)=count($interlopers))]"/>

Note: untested.

Good luck,
Wendell


On Wed, Feb 17, 2021 at 8:32 PM Wolfhart Totschnig
wolfhart.totschnig@xxxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
wrote:

> Dear list,
>
> I am facing an XPath problem for which I cannot find the solution. I
> want to select all following sibling elements of name "foo" up to the
> first non-"foo" element. So, in the following case, the first two <foo>
> elements should be selected:
>
> <foo/>
> <foo/>
> <bar/>
> <foo/>
>
> In the following case, all three <foo> elements should be selected:
>
> <foo/>
> <foo/>
> <foo/>
>
> And in the following case, nothing should be selected:
>
> <bar/>
> <foo/>
> <foo/>
>
> I came up with the following non-working approach:
>
>              <xsl:choose>
>                  <xsl:when
> test="not(following-sibling::*[not(self::foo)])">
>                      <xsl:value-of select="following-sibling::*"/>
>                  </xsl:when>
>                  <xsl:otherwise>
>                      <xsl:value-of
>
> select="following-sibling::*[not(self::source)][1]/preceding-sibling::*[self::source][preceding-sibling::current()]"/>
>                  </xsl:otherwise>
>              </xsl:choose>
>
> That is, test whether there are non-"foo" following siblings. If there
> are none, take all following siblings. If there are, go forward to the
> first non-"foo" sibling, and from there go backwards, taking all the
> "foo" siblings up to the current node.
>
> But this does not work. Apparently, the expression
> "preceding-sibling::current()" is not a valid construct. So what is the
> correct way to do what I have in mind (or a simpler solution, if there
> is one). Please note that this stylesheet needs to be executed by a web
> browser, and so the solution has to remain within XPath 1.0.
>
> Thanks in advance for your help!
> Wolfhart
> 
>
>

-- 
...Wendell Piez... ...wendell -at- nist -dot- gov...
...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.