Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 274217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:34:32+00:00 2026-05-12T00:34:32+00:00

I know there is the current() function to retrieve the current node in XSL,

  • 0

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?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T00:34:33+00:00Added an answer on May 12, 2026 at 12:34 am

    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:

    1. You do: <xsl:apply-templates select="*" /><!-- select 3 nodes (a,b,c) -->
    2. The XSLT processor makes list of nodes to be processed (a,b,c)
    3. For each of those nodes, the XSLT processor selects and executes a matching template
    4. When the template is called, the current() node is defined, and position() is defined, but other than that the template has no knowledge of the execution flow.
    5. Execution order is subject to the processors preferences, as long as the outcome is guaranteed to be the same. Your (theoretical) predictions might be true for one processor, and wrong for another. For a side-effects free programming language like XSLT, knowledge like this would be a dangerous thing, I think (because people would start to rely on execution order).

    You can do use the following::sibling or preceding::sibling XPath axes, but that’s something different from knowing what node will be processed next

    EDIT

    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):

    <items>
      <item type="a"></item>
      <item type="a"></item>
      <item type="a"></item>
      <item type="a"></item>
      <item type="b"></item>
      <item type="e"></item>
    </items>
    

    XSLT

    <xsl:stylesheet 
      version="1.0" 
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    >
    
      <xsl:template match="/items">
        <!-- copy the root element -->
        <xsl:copy>
          <!-- select those items that differ from any of their predecessors -->
          <xsl:apply-templates select="
            item[
              not(@type = preceding-sibling::item/@type)
            ]
          " />
        </xsl:copy>
      </xsl:template>
    
      <xsl:template match="item">
        <!-- copy the item to the output -->
        <xsl:copy-of select="." />
      </xsl:template>
    
    </xsl:stylesheet>
    

    Output:

    <items>
      <item type="a"></item>
      <item type="b"></item>
      <item type="e"></item>
    </items>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 212k
  • Answers 212k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I accidentally downloaded the wrong distribution, which did not contain… May 12, 2026 at 10:24 pm
  • Editorial Team
    Editorial Team added an answer You just need to set the truncate-lines variable to nil… May 12, 2026 at 10:24 pm
  • Editorial Team
    Editorial Team added an answer See this SO question how to create a RSACryptoServiceProvider from… May 12, 2026 at 10:24 pm

Related Questions

I'm trying to work out a way of passing the web current http context
Using this example coming from Wikipedia, in which DrawSquare() calls DrawLine() : (Note that
I am trying to write a static function to Or two expressions, but recieve
I have a function that is often called inside of other functions, and I'd

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.