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 7188661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:08:02+00:00 2026-05-28T19:08:02+00:00

(Note: This post has been edited to show specific use case. See bottom.) I

  • 0

(Note: This post has been edited to show specific use case. See bottom.)

I want to use the current node’s value of position() inside an xpath expression (in which the context changes). Unfortunately, I don’t see any simple way of doing this because current()/position() appears to always equal 1.

[I assume this is because current()/position() says “what is the position of node current() within the context of… the one-node set containing only current().]

To be specific, let’s say I have a sequence of nodes $seq and I want to return the *n*th node in the sequence ($seq[n]) where n equals the current value of position() (that is, the value of position() prior to the statement being evaluated).

Clearly, $seq[position()] won’t work, because that expands to seq[position() = position()], returning the entire sequence.

$seq[position(current())] is jibberish.

The only thing I could find that appears to maybe work is

for $pos in position() return $seq[$pos]

I assume there is a simpler way.

Edit
It was requested that I give a more specific example of what I’m trying to do. I actually found the first person’s answer sufficient to my needs, though not much simpler than what I had come up with myself (the “for $pos in position() return $correctOrder[$pos]” option).

Here is the actual situation: I have a set of “session” nodes, each of which has a @startTime attribute. I want to find which ones are out of order with respect to that @startTime attribute, or at least not in the proper place they would be if the input document’s nodes were properly sorted by @startTime.

This is just one of many tests that are performed on each of the session nodes.

What I wanted to do was create a sequence that had the nodes in the correct order and compare the nth element in the document-ordered sequence with the nth-element in the correctly ordered sequence.

Something like this:

<xsl:template match="/">
<xsl:variable name="correctOrder" as="node()*">
<xsl:for-each select="session">
<xsl:sort select="@xs:dateTime(@startTime)"/>
<xsl:sequence select="."/>
</xsl:for-each>
</xsl:variable>

<xsl:for-each select="session">

<—- Lots of various tests —->

<xsl:if test="current()/@startTime eq 
$correctOrder[<-here I want to put the value "position()" had prior to this <xsl:if> statement->]/@startTime"
<error description="Node out of order."/>
</xsl:if>

<— Lots of other tests—–>

</xsl:for-each>
  • 1 1 Answer
  • 0 Views
  • 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-28T19:08:03+00:00Added an answer on May 28, 2026 at 7:08 pm

    Well as you have tagged your question as XSLT 2.0 I would use a variable e.g.

    <xsl:variable name="pos" as="xs:integer" select="position()"/>
    

    and then use that variable e.g.

    <xsl:sequence select="$seq[$pos]"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it a bad practice to mix GET and POST? (note this is in
Note This is not a REBOL-specific question. You can answer it in any language.
I'm sure this question has been asked a thousand times but after an hour
Can anyone think of a way to reverse a POST that has been issued
Note These URL's are likely not available. Facebook has been updated a number of
This has been bothering me for a while now: Could not load file or
Note: This was posted when I was starting out C#. With 2014 knowledge, I
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Note: this is a different problem to https - it's related to privacy security
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using

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.