Re: [xsl] how to test previous node name

Subject: Re: [xsl] how to test previous node name
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 12 Feb 2007 12:46:58 +0100
Florent Georges wrote:
Abel Braaksma wrote:
the parent node if the current node is its first child,
and the preceding sibling, if the current node is not the
first child of its parent.

Which reads the following in XPath:


( parent::*[1]|preceding-sibling::*[1] )[last()]

Nice shortcut! I like it much better than my original solution (which looks awkward with generate-id). The predicate [1] is not needed on parent::, it always returns one node.


The OP wanted to test for 'test1' or 'text' nodes, which, when added to your solution, becomes:

(parent::* | preceding-sibling::*[1] )[last()][self::test1 | self::text]

-- Abel

Current Thread