RE: [xsl] select immediately following siblings with constraints?

Subject: RE: [xsl] select immediately following siblings with constraints?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 23 Feb 2006 19:10:38 -0000
> XPath gives 
> no way to look along an axis up to a particular point and no further. 
> (Well, actually I shouldn't say this categorically about XPath 2.0 
> without giving it some good hard thought first, or inviting others to 
> demonstrate a method. :-) 

Let's say you want all the nodes on a forwards axis X up to and excluding
the first one that satisfies condition PRED. Then you can write

for $stop in x::node()[PRED][1] return x::node()[.<<$stop]

substituting >> if it's a reverse axis. If you want to include the stop
node, 

return (x::node()[.<<$stop], $stop)

It's not vastly elegant - this is one of those things that could have been
done so much better with higher-order functions - but it's workable. It's
not too difficult to optimize, either, though Saxon doesn't attempt this
currently.

Michael K

Current Thread