I know there is the current() function to retrieve the current node in XSL, but is there a way to be able to reference the “previous” and “next” nodes in reference to the current position?
I know there is the current() function to retrieve the current node in XSL,
Share
No. The current context cannot know which nodes are “next” or “previous”.
This is because when, for example, templates are applied, the mechanics go like this:
<xsl:apply-templates select="*" /><!-- select 3 nodes (a,b,c) -->current()node is defined, andposition()is defined, but other than that the template has no knowledge of the execution flow.You can do use the
following::siblingorpreceding::siblingXPath axes, but that’s something different from knowing what node will be processed nextEDIT
The above explanation tries to answer the question as it has been asked, but the OP meant something different. It’s about grouping/outputting unique nodes only.
As per the OP’s request, here a quick demonstration of how to achieve a grouping using the XPath axes.
XML (the items are pre-sorted):
XSLT
Output: