xsl-list
[Top] [All Lists]

Re: [xsl] Pattern notation for preceding-sibling

2014-08-12 11:09:56
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(_at_)heiko-niemann(_dot_)de [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
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>