xsl-list
[Top] [All Lists]

Re: [xsl] Best Way to Select Following Elements With An Ancestor?

2014-03-22 12:16:18
On Sat, Mar 22, 2014 at 1:46 PM, Eliot Kimber <ekimber(_at_)contrext(_dot_)com> 
wrote:
I have a document where each child of the root element establishes a
unique content with regard to the output result (in this case,
corresponding to InDesign frames).

For a given descendant of one of these elements I need to know if there
are any following elements within the same context.

I may be thinking about this the wrong way, but it seems like the
situation you describe (some following element exists that is a
descendant of the same context-setting node) is equivalent to saying
"Either this node has a following-sibling, or some ancestor of it has
a following-sibling, not counting the context-setting nodes."

Is the above accurate?

If the above understanding is correct, then a more elegant answer
would be to use recursive functions:

Define a recursive function that uses the following logic:
f($x) = false if $x is one of the context nodes (/child::element())
f($x) = true if $x has any following::sibling elements.
f($x) = f($x/..) if neither of the above statements resolves the answer.

Or, without recursive functions:

Define a variable containing the context-setting nodes:
$context_nodes = /child::element()

Then the predicate you want is:

boolean(ancestor-or-self::element()[not($context_nodes)]/following-sibling::element()

-David

-- 

"A false conclusion, once arrived at and widely accepted is not
dislodged easily, and the less it is understood, the more tenaciously
it is held." - Cantor's Law of Preservation of Ignorance.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--