RE: Sequences of numeric values in XPath predicate expressions

> > Use: Since <xsl:copy-of> can now be used to copy a sequence
> > of items, it would be excellent if one could write
> > 
> > <xsl:copy-of select="foo[1 to 4]"/>
> > 
> > instead of the more long-winded
> > 
> > <xsl:for-each select="1 to 4">
> >      <xsl:copy-of select="foo[.]"/>
> > </xsl:for-each>
> > 

I should also have mentioned that your example is incorrect. "." within a
predicate applied to a node-set always selects a node, so its effective
boolean value is true.

You meant to write:

  <xsl:for-each select="1 to 4">
    <xsl:variable name="n" select="."/>
    <xsl:copy-of select="foo[$n]"/>
  </xsl:for-each>

But of course you can also do this as:

  <xsl:copy-of select="foo[position() &lt; 5]"/>

or you can use the subsequence() function if you prefer.

Michael Kay

Received on Thursday, 5 June 2003 05:30:50 UTC