I apologize if this is not an issue with SAXON in particular, but I using the expression:

index-of($orderd,current())

inside a for-each statement, and it sometimes (not often) returns a sequence of two (or more) indices, but the sequence $orderd has only unique nodes.

Below I give the closest thing I can make of a short example. Can someone explain what is going on, or is this an error in the implementation?
-David

Example:
$orderd is a sorted sequence of the nodes /data/session, sorted with respect to @startedOn, an expression I convert into an xs:dateTime.

Input Document:

<data>
  <student userID="1" userName="user1"/>
  <session startedOn="01/17/2012 15:01:18">
  </session>
 <session startedOn="11/16/2011 13:31:33">
  </session>
  </data>

XSLT document:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:fn="http://www.w3.org/2005/xpath-functions"
    xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
    xmlns:err="http://www.w3.org/2005/xqt-errors"
    xmlns:saxon="http://saxon.sf.net/"
    xmlns:udf="mynamespace"
    exclude-result-prefixes="xs xdt err fn udf saxon">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="/">
    <xsl:variable name="nodes" as="node()*" select="/data/session"></xsl:variable>
    <xsl:variable name="orderd" as="node()*">
    <xsl:for-each select="$nodes">
    <xsl:sort select="xs:dateTime(xs:dateTime(concat(substring(normalize-space(@startedOn),7,4),'-',substring(normalize-space(@startedOn),1,2),'-',substring(normalize-space(@startedOn),4,2),'T',substring(normalize-space(@startedOn),12,8)))
    )" order="ascending"/>
        <xsl:sequence select="."/>
    </xsl:for-each>
    </xsl:variable>
<output>
    <xsl:for-each select="$nodes">
    <xsl:sort select="position()" order="descending"></xsl:sort>
    <xsl:variable name="index" select="index-of($orderd,current())" as="xs:integer*"></xsl:variable>
    <xsl:variable name="pos" select="position()"></xsl:variable>
    <session   documentOrder="{$pos}"  sortedOrder="{$index}" />
</xsl:for-each>
</output>
</xsl:template>
</xsl:stylesheet>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<output>
   <session documentOrder="1"
            sortedOrder="1 2"
            startedOnSortValue="2011-11-16T13:31:33"/>
   <session documentOrder="2"
            sortedOrder="1 2"
            startedOnSortValue="2012-01-17T15:01:18"/>
</output>



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.