Re: [xsl] Pattern notation for preceding-sibling

Subject: Re: [xsl] Pattern notation for preceding-sibling
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 12 Aug 2014 16:09:44 -0000
Note that your subjectline suggests patterns, but your question is about
expressions. Patterns (as in <xsl:template match="X">) cannot use the
preceding-sibling axis, unless inside a predicate.


> From: Heiko Niemann kontakt@xxxxxxxxxxxxxxxx [mailto:xsl-list-
> Sent: Monday, August 11, 2014 11:50 AM
>
>
> /foo/E/preceding-sibling::(A,N)

Indeed, this is currently disallowed syntax.

>
> But it does not, so I either have to write
>
> /foo/E/(preceding-sibling::A, preceding-sibling::N) or
>
> /foo/E/*[name() = ('A','N')]
>

These two are not the same, the latter takes the children of E, not the
preceding siblings.

You can also do:
/foo/E/preceding-sibling::*[self::A | self::N]

Or, if you have a sequence of names, you can use:
/foo/E/preceding-sibling::*[name() = $names]

Or you can revert the test and use following-sibling in a predicate
(potentially shortest):
/foo/(A, N)[following-sibling::E]

The only reason that expressions such as (A, N) are shorter, is that they are
implicitly using the child axis. You are actually writing (child:A, child:N).
The axis specification is required, which is why, if you are not processing
the default child axis, expressions can quickly get verbose, because the axis
has to be specified for each node test.

Note that if you have multiple sibling E elements, the result may not be what
you expect, you will return overlapping elements.

Cheers,

Abel Braaksma
Exselt streaming XSLT 3.0 processor
http://exselt.net

Current Thread