with XPath 1.0, select all following sibling elements of name "foo" up to the first non-"foo" element

"Wolfhart Totschnig [email protected]" <[email protected]> Thu, 18 Feb 2021 01:32:17 -0000
Newsgroups gmane.text.xml.xsl.general.mulberrytech
Message-ID <[email protected]>
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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/3329386
or by email: [email protected]
--~--