Wouldn't a simpler option be to use "current()" rather than "."

<xsl:template match="/">
   <test>
       <xsl:variable name="tokens" select="tokenize('foo bar bat', '
')"/>
       <xsl:for-each select="1 to count($tokens)">
           <token index="{.}">
               <xsl:value-of select="$tokens[current()]"/>
           </token>
       </xsl:for-each>
   </test>
</xsl:template>


On Tue, Jun 5, 2012 at 2:15 PM, Gunther Rademacher <grd@gmx.de> wrote:
Eric van der Vlist wrote:
> Hmmm... When count($tokens) is equal to 3, why should there
> be any difference between "1 to count($tokens)" and "1 to
> 3"?

Agreed, I don't see a difference either.

> Shouldn't the <xsl:for-each/> the context item to the atomic
> values 1, 2 and 3?

Yes.

> > The workaround thus is what you want in the first place.
>
> Yes, but I don't understand why I need this variable.

Because the predicate opens a new, inner context. The XPath
recommendation (http://www.w3.org/TR/xpath20/#dt-context-item)
explains it as follows:

  "Certain language constructs, notably the path expression
  E1/E2 and the predicate E1[E2], create a new focus for the
  evaluation of a sub-expression. In these constructs, E2 is
  evaluated once for each item in the sequence that results
  from evaluating E1. Each time E2 is evaluated, it is
  evaluated with a different focus. The focus for evaluating
  E2 is referred to below as the inner focus, while the focus
  for evaluating E1 is referred to as the outer focus. The
  inner focus exists only while E2 is being evaluated. When
  this evaluation is complete, evaluation of the containing
  expression continues with its original focus unchanged."

Best regards
Gunther






--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--

"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.