[xsl] last() and distinct-values 2.0

Subject: [xsl] last() and distinct-values 2.0
From: Jurn Ho <jurn@xxxxxxxxxxxxxxxx>
Date: Tue, 26 Oct 2004 12:08:53 +1000

I'm trying to change our stylesheets over to 2.0 and saxon 8, but am getting confused about the behaviour of the last() function.
My test case is below, it has a variable called $languages, with many <lang> elements.
I wanted to get the 3 distinct languages from there.
If I comment out the last() function, it works as I expect, but when I add the last() function inside the for-each loop I get it returning '2', and only get 1 iteration from the loop.
I expect the last() function to return 3.

Any suggestions/hints would be welcome


<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
  <xsl:template match="/">
    <xsl:variable name="languages">
    <xsl:for-each select="fn:distinct-values($languages/lang)">
      <xsl:value-of select="position()"/>,
      <xsl:value-of select="."/>,
      <xsl:value-of select="last()"/>

Current Thread